My AudioTools project is supporting quite a few audio encoders and decoders. They are critical to reduce the storage or transmission volume of audio.

Though I support the encoding of AAC and MP3, I can’t really recommend this: it requires a lot of memory and processing time.

For an introduction how to use the codecs, please read the Wiki.

Below you can find my short list of my favorite codecs which are fast and efficient. I tried to measure the thruput with the help of the following Arduino sketch

Measuring Sketch

#include "AudioTools.h"
#include "AudioCodecs/CodecSBC.h"
#include "AudioLibs/AudioKit.h"

AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave( 32000);  // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
MeasuringStream out(100, &Serial); 
EncodedAudioStream decoder(&out, new SBCDecoder()); // encode and write
EncodedAudioStream encoder(&decoder, new SBCEncoder()); // encode and write
StreamCopy copier(encoder, sound);     

void setup() {
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Warning);

  out.begin();

  // Setup sine wave
  auto cfgs = sineWave.defaultConfig();
  cfgs.copyFrom(info);
  sineWave.begin(info, N_B4);

  // start decoder
  decoder.begin(info);

  // start encoder
  encoder.begin(info);

  Serial.println("Test started...");
}


void loop() { 
  copier.copy();
}

We generate a stereo sine tone with a sample rate of 44100 samples/second and just measure the bytes per second on the output side.

Result

Here is the result of my favorite codecs:

Codec Bytes/second Frames/second
SBC 327’000 81’750
ADPCM 609’000 152’250
L8 1’951’000 487’750
861’000 215’250

The sketch is usually reporting multiple values and I was just picking the smallest of them.

The SBC codec is usually the default codec for the A2DP Bluetooth audio profile.

ADPCM is a Adaptive differential pulse-code modulation codec. It is out of fashion on desktops, but on microcontrollers it still shines.

L8 is just a 8 bit unsigned signal, so it is cutting the transmission volume in half at the cost of the reduced resolution. But 8 bit is still giving a decent audio quality!

It is surprising to see that the processing with L8 is even faster than with no codec!

If you plan to transmit speech over slow transmission lines, I suggest that you consider the codecs that have been designed for that purpose: e.g. GSM, a-low, u-low, G.721 etc (See the classification in the Wiki)


3 Comments

Mike · 11. May 2023 at 10:01

Interesting, I plan to repeat your test with a noise generator instead of a sine generator and see if there is any difference. It will be also interesting to compare the compression of each codec, as I will be streaming to file.

    pschatzmann · 11. May 2023 at 10:27

    Yes, codecs with a higher compression ratio will do better on slow lines.
    I was just looking at the speed of the codecs…

Dane · 10. May 2023 at 18:08

Great info Phil and huge differences in your tests. That will help narrow down selection for my upcoming speech to text project. Thanks!

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *