WAV Format
Format type | Sound |
---|---|
Hardware | PCM |
Number of sounds | 1 |
Sampling rate | Any |
Channel count | Any |
Bits per sample | 8,16,24,32 |
Compressed? | No |
Tags? | Name |
Games |
The WAVE File Format is a file format for storing digital audio (waveform) data. It supports a variety of bit resolutions, sample rates and channels. The format is a subset of Resource Interchange File Format (RIFF) created by Microsoft, which itself inspired by the Interchange File Format (IFF).
Data in the WAVE format is stored in chunks. Each chunk begins with a 4 character chunkId which is often a recognizable ASCII sequence, and is followed by a 32-bit chunk length, and then the payload for that chunk.
General Layout
In general there is no restriction on the order of chunks in a WAVE file, except that the format chunk must precede the data chunk.
The minimum layout would be
Type | Name | Description |
---|---|---|
FOURCC | riffID | RIFF. |
UINT32LE | fileLength | Length of the file (less the 8 bytes for the RIFF header and length). |
FOURCC | formID | WAVE identifies this as a WAVE file. |
FOURCC | chunkID | Type of chunk. |
UINT32LE | chunkLength | Length of the chunk (less the 8 bytes for the chunkID and length). |
... | etc | More chunks until the file is complete. |
Format Chunk
The format chunk describes way that the sample data is organised in the WAVE file.
Type | Name | Description |
---|---|---|
FOURCC | chunkID | 'fmt '. |
UINT32LE | chunkLength | Length of the chunk. |
INT16LE | formatTag | Indication of any compression. If 1 there is no compression. If compression is used, there may be additional fields in the chunk. |
UINT16LE | channels | Number of channels in the file. |
UINT32LE | samplesPerSec | Sample rate in Hz. |
UINT32LE | avgBytesPerSec | Average bytes per second. (Useful for calculating appropriate buffer sizes). |
UINT16LE | blockAlign | should equal channels * ((bitsPerSample / 8) rounded up) |
UINT16LE | bitsPerSample | number of bits per sample. |
Data Chunk
The data chunk contains the sample data.
PCM data with a resolution greater than 8 bits per sample is represented in twos-complement form. i.e 16-bit sample data ranges from -32768 to +32767, the zero-crossing point is at 0.
If the resolution is 8 bits or less, then the data is represented within an unsigned byte. The full dynamic range is from 0 to 255 and the zero-crossing point is at 128.
If the number of bits per channel is not divisible by 8, the sample is left justified within the binary field. i.e. only the most significant bits are used; the unused least significant bits should be zeroed.
If the number of bits per channel is more than 8, the data is stored in a little-endian fashion.
If the number of channels is more than 1, then the channels are interleaved. The first sample is stored for each of the channels, then the second sample for each of the channels etc.
There are some standard channel orders.
stereo: Left, Right
3 channel: Left, Right, Center
4 channel: Left, Center, Right, Surround
Quad: Front Left, Front Right, Rear Left, Rear Right
6 channel: Left Center, Left, Center, Right Center, Right, Surround
Type | Name | Description |
---|---|---|
FOURCC | chunkID | 'data'. |
UINT32LE | chunkLength | Length of the chunk. |
UINT8[chunkLength] | waveFormData | Sample data packed as described above |
UINT8 | paddingByte | May or may not be present. The length of data should be an even number of bytes. A single padding byte may be needed. |
Other Chunks
Other optional chunks may appear in the file.
FourCC | Name | Description |
---|---|---|
'cue ' | Cue | Cue points |
'plst' | Playlist | The playlist specifies an order for a series of cue points. It can indicate looping sections. |
'LIST' | IFF List | An IFF List embedded in the file. Most often for an adtl. |
'adtl' | Associated Data List | A list of data associated with the cue points |
'smpl' | Sampler | Basic parameters that a sampler could use to play the waveform e.g. information about looping for a sustain effect |
Credits
This file format was documented by Val Mushinskiy. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)