|
WAV (WAVE) File Format
WAV audio file format is a Microsoft and IBM audio file format standard for storing audio on PC.
It's a variant of the Resource Interchange File Format (RIFF). This file format is generic meta-format for storing data in tagged chunks. It is clone of older Audio Interchange File Format (AIFF) used on Macintosh computers. The only difference is how write/read multi-byte integers, in little-endian format or in big-endian format.
RIFF RIFF files consist of a simple header followed by "chunks". Header:
- 4 bytes - the ASCII identifier "RIFF"
- 4 bytes - an unsigned 32-bit integer with the size of overall file (except 8 bytes)
- 4 bytes - an ASCII identifier for this particular file type (such as "WAVE")
Chunk:
- 4 bytes - an ASCII identifier for this chunk ("fmt " or "data")
- 4 bytes - an unsigned 32-bit integer with the size of this chunk (expect 8 bytes)
- Variable-sized field, the size given in the previous field
- A pad byte, if the chunk's size is not even
WAVE The WAVE format is a subset of RIFF specification. A WAVE file is often just a RIFF file with "WAVE" chunk which consists of two sub-chunk:
- "fmt " chunk - specifying the data format
- "data" chunk - containing the actual sample data.
"fmt " sub-chunk This chunk contains information about how the wave data is stored and should be played back including the type of compression used, number of channels, sample rate, etc. - 4 bytes - ChunkID. ChunkID is always "fmt "
- 4 bytes - ChunkDataSize. This is the size the rest of the "fmt " sub-chunk
- 2 bytes - CompressionCode. It specifies the type of compression used on the wave data. A value of 1 means there is no compression (Pulse Code Modulation (PCM) code)
- 2 bytes - NumberOfChannels. The number of channels specifies how many separate audio signals that are encoded in the wave "data" chunk. A value of 1 means a mono signal, a value of 2 means a stereo signal, etc.
- 4 bytes - SampleRate. The number of sample slices per second (44100, 48000, 96000, ...)
- 4 bytes - AverageBytesPerSecond. This value indicates how many bytes of wave data must be streamed to a D/A converter per second in order to play the wave file. This value can be easily calculated with the formula: AverageBytesPerSecond = BlockAlign * SampleRate
- 2 bytes - BlockAlign. The number of bytes per sample slice including all channels. This value can be calculated by the formula: BlockAlign = SignificantBitsPerSample * NumberOfChannels/8
- 2 bytes - SignificantBitsPerSample. This value specifies the number of bits used to define each sample. (Usually 8, 16, 24, 32 bits)
- 2 bytes - ExtraFormatBytes. It doesn't exist if the CompressionCode is 1 (uncompressed PCM file)
"data" sub-chunk The "data" sub-chunk contains the size of the data and the actual sound data.
- 4 bytes - ChunkID. ChunkID is always "data"
- 4 bytes - ChunkDataSize. This is the number of bytes in the data. If CompressionCode=1 (PCM), this value can be calculated by the formula: ChunkDataSize = NumberOfSamples * BlockAlign
- Data. The actual sound data. If NumberOfChannels =1, and SignificantBitsPerSample=16 you have:
- sample0_for_channel1 (2 bytes)
- sample1_for_channel1 (2 bytes), etc.
In case when NumberOfChannels =2, you have:
- sample0_for_channel1 (2 bytes)
- sample0_for_channel2 (2 bytes)
- sample1_for_channel1 (2 bytes)
- sample1_for_channel2 (2 bytes), etc.
Wav File Format - References: |