"Wave File Format"

<a href='http://www.sonicspot.com/phpadsnew/adclick.php?n=a14ed9fe' target='_blank'><img src='http://www.sonicspot.com/phpadsnew/adview.php?what=<button>,_[wavefiles],_120x60,<button>,_(wavefiles),_120x60,<button>,_(fileformatspecs),_120x60,<button>,_(fileformats),_120x60,<button>,_(guide),_120x60,<button>,_(all),_120x60|<button>,_120x60|120x60&n=a14ed9fe' border='0' alt=''></a>
<a href='http://www.sonicspot.com/phpadsnew/adclick.php?n=a14ed9fe' target='_blank'><img src='http://www.sonicspot.com/phpadsnew/adview.php?what=<top>,_[wavefiles],_728x90,<top>,_(wavefiles),_728x90,<top>,_(fileformatspecs),_728x90,<top>,_(fileformats),_728x90,<top>,_(guide),_728x90,<top>,_(all),_728x90|<top>,_728x90|728x90&n=a14ed9fe' border='0' alt=''></a>

"Wave File Format"

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.

7'e''x''a''m''p''l''e'
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.

OffsetSizeDescriptionValue
0x004Chunk ID"RIFF" (0x52494646)
0x044Chunk Data Size(file size) - 8
0x084RIFF 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.

OffsetSizeDescription
0x004Chunk ID
0x044Chunk Data Size
0x08Chunk 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.

OffsetSizeDescriptionValue
0x004Chunk ID"fmt " (0x666D7420)
0x044Chunk Data Size16 + extra format bytes
0x082Compression code1 - 65,535
0x0a2Number of channels1 - 65,535
0x0c4Sample rate1 - 0xFFFFFFFF
0x104Average bytes per second1 - 0xFFFFFFFF
0x142Block align1 - 65,535
0x162Significant bits per sample2 - 65,535
0x182Extra format bytes0 - 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.

Related

CodeDescription
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

Links: Streaming Wave Files with DirectSound

 
<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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值