C++ Reading the Data part of a WAV file

This image is taken from a Stanford course

WAV File Format

So you can see that the audio data occurs immediately after the headers you already read and there will be Subchunk2Size bytes of audio data.

The pseudocode for this would be

ReadRIFF();
ReadFMT();
int32 chunk2Id = Read32(BigEndian);
int32 chunk2Size = Read32(LittleEndian);
for (int i = 0; i < chunk2Size; i++)
{
    audioData[i] = ReadByte();
}

If the audio is stereo you’ll have two audio streams in data. If the audio is compressed (mp3, aac, etc) you’ll have to decompress it first.

Leave a Comment