|
ADPCM Codecs
|
ADPCM (Adaptive Differential Pulse Code Modulation) is a lossy audio codec with a good compression ratio and very low requirements in terms of memory and cpu for both the decoding and encoding. It is also purely based on integer arithemtic. It has lost it's imporance on the desktop, but it is still one of the best codecs to be used on microcontrollers.
Unfortunately it is not standardized and there are many alternative implementations which are incompatible between each other.
I was looking for a complete ADPCM codec library that is suitable to be used on some microcontrollers and supports the most important implementations.
The best implementation that I could find is provided by FFmpeg but unfortunately FFmpeg itself is unsuited for microcontrollers.
Therefore I decided to extract the implementation and provide it as a stand alone libarary with a simple API and provide the functionality as header-only C++ implementation.
This library can be used directly with cmake or as an Arduino library. However I recommend to use it as Codec with the Arduino Audio Tools.
The API documentation is generated with Doxygen and published to GitHub Pages on every push to main (see doxygen-gh-pages.yml).
The encoders that inherit from ADPCMEncoderTrellis (IMA_WAV, IMA_QT, IMA_AMV, SWF, MS, YAMAHA) support an optional trellis search algorithm. Standard ADPCM encodes each sample greedily, while trellis explores multiple encoding paths simultaneously and picks the one that minimizes total distortion. This produces better audio quality at the cost of more CPU and memory.
Without trellis (the default), encoding is faster but produces slightly more distortion. For real-time encoding on microcontrollers, you would typically leave trellis off. For offline or quality-critical encoding, set it to 2-4.
The following examples are encoding and decoding a sine tone:
You can download the library as zip and call include Library -> zip library. Or you can git clone this project into the Arduino libraries folder e.g. with
I recommend to use git because you can easily update to the latest version just by executing the git pull command in the project folder. If you want to use the library in PlatformIO, you can find a detailed description in the Wiki.
Just add this library to your platformio.ini. You can also activate or deactivate individual encoders and decoders
You can install this library directly from gihub in your CMakeLists.txt