-
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
Allow passing feedback value unchanged through tud_audio_n_fb_set #1234
Comments
For future reference: this blog describes how to get logs from the Windows driver. The driver complains after the feedback value being out of range when in 10.14 format. |
That's interesting, though I don't remember I had issue testing full-speed. |
It happens on the Raspberry Pi Pico. I'd be interested to learn if it's specific to this device. |
@PanRe haven't see you for awhile, do you remember something about this ? |
@HiFiPhile yeah it has been a while true! How are you all good? @vmilea The driver can not know in advance if it is operated in full or high speed mode. Hence, the driver was designed such that the feedback value is always saved in 16.16 format and in case of full speed mode, the driver takes care of reforamting the value to the specified 10.14 format for sending. This way, the user does not need to care about the format with respect to the speed setting, just always set the value in 16.16 format. Until now, there were no issues with this design. |
@PanRe The API design is fine, it's just that the reformatting to 10.14 sometimes gets in the way. I'm proposing something like This is to work around a bug in the actual Windows driver. When passing 10.14 format on my full-speed device it refuses the value:
The driver is expecting instead a 16.16 value between 0x2c.0-0x2d.0 (44.0-45.0). |
@vmilea Ah yeah now i see. Would you file a PR therefore? However, it is up to @hathach to decide if the PR is accepted. I would say it would be reasonable to do as you proposed. But i would prefer |
I've a guess but doesn't have a board to test with for the moment. In XMOS's lib they use 3 bytes feedback for FS and 4 bytes for HS.
Maybe Windows use the byte length to decide coding format. @vmilea Could you try to change 4 to 3 to see what happens ? tinyusb/src/class/audio/audio_device.c Line 1042 in f8288be
|
@HiFiPhile Good guess. Unfortunately it doesn't work:
I also tried setting
|
Done.
I don't right now. It's not too difficult to create one with dummy output and fixed feedback value, but without real audio output the bug can only be checked through Windows driver logs. |
thank you @vmilea for the issue and @HiFiPhile and @PanRe for helpful input. PR #1235 look good, though I would like to get more info with your example and set up for reproducing purpose, specially with descriptor. Which could potentially cause windows driver confusion. Would you mind provide
I will try to pull out my old windows machine to test with. |
Ok, I'll come up with a minimal example tomorrow. |
Windows 10 Version 21H2 (OS Build 19044.1348). |
Here is the test code. It's based on Follow these instructions to capture driver logs: https://matthewvaneerde.wordpress.com/2017/10/23/how-to-gather-and-read-logs-for-microsofts-usb-audio-2-0-class-driver/ I've left
With
|
thank you for the update, I will test it out as soon as I could, please be patient. |
I feel like we have been working on a similar project...I fought with this a week or 2 ago. The issue is windows actually ignores the speed of the device and checks the bcdUSB field. My solution was to just make a separate function that took in boolean to select the speed. However this approach is probably cleaner. This also causes problems with using the device between Windows and Linux, Linux kernel driver properly uses the format based on device enumeration speed. NOT the bcdUSB field. My very hacky workaround to this was to count sample data for 1000 frames(1 second) and see if we got any deviation from the expected sample rate, If we did we know feedback is working.
|
It's by no means "perfect" but in my test case of every PC/device in my home it seems to get the job done and select the appropriate format. ...except my android phone which just crashes the usb stack heh. |
It is definitely Windows UAC2 driver issue, despite of fullspeed detection, it still mis-interprets as highspeed endpoint
I have tried to alter descriptor here and there, and change the feedback endpoint packet size to 3 following linux uac2 driver https://github.com/torvalds/linux/blob/master/drivers/usb/gadget/function/f_uac2.c#L387 .
I will try a bit more to see which parameter windows uac2sys used to determine device is highspeed endpoint (regardless of actual link speed). If it does not work out, we could use one of above walkaround. attached is full log iso-fb-3bytes.txt PS: Sorry for late response, I am still trying to catch up. |
I agree with @PanRe that @geekbozu walkaround is a better solution since it is more portable and allow device to work with both windows and Linux/macOS. @geekbozu do you have time to make an PR to get this upstream. We could add an comment note to remind us that we could remove or off it out when later windows update e.g win11 fix this issue etc.. |
I should be able to find some time in the next week or so. I need to think of how I would want to bake this into the driver properly. If at at all. I actually wonder if just extending tud_audio_fb_set to take a parameter on which format to convert to. Or adding a function that does no conversion and letting the user handle it is the better choice, With documentation of course |
That would be great
It is also a good approach as well, I think we should also take this chance to name the function more explicitly e.g |
Sorry for the late reply. I am not sure if it is a good idea to make the feedback function so flexible:
How about changing the driver such that there are four compile options:
Incorporate it using common |
I think But to clarify a couple things about original proposal vmilea@ef879e8:
|
Regarding cross-platform: Fixed 16.16 format is currently viable on Windows (10 / 11) and Linux (ALSA driver detects if the feedback rate is out of bounds and switches to the other format automatically). Unfortunately I don't have a Mac to check there as well. |
I originally thought so as well, but as @geekbozu showed we may guess: if the incoming data rate doesn't correlate with feedback rate, than likely the feedback format is wrong. |
@vmilea Well, i would strongly vote for not letting the user (i mean the poor developer) handle this case. IMHO the tinyUSB driver should take care of this matter. This saves the users a lot of time and us a lot of bug reports. Nevertheless, the ALSA driver you mentioned kept me thinking. Against the specifications they check and allow different formats too. I guess to robustify their driver against other UAC drivers which also do not respect the specs. Maybe we should do that too? Since not even Microsoft was capable of implementing the specs corretly, there may be more wrongly implented drivers floating around?! |
Supporting both formats on host driver is trivial (shift feedback value by 2 if it's closer to the nominal rate). On the other side, the client driver can't detect format mismatch directly. So tinyusb would just guesstimate after a number of frames based on data rate. In my experience, these heuristics are tricky to implement and tend to fail in surprising ways. This is why I proposed leaving it out of the library. |
@hathach Have you reported the Windows driver bug? I think there was a Feedback Hub app for that. If not, I'll do it once I'm back from vacation. |
Thank you @PanRe and @vmilea for the feedback
I did a quick check with
Please proceed to file issue on windows feedback hub when you have time, I only run windows on VM when needed to test and not familiar with their driver development. |
yeah I agree with all of your points, we need a dynamic solution that works with all OS windows/linux/macos. I have tested both 16.16 and 10.14 on Linux/MacOS, and it works great on both platforms with both format on Fullspeed device. Apparently they do some feedback correction in the host driver.
To sum up FS 16.16 is universally supported by major OS.
I think these are pretty much the same as @vmilea with correction on/off. Where the SUM UP: we will merge 1235 with macro rename from |
@hathach Thanks for the additional testing. I agree, in practice 16.16 is a better default. |
Let em start with I am all for this. I think its a saner default. All of our examples default to a usb2.0 device even though we are full speed. If linux/mac support FullSpeed USB 2.0 16.16 out of the box. I agree this is a better default as well. |
Yeah, you are right. Since UAC 2.0 (2006) came after USB 2.0 (2000), it is absolutely normal to have fullspeed only to have bcd = 2.0. Since the new default does not correct format, application could just pass 10.14 when using with bcd = 1.1. We surely need to update the comment/document a bit to better explain these scenario. |
So do we want to make a separate PR to allow modifications at runtime to the Feedback value? Or is getting the documentation updated in #1235 enough for everyone? |
your format mismatched detection snippet is awesome, I think we should also put it into the example with explanation (either enabled or commented out). If possible, it is probably better to be a separated PR after #1235. @PanRe do you think having 16.16 as default is reasonable. If yes, we will wrap up #1235 . Of course, this change could be reverted/changed later on if there is issue in practice. |
@hathach yes I think 16.16. as default is the most elegant approach! Thx for testing it on Mac! :)Happy new year everybody btw! ;)
|
Merge #1235 and I can add update one of the examples with a PR adding that snippet above! As it requires more then just copying that code somewhere. The good news is using 16.16 format by default actually removes any custom formatting. So the above snipped can be modified to work properly. (just by sending 10.14 format to the routine) Thanks everyone for the sleuthing as well. This was a tricky one to debug out on my end so its nice getting some help :D |
FYI I opened a feedback request on the hub a when this started for the Windows driver. But no traction yet |
Thanks, I've upvoted and added a few details. |
thanks @vmilea for the update, I was a bit busy, will check that out asap. |
Support disabling feedback format correction #1234
#1235 is merged, I think we are good to close this. Thank you every one for joining the discussion and helping to resolve this. |
Sorry for warming this up, this was an interesting read. We currently have some issues with MacOS, where the kernel complains about "babble" error on the feedback endpoint of our UAC2.0 device. Did anybody else notice a problem like this on MacOS? See the log in our issue here skuep/AIOC#13 (comment) Is it possible that (for some reason) MacOS now wants a 3-byte endpoint packet? |
Hi, long time no see. In short yes, you can find more info in #2328 |
@HiFiPhile: Good to see you're still active on the tinyusb audio part :-) Thanks a ton for the pull request reference. Another rabbit hole to traverse into... :-( |
The Windows driver for USB Audio 2.0 seems to disregard the spec and expects 16.16 format instead of 10.14 on my full-speed device. Interestingly, on Linux the ALSA driver supports either format. So for now I'm calling
tud_audio_n_fb_set(feedback << 2)
to force 16.16 format everywhere. This works but is a bit hacky.Could we have a config flag to disable the format conversion in
tud_audio_n_fb_set()
?The text was updated successfully, but these errors were encountered: