蓝牙传输音频时扬声器输出音频时每句话开始时有卡顿

我在做蓝牙音频方面的测试时发现,设备在sink模式下,跟手机ai对话时设备输出的ai语音每句话的第一个词都会卡顿,我尝试了你们的sink例程,也尝试了黄山派的板子,但是无论怎样都会出现卡顿。

```c
void xz_audio_downlink(uint8_t *data, uint32_t size, uint32_t *aes_value,
                       uint8_t need_aes)
{
    int try_times = 0;
    xz_audio_t *thiz = &xz_audio;
    rt_slist_t *idle;
    if (!thiz->inited)
    {
        LOG_I("%s invalid\r\n", __FUNCTION__);
        return;
    }
    // LOG_I("%s tx=%d inited=%d\r\n", __FUNCTION__, thiz->is_tx_enable,
    // thiz->inited);
wait_speaker:
    rt_enter_critical();
    idle = rt_slist_first(&thiz->downlink_decode_idle);
    rt_exit_critical();
    if (idle)
    {
        xz_decode_queue_t *queue =
            rt_container_of(idle, xz_decode_queue_t, node);
        if (queue->size < size + 16)
        {
            opus_heap_free(queue->data);
            queue->size = size + 16;
            queue->data = opus_heap_malloc(queue->size);
            RT_ASSERT(queue->data);
        }
        queue->data_len = size;
        if (need_aes)
        {
            HAL_AES_init((uint32_t *)&(g_xz_context.key[0]), 16, aes_value,
                         AES_MODE_CTR);
            HAL_AES_run(AES_DEC, data, queue->data, size);
        }
        else
        {
            memcpy(queue->data, data, size);
        }
        rt_enter_critical();
        rt_slist_remove(&thiz->downlink_decode_idle, idle);
        rt_slist_append(&thiz->downlink_decode_busy, idle);
        rt_exit_critical();

        rt_event_send(thiz->event, XZ_EVENT_DOWNLINK);
```

这里rt_event_send(thiz->event, XZ_EVENT_DOWNLINK);加个第一次的处理,第一次攒几包在发送。

在speaker open时,thiz->trigger_count = 0;

在这里改为

```
   if (this->triiger_count < 4) / *但是服务器会不会某次一共只来1~3个包 */
   {
        this->triiger_count++;
   }
   else
   {
       rt_event_send(thiz->event, XZ_EVENT_DOWNLINK);
   }
```

XZ_DOWNLINK_QUEUE_NUM

你的意思在xz_audio_downlink函数接收到一定量的音频数据后,才开始向speaker传输音频数据

image

不能每次都==4, 是刚开始时这样,后面要每次都send

没有,感觉不是这个的问题

现在什么情况,有改善吗?