Wav 文件的四个组成部分:
RIFF WAVE Chunk | ID = 'RIFF' | RiffType= 'WAVE' |
|
Format Chunk | ID = 'fmt ' |
| |
Fact Chunk (optional) | ID = 'fact' |
| |
Data Chunk | ID ='data' |
|
其中RIFF WAVE Chunk:
名称 | 长度 | 内容 |
ID | 4 Bytes | 'RIFF' |
Size | 4 Bytes | FileLen-8,整个文件大小-8 |
Type | 4 Bytes | 'WAVE' |
struct RIFF_HEADER
{
char szRiffID[4]; // 'R','I','F','F'
DWORD dwRiffSize;
char szRiffFormat[4]; // 'W','A','V','E'
};
其中Format Chunk:
名称 | 长度 | 内容 |
|
ID | 4 Bytes | 'fmt ' |
|
Size | 4 Bytes | 18/16 (有无附加信息) | 本结构大小(除ID,Size) |
FormatTag | 2 Bytes | 通常0x0001 | 编码方式 |
Channels | 2 Bytes | 1--单声道;2--双声道立体声 | 声道数目 |
SamplesPerSec | 4 Bytes |
| 采样频率 |
AvgBytesPerSec | 4 Bytes |
| 每秒所需字节数 |
BlockAlign | 2 Bytes | 数据块对齐单位 |
|
BitsPerSample | 2 Bytes |
| 每个采样需要的位bit数 |
附加信息 | 2 Bytes | (可选,通过Size来判断有无) | 附加信息 |
结构定义如下:
struct WAVE_FORMAT
{
WORD wFormatTag;
WORD wChannels;
DWORD dwSamplesPerSec;
DWORD dwAvgBytesPerSec;
WORD wBlockAlign;
WORD wBitsPerSample;
};
struct FMT_BLOCK
{
char szFmtID[4]; // 'f','m','t',' '
DWORD dwFmtSize;
WAVE_FORMAT wavFormat;
};
其中 Fact Chunk (optional) :(可选)
|
|
|
ID | 4 Bytes | 'fact' |
Size | 4 Bytes | 数值为4 |
data | 4 Bytes |
|
struct FACT_BLOCK
{
char szFactID[4]; // 'f','a','c','t'
DWORD dwFactSize;
};
其中Data Chunk:
|
|
|
ID | 4 Bytes | 'data' |
Size | 4 Bytes | 数据区大小 |
data | 4 Bytes | 数据区,真正存储数据的地方 |
Data Chunk头结构定义如下:
struct DATA_BLOCK
{
char szDataID[4]; // 'd','a','t','a'
DWORD dwDataSize;
};