Hello, having a weird problem and wondering if someone can help me.. Basically, I'm trying to read in a .wav file, and I have read in the header information and that's all fine, it's just the data..

Here is the code:

bool Wav::readHeader(ifstream &file)
{

    file.read(this->chunkId,                                 4);
    file.read(reinterpret_cast<char*>(&this->chunkSize),     4);
    file.read(this->format,                                  4);

    file.read(this->formatId,                                4);
    file.read(reinterpret_cast<char*>(&this->formatSize),    4);
    file.read(reinterpret_cast<char*>(&this->format2),       2);
    file.read(reinterpret_cast<char*>(&this->numChannels),   2);
    file.read(reinterpret_cast<char*>(&this->sampleRate),    4);
    file.read(reinterpret_cast<char*>(&this->byteRate),      4);
    file.read(reinterpret_cast<char*>(&this->align),         2);
    file.read(reinterpret_cast<char*>(&this->bitsPerSample), 4);

    char testing[4] = {0};
    int testingSize = 0;

    while(file.read(testing, 4) && (testing[0] != 'd' ||
                                    testing[1] != 'a' ||
                                    testing[2] != 't' ||
                                    testing[3] != 'a'))
    {

    file.read(reinterpret_cast<char*>(&testingSize), 4);
    file.seekg(testingSize, std::ios_base::cur);

   }

   this->dataId[0] = testing[0];
   this->dataId[1] = testing[1];
   this->dataId[2] = testing[2];
   this->dataId[3] = testing[3];
   file.read(reinterpret_cast<char*>(&this->dataSize),     4);

   this->data = new char[this->dataSize];

   file.read(data,                     this->dataSize);

   unsigned int *te;

   te = reinterpret_cast<int*>(&this->data);

   cout << te[3];

   return true;
 }

Now if I use the readwav in Matlab I get the result (of the third element, same file): -0.0078 But in the C++ output I get 1031127695

I have heard it's something to do with the fact I'm outputting it as an integer, but I've tried every data type there is.

Any ideas? Thanks :)

It might also depend on which operating system the wav file was originally written with -- such as Big or Little Endian

So, how, I am reading it from memory?

Thank's for your reply

wav files reside on disk, so you read it from disk (don't know what wrote it)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.