-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix UAC encoding, update example. #2259
Conversation
634df4e
to
6be7f35
Compare
c22e907
to
624ef66
Compare
@PanRe could you take a look when you are free ? It's tested on stm32g0b1 and stm32f407. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for fixing the bug! Nice work as usual!
@@ -400,7 +420,17 @@ bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, u | |||
(void) ep_in; | |||
(void) cur_alt_setting; | |||
|
|||
for (uint8_t cnt=0; cnt < CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO; cnt++) | |||
|
|||
// In read world application data flow is driven by I2S clock, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In real world ;)
@PanRe Thanks for your quick return :) I'll try to optimize IN transfer data flow in a following PR. For TYPE-I format the allowed sample in each packet is navg+-1, for example 48kHz with a FS device gives 47~49 samples per packet. Currently it always try to send all the data in FIFO. If we take example of a 48 sample length I2S buffer, who writes all samples to UAC FIFO every 1ms:
What I'm think is increase IN FIFO size to at least 4*packet size:
SO the above example packet length becomes 48 48 48 47 48 48 48 47. |
Interesting idea, but isn't that what you already implemented in one of your projects? I remember you mentioned something like that for the feedback value calculation? Nevertheless, I like the idea. However, it introduces a lag and some users might not want that. I know, it is hard to get it working without some kind of buffering. How about defining a minimum buffer fill level? The higher it is, the more robust it gets. For users which don't want a buffering, they can set the fill level to zero. Do we need to need to modify the feedback value depending on the buffer settings? |
It was for OUT transfer, in that case user code has the responsibility to calculate feedback correctly. For IN transfer the feedback is implicite, simply determined by how much data is sent. After thinking current code only support fixed sample rate, it's necessary to calculate navg based on sample rate to let multi-rate work. For example in 48k & 96k case the FIFO size will be 96+1, when 48k is chosen sent packet could be 96 0 96 0....
As the FIFO will be filled in to 50% in average so there will be an additional delay of 1ms for FS or 125us for HS. Compared to OS's latency it's mostly neageible.
The only case is when I2S clock perfectly synced with USB clock, like current examples where data is simply looped back. |
I see! I think it is a great idea! |
awesome, great work as usual 👍 👍 |
Describe the PR
Currently interleaved copy in UAC2 is bugged with wrong stride, resulting samples become scrambled if encoding/decoding is enabled.
#2256, maybe #1722
Additional context
audio_4_channel_mic
example use identical sample for all channels, makes the problems less obvious, now it has been updated to output different waveforms each channel.