For quite some time I was wondering why my arduino-fdk-aac library was using so much memory for the encoding of AAC files. Now that I have an AudioKit working with the debugger it was easier to analyze the situation and – oh boy – I found quite some errors.

So I decided to address the issues and published a new corrected release.

Arduino Sketch

Here is a quick Arduino Sketch which demonstrates how to use the Encoder with the AudioKit:

#define USE_FDK

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

AudioKitStream kit;    
AACEncoderFDK *fdk=nullptr;
AudioEncoderServer *server=nullptr;  

// Arduino setup
void setup(){
  // Defining Loglevels for the different libraries
  //AudioLogger::instance().begin(Serial, AudioLogger::Info);

  // setup and configure fdk
  fdk = new AACEncoderFDK();  
  fdk->setAudioObjectType(2);  // AAC low complexity
  fdk->setOutputBufferSize(1024); // decrease output buffer size
  fdk->setVariableBitrateMode(2); // low variable bitrate
  server = new AudioEncoderServer(fdk,"WIFI","password");  

  // start i2s input with default configuration
  Serial.println("starting AudioKit...");
  auto config = kit.defaultConfig(RX_MODE);
  config.input_device = AUDIO_HAL_ADC_INPUT_LINE2;
  config.sample_rate = 44100; 
  config.default_actions_active = false; 
  config.channels = 2; 
  Serial.println("AudioKit started");

  // start data sink
  server->begin(kit, config);
  Serial.println("Server started");


// Arduino loop  
void loop() {
  // Handle new connections

This demo shows

  • how to set up the logger for the different libraries and
  • how to configure the AACEncoderFDK.

The shown encoder configuration values are corresponding with my updated default values proposed by the library – so they would not be necessary. But I left them to demonstrate how you could define your own settings. The available configuration methods are documented in the class documentation.

Source Code

The (potentially updated) example can also be found on Github.


Leave a Reply

Avatar placeholder

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