WAV

Introduction

WAV files are probably the simplest of the common formats for storing audio samples. Unlike MPEG and other compressed formats, WAVs store samples "in the raw" where no pre-processing is required other that formatting of the data.


File Structure

The WAV file format is a variant of the RIFF format for data interchange between programs. This format was designed so that data in a file is broken up into self-described, independent "chunks". Each chunk has a prefix which describes the data in that chunk. The prefix is a four-character chunk ID which defines the type of data in the chunk, followed by a 4-byte integer which is the size of the rest of the chunk in bytes. The size does not include the 8 bytes in the prefix. The chunks can be nested. In fact, a RIFF file contains a single chunk of type "RIFF", with other chunks nested inside it. Therefore, the first four bytes of a WAV file are "RIFF", and the four bytes after that contain the size of the whole file minus 8 bytes.

After the RIFF header is the WAV data, consisting of the string "WAVE" and two important chunks: the format header and the audio data itself. There may also be other chunks in a WAV file that contain text comments, copyrights, cue points, list instrument parameters, store application-specific information etc., but they are not needed to play the recorded sound. These chunks are optional.
All applications that use WAVE must be able to read the 2 required chunks and can choose to selectively ignore the optional chunks. A program that copies a WAVE should copy all of the chunks in the WAVE, even those it chooses not to interpret.
There are no restrictions upon the order of the chunks within a WAVE file, with the exception that the Format chunk must precede the Data chunk. Some inflexibly written programs expect the Format chunk as the first chunk (after the RIFF header) although they shouldn't because the specification doesn't require this.
Here is a graphical overview of an example, minimal WAVE file. It consists of a single WAVE containing the 2 required chunks, a Format and a Data Chunk.


Each chunk has a 32-bit Id field, followed by a 32-bit chunk length, followed by the chunk data. Each Chunk breaks down as follows:

RIFF Chunk (12 bytes in length total)

Byte Number
 
0 - 3 "RIFF" (ASCII Characters)
4 - 7 Total Length Of Package To Follow (Binary, little endian)
8 - 11
"WAVE" (ASCII Characters)


FORMAT Chunk (24 bytes in length total)

Byte Number
 
0 - 3 "fmt_" (ASCII Characters)
4 - 7 Length Of FORMAT Chunk (Binary, always 0x10)
8 - 9 Always 0x01
10 - 11 Channel Numbers (Always 0x01=Mono, 0x02=Stereo)
12 - 15 Sample Rate (Binary, in Hz)
16 - 19 Bytes Per Second
20 - 21 Bytes Per Sample: 1=8 bit Mono, 2=8 bit Stereo or 16 bit Mono, 4=16 bit Stereo
22 - 23 Bits Per Sample

DATA Chunk

Byte Number
 
0 - 3 "data" (ASCII Characters)
4 - 7 Length Of Data To Follow
8 - end Data (Samples)

 

[Index] [WAV] [BMP] [Danish Naeem]