summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2022-03-15 20:45:06 +0100
committerReinhard Panhuber <[email protected]>2022-03-15 20:45:06 +0100
commit90502739c34b8cbcf37229031eb4f575c33311fa (patch)
tree0d4947e29dc82a6cf1e3ba12b5c9db1d5504ce2c /src
parentc9b444e771e138ee50ed8cbff67d895722b46008 (diff)
Fix cycle count calculation
Diffstat (limited to 'src')
-rw-r--r--src/class/audio/audio_device.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c
index 5ca95658e..1dbeb7643 100644
--- a/src/class/audio/audio_device.c
+++ b/src/class/audio/audio_device.c
@@ -310,6 +310,7 @@ typedef struct
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_DETERMINATION_WITHIN_SOF_ISR
uint8_t n_frames; // Number of (micro)frames used to estimate feedback value
uint8_t n_frames_current; // Current (micro)frame number
+ uint32_t n_cycles_old; // Old cycle count
uint32_t feeback_param_factor_N; // Numerator of feedback parameter coefficient
uint32_t feeback_param_factor_D; // Denominator of feedback parameter coefficient
#endif
@@ -1673,6 +1674,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_DETERMINATION_WITHIN_SOF_ISR
usbd_sof_enable(rhport, true); // Enable SOF interrupt
audio->n_frames_current = 0;
+ audio->n_cycles_old = 0;
#endif
// Invoke callback after ep_out is set
@@ -2043,10 +2045,11 @@ void audiod_sof (uint8_t rhport, uint32_t frame_count)
if (audio->n_frames_current == audio->n_frames)
{
uint32_t n_cylces = tud_audio_n_get_fm_n_cycles_cb(rhport, audio->ep_fb);
- uint32_t feedback = (n_cylces << 3) * audio->feeback_param_factor_N / audio->feeback_param_factor_D; // feeback_param_factor_N has scaling factor of 13 bits, n_cycles 3 and feeback_param_factor_D 1, hence 16.16 precision
+ uint32_t feedback = ((n_cylces - audio->n_cycles_old) << 3) * audio->feeback_param_factor_N / audio->feeback_param_factor_D; // feeback_param_factor_N has scaling factor of 13 bits, n_cycles 3 and feeback_param_factor_D 1, hence 16.16 precision
tud_audio_n_fb_set(i, feedback);
audio->n_frames_current = 0;
+ audio->n_cycles_old = n_cylces;
}
}
}