USB Audio 多采样率设计,1.0和2.0是有很大的区别,本章将浅谈两种标准的设计方法。
1.USB Audio 1.0 标准设计:
首先我们先了解一下,Audio 类,一些特殊的描述符,特别注意:0x24 CS_INTERFACE
AC Interface (0x24) 描述符中有如下子类:
AS Interface (0x24) 描述符中有如下子类:
在配置当中,需要注意该接口的种类:C型(控制)接口,S型(音频流)接口,控制型接口通常是音量相关调节使用,音频流型接口可配置采样率等等。所以在配置采样率时,注意当前接口类型 Audio Streaming:
在Audio Streaming 接口描述符子类为Format Type(0x02)的描述符中可配置其采样率:
如下为多采样率配置方法:
------- Audio Streaming Format Type Descriptor --------
bLength : 0x17 (23 bytes)
bDescriptorType : 0x24 (Audio Interface Descriptor)
bDescriptorSubtype : 0x02 (Format Type)
bFormatType : 0x01 (FORMAT_TYPE_I)
bNrChannels : 0x02 (2 channels)
bSubframeSize : 0x02 (2 bytes per subframe)
bBitResolution : 0x10 (16 bits per sample)
bSamFreqType : 0x05 (supports 5 sample frequencies)
tSamFreq[1] : 0x07D00 (32000 Hz)
tSamFreq[2] : 0x0AC44 (44100 Hz)
tSamFreq[3] : 0x0BB80 (48000 Hz)
tSamFreq[4] : 0x15888 (88200 Hz)
tSamFreq[5] : 0x17700 (96000 Hz)
Data (HexDump) : 17 24 02 01 02 02 10 05 00 7D 00 44 AC 00 80 BB
00 88 58 01 00 77 01
2.USB Audio 2.0 标准设计:
在Audio 2.0标准下,Audio Streaming 子类为Format Type(0x02)的描述符,没有了配置采样率的要求,如下仅仅是音频的基本格式:
----- Audio Streaming Format Type Descriptor 2.0 ------
bLength : 0x06 (6 bytes)
bDescriptorType : 0x24 (Audio Interface Descriptor)
bDescriptorSubtype : 0x02 (Format Type)
bFormatType : 0x01 (FORMAT_TYPE_I)
bSubslotSize : 0x04 (4 bytes)
bBitResolution : 0x18 (24 bits)
Data (HexDump) : 06 24 02 01 04 18
Audio 2.0多采样率的实现分两步,一个是定义一个满足最高采样率的端点大小(配置端点描述符size),另外就是在Audio类请求中,通知主机当前接口支持的采样率有哪些。
比如,定义一个端点大小为:1024byte的音频端点
----------------- Endpoint Descriptor -----------------
bLength : 0x07 (7 bytes)
bDescriptorType : 0x05 (Endpoint Descriptor)
bEndpointAddress : 0x01 (Direction=OUT EndpointID=1)
bmAttributes : 0x05 (TransferType=Isochronous SyncType=Asynchronous EndpointType=Data)
wMaxPacketSize : 0x0400
Bits 15..13 : 0x00 (reserved, must be zero)
Bits 12..11 : 0x00 (0 additional transactions per microframe -> allows 1..1024 bytes per packet)
Bits 10..0 : 0x400 (1024 bytes per packet)
bInterval : 0x01 (1 ms)
Data (HexDump) : 07 05 01 05 00 04 01
类请求中实现多采样率,部分代码:
g_composite.audioUnified.freqControlRange.wFreNum = 0x05U, //支持的采样率数量
g_composite.audioUnified.freqControlRange.wPara[0] = 44100U,
g_composite.audioUnified.freqControlRange.wPara[1] = 44100U,
g_composite.audioUnified.freqControlRange.wPara[2] = 0U,
g_composite.audioUnified.freqControlRange.wPara[3] = 48000U,
g_composite.audioUnified.freqControlRange.wPara[4] = 48000U,
g_composite.audioUnified.freqControlRange.wPara[5] = 0U,
g_composite.audioUnified.freqControlRange.wPara[6] = 88200U,
g_composite.audioUnified.freqControlRange.wPara[7] = 88200U,
g_composite.audioUnified.freqControlRange.wPara[8] = 0U,
g_composite.audioUnified.freqControlRange.wPara[9] = 96000U,
g_composite.audioUnified.freqControlRange.wPara[10] = 96000U,
g_composite.audioUnified.freqControlRange.wPara[11] = 0U,
g_composite.audioUnified.freqControlRange.wPara[12] = 192000U,
g_composite.audioUnified.freqControlRange.wPara[13] = 192000U,
g_composite.audioUnified.freqControlRange.wPara[14] = 0U,
。。。。。。
case USB_DEVICE_AUDIO_GET_RANGE_SAM_FREQ_CONTROL:
{
request->buffer = (uint8_t *)&g_composite.audioUnified.freqControlRange;
request->length = sizeof(g_composite.audioUnified.freqControlRange);
}
break;
。。。。。。。
3.多采样率注意事项
实现USB Audio 的多采样率后,还需要注意音频外设的多采样率实现,因为不同采样率主时钟很有可能是不一样的,如:44.1K 主时钟可能为11.2896M 48K主时钟可能采用12.288M。所以USB Audio在切换采样率的时候,音频外设时钟也需要切换。USB Audio 切换采样的时候都会触发相应的类请求和接口请求,可根据接收这些信息,外设也做对应处理就行了。
4.多采样率的支持水平
难道说采样率是可以无限制做到很高的吗?事实并不是这样,Audio 1.0 和 Audio 2.0 采用的USB标准是有区别的,所以支持的带宽是有相应限制的,参考如下: