Friday, 7 November 2008

Structure Of *.wav Audio Files

Wave file structure is very simple. The structure can be divided into 3 parts (chunks).

First chunk: The first 4 bytes should be "RIFF". Then come 4 bytes, which indicate the size of file. Then comes "WAVE".

Second chunk: It starts with "fmt ". Then come 4 bytes showing the length of "fmt " chunk. Then come audio format, number of channels, sample rate, Byterate, Block align and bits ber sample.

Third chunk: It is the audio data itself. As always 4 first bytes - name of the chunk. 4 bytes after that - the length of the chunk in bytes. After that come samples itself. 2 * number_of_channels bytes each sample.

There can be also other chunks between the first and the third, but they are really not widely used. If you got interested in it, a very good article about "Wave file format" is on The Sonic Spot.

So we have here an example. We see the first chunk (purple). It shows the length of the file - 0x(00 00 08 24) = 0x824 = 2084

Bytes should be read in reverse direction. First read byte has the smallest rank!

You can check yourself: left channel sample #5 = 0xE734 and right one is 0xA623.


Continued there...