Hello,
I'm trying to read the header information of a .wav file and I'm kind of stuck.
Basically, the header information is located at different offsets in the file. So for example:
(0-4) = ChunkID
(4-8) = ChunkSize
(8-12) = Format
.. ..
.. ..
.. ..
From this: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
Now the problem I'm having is when I try to read the data like this, the data does not store correctly and I end up with missing data. This is the code I have written:
bool Wav::readHeader(FILE *dataIn)
{
// RIFF
int i=0;
fread(this->chunkId, sizeof(char), 4, dataIn);
i += 4;
fread(&this->chunkSize, sizeof(int), 1, dataIn);
fread(this->format, sizeof(char), 4, dataIn);
cout << "RIFF DATA" << endl;
cout << "Chunk ID: " << this->chunkId << endl;
cout << "Chunk Size: " << this->chunkSize << endl;
cout << "Format: " << this->format << endl;
fread(this->formatId, sizeof(char), 4, dataIn);
fread(&this->formatSize, sizeof(int), 4, dataIn);
fread(&this->format2, sizeof(short), 2, dataIn);
fread(&this->numChannels, sizeof(int), 2, dataIn);
fread(&this->sampleRate, sizeof(int), 4, dataIn);
cout << endl << endl;
cout << "FORMAT DATA" << endl;
cout << "Format ID: " << this->formatId << endl;
cout << "Format S: " << this->formatSize << endl;
cout << "Format SS: " << this->format2 << endl;
cout << "Channels: " << this->numChannels << endl;
cout << "Sample Rt: " << this->sampleRate << endl;
return true;
}
Here are the class members/variables:
// Define the class-variables for the Header Information
// riff
char chunkId[4];
int chunkSize;
char format[4];
// …