Skip to content

Commit 11f0ffd

Browse files
author
Reinhard Panhuber
committed
Generalize feedback value min and max
1 parent 7094ff7 commit 11f0ffd

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/class/audio/audio_device.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ typedef struct
312312

313313
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_DETERMINATION_OPTION == CFG_TUD_AUDIO_ENABLE_FEEDBACK_DETERMINATION_OPTION_SOF_BY_AUDIO_DRIVER
314314
volatile uint32_t fb_val; // Feedback value for asynchronous mode (in 16.16 format).
315+
uint32_t fb_val_min; // Maximum allowed feedback value according to UAC2 FMT-2.0 section 2.3.1.1.
316+
uint32_t fb_val_max; // Maximum allowed feedback value according to UAC2 FMT-2.0 section 2.3.1.1.
315317
uint8_t fb_n_frames; // Number of (micro)frames used to estimate feedback value
316318
volatile uint8_t fb_n_frames_current; // Current (micro)frame number
317319
volatile uint32_t fb_n_cycles_old; // Old cycle count
@@ -2094,6 +2096,9 @@ TU_ATTR_WEAK bool tud_audio_set_fb_params(uint8_t func_id, uint32_t f_m, uint32_
20942096
audio->fb_param_factor_D = (uint64_t)f_m * audio->fb_n_frames;
20952097
#endif
20962098

2099+
audio->fb_val_min = ((TUSB_SPEED_FULL == tud_speed_get() ? (f_s/1000) : (f_s/8000)) - 1) << 16; // Minimal value in 16.16 format for full speed (1ms per frame) or high speed (125 us per frame)
2100+
audio->fb_val_max = ((TUSB_SPEED_FULL == tud_speed_get() ? (f_s/1000) : (f_s/8000)) + 1) << 16; // Maximum value in 16.16 format
2101+
20972102
return true;
20982103

20992104
}
@@ -2139,16 +2144,18 @@ TU_ATTR_WEAK void audiod_sof (uint8_t rhport, uint32_t frame_count)
21392144
feedback = ((n_cylces - audio->fb_n_cycles_old) << 3) * audio->fb_param_factor_N / audio->fb_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
21402145
#endif
21412146

2142-
// Buffer count checks ?
2147+
// For Windows: https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/usb-2-0-audio-drivers
2148+
// The size of isochronous packets created by the device must be within the limits specified in FMT-2.0 section 2.3.1.1. This means that the deviation of actual packet size from nominal size must not exceed +/- one audio slot (audio slot = channel count samples).
21432149

2144-
// Magic checks - where are they from?
2145-
if (feedback > 2949166){ // 45.0007 in 16.16 format
2146-
feedback = 2949166;
2150+
if (feedback > audio->fb_val_max){
2151+
feedback = audio->fb_val_max;
21472152
}
2148-
if ( feedback < 2883630) { // 44.0007 in 16.16 format
2149-
feedback = 2883630;
2153+
if ( feedback < audio->fb_val_min) {
2154+
feedback = audio->fb_val_min;
21502155
}
21512156

2157+
// Buffer count checks ?
2158+
21522159
tud_audio_n_fb_set(i, feedback);
21532160
audio->fb_n_frames_current = 0;
21542161
audio->fb_n_cycles_old = n_cylces;

0 commit comments

Comments
 (0)