本文共 4087 字,大约阅读时间需要 13 分钟。
https://msdn.microsoft.com/en-us/library/ms713498.aspx
https://msdn.microsoft.com/en-us/library/ms713497.aspx
typedef struct { WORD wFormatTag; WORD nChannels; DWORD nSamplesPerSec; DWORD nAvgBytesPerSec; WORD nBlockAlign; WORD wBitsPerSample; WORD cbSize; } WAVEFORMATEX;
Members
wFormatTag
1)在 Mmreg.h 查看完整tag信息. For one- or two-channel PCM data, this value should be WAVE_FORMAT_PCM.
2)When this structure is included in a WAVEFORMATEXTENSIBLE structure, this value must be WAVE_FORMAT_EXTENSIBLE.
nChannels
Monaural data uses one channel and stereo data uses two channels.
nSamplesPerSec (一个channel)
Sample rate, in samples per second (hertz). If wFormatTag is WAVE_FORMAT_PCM, then common values for nSamplesPerSec are 8.0 kHz, 11.025 kHz, 22.05 kHz, and 44.1 kHz.
nAvgBytesPerSec (所有channel)
Required average data-transfer rate, in bytes per second, for the format tag.
If wFormatTag is WAVE_FORMAT_PCM,nAvgBytesPerSec = nSamplesPerSec * nBlockAlign.
For example, 16-bit stereo at 44.1 kHz has an average data rate of 176,400 bytes per second (2 channels — 2 bytes per sample per channel — 44,100 samples per second).
nBlockAlign (所有channel)
Block alignment, in bytes. The block alignment is the minimum atomic unit of data for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM or WAVE_FORMAT_EXTENSIBLE, nBlockAlign must be equal to the product of nChannels and wBitsPerSampledivided by 8 (bits per byte).
Software must process a multiple of nBlockAlign bytes of data at a time. Data written to and read from a device must always start at the beginning of a block. For example, it is illegal to start playback of PCM data in the middle of a sample (that is, on a non-block-aligned boundary).
For PCM data, the block alignment is the number of bytes used by a single sample, including data for both channels if the data is stereo. For example, the block alignment for 16-bit stereo PCM is 4 bytes (2 channels — 2 bytes per sample).
wBitsPerSample(一个channel)
Bits per sample for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM, then wBitsPerSample should be equal to 8 or 16.
For non-PCM formats, this member must be set according to the manufacturer's specification of the format tag. If wFormatTagis WAVE_FORMAT_EXTENSIBLE, this value can be any integer multiple of 8 and represents the container size, not necessarily the sample size; for example, a 20-bit sample size is in a 24-bit container. Some compression schemes cannot define a value forwBitsPerSample, so this member can be 0.
一般情况下,一帧PCM是由2048次采样组成的
下面我们具体地分析 WAVE 文件的格式
endian | field name | Size | |
big | ChunkID | 4 | 文件头标识,一般就是" RIFF" 四个字母 |
little | ChunkSize | 4 | 整个数据文件的大小,不包括上面ID和Size本身 |
big | Format | 4 | 一般就是" WAVE" 四个字母 |
big | SubChunk1ID | 4 | 格式说明块,本字段一般就是"fmt " |
little | SubChunk1Size | 4 | 本数据块的大小,不包括ID和Size字段本身 |
little | AudioFormat | 2 | 音频的格式说明 |
little | NumChannels | 2 | 声道数 |
little | SampleRate | 4 | 采样率 |
little | ByteRate | 4 | 比特率,每秒所需要的字节数 |
little | BlockAlign | 2 | 数据块对齐单元 |
little | BitsPerSample | 2 | 采样时模数转换的分辨率 |
big | SubChunk2ID | 4 | 真正的声音数据块,本字段一般是"data" |
little | SubChunk2Size | 4 | 本数据块的大小,不包括ID和Size字段本身 |
little | Data | N | 音频的采样数据 |
以下是对各个字段的详细解说:
ChunkID | 4bytes | ASCII 码表示的“RIFF”。(0x52494646) |
ChunkSize | 4bytes | 36+SubChunk2Size,或是 4 + ( 8 + SubChunk1Size ) + ( 8 + SubChunk2Size ), 这是整个数据块的大小(不包括ChunkID和ChunkSize的大小)。 即所有长度减8 |
Format | 4bytes | ASCII 码表示的“WAVE”。(0x57415645) |
SubChunk1ID | 新的数据块(格式信息说明块) ASCII 码表示的“fmt ”——最后是一个空格。(0x666d7420) | |
SubChunk1Size | 4bytes | 本块数据的大小(对于PCM,值为16)。 |
AudioFormat | 2bytes | PCM = 1 (比如,线性采样),如果是其它值的话,则可能是一些压缩形式 |
NumChannels | 2bytes | 1 => 单声道 | 2 => 双声道 |
SampleRate | 4bytes | 采样率,如 8000,44100 等值 |
ByteRate | 4bytes | 等于: SampleRate * numChannels * BitsPerSample / 8 |
BlockAlign | 2bytes | 等于:NumChannels * BitsPerSample / 8 |
BitsPerSample | 2bytes | 采样分辨率,也就是每个样本用几位来表示,一般是 8bits 或是 16bits |
SubChunk2ID | 4bytes | 新数据块,真正的声音数据 ASCII 码表示的“data ”——最后是一个空格。(0x64617461) |
SubChunk2Size | 4bytes | 数据大小,即,其后跟着的采样数据的大小。 |
Data | N bytes | 真正的声音数据 |
http://www.digitalpreservation.gov/formats/fdd/fdd000001.shtml
http://www.moon-soft.com/program/FORMAT/windows/wavec.htm
introduction_to_digital_audio_coding_and_standards.pdf