Skip to content

Commit 2888675

Browse files
koffesnordicjm
authored andcommitted
Applications: Audio: Resolved wrapping calculation
- OCT-3204 - Resolved a calculation not considering wrapping - Minor changes to naming and comments Signed-off-by: Kristoffer Rist Skøien <[email protected]>
1 parent 7fdaf5b commit 2888675

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

applications/nrf5340_audio/src/audio/audio_datapath.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ static struct {
161161
} pres_comp;
162162
} ctrl_blk;
163163

164+
/**
165+
* @brief Get the current number of blocks in the output buffer.
166+
*/
167+
static int filled_blocks_get(void)
168+
{
169+
if (ctrl_blk.out.cons_blk_idx < ctrl_blk.out.prod_blk_idx) {
170+
return ctrl_blk.out.prod_blk_idx - ctrl_blk.out.cons_blk_idx;
171+
} else if (ctrl_blk.out.cons_blk_idx > ctrl_blk.out.prod_blk_idx) {
172+
return (FIFO_NUM_BLKS - ctrl_blk.out.cons_blk_idx) + ctrl_blk.out.prod_blk_idx;
173+
} else {
174+
return 0;
175+
}
176+
}
177+
164178
static bool tone_active;
165179
/* Buffer which can hold max 1 period test tone at 100 Hz */
166180
static uint16_t test_tone_buf[CONFIG_AUDIO_SAMPLE_RATE_HZ / 100];
@@ -433,6 +447,7 @@ static void audio_datapath_presentation_compensation(uint32_t recv_frame_ts_us,
433447
return;
434448
}
435449

450+
/* Operation to obtain nearest whole number in subsequent operations */
436451
if (pres_adj_us >= 0) {
437452
pres_adj_us += (BLK_PERIOD_US / 2);
438453
} else {
@@ -961,8 +976,7 @@ void audio_datapath_stream_out(const uint8_t *buf, size_t size, uint32_t sdu_ref
961976
}
962977

963978
/*** Add audio data to FIFO buffer ***/
964-
965-
int32_t num_blks_in_fifo = ctrl_blk.out.prod_blk_idx - ctrl_blk.out.cons_blk_idx;
979+
uint32_t num_blks_in_fifo = filled_blocks_get();
966980

967981
if ((num_blks_in_fifo + NUM_BLKS_IN_FRAME) > FIFO_NUM_BLKS) {
968982
LOG_WRN("Output audio stream overrun - Discarding audio frame");

0 commit comments

Comments
 (0)