MohammedBENHADINE / ReceiverBL

Receiver SW that connects to Cube via BL and plays stream in the audio line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Supported Targets ESP32

ReceiverBL

ReceiverBL implements the A2DP audio sink role

API implementing Advanced Audio Distribution Profile to receive an audio stream.

This example involves the use of Bluetooth legacy profile A2DP for audio stream reception, AVRCP for media information notifications, and I2S for audio stream output interface.

How to use this example

Hardware Required

Receiver board is needed as it implements the audio pipeline along with IOs controls

Configure the project

idf.py menuconfig
  • Choose external I2S codec or internal DAC for audio output, and configure the output PINs under Configuration

  • Enable Classic Bluetooth and A2DP under Component config --> Bluetooth --> Bluedroid Enable

Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output.

idf.py -p PORT flash monitor

(To exit the serial monitor, type Ctrl-].)

Console Output

After the program is started, the code starts inquiry scan and page scan, awaiting being discovered and connected. Other bluetooth devices such as smart phones can discover a device named "ESP_SPEAKER". A smartphone or Cube can be used to connect to the local device.

Once A2DP connection is set up, there will be a notification message with the remote device's bluetooth MAC address like the following:

I (106427) BT_AV: A2DP connection state: Connected, [64:a2:f9:69:57:a4]

If a smartphone is used to connect to local device, starting to play music with an APP will result in the transmission of audio stream. The transmitting of audio stream will be visible in the application log including a count of audio data packets, like this:

I (120627) BT_AV: A2DP audio state: Started
I (122697) BT_AV: Audio packet count 100
I (124697) BT_AV: Audio packet count 200
I (126697) BT_AV: Audio packet count 300
I (128697) BT_AV: Audio packet count 400

Also, the sound will be heard if a loudspeaker is connected and possible external I2S codec is correctly configured. For ESP32 A2DP source example.

Troubleshooting

  • For current stage, the supported audio codec in ESP32 A2DP is SBC. SBC data stream is transmitted to A2DP sink and then decoded into PCM samples as output. The PCM data format is normally of 44.1kHz sampling rate, two-channel 16-bit sample stream. Other SBC configurations in ESP32 A2DP sink is supported but need additional modifications of protocol stack settings.

About

Receiver SW that connects to Cube via BL and plays stream in the audio line


Languages

Language:C 98.3%Language:CMake 0.9%Language:Makefile 0.8%