Skip to content

Commit

Permalink
doom: fix potential zero delay
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Mar 29, 2024
1 parent 96d6e99 commit 7521846
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions firmware/doom/src/i_i2ssound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,13 @@ void soundTask(void* param) {
// We do this to prevent blocking in i2s_write and thus acquiring the mutex for too long.
// This is done by calculating delay from sample rate & bytes written.
// TODO: BTW - ring buffer mixing sucks with variable sample rates... /AD
vTaskDelayUntil(
&xLastWakeTime, written / 2 * 1000 / 11025 / portTICK_PERIOD_MS * 7 / 8
); // Wait 7/8 of the time to prevent buffer underrun. Not the best solution, but works for now.
uint64_t delay = written / 2 * 1000 / 11025 / portTICK_PERIOD_MS;
// Wait 7/8 of the time to prevent buffer underrun. Not the best solution, but works for now.
delay = delay * 7 / 8;
if (delay) {
// vTaskDelayUntil doesn't like zero delays
vTaskDelayUntil(&xLastWakeTime, delay);
}
}
taskYIELD();
}
Expand Down

0 comments on commit 7521846

Please sign in to comment.