0%

audio_wav

wav格式介绍:

1 wave格式:
文件描述:WAVE or RIFF WAVE sound
文件扩展名:.wav/.wave
文件字节序:小端
参考文档:http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
wave有几个spec,和几种数据类型;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
wave文件格式:
1)wave头:wave文件有一个主要的RIFF chunk 包含了WAVE标识符,并紧跟着子chunks.数据是小端排序;
Field Length Contents
ckID 4 Chunk ID: RIFF
cksize 4 Chunk size: 4+n
WAVEID 4 WAVE ID: WAVE
WAVE chunks n Wave chunks containing format information and sampled data

2)fmt chunk:fmt 具体化数据的格式,有三种不同的sampled data,它们的不同之处在于对基本fmt块的扩展
Field Length Contents
ckID 4 Chunk ID: fmt
cksize 4 Chunk size: 16, 18 or 40
wFormatTag 2 Format code
nChannels 2 Number of interleaved channels
nSamplesPerSec 4 Sampling rate (blocks per second)
nAvgBytesPerSec 4 Data rate
nBlockAlign 2 Data block size (bytes)
wBitsPerSample 2 Bits per sample
以下四个字段在音频采样数据非PCM,且为扩展的WAVE_FORMAT_EXTENSIBLE才会用到,24B/48B
cbSize 2 Size of the extension (0 or 22)
wValidBitsPerSample 2 Number of valid bits
dwChannelMask 4 Speaker position mask
SubFormat 16 GUID, including the data format code 这里分类型:

wavform数据的标准编码格式有以下几种;上面的参考文献提供了更多的压缩数据格式代码,其中很大一部分现在已经过时了
Format Code PreProcessor Symbol Data
0x0001 WAVE_FORMAT_PCM PCM
0x0003 WAVE_FORMAT_IEEE_FLOAT IEEE float
0x0006 WAVE_FORMAT_ALAW 8-bit ITU-T G.711 A-law
0x0007 WAVE_FORMAT_MULAW 8-bit ITU-T G.711 µ-law
0xFFFE WAVE_FORMAT_EXTENSIBLE Determined by SubFormat
以上几种,若是non-PCM,则需要带一个fact chunk

3) fact chunk non-PCM才需要
4)data chunk 音频数据部分:包含了采样数据:

Field Length Contents
ckID 4 Chunk ID: data
cksize 4 Chunk size: n
sampled data n Samples
pad byte 0 or 1 Padding byte if n is odd

标准给了一个例子:
Examples
Consider sampled data with the following parameters,
Nc channels
The total number of blocks is Ns. Each block consists of Nc samples.
Sampling rate F (blocks per second)
Each sample is M bytes long

PCM Data:
Field Length Contents
ckID 4 Chunk ID: RIFF
cksize 4 Chunk size: 4 + 24 + (8 + M*Nc*Ns + (0 or 1)
WAVEID 4 WAVE ID: WAVE
ckID 4 Chunk ID: fmt
cksize 4 Chunk size: 16
wFormatTag 2 WAVE_FORMAT_PCM
nChannels 2 Nc
nSamplesPerSec 4 F
nAvgBytesPerSec 4 F*M*Nc
nBlockAlign 2 M*Nc
wBitsPerSample 2 rounds up to 8*M
ckID 4 Chunk ID: data
cksize 4 Chunk size: M*Nc*Ns
sampled data M*Nc*Ns Nc*Ns channel-interleaved M-byte samples
pad byte 0 or 1 Padding byte if M*Nc*Ns is odd

更多例子见文档;

二、wav播放器3: