I am providing a Bluetooth A2DP audio library for the ESP32, which can receive audio from a Bluetooth Source (e.g. a mobile phone) and play it via the I2S API provided by the IDF framework.

Unfortunately Espressif has decided to go for a completely new I2S API which means that my integration needs to be rewritten.

For quite some time now, I am supporting this new API via my AudioTools library, and I was considering to remove the I2S output functiontlity completely from my A2DP library and just use it a data provider for the AudioTools.

My latest design however looks as follows:

  • I am providing a separate output API in the A2DP library with the following class implementations:
  • If you use a Arduino ESP32 core version < 3.0.0 the legacy functionality continues to work
  • Starting from now, you can use the new API independently on the ESP32 core version.

I have updated the documentation and examples to use the new API.

I recommend to use the new API because this way you can be sure that your sketch will work in future ESP32 cores versions.

Example Sketch with the new API

#include "AudioTools.h
#include "BluetoothA2DPSink.h"

I2SStream i2s;
BluetoothA2DPSink a2dp_sink(i2s);

void setup() {
    auto cfg = i2s.defaultConfig();
    cfg.pin_bck = 14;
    cfg.pin_ws = 15;
    cfg.pin_data = 22;
    i2s.begin(cfg);

    a2dp_sink.start("MyMusic");
}

void loop() {
}

This comes at the cost, that you also need to install the AudioTools library now!


4 Comments

Jyrki Sipinen · 12. June 2024 at 13:03

Great library! Seems that bt_music_receiver_and_BLE example need some additional lines for correct I2S operation:

#include “AudioTools.h”

auto cfg = i2s.defaultConfig();
cfg.pin_bck = 27; // SCK, BCLK, BCK
cfg.pin_ws = 26; // WS, LRC
cfg.pin_data = 25; // DOUT, SDOUT
i2s.begin(cfg);

Jacob Schmidt · 4. June 2024 at 1:53

Is the updated A2DP library compatible with ESP32-S3? I have a compile error (# error “ESP32C3, ESP32S2, ESP32S3 do not support A2DP”), but I am not sure if I have completed the installation/updating correctly.

Thank you for all of your work- these tools are very useful!

Leave a Reply

Avatar placeholder

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