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