因为种种原因,最近需要把原始的wav文件压缩成ADPCM格式。但是网上几乎搜不到相关的中文资料。花了相当长的时间,七拼八凑的从一些文章中得到了些信息,终于搞定了它。为了方便遇到跟我一样麻烦的人,我决定把它详细的写下来。
ADPCM分为Microsoft ADPCM和IMA ADPCM两种数据格式,如果应用到STM32中,建议大家使用IMA
ADPCM格式来编码和解码,这种格式方便C语言编程,算法工作量比较小。Microsoft
ADPCM解码算法用STM32容易实现,但是编码算法需要耗费的系统资源比较大,影响实时语音数据的传输。
首先要了解PCM文件格式,一般默认存储为*.wav。
http://s10/mw690/56e19aa7gx6BNh9JXBfb9&690ADPCM与PCM格式之间的相互转换(VB.NET ADPCM编解码)" TITLE="IMA ADPCM与PCM格式之间的相互转换(VB.NET ADPCM编解码)" />
Offset Size
Name
Description
The canonical WAVE format starts with the RIFF header:
0
4
ChunkID
Contains the letters "RIFF" in ASCII form
(0x52494646 big-endian form).
4
4
ChunkSize
36 + SubChunk2Size, or more precisely:
4 + (8 + SubChunk1Size) + (8 + SubChunk2Size)
This is the size of the rest of the chunk
following this number. This is the size of
the
entire file in bytes minus 8 bytes for the
two fields not included in this count:
ChunkID and ChunkSize.