forked from PAWPAW-Mirror/lib_xua
Doc updates
This commit is contained in:
49
module_usb_audio/usb_buffer/get_adc_counts.c
Normal file
49
module_usb_audio/usb_buffer/get_adc_counts.c
Normal file
@@ -0,0 +1,49 @@
|
||||
extern unsigned int g_curUsbSpeed;
|
||||
#define XUD_SPEED_HS 2
|
||||
|
||||
/* Returns the max and min packet sizes to send back to host for a given sample frequency
|
||||
* See page 13 of USB Audio Device Class Definitions for Audio Data Formats Spec (v2.0)
|
||||
*
|
||||
* Audio samples per frame = INT(sampFreq/frametime); Variation allowed is + 1;
|
||||
*
|
||||
* For HS frame time = 8 * 1000
|
||||
*
|
||||
* so n = INT(SampFreq/8000) | INT (SampFreq/8000) + 1
|
||||
*
|
||||
* In the case where INT(SampFreq/8000) == SampFreq/8000) n may vary between
|
||||
*
|
||||
* INT(SamFreq/8000) - 1 | INT(SampFreq/8000) | INT (SampFreq/8000) + 1
|
||||
*
|
||||
* Note: Assumes HS (i.e. 8 frames per 1ms)
|
||||
*
|
||||
* Examples:
|
||||
* 44100: min: 5 max: 6
|
||||
* 48000: min: 5 max: 7
|
||||
* 96000: min: 11 max: 13
|
||||
* 88200: min: 11 max: 12
|
||||
* 176400: min: 22 max: 23
|
||||
* 192000: min: 23 max: 25
|
||||
*
|
||||
*/
|
||||
void GetADCCounts(unsigned samFreq, int *min, int *mid, int *max)
|
||||
{
|
||||
unsigned frameTime;
|
||||
int usb_speed;
|
||||
usb_speed = g_curUsbSpeed;
|
||||
if (usb_speed == XUD_SPEED_HS)
|
||||
frameTime = 8000;
|
||||
else
|
||||
frameTime = 1000;
|
||||
|
||||
*min = samFreq / frameTime;
|
||||
*max = *min + 1;
|
||||
|
||||
*mid = *min;
|
||||
|
||||
/* Check for INT(SampFreq/8000) == SampFreq/8000 */
|
||||
if((samFreq % frameTime) == 0)
|
||||
{
|
||||
*min -= 1;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user