Wave file format

WAV files use the RIFF file structure. The RIFF format was designed for multi-media purposes. A RIFF files consists of a number of "chunks":

OffsetLabelLengthDescription
00hrID4hContains the characters "RIFF"
04hrLen4hThe length of the data in the next chunk
08hrData rLenThe data chunk

The WAVE form chunk
The rData chunk in a WAV file is split up into several further chunks:
of the Data in the Data Chunk
rData byte offsetLabelLengthDescription
00hwID4hContains the characters "WAVE"
04hFormat Chunk14hContains data which specifies the format
18hWAVE Data Chunk-Contains the WAV audio data

The format chunk
The Windows .WAV files are RIFF format files. Some programs expect the fmt block right behind the RIFF header itself, so your programs should write out this block as the first block in the RIFF file. Note the space in the id string

The Format Chunk is split up into these fields:
Format Chunk OffsetLabelLengthDescription
00hfId4Contains the characters "fmt "
04hfLen4Length of data in the format chunk
08hwFormatTag2 The wFormatTag specifies the wave format, eg 1 = Pulse Code Modulation (or in plain english, regular 8 bit sampled uncompressed sound)
0AhnChannels2Number of channels, 1=mono, 2=stereo
0ChnSamplesPerSec2Playback frequency (Sample Rate)
0EhnAvgBytesPerSec2 Indicates the average number of bytes a second the data should be transferred at = nChannels * nSamplesPerSec * (nBitsPerSample / 8)
10hnBlockAlign 2Indicates the block alignment of the data in the data chunk. Software needs to process a multiplt of nBlockAlign at a time. nBlockAlign = nChannels * (nBitsPerSample / 8)
12hFormatSpecific2Format specific data area

The Data chunk
The Data Chunk is split up into these fields:
Data Chunk OffsetLabelLengthDescription
00hdId4Contains the characters "data"
02hdLen4Length of data in the dData field
00hdDatadLenThe actual waveform data

For example, if the file is a mono, 8-bit file, each byte represents one sample. In stereo 8-bit files two bytes are stored for each sample, the first byte is the left channel value, the next is the right channel value.

The loop chunk
Im not sure if this is an official block type but it is used to specify a sample that is repeated.
loop chunk offsetlengthdescription
00h1Start of sample loop
04h1End of sample loop