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