WAV文件格式详解
<p class="artical_littlestyle1">1、WAV文件概述</p><p style="text-indent: 2em;">WAV是微软公司开发的一种音频格式文件,用于保存Windows平台的音频信息资源,它符合资源互换文件格式(Resource Interchange File Format,RIFF)文件规范。标准格式化的WAV文件和CD格式一样,也是44.1K的取样频率,16位量化数字,因此在声音文件质量和CD相差无几!<br/></p><p style="text-indent: 2em;">WAV通常用来保存PCM格式的原始音频数据,所以通常被称为无损音频。但是严格意义上来讲,WAV也可以存储其它压缩格式的音频数据。<br/></p><p class="artical_littlestyle2">2、WAV文件格式</p><p style="text-indent: 2em;">WAV符合RIFF文件格式标准,可以看作是RIFF文件的一个具体实例。既然WAV符合RIFF规范,其基本的组成单元也是chunk。一个WAV文件通常有三个chunk以及一个可选chunk,其在文件中的排列方式依次是:RIFF chunk,Format chunk,Fact chunk(附加块,可选),Data chunk。示意图如下:<br/></p><p style="text-align:center"><img src="/uploads/AilsonJack/2020.03.29/1585475798718997.png" onclick="preview_image('/uploads/AilsonJack/2020.03.29/1585475798718997.png')"/></p><p style="text-indent: 2em;">一个WAV文件,首先是一个RIFF chunk,其格式类型为'WAVE'。RIFF chunk包括两个子chunk,ID分别为 'fmt '和'data',还有一个可选的Fact chunk。Format chunk用于表示音频数据的属性,包括编码方式、声道数目、采样频率、每个采样需要的bit数等等信息。Fact chunk是一个可选chunk,一般当WAVE文件由某些软件转化而成就包含Fact chunk。Data chunk包含WAVE文件的数字化波形声音数据。 WAVE整体结构如下图所示:</p><p style="text-align:center"><img src="/uploads/AilsonJack/2020.03.29/1585475798873094.png" onclick="preview_image('/uploads/AilsonJack/2020.03.29/1585475798873094.png')"/></p><p style="text-indent: 2em;">接下来讲讲各个chunk的具体内容。<br/></p><p class="artical_littlestyle3">3、各个chunk的具体内容</p><p style="text-indent: 0em;">(1).RIFF chunk<br/></p><p style="text-indent: 2em;">ID:4字节,值为"RIFF"。<br/></p><p style="text-indent: 2em;">Size:4字节,ChunkData字段中数据的大小,单位:字节。</p><p style="text-indent: 2em;">ChunkData:包含FormType和其他chunk的内容。<br/> FormType:4字节,值为"WAVE"。<br/> Data:其他chunk的内容。<br/>(2).Format chunk</p><p style="text-indent: 2em;">ID:4字节,值为"fmt ",最后一个字符是空格。</p><p style="text-indent: 2em;">Size:4字节,数据字段(Data)包含的数据大小。如无扩展块,则值为16;有扩展块,则值为= 16 + 2字节扩展块长度 + 扩展块内容,或者值为18(只有扩展块长度为2字节,并且扩展块长度值为0),单位:字节。</p><p style="text-indent: 2em;">Data:存放音频格式、声道数、采样率等信息。<br/> audio_format:2字节,表示音频数据的格式。如值为1,表示使用PCM格式。<br/> channels:2字节,声道数。值为1则为单声道,为2则是双声道。<br/> sample_rate:4字节,采样频率,主要有22.05KHz,44.1kHz和48KHz等,例如0xAC44表示44100Hz。<br/> bytes_per_sec:4字节,音频的码率,每秒播放的字节数。其值为:声道数 * 采样频率 * 量化位数 / 8,可以估算出使用缓冲区的大小。<br/> block_align:2字节,每个采样点所需的字节数,其值为:声道数 * 量化位数 / 8。<br/> bits_per_sample:2字节,量化位数,有16位,24位和32位等。<br/> cbSize:2字节,扩展块的长度,其值可以为0或者22。<br/> cbContent:0字节或22字节,扩展块内容,具体介绍在下文提及。<span style="color: rgb(255, 0, 0);"><br/></span></p><p style="text-indent: 2em;"><span style="color: rgb(255, 0, 0);">备注:</span>这个区域只需要关心channels,sample_rate,bits_per_sample三个参数就可以了,其它的都是依据这三个计算出来的。<br/>(3).Fact chunk(可选)<br/></p><p style="text-indent: 2em;">fact chunk为可选的,在大多数的WAV文件中是不存在的。采用压缩编码的WAV文件,必须要有Fact chunk,该块中只有一个数据,为每个声道的采样总数。<br/>ID:4字节,值为"fact"。<br/>Size:4字节,数据字段的长度,其值最小为4。<br/>Data:采样总数。<br/>(4).Data chunk<br/>ID:4字节,值为"data"。<br/>Size:4字节,音频数据的长度。<br/>Data:具体的音频数据内容存放在这里。<br/></p><p class="artical_littlestyle4">4、Format chunk中的音频数据格式</p><p style="text-indent: 2em;">在format chunk中,有一个字段audio_format,该字段表示音频数据是以何种方式进行编码存放的。其可选的取值有:<br/>0x0001:WAVE_FORMAT_PCM,采用PCM格式,此时WAV文件中不包含Fact chunk。<br/>0x0002:WAVE_FORMAT_ADPCM,此时WAV文件中包含Fact chunk。<br/>0x0006:WAVE_FORMAT_ALAW,此时WAV文件中包含Fact chunk。<br/>0x0007:WAVE_FORMAT_MULAW,此时WAV文件中包含Fact chunk。<br/>0xFFFE:WAVE_FORMAT_EXTENSIBLE,具体的编码方式由Format chunk中扩展块的sub_format字段决定。<br/></p><p style="text-indent: 2em;"><span style="color: rgb(255, 0, 0);">备注:</span>一般情况下,我们遇到的WAV文件的音频数据编码格式是PCM,介绍上述内容,只是让大家多了解下其他的编码格式的值与名称,当遇到这类编码时,能够知道其名称,从而方便查询相关资料。<br/></p><p class="artical_littlestyle1">5、Format chunk中的扩展块</p><p style="text-indent: 2em;">当WAV文件使用的不是PCM编码方式时,就需要扩展格式块,它是在基本的Format chunk中又添加一段数据。该数据的前两个字节,表示的是扩展块的长度。紧接其后的是扩展块的数据区,含有扩展的格式信息,其具体的长度取决于压缩编码的类型。当某种编码方式的扩展块的数据区长度为0,此时扩展块只包含了扩展块长度字段,扩展块的长度字段还必须保留,只是其值设置为0。<br/>扩展块的各个字节的含义如下:<br/></p><p style="text-indent: 2em;">cbSize:2字节,扩展块的长度,其值可以为0或者22。<br/></p><p style="text-indent: 2em;">cbContent:0字节或22字节,扩展块内容。<br/> valid_bits_per_sample:2字节,有效的采样位数,最大值为block_align * 8。可以使用更灵活的量化位数,通常音频sample的量化位数为8的倍数,但是使用了WAVE_FORMAT_EXTENSIBLE时,量化的位数由扩展块中的valid_bits_per_sample来描述,可以小于Format chunk中指定的bits_per_sample。<br/> channle_mask:4字节,声道掩码。<br/> sub_format:16字节,数据格式码。</p><p style="text-indent: 0em;">在Format chunk中的audio_format设置为0xFFFE时,表示使用扩展区中的sub_format来决定音频的数据的编码方式。在以下几种情况下必须要使用WAVE_FORMAT_EXTENSIBLE:<br/></p><p style="text-indent: 2em;">PCM数据的量化位数大于16。<br/></p><p style="text-indent: 2em;">音频的采样声道大于2。<br/></p><p style="text-indent: 2em;">实际的量化位数不是8的倍数。<br/></p><p style="text-indent: 2em;">存储顺序和播放顺序不一致,需要指定从声道顺序到声卡播放顺序的映射情况。<br/></p><p style="text-indent: 2em;"><span style="color: rgb(255, 0, 0);">备注:</span>一般情况下,我们遇到的WAV文件中是不含有扩展块的。<br/></p><p class="artical_littlestyle2">6、声音数据格式</p><p style="text-indent: 2em;">Data chunk中的Data块中存放的是音频的采样数据。每个sample按照采样的时间顺序写入,对于使用多个字节的sample,使用小端模式存放(低位字节存放在低地址,高位字节存放在高地址)。对于多声道的sample采用交叉存放的方式。例如:立体双声道的sample存储顺序为:声道1的第一个sample,声道2的第一个sample;声道1的第二个sample,声道2的第二个sample;依次类推....。<br/></p><p style="text-indent: 2em;">对于Data chunk中的Data字段,也就是音频数据内容的存储,根据声道数和采样位数的不同情况,布局如下(每1列代表8 bits):<br/></p><p style="text-align:left"><strong><span style="font-size:19px;font-family:'Calibri',sans-serif">1.8 bit </span></strong><strong><span style="font-size:19px;font-family:宋体">单声道</span></strong></p><table><tbody><tr class="firstRow"><td style="border: 1px solid rgb(163, 163, 163); padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="57" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="57" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td></tr></tbody></table><p style="text-align:left"><strong><span style="font-size:19px;font-family:'Calibri',sans-serif">2.8 bit </span></strong><strong><span style="font-size:19px;font-family:宋体">双声道</span></strong></p><table><tbody><tr class="firstRow"><td style="border: 1px solid rgb(163, 163, 163); padding: 5px;" width="101" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="101" valign="top"><br/></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="101" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="74" valign="top"><br/></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="103" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="103" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="103" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="95" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td></tr></tbody></table><p style="text-align:left"><strong><span style="font-size:19px;font-family:宋体">3.16bit 单声道</span></strong></p><table><tbody><tr class="firstRow"><td style="border: 1px solid rgb(163, 163, 163); padding: 5px;" width="104" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="104" valign="top"><br/></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="104" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="77" valign="top"><br/></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="106" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">低字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="106" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">高字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="106" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">低字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="98" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">高字节</span></p></td></tr></tbody></table><p style="text-align:left"><strong><span style="font-size:19px;font-family:宋体">4.16bit 双声道</span></strong></p><table><tbody><tr class="firstRow"><td style="border: 1px solid rgb(163, 163, 163); padding: 5px;" width="149" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="149" valign="top"><br/></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="149" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="122" valign="top"><br/></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="151" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">低字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="151" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">高字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="151" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">低字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="143" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">高字节</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="149" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="149" valign="top"><br/></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="149" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">采样</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="122" valign="top"><br/></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="151" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">低字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="151" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">1</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">高字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="151" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">低字节</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="143" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">数据</span><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span><span style="font-size:16px;font-family:宋体">高字节</span></p></td></tr></tbody></table><p class="artical_littlestyle3">7、WAV文件实例分析</p><p style="text-indent: 2em;">利用winhex工具软件可以非常方便的以十六进制查看文件,下图是我用winhex软件打开一个WAV音频文件时的部分界面截图:<br/></p><p style="text-align:center"><img src="/uploads/AilsonJack/2020.03.29/1585475798376803.png" onclick="preview_image('/uploads/AilsonJack/2020.03.29/1585475798376803.png')"/></p><p style="text-align:left"><span style="font-size:16px;font-family:宋体">下表对文件格式进行解读:</span></p><table><tbody><tr class="firstRow"><td style="border: 1px solid rgb(163, 163, 163); padding: 5px;" width="87" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">偏移地址</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="66" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">字节数</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="102" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">16</span><span style="font-size:16px;font-family:宋体">进制源码</span></p></td><td style="border-color: rgb(163, 163, 163) rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: solid solid solid none; border-width: 1px 1px 1px medium; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="209" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">内容</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">00H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">52 49 46 46</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="214" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">'RIFF'</span><span style="font-size:16px;font-family:宋体">标识符</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">04H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">F4 FE 83 01</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="235" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">数据长度</span><span style="font-size:16px;font-family:'Calibri',sans-serif">:0x0183FEF4(</span><span style="font-size:16px;font-family:宋体">注意顺序</span><span style="font-size:16px;font-family:'Calibri',sans-serif">)</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">08H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">57 41 56 45</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="214" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">'WAVE'</span><span style="font-size:16px;font-family:宋体">标识符</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">0CH</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">66 6D 74 20</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="214" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">'fmt ',</span><span style="font-size:16px;font-family:宋体">最后一位为空格</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">10H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">10 00 00 00</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="225" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">For</span><span style="font-size:16px;font-family:宋体">mat chunk</span><span style="font-size:16px;font-family:宋体">大小:0x10</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">14H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">01 00</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="214" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">编码格式:</span><span style="font-size:16px;font-family:'Calibri',sans-serif">0x01</span><span style="font-size:16px;font-family:宋体">为</span><span style="font-size:16px;font-family:'Calibri',sans-serif">PCM</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">16H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">02 00</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="225" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">声道数目:</span><span style="font-size:16px;font-family:'Calibri',sans-serif">0x02</span><span style="font-size:16px;font-family:宋体">为双声道</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">18H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">44 AC 00 00</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="233" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">采样频率:</span><span style="font-size:16px;font-family:'Calibri',sans-serif">0xAC44</span><span style="font-size:16px;font-family:宋体">表示</span><span style="font-size:16px;font-family:'Calibri',sans-serif">44100Hz</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">1CH</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">10 B1 02 00</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="214" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">每秒字节数:</span><span style="font-size:16px;font-family:'Calibri',sans-serif">0x02B110</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">20H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">04 00</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="235" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">每个采样点所需的字节数:</span><span style="font-size:16px;font-family: 'Calibri',sans-serif">0x04</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">22H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">2</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">10 00</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="214" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">量化位数:</span><span style="font-size:16px;font-family:'Calibri',sans-serif">0x10</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">24H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">64 61 74 61</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="214" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">'data'</span><span style="font-size:16px;font-family:宋体">标识符</span></p></td></tr><tr><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163); border-style: none solid solid; border-width: medium 1px 1px; border-image: none 100% / 1 / 0 stretch; padding: 5px;" width="85" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">28H</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px;" width="64" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">4</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px; word-break: break-all;" width="100" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:'Calibri',sans-serif">48 FE 83 01</span></p></td><td style="border-color: currentcolor rgb(163, 163, 163) rgb(163, 163, 163) currentcolor; border-style: none solid solid none; border-width: medium 1px 1px medium; padding: 5px; word-break: break-all;" width="225" valign="top"><p style="text-align:left"><span style="font-size:16px;font-family:宋体">音频数据的长度:</span><span style="font-size:16px;font-family: 'Calibri',sans-serif">0x0183FE48</span></p></td></tr></tbody></table><p style="text-align:left"><span style="font-size:16px;font-family:宋体;color:white">从偏</span><span style="font-size:16px;font-family:'Calibri',sans-serif"></span></p><p style="text-indent: 2em;">2CH开始就是音频数据了。<br/></p><p style="text-indent: 2em;">如果觉得文章写的不错,对你有帮助,欢迎点赞,关注博主哟!</p>
你可能也喜欢:
暂无评论,要不要来个沙发
发表评论
JLink V9掉固件修复(灯不亮) 3Zephyr笔记2 - 在STM32F429上运行HelloWorld 2计算NandFlash要传入的行地址和列地址 1Linux MMC子系统 - 6.eMMC 5.1工作模式-设备识别模式 0Linux MMC子系统 - 5.eMMC 5.1工作模式-引导模式 0Linux MMC子系统 - 4.eMMC 5.1常用命令说明(2) 0
标签云
Linux嵌入式实用技巧ARM内核学习问题集合CC++编程语言阅读笔记汇编Linux内核完全注释Windows驱动开发计算机基础ARM11ARMv7-ASTM32IDESublimeLinux内核学习eMMCMMC子系统Ubuntu操作系统OfficeVMWareAPUEgccRTOS中断漫游世界随笔感悟开发工具软件应用编程VsCodearmccarmclang编译器ZephyrSPIJLink网卡驱动安装各种芯片库函数NFSμCOS内核sambaFlashUnix命令与脚本输入法Linux内核设计与实现gitRIFFWAVJATGFTPar8161安装centos有线上网μCGUI字库工程建立右键菜单网络文件系统Firefox百度NTFS文件系统CodeBlocksCentOS数据结构算法PhotoShop51KeilQTUltraEditscanfglibc宏定义UIDGID优先级娱乐天地SourceInsight磁盘扇区总线I2CPDFBComparePythonI2SFPUMakefileSWDCPUARP软件推荐FileZilla