USB Audio Class: Explanation of the feedback sync function

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB Audio Class: Explanation of the feedback sync function

2,435 Views
anton_glukhov
Contributor III

Hello,

I'm working with evkmimxrt1010_dev_audio_speaker_freertos example and would like to understand USB_AudioFeedbackDataUpdate function. It works for 2 channels 16bit audio stream, but I would like to change the number of channels and use 24bit or 32bit instead of 16bit. The general idea of feedback endpoint is clear the same as the format of the provided frame rate from the device to the host. But the implementation of calculation feedbackValue, unfortunately, is not very clear. It would be good if you can share/provide some documentation or short clarification of the ideas behind it.

The second part is the tuning process. Once I adjust this function for my stream rate, how to tune the calculation of feedback rate in the most efficient way? What is the best options here? For example I can track the size of the income packets from the USB audio stream and easily see when host add/remove one packet. Another option is to track the buffer size, but using USB_AudioSpeakerBufferSpaceUsed function. These two marker are very useful, but they don't really help with analyzing if feedback value calculate efficiency.

Thank you!

Best regards,

Anton

Labels (1)
0 Kudos
3 Replies

2,264 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi  Anton:

The USB_AudioFeedbackDataUpdate function is not the right funciton that to modify the number of channels and the bits. this function is used to solve the problem of data unsynchronization that may exist between host and device.

If you need to use the usb device to play the audio with different sampling rate, channels, quantization depth, you can change the settings of descriptor in usb_device_descriptor.c

pastedImage_3.png

These settings can be found in usb_device_descriptor.h and in the form of macros.

In addition, the setting of SAI&EDMA should also make corresponding adjustments. Related functions are in audio_speaker.c

Hope it helps.

Regards

Daniel

0 Kudos

2,264 Views
anton_glukhov
Contributor III

Hi Daniel,

Thank you for the quick response and sorry for a bit confusing question.

The question is not about how to set up the proper amount of channels and bit-depth. I changed it in USB descriptors and adjust the audio buffer. Everything works as expected with a small exception... The synchronization sometimes glitching. What I mean by glitching is with a certain case (for example when I quickly reconnect the device) it loses synchronization and buffer overrun/underrun occurs. That's why the main question is "how exactly this synchronization function works"? What is the logic to calculate and compensate this "unsynchronizations". My goal is to tune it and test it somehow, but there is no description but only source code which is not fully clear.

In other words, I would like to know how:
1. understand the cause of "unsynchronizations"
2. be able to reproduce it
3. tune it and test it again comparing with the previous result
4. debug synchronization feedback

Thank you!

Best regards,

Anton

0 Kudos

2,264 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Anton:

The case you proposed is actually not related to the synchronization function, when you quickly reconnect the device, host will re-enumerate the device and it will not trigger synchronous feedback.

For the four questions you listed:

1. The unsynchronization means unsynchronization for clock. More specific, the speaker play audio with 48k sampling rate,2 channels and 16 bit depth, so every millisecond, the host should send 48*2*2 = 196 bytes data, but the host may have something wrong with the clock, it send 198 bytes every millisecond, and then the device will give host the feedback to make host change it clock and send the correct 196 bytes per millsecond.

2. If you use PC as host, you cannot control the host to send more data, maybe you can try different PCs. Or you can use another RT1010 as Host, change the length of send packet to Max packet size+2, you can easily get the overrun result.

For 3 and 4,  the logic to calculate and compensate the unsynchronization is based on the spec of usb audio, you can refer to the USB audio spec  for more detailed information.

Regards

Daniel

0 Kudos