Audio File Format Specifications

File Description: WAVE or RIFF WAVE sound file
File Extension: Commonly .wav, sometimes .wave
File Byte Order: Little-endian

Prof. Peter Kabal, MMSP Lab, ECE, McGill University: Last update: 2011-01-03

WAVE Specifications

The WAVE file specifications came from Microsoft. The WAVE file format use RIFF chunks, each chunk consisting of a chunk identifier, chunk length and chunk data.

Data Types

The data in WAVE files can be of many different types. Data format codes are listed in the following:

Wave File Format

Wave files have a master RIFF chunk which includes a WAVE identifier followed by sub-chunks. The data is stored in little-endian byte order.

Field Length Contents
ckID 4 Chunk ID: "RIFF"
cksize 4 Chunk size: 4+n
  WAVEID 4 WAVE ID: "WAVE"
WAVE chunks n Wave chunks containing format information and sampled data

Format Chunk

The Format chunk specifies the format of the data. There are 3 variants of the Format chunk for sampled data. These differ in the extensions to the basic Formant chunk.

Field Length Contents
ckID 4 Chunk ID: "fmt "
cksize 4 Chunk size: 16 or 18 or 40
  wFormatTag 2 Format code
nChannels 2 Number of interleaved channels
nSamplesPerSec 4 Sampling rate (blocks per second)
nAvgBytesPerSec 4 Data rate
nBlockAlign 2 Data block size (bytes)
wBitsPerSample 2 Bits per sample

cbSize 2 Size of the extension (0 or 22)

wValidBitsPerSample 2 Number of valid bits
dwChannelMask 4 Speaker position mask
SubFormat 16 GUID, including the data format code

The standard format codes for waveform data are given below. The references above give many more format codes for compressed data, a good fraction of which are now obsolete.

Format Code PreProcessor Symbol Data
0x0001 WAVE_FORMAT_PCM PCM
0x0003 WAVE_FORMAT_IEEE_FLOAT IEEE float
0x0006 WAVE_FORMAT_ALAW 8-bit ITU-T G.711 A-law
0x0007 WAVE_FORMAT_MULAW 8-bit ITU-T G.711 -law
0xFFFE WAVE_FORMAT_EXTENSIBLE Determined by SubFormat

PCM Format

The first part of the Format chunk is used to describe PCM data.

Non-PCM Formats

An extended Format chunk is used for non-PCM data. The cbSize field gives the size of the extension.

Extensible Format

The WAVE_FORMAT_EXTENSIBLE format code indicates that there is an extension to the Format chunk. The extension has one field which declares the number of "valid" bits/sample (wValidBitsPerSample). Another field (dwChannelMask) contains a bits which indicate the mapping from channels to loudspeaker positions. The last field (SubFormat) is a 16-byte globally unique identifier (GUID).

The WAVE_FORMAT_EXTENSIBLE format should be used whenever:

Fact Chunk

All (compressed) non-PCM formats must have a Fact chunk (Rev. 3 documentation). The chunk contains at least one value, the number of samples in the file.

Field Length Contents
ckID 4 Chunk ID: "fact"
cksize 4 Chunk size: minimum 4
  dwSampleLength 4 Number of samples (per channel)

Data Chunk

The Data chunk contains the sampled data.

Field Length Contents
ckID 4 Chunk ID: "data"
cksize 4 Chunk size: n
  sampled data n Samples
pad byte 0 or 1 Padding byte if n is odd

 

Examples

Consider sampled data with the following parameters,

PCM Data

Field Length Contents
ckID 4 Chunk ID: "RIFF"
cksize 4 Chunk size: 4 + 24 +
(8 + M * Nc * Ns + (0
or 1))
  WAVEID 4 WAVE ID: "WAVE"

ckID 4 Chunk ID: "fmt "
cksize 4 Chunk size: 16
  wFormatTag 2 WAVE_FORMAT_PCM
nChannels 2 Nc
nSamplesPerSec 4 F
nAvgBytesPerSec 4 F * M * Nc
nBlockAlign 2 M * Nc
wBitsPerSample 2 rounds up to 8 * M

ckID 4 Chunk ID: "data"
cksize 4 Chunk size: M * Nc* Ns
  sampled data M * Nc * Ns Nc * Ns channel-interleaved M-byte samples
pad 0 or 1 Padding byte if M * Nc * Ns is odd

Notes

Non-PCM Data

Field Length Contents
ckID 4 Chunk ID: "RIFF"
cksize 4 Chunk size: 4 + 26 + 12 +
(8 + M * Nc * Ns + (0
or 1))
  WAVEID 4 WAVE ID: "WAVE"

ckID 4 Chunk ID: "fmt "
cksize 4 Chunk size: 18
  wFormatTag 2 Format code
nChannels 2 Nc
nSamplesPerSec 4 F
nAvgBytesPerSec 4 F * M * Nc
nBlockAlign 2 M * Nc
wBitsPerSample 2 8 * M (float data) or 16 (log-PCM data)
cbSize 2 Size of the extension:0

ckID 4 Chunk ID: "fact"
cksize 4 Chunk size: 4
  dwSampleLength 4 Nc * Ns

ckID 4 Chunk ID: "data"
cksize 4 Chunk size: M * Nc * Ns
  sampled data M * Nc * Ns Nc * Ns channel-interleaved M-byte samples
pad 0 or 1 Padding byte if M * Nc * Nsis odd

Extensible Format

Field Length Contents
ckID 4 Chunk ID: "RIFF"
cksize 4 Chunk size: 4 + 48 + 12 +
(8 + M * Nc * Ns + (0
or 1))
  WAVEID 4 WAVE ID, "WAVE"

ckID 4 Chunk ID: "fmt "
cksize 4 Chunk size: 40
  wFormatTag 2 WAVE_FORMAT_EXTENSIBLE
nChannels 2 Nc
nSamplesPerSec 4 F
nAvgBytesPerSec 4 F * M * Nc
nBlockAlign 2 M * Nc
wBitsPerSample 2 8 * M
cbSize 2 Size of the extension: 22
wValidBitsPerSample 2 at most 8 * M
dwChannelMask 4 Speaker position mask: 0
SubFormat 16 GUID (first two bytes are the data format code)

ckID 4 Chunk ID: "fact"
cksize 4 Chunk size: 4
  dwSampleLength 4 Nc * Ns

ckID 4 Chunk ID: "data"
cksize 4 Chunk size: M * Nc * Ns
  sampled data M * Nc * Ns Nc * Ns channel-interleaved M-byte samples
pad 0 or 1 Padding byte if M * Nc * Ns is odd

Sample Wave Files