From 500e4bd06d7e4f48176f883aa662764cdf10855c Mon Sep 17 00:00:00 2001 From: jincheng Date: Tue, 1 Mar 2022 21:49:44 +0800 Subject: [PATCH] correct the rate of data-producing Closes https://github.com/espressif/esp-idf/issues/7911 --- .../bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c index 394c78e2b7..11fa79a574 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c @@ -221,11 +221,14 @@ static void bt_app_send_data_task(void *arg) s_us_duration = s_now_enter_time - s_last_enter_time; if(s_audio_code == ESP_HF_AUDIO_STATE_CONNECTED_MSBC) { // time of a frame is 7.5ms, sample is 120, data is 2 (byte/sample), so a frame is 240 byte (HF_SBC_ENC_RAW_DATA_SIZE) - frame_data_num = s_us_duration / (PCM_BLOCK_DURATION_US / WBS_PCM_INPUT_DATA_SIZE); - s_last_enter_time += frame_data_num * (PCM_BLOCK_DURATION_US / WBS_PCM_INPUT_DATA_SIZE); + frame_data_num = s_us_duration / PCM_BLOCK_DURATION_US * WBS_PCM_INPUT_DATA_SIZE; + s_last_enter_time += frame_data_num / WBS_PCM_INPUT_DATA_SIZE * PCM_BLOCK_DURATION_US; } else { - frame_data_num = s_us_duration / (PCM_BLOCK_DURATION_US / PCM_INPUT_DATA_SIZE); - s_last_enter_time += frame_data_num * (PCM_BLOCK_DURATION_US / PCM_INPUT_DATA_SIZE); + frame_data_num = s_us_duration / PCM_BLOCK_DURATION_US * PCM_INPUT_DATA_SIZE; + s_last_enter_time += frame_data_num / PCM_INPUT_DATA_SIZE * PCM_BLOCK_DURATION_US; + } + if (frame_data_num == 0) { + continue; } buf = osi_malloc(frame_data_num); if (!buf) {