Bugfixing a2dp_sink volume control

maggusxy
Posts: 1
Joined: Tue Feb 25, 2020 12:25 pm

Bugfixing a2dp_sink volume control

Postby maggusxy » Tue Feb 25, 2020 12:33 pm

Dear all,

I needed to use the ESP32 as a2dp_sink.
I tried out the example project provided with the 4.0 release - this also works - however I found out, that changing the volume on the smartphone side, does not affect the volume of the outcoming samples on the i2s-port. It is always the same loudness.

But in the debug-information, I saw, that the commands for changing the volume were received correctly.

Here a short workaround how to fix this:

1. Go to bt_app_av.c
->go to following line

Code: Select all

static uint8_t s_volume = 0;

and remove the "static".

2. Go to bt_app_av.h
-> declare the s_volume variable as extern by adding the following statement:

Code: Select all

extern uint8_t s_volume;
3. Go to bt_app_core.c
-> add following include statement

Code: Select all

#include "bt_app_av.h
-> so that the s_volume variable is available in the bt_app_core.c

Now go to the bt_i2s_task_handler where the samples are written to the i2s buffer and change it to following:

Code: Select all

static void bt_i2s_task_handler(void *arg)
{
    uint8_t *data = NULL;
    size_t item_size = 0;
    size_t bytes_written = 0;

    for (;;) {
        data = (uint8_t *)xRingbufferReceive(s_ringbuf_i2s, &item_size, (portTickType)portMAX_DELAY);
        if (item_size != 0){
			int16_t * pcmdata = (int16_t *)data;
			for (int i=0; i<item_size/2; i++) {
				*pcmdata = ((*pcmdata)*s_volume)/127;
				pcmdata++;
			}
            i2s_write(0, data, item_size, &bytes_written, portMAX_DELAY);
            vRingbufferReturnItem(s_ringbuf_i2s,(void *)data);
        }
    }
}
Hope this helps,
Markus

Who is online

Users browsing this forum: No registered users and 242 guests