Skip to content

Commit e715e59

Browse files
committed
fix(usb_device_uac): enforce MIC_INTERVAL_MS pacing to avoid usb_mic_task overrun
usb_device_uac: Throttle usb_mic_task to match MIC_INTERVAL_MS The usb_mic_task previously ran in a tight loop, pulling audio data as fast as possible. This caused USB audio to exceed the expected data rate, leading to glitches and distorted output. It also triggered the task watchdog due to lack of blocking. This patch introduces vTaskDelayUntil() to enforce the configured MIC_INTERVAL_MS rate, ensuring correct USB audio pacing and RTOS compliance.
1 parent 40e383f commit e715e59

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

components/usb/usb_device_uac/usb_device_uac.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,12 @@ static void usb_spk_task(void *pvParam)
456456
#if CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX
457457
static void usb_mic_task(void *pvParam)
458458
{
459+
TickType_t xLastWakeTime = xTaskGetTickCount();
459460
while (1) {
460461
if (s_uac_device->mic_active == false) {
461462
// clear the notification
462463
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
464+
xLastWakeTime = xTaskGetTickCount();
463465
continue;
464466
}
465467
// clear the notification
@@ -479,6 +481,8 @@ static void usb_mic_task(void *pvParam)
479481
s_uac_device->mic_data_size = bytes_read;
480482
UAC_EXIT_CRITICAL();
481483
}
484+
485+
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(MIC_INTERVAL_MS));
482486
}
483487
}
484488
#endif

0 commit comments

Comments
 (0)