Table of Contents
Overview The Wave file format is Windows' native file format for storing digital audio data. It has become one of the most widely supported digital audio file formats on the PC due to the popularity of Windows and the huge number of programs written for the platform. Almost every modern program that can open and/or save digital audio supports this file format, making it both extremely useful and a virtual requirement for software developers to understand. The following specification gives a detailed description of the structure and inner workings of this format. Data Formats Since the Wave file format is native to Windows and therefor Intel processors, all data values are stored in Little-Endian (least significant byte first) order. Strings Wave files may contain strings of text for specifying cue point labels, notes, etc. Strings are stored in a format where the first byte specifies the number of following ASCII text bytes in the string. The following bytes are of course the ASCII character bytes that make up the text string. Pascal programmers will notice that this is the same format used for Pascal strings.
Wave String Format Example
File Structure
Basic Wave File Layout
Chunk ID "RIFF" Chunk Data Size |
RIFF Type ID "WAVE" |
Chunk ID "fmt " Chunk Data Size | Sample Format Info | |
Chunk ID "data" Chunk Data Size | Digital Audio Samples | | |
| Chunk Header |
| Chunk Data Bytes |
| Wave files use the standard RIFF structure which groups the files contents (sample format, digital audio samples, etc.) into separate chunks, each containing it's own header and data bytes. The chunk header specifies the type and size of the chunk data bytes. This organization method allows programs that do not use or recognize particular types of chunks to easily skip over them and continue processing following known chunks. Certain types of chunks may contain sub-chunks. For example, in the diagram to the right, you can see that the "fmt " and "data" chunks are actually sub-chunks of the "RIFF" chunk. One tricky thing about RIFF file chunks is that they must be word aligned. This means that their total size must be a multiple of 2 bytes (ie. 2, 4, 6, 8, and so on). If a chunk contains an odd number of data bytes, causing it not to be word aligned, an extra padding byte with a value of zero must follow the last data byte. This extra padding byte is not counted in the chunk size, therefor a program must always word align a chunk headers size value in order to calculate the offset of the following chunk. Wave File Header - RIFF Type Chunk Wave file headers follow the standard RIFF file format structure. The first 8 bytes in the file is a standard RIFF chunk header which has a chunk ID of "RIFF" and a chunk size equal to the file size minus the 8 bytes used by the header. The first 4 data bytes in the "RIFF" chunk determines the type of resource found in the RIFF chunk. Wave files always use "WAVE". After the RIFF type comes all of the Wave file chunks that define the audio waveform.
Offset | Size | Description | Value | 0x00 | 4 | Chunk ID | "RIFF" (0x52494646) | 0x04 | 4 | Chunk Data Size | (file size) - 8 | 0x08 | 4 | RIFF Type | "WAVE" (0x57415645) | 0x10 |
Wave chunks
|
RIFF Type Chunk Values
|
Wave File Chunks There are quite a few types of chunks defined for Wave files. Many Wave files contain only two of them, specifically the Format Chunk and the Data Chunk. These are the two chunks needed to describe the format of the digital audio samples and the samples themselves. Although it is not required by the official Wave file specification, it is good practice to place the Format Chunk before the Data Chunk. Many programs expect the chunks to be stored in this order and it is more sensible when streaming digital audio from a slow, linear source such as the Internet. If the format were to come after the data, all of the data and then the format would have to be streamed before playback could start correctly. All RIFF Chunks and therefore Wave Chunks are stored in the following format. Notice that even the above mentioned RIFF Type Chunk conforms to this format.
Offset | Size | Description | 0x00 | 4 | Chunk ID | 0x04 | 4 | Chunk Data Size | 0x08 | Chunk Data Bytes |
RIFF Chunk Format
|
The rest of this document goes through the different types of Wave chunks, describing the format of their data bytes and what they mean. You can use the table of contents at the beginning of this document to help find the chunk type you are interested in. Format Chunk - "fmt " The format chunk contains information about how the waveform data is stored and should be played back including the type of compression used, number of channels, sample rate, bits per sample and other attributes.
Offset | Size | Description | Value | 0x00 | 4 | Chunk ID | "fmt " (0x666D7420) | 0x04 | 4 | Chunk Data Size | 16 + extra format bytes | 0x08 | 2 | Compression code | 1 - 65,535 | 0x0a | 2 | Number of channels | 1 - 65,535 | 0x0c | 4 | Sample rate | 1 - 0xFFFFFFFF | 0x10 | 4 | Average bytes per second | 1 - 0xFFFFFFFF | 0x14 | 2 | Block align | 1 - 65,535 | 0x16 | 2 | Significant bits per sample | 2 - 65,535 | |
0x18 | 2 | Extra format bytes | 0 - 65,535 | 0x1a |
Extra format bytes *
| Wave Format Chunk Values, * read following text for details
Chunk ID and Data Size The chunk ID is always "fmt " (0x666D7420) and the size is the size of the standard wave format data (16 bytes) plus the size of any extra format bytes needed for the specific Wave format, if it does not contain uncompressed PCM data. Note the chunk ID string ends with the space character (0x20). Compression Code The first word of format data specifies the type of compression used on the Wave data included in the Wave chunk found in this "RIFF" chunk. The following is a list of the common compression codes used today.
Code | Description | 0 (0x0000) | Unknown | 1 (0x0001) | PCM/uncompressed | 2 (0x0002) | Microsoft ADPCM | 6 (0x0006) | ITU G.711 a-law | 7 (0x0007) | ITU G.711 µ-law | 17 (0x0011) | IMA ADPCM |
<a href='http://www.sonicspot.com/phpadsnew/adclick.php?n=a14ed9fe' target='_blank'><img src='http://www.sonicspot.com/phpadsnew/adview.php?what=<bottom>,_[wavefiles],_728x90,<bottom>,_(wavefiles),_728x90,<bottom>,_(fileformatspecs),_728x90,<bottom>,_(fileformats),_728x90,<bottom>,_(guide),_728x90,<bottom>,_(all),_728x90|<bottom>,_728x90|728x90&n=a14ed9fe' border='0' alt=''></a>
|