Ring This... Wave File Format

This is a brief outline of the wav file spec. It isn't comprehensive, but it's enough to get you started writing wav files yourself.

Rent A Coder!

Quick and Dirty WAV layout

This is what is missing as far as documentation I've found. There's a lot of theory and introduction, but when it comes time to implement this bad boy, it's tough to find. So, without further ado, here is the wave header for a general purpose, PCM format WAV file:

Description Size (bytes) - Data Type (Windows) Usual contents
"RIFF" file description header 4 bytes - FOURCC The ascii text string "RIFF". mmsystem.h provides the macro FOURCC_RIFF for this purpose.
size of file 4 bytes - DWORD The file size LESS the size of the "RIFF" description (4 bytes) and the size of file description (4 bytes). This is usually file size - 8.
"WAVE" description header 4 bytes - FOURCC The ascii text string "WAVE". Check out the mmioFOURCC macro in mmsystem.h.
"fmt " description header 4 bytes - FOURCC The ascii text string "fmt " (note the trailing space). Check out the mmioFOURCC macro in mmsystem.h.
size of WAVE section chunck 4 bytes - DWORD The size of the WAVE type format (2 bytes) + mono/stereo flag (2 bytes) + sample rate (4 bytes) + bytes/sec (4 bytes) + block alignment (2 bytes) + bits/sample (2 bytes). This is usually 16 (or 0x10).
WAVE type format 2 bytes - WORD Type of WAVE format. This is a PCM header, or a value of 0x01.
mono/stereo 2 bytes - WORD mono (0x01) or stereo (0x02)
sample rate 4 bytes - DWORD Sample rate.
bytes/sec 4 bytes - DWORD Bytes/Second
Block alignment 2 bytes - WORD Block alignment
Bits/sample 2 bytes - WORD Bits/Sample
"data" description header 4 bytes - FOURCC The ascii text string "data". Check out the mmioFOURCC macro in mmsystem.h.
size of data chunk 4 bytes - DWORD Number of bytes of data is included in the data section.
Data Unspecified data buffer Your data.

Some gotchas

Other WAV resources


The Drinking Games | The Development Site | Resume
webmaster@ringthis.com

Valid HTML 4.01!