Can someone explain the function USB_AudioFeedbackDataUpdate in USB speaker example?

cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone explain the function USB_AudioFeedbackDataUpdate in USB speaker example?

77 Views
Contributor I

Hi,

I need to use the USB speaker example for a project and adapt it to our needs. The code works fine but there is one thing I don't understand, the function USB_AudioFeedbackDataUpdate. There is no comment and when I look at the USB specifications, I doesn't seem to be right.

To me, it should be as simple as computing the average number of bytes consumed divided by the number of intervals at which the feedback value is sent (256 in this example) and by the number of channels (2) and bytes per sample (2).

 

avg = (audioSpeakerUsedSpace - audioSpeakerLastUsedSpace) / AUDIO_CALCULATE_Ff_INTERVAL;
avg = avg / (AUDIO_FORMAT_CHANNELS * AUDIO_FORMAT_SIZE);

 


So if we have a sampling rate of 48 kHz, 192 bytes (48 samples * 2 channels * 2 bytes per channels) should be consumed per ms. If we calculate the feedback value every 256 micro frames (1 micro frame / ms for full speed so every 256 ms), the device should have consumed 192 * 256 = 49152 bytes. If more or less bytes were consumed, then the feedback data rate can be adjusted to 48 +/- 1.

1. Did I get it right from what I've written above?

2. Can someone explain the line 851 from audio_speaker.c file in example directory. Why is there a multiplication by 1024?
( originFeedbackValue *= (1024U / AUDIO_CALCULATE_Ff_INTERVAL); )

3. Can someone explain the threshold (s32AudioSpeakerDiffThres) used in this example?

Thanks

Hugo

Labels (1)
0 Kudos
2 Replies

48 Views
Contributor I

Hi Jing,

I still don't understand the threshold calculation implemented in the example but I implemented the simple feedback as I have described in my first post and it seems to work.

Regards,
Hugo

0 Kudos

62 Views
NXP TechSupport
NXP TechSupport

Hi Hugo,

Yes, your calculation is correct. I think this is because the feedback frequency need high precision.  If you divide AUDIO_CALCULATE_Ff_INTERVAL directly. That will lost of accuracy. It multiply 1024 (2^10) first. Then use AUDIO_UPDATE_FEEDBACK_DATA to change data to 10.14 format. The high 10 bit represent integral part. The low 14 bit is fractional part.

 

Regards,

Jing

0 Kudos