Bluetooth example question

guidoglorioso
Posts: 1
Joined: Thu Dec 07, 2023 2:48 pm

Bluetooth example question

Postby guidoglorioso » Thu Dec 07, 2023 3:00 pm

hello, i am using the A2DP_SINK example from de SDK. I need to work with the data wich comes from the bluetooth but i am strugling quite a lot. I see on a post that you can "intercept" the data in the write_ringbuf from the app_core, using a function that takes de *data and returning the new data to use:

size_t write_ringbuf(const uint8_t *data, size_t size)
{
size_t item_size = 0;
BaseType_t done = pdFALSE;

if (ringbuffer_mode == RINGBUFFER_MODE_DROPPING) {
//ESP_LOGW(BT_APP_CORE_TAG, "ringbuffer is full, drop this packet!");
vRingbufferGetInfo(s_ringbuf_i2s, NULL, NULL, NULL, NULL, &item_size);
if (item_size <= RINGBUF_PREFETCH_WATER_LEVEL) {
//ESP_LOGI(BT_APP_CORE_TAG, "ringbuffer data decreased! mode changed: RINGBUFFER_MODE_PROCESSING");
ringbuffer_mode = RINGBUFFER_MODE_PROCESSING;
}
return 0;
}

// codigo que agrego
uint8_t *volumedData = (uint8_t *)malloc(sizeof(uint8_t)*size);
done = xRingbufferSend(s_ringbuf_i2s,(void*) volume_control_changeVolume(data, volumedData, size, master_volume) , size, portMAX_DELAY);
// data
free(volumedData);
// fin codigo que agrego

//done = xRingbufferSend(s_ringbuf_i2s, (void *)data, size, (TickType_t)0);

if (!done) {
//ESP_LOGW(BT_APP_CORE_TAG, "ringbuffer overflowed, ready to decrease data! mode changed: RINGBUFFER_MODE_DROPPING");
ringbuffer_mode = RINGBUFFER_MODE_DROPPING;
}

if (ringbuffer_mode == RINGBUFFER_MODE_PREFETCHING) {
vRingbufferGetInfo(s_ringbuf_i2s, NULL, NULL, NULL, NULL, &item_size);
if (item_size >= RINGBUF_PREFETCH_WATER_LEVEL) {
//ESP_LOGI(BT_APP_CORE_TAG, "ringbuffer data increased! mode changed: RINGBUFFER_MODE_PROCESSING");
ringbuffer_mode = RINGBUFFER_MODE_PROCESSING;
if (pdFALSE == xSemaphoreGive(s_i2s_write_semaphore)) {
//ESP_LOGE(BT_APP_CORE_TAG, "semphore give failed");
}
}
}

return done ? size : 0;
}

however i am quite stack because i have no idea which is the format off the data. The data is the same as a normal PCMdata like an MP3 data format? Or is diferrent?
I thought that the data was given as :
LEFT_CHANEL_FIRST8bit , LEFT_CHANEL_SECOND8bit, RIGHT_CHANEL_FIRST8bit , RIGHT_CHANEL_SECOND8bit
so my code to recover the data was:
uint8_t *volume_control_changeVolume(const uint8_t *data, uint8_t *outputData, size_t size, uint8_t volume) {
const int numBytesShifted = 2;
uint8_t my_volume = 16;
int16_t pcmData;
int channel = 0;

memcpy(outputData, data, size);
size_t h = 0;

for (h = 0; h < size; h += numBytesShifted) {
printf("%d",data[h]);
printf("%d",data[h+1]);
pcmData = ((uint16_t) data[h +1 ] << 8) | data[h];

xQueueSend(queue_data_out,&pcmData,0);

}

return outputData;
}
but that does not work for me to recover the data and work with them.
.
Any help is welcome!

Who is online

Users browsing this forum: No registered users and 88 guests