A2DP Sink: how to get bit depth and sample rate

BuddyCasino
Posts: 263
Joined: Sun Jun 19, 2016 12:00 am

A2DP Sink: how to get bit depth and sample rate

Postby BuddyCasino » Sun May 07, 2017 8:56 pm

I've gotten the A2DP example to work with audio output to I2S - thanks for the example code!
I have used 44100Hz / 16 bit as default, but I saw that 16000 - 48000Hz are possible. Is there a way to be notified what the SBC decoder actually found?

I tried to find out more by looking at the log output from btc_media_task.c and changed the appl_trace_level in bta_sys_main.c on line 62 to BT_TRACE_LEVEL_DEBUG, but that didn't do anything.

Also, since I have gotten the libfaad2 decoder to work I'd like to see if I can select it as an A2DP codec. I guess there is currently no interface for user-provided codecs?

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: A2DP Sink: how to get bit depth and sample rate

Postby rudi ;-) » Sun May 07, 2017 11:03 pm

BuddyCasino wrote:I've gotten the A2DP example to work with audio output to I2S - thanks for the example code!
I have used 44100Hz / 16 bit as default, but I saw that 16000 - 48000Hz are possible. Is there a way to be notified what the SBC decoder actually found?
hi mike,
which SBC decoder you use?
have you example seen this this Line can notified the info - do you have your example work for A2DP and output I2S online for a lookup?
best wishes
rudi ;-)

edit, not sure how your SBC decoder looks: lookup to the header of stream.... or header info

info Side 4 and Side 5
general info
Attachments
avt-8.pdf
Info Side 4 and 5
(316.52 KiB) Downloaded 749 times
A2DP_spec_v10.pdf
(2.25 MiB) Downloaded 837 times
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

BuddyCasino
Posts: 263
Joined: Sun Jun 19, 2016 12:00 am

Re: A2DP Sink: how to get bit depth and sample rate

Postby BuddyCasino » Mon May 08, 2017 6:07 am

Espressif conviently take care of the details, the SBC decoder is part of the Bluedroid stack in the ESP-IDF. They provide a callback function where they pass the decoded audio as PCM samples, I literally had it running in about an hour.

I added it to the webradio project, theres a guide in the Readme how to activate Bluetooth speaker mode.

kearins
Posts: 21
Joined: Sun Jul 23, 2017 11:48 pm

Re: A2DP Sink: how to get bit depth and sample rate

Postby kearins » Mon Jul 24, 2017 12:50 am

Hi Mike,
I've gotten the A2DP example to work too, but when I play audiobook over Bluetooth I've got rattling sound on PCM5102 connected to esp32. It's rather hard to understand artists' words. I don't know in which direction to dig.
I've got SBC stream (mcc.type==0)
i2s is inited as:

Code: Select all

    i2s_config_t i2s_config = {
        .mode = I2S_MODE_MASTER | I2S_MODE_TX,
        .sample_rate = 44100,
        .bits_per_sample = 16,                                              
        .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
        .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
        .dma_buf_count = 8,
        .dma_buf_len = 64,
        .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1
    };
    i2s_pin_config_t pin_config = {
        .bck_io_num = 26,
        .ws_io_num = 25,
        .data_out_num = 22,
        .data_in_num = -1
    };
    i2s_driver_install(0, &i2s_config, 0, NULL);
    i2s_set_pin(0, &pin_config);
    i2s_set_clk(0, i2s_config.sample_rate, i2s_config.bits_per_sample, 2);
I send samples to i2s from callback:

Code: Select all

void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len)
{
    int bytes_written = i2s_write_bytes(0, (const char *)data, len, portMAX_DELAY);
    if (++m_pkt_cnt % 100 == 0) {
        ESP_LOGE(BT_AV_TAG, "audio data pkt cnt %u", m_pkt_cnt);
    }
}
Could anybody give me some hint?

kearins
Posts: 21
Joined: Sun Jul 23, 2017 11:48 pm

Re: A2DP Sink: how to get bit depth and sample rate

Postby kearins » Mon Jul 24, 2017 9:39 am

BuddyCasino wrote:I have used 44100Hz / 16 bit as default, but I saw that 16000 - 48000Hz are possible. Is there a way to be notified what the SBC decoder actually found?
To define sample rate I do check in callback for A2DP sink: in case of ESP_A2D_AUDIO_CFG_EVT I do:

Code: Select all

        a2d = (esp_a2d_cb_param_t *)(param);
                 uint8_t sbc0 = a2d->audio_cfg.mcc.cie.sbc[0];
One of 4 bits in sbc0 indicates sample rate:

Code: Select all

	if (sbc0 & 0x80)	sample_rate = 16000;
	if (sbc0 & 0x40)	sample_rate = 32000;
	if (sbc0 & 0x20)	sample_rate = 44100;
	if (sbc0 & 0x10)	sample_rate = 48000;

BuddyCasino
Posts: 263
Joined: Sun Jun 19, 2016 12:00 am

Re: A2DP Sink: how to get bit depth and sample rate

Postby BuddyCasino » Mon Jul 24, 2017 1:53 pm

Good find. Thanks!

Who is online

Users browsing this forum: netfox, rrwatt and 162 guests