diff --git a/lib_xua/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/lib_xua/src/core/buffer/ep/ep_buffer.xc index 8cfbdbd..0027654 100644 --- a/lib_xua/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -737,8 +737,15 @@ void XUA_Buffer_Ep( if(usb_speed != XUD_SPEED_HS) feedbackMul = 8ULL; /* TODO Use 4 instead of 8 to avoid windows LSB issues? */ - /* Number of MCLK ticks in this SOF period (E.g = 125 * 24.576 = 3072) */ - int count = (int) ((short)(u_tmp - lastClock)); + /* Number of MCLK ticks in this SOF period (E.g = 125 * 24.576 = 3072) + * 改动原因:原 (short) 截断只能处理 MCLK 计数 < 32768 的情况。 + * UAC1 使用 FS USB(SOF 周期 1ms),1024x MCLK(49.152MHz)时 + * 每个 SOF 产生 49152 ticks > 32767,(short) 溢出为 -16384(负数), + * 导致 feedback 计算错误,录音 IN endpoint 缓冲区管理失败,录音卡住。 + * 改为 (unsigned short) 后:49152 = 0xC000,truncate 后仍为 49152, + * 同时保留对 16-bit 端口计时器回绕(wraparound)的正确处理。 + * UAC2 HS SOF(125µs)下最大 6144 ticks < 32768,两者等价,无副作用。 */ + int count = (int) ((unsigned short)(u_tmp - lastClock)); unsigned long long full_result = count * feedbackMul * sampleFreq;