I am trying to use ESP32's HFP_AG profile to send and receive audio from Bluetooth headphones/speakers. I am planning on doing some signal processing on the microphone input and sending a custom output to the client, and as far as I can tell that means I need to configure the audio path to communicate using HCI instead of PCM. So, I register the incoming and outcoming data callbacks, connect to the target device, and initiate an audio connection with the device. However, I get consistent errors when I start connecting to the device. Here is a short taste:
E (7130) BT_BTM: btm_sco_connected, handle 181
I (7130) HFP: Audio state connected
W (7160) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7160) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7170) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7180) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7190) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7190) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7200) BT_APPL: bta_ag_sco_read_cback: status(2)
W (7210) BT_APPL: bta_ag_sco_read_cback: status(2)
Occasionally, I get a few of these sco read status updates that have a 1. I looked a little deeper and found that a 2 status means that it detected no data from the callback, while a 1 means there was a parity error. These are my callback functions:
Code: Select all
static const int16_t sine_int16[] = {
0, 2057, 4107, 6140, 8149, 10126, 12062, 13952, 15786, 17557,
19260, 20886, 22431, 23886, 25247, 26509, 27666, 28714, 29648, 30466,
31163, 31738, 32187, 32509, 32702, 32767, 32702, 32509, 32187, 31738,
31163, 30466, 29648, 28714, 27666, 26509, 25247, 23886, 22431, 20886,
19260, 17557, 15786, 13952, 12062, 10126, 8149, 6140, 4107, 2057,
0, -2057, -4107, -6140, -8149, -10126, -12062, -13952, -15786, -17557,
-19260, -20886, -22431, -23886, -25247, -26509, -27666, -28714, -29648, -30466,
-31163, -31738, -32187, -32509, -32702, -32767, -32702, -32509, -32187, -31738,
-31163, -30466, -29648, -28714, -27666, -26509, -25247, -23886, -22431, -20886,
-19260, -17557, -15786, -13952, -12062, -10126, -8149, -6140, -4107, -2057,
};
#define TABLE_SIZE_CVSD 100
static uint32_t outgoing_cb(uint8_t *p_buf, uint32_t sz)
{
int sine_phase = esp_random();
ESP_LOGI(HFP_TAG, "MADE IT");
for (int i = 0; i < TABLE_SIZE_CVSD; i++) {
p_buf[i * 2] = sine_int16[sine_phase];
p_buf[i * 2 + 1] = sine_int16[sine_phase];
++sine_phase;
if (sine_phase >= TABLE_SIZE_CVSD) {
sine_phase -= TABLE_SIZE_CVSD;
}
}
return sz;
}
static void incoming_cb(const uint8_t *buf, uint32_t len) {
//ESP_LOGI(HFP_TAG, "Data in: address: %x Length: %d", (int) buf, len);
esp_hf_outgoing_data_ready();
}
I understand that there are many issues on this forum, and time is not a free resource. I was hoping for either some feedback on what I might be doing wrong, or an update on whether or not this issue can be fixed. I've seen at least 1 other person with the same issue a few years ago. Maybe things have changed since then?
Thanks,
Searock