Demo of A2DP audio source role
This is the demo of using Advanced Audio Distribution Profile APIs to transmit audio stream. Application can take advantage of this example to implement portable audio players or microphones to transmit audio stream to A2DP sink devices.
This example is able to run on any commonly available ESP32 development board. And is supposed to connect to A2DP sink stream example in ESP-ADF.
This example is will run on boards marked with green checkbox. Please remember to select the board in menuconfig as discussed is section Usage below.
Board Name | Getting Started | Chip | Compatible |
---|---|---|---|
ESP32-LyraT | ![]() |
![]() |
|
ESP32-LyraTD-MSC | ![]() |
![]() |
|
ESP32-LyraT-Mini | ![]() |
![]() |
|
ESP32-Korvo-DU1906 | ![]() |
![]() |
|
ESP32-S2-Kaluga-1 Kit | ![]() |
![]() |
make menuconfig
- Enable Classic Bluetooth and A2DP under Component config --> Bluetooth --> Bluedroid Enable
- Set up the BT parameter in
menuconfig
->Example Configuration
-> Fill inBT remote device name
.
- Save "test.mp3" file to SDcard as the source file.
- Build the project and flash it to the board, then run monitor tool to view serial output.
make -j4 flash monitor
(To exit the serial monitor, type Ctrl-]
.)
- The audio board will first connect to the BT Speaker.
- Then it will send the music to the BT Speaker over Bluetoooth.
After the local device discovers the target device and initiates connection, there will be logging message like this:
I (4090) A2DP_STREAM: a2dp source connected
I (4090) A2DP_STREAM: a2dp media ready checking ...
If connection is terminated, there will be such message:
I (5100) A2DP_STREAM: a2dp source disconnected
- For current stage, the supported audio codec in ESP32 A2DP is SBC. SBC audio stream is encoded from PCM data normally formatted as 44.1kHz sampling rate, two-channel 16-bit sample data. Other SBC configurations can be supported but there is a need for additional modifications to the protocol stack.
- The raw PCM media stream in the example is generated by a sequence of random number, so the sound played on the sink side will be piercing noise.
- As a usage limitation, ESP32 A2DP source can support at most one connection with remote A2DP sink devices. Also, A2DP source cannot be used together with A2DP sink at the same time, but can be used with other profiles such as SPP and HFP.