ADPCM Codecs
Loading...
Searching...
No Matches
ADPCM Audio Codec Library

Arduino Library Zephyr Library IDF Component CMake License: GPL v3

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.

Usage

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.

Class Documentation

The API documentation is generated with Doxygen and published to GitHub Pages on every push to main (see doxygen-gh-pages.yml).

Trellis Encoding

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.

#include "ADPCM.h"
EncoderADPCM_IMA_WAV encoder;
encoder.setTrellis(true); // enables with value 1 (2 candidates)

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.

Examples

The following examples are encoding and decoding a sine tone:

Installation

Arduino

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

cd ~/Documents/Arduino/libraries
git clone https://github.com/pschatzmann/codec-adpcm

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.

PlatformIO

Just add this library to your platformio.ini. You can also activate or deactivate individual encoders and decoders

lib_deps = https://github.com/pschatzmann/codec-adpcm

CMake

You can install this library directly from gihub in your CMakeLists.txt

project(your-target)
# acivate FetchContent
include(FetchContent)
# install adpcm from github
FetchContent_Declare(adpcm_ffmpeg GIT_REPOSITORY "https://github.com/pschatzmann/adpcm" GIT_TAG main )
FetchContent_GetProperties(adpcm_ffmpeg)
if(NOT adpcm_ffmpeg)
FetchContent_Populate(adpcm_ffmpeg)
add_subdirectory(${adpcm_ffmpeg_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/adpcm)
endif()
# activate/deactivate individual encoders or decoders
target_compile_definitions(your-target PUBLIC -DCONFIG_ADPCM_ARGO_DECODER=0)
# specify libraries
target_link_libraries(your-target adpcm_ffmpeg)
...