Skip to content

Commit

Permalink
Optimize fifo level display.
Browse files Browse the repository at this point in the history
  • Loading branch information
HiFiPhile committed May 12, 2024
1 parent 08f9e4e commit df67403
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions examples/device/uac2_speaker_fb/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ void audio_task(void);
#if CFG_AUDIO_DEBUG
void audio_debug_task(void);
uint8_t current_alt_settings;
uint16_t fifo_count;
uint32_t fifo_count_avg;
#endif

/*------------- MAIN -------------*/
Expand Down Expand Up @@ -367,6 +369,21 @@ void tud_audio_feedback_params_cb(uint8_t func_id, uint8_t alt_itf, audio_feedba
feedback_param->sample_freq = current_sample_rate;
}

#if CFG_AUDIO_DEBUG
bool tud_audio_rx_done_pre_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t func_id, uint8_t ep_out, uint8_t cur_alt_setting)
{
(void)rhport;
(void)func_id;
(void)ep_out;
(void)cur_alt_setting;

fifo_count = tud_audio_available();
// Same averaging method used in UAC2 class
fifo_count_avg = (uint32_t)(((uint64_t)fifo_count_avg * 63 + ((uint32_t)fifo_count << 16)) >> 6);

return true;
}
#endif
//--------------------------------------------------------------------+
// AUDIO Task
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -418,7 +435,6 @@ void led_blinking_task(void)
//--------------------------------------------------------------------+
// HID interface for audio debug
//--------------------------------------------------------------------+

// Every 1ms, we will sent 1 debug information report
void audio_debug_task(void)
{
Expand All @@ -427,12 +443,6 @@ void audio_debug_task(void)
if ( start_ms == curr_ms ) return; // not enough time
start_ms = curr_ms;

uint16_t fifo_count = tud_audio_available();
static uint32_t fifo_count_avg;

// Same averaging method used in UAC2 class
fifo_count_avg = (uint32_t)(((uint64_t)fifo_count_avg * 63 + ((uint32_t)fifo_count << 16)) >> 6);

audio_debug_info_t debug_info;
debug_info.sample_rate = current_sample_rate;
debug_info.alt_settings = current_alt_settings;
Expand Down

0 comments on commit df67403

Please sign in to comment.