Skip to content

Contributed by O2C14, curated by Ai-Thinker

btstack_a2dp_player

It is still a work in progress.

Getting the Source Code

Run the following in the example directory:

html
git clone https://github.com/O2C14/btstack_test.git -b a2dp_player
cd ./btstack_test
rm -rf ./btstack
git clone https://github.com/bluekitchen/btstack.git -b v1.6.1

Configure the pins in gpio_config.h; currently only the ES9038Q2M is supported.

Known Issues:

The minimum buffer currently used is 100ms, but even so, synchronization may be lost.

How to Configure DMA:

base_buffer_size in pcm_open determines the frequency of DMA interrupts, and also the frequency of synchronization checks.

The product of buffer_num and base_buffer_size in pcm_open is the total buffer size, in bytes.

The set_start_loc function determines the sizes of the overload buffer and underload buffer. A parameter of 0 means the underload buffer size is 0, i.e., underload is not acceptable; once underload occurs, the DMA is reset directly. The sum of the overload buffer and the underload buffer is the final buffer size.

Configuration Process:

Operation Steps

1
Get the output length of the decoder for each decode; it must be a fixed value (in samples), i.e., `nframes_per_buffer` in `a2dp_decoder.h`

Get the output length of the decoder for each decode; it must be a fixed value (in samples), i.e., nframes_per_buffer in a2dp_decoder.h

2
Calculate the duration corresponding to the output length (in ms), multiply it by an integer so it exceeds 10ms (the check interval), i.e., `base_size` in `init_decoder`

Calculate the duration corresponding to the output length (in ms), multiply it by an integer so it exceeds 10ms (the check interval), i.e., base_size in init_decoder

3
Calculate the final buffer size; be careful not to exceed `pcm_buffer`

Calculate the final buffer size; be careful not to exceed pcm_buffer

4
Calculate the parameter of `set_start_loc`; the recommended size is an integer multiple of `nframes_per_buffer`, and make the overload buffer

Calculate the parameter of set_start_loc; the recommended size is an integer multiple of nframes_per_buffer, and make the overload buffer and underload buffer the same size.

I2S Porting:

It is already described in es9038q2m.h.

Possible Problems:

I2S has no output, GPIO_PIN_12 is pulled high (shown as a red LED on the Ai-M61-32S-Kit). This means the I2S has crashed and cannot be recovered by resetting I2S and DMA; you should check whether the MCU power supply is stable.

Currently Supported Codecs:

LHDCV5 (not public), LDAC, AAC, SBC

LHDCV5 latency test screenshot:

Have questions?

For other questions, please visit the unified discussion area: Ai-Thinker Discussions

Released under the MIT License. Build Time 2026-09-11 14:52:23