User Tools

Site Tools


Sidebar

Go Back

Refresh

You are not allowed to add pages

Direct Link

library:usb:audioclass

USB音频类描述符(Usb Audio Device Descriptor)

1. Standard Audio Control Interface Descriptor

struct usb_ac_interface_descriptor {

  U8      bLength;            /* Size of this descriptor in bytes */
  U8      bDescriptorType;        /* INTERFACE descriptor type */
  U8      bInterfaceNumber;   /* Number of the interface (0 based) */
  U8      bAlternateSetting;
  U8      bNumEndpoints;      /* Number of endpoints in this interface */
  U8      bInterfaceClass;    /* AUDIO Interface class code */
  U8      bInterfaceSubclass; /* AUDIO_STREAMING Interface subclass code */
  U8      bInterfaceProtocol; /* IP_VERSION_02_00 Interface protocol code */
  U8      iInterface;         /* String descriptor of this Interface */

};

bLength = 0x09; struct size,固定0x09; bDescriptorType = 0x04; 表明此数据是Interface描述符; bInterfaceClass = 0x01; 说明这是一个Audio device; bInterfaceSubclass = 0x01; 说明这是一个audio control interface; 0x02 是audio streaming interface; 0x03 是midi streaming interface; bInterfaceNumber : 同配置的Interface index,以0开始; bAlternateSetting: 可替换的Interface index; bNumEndpoints: 除0端点外,此Interface所使用的端点数量,如果有可替换的端点,则为1,否则是0; bInterfaceProtocol: 未使用,必须设为0; iInterface: 如果有字符串描述符,则描述此Interface的字符串描述符索引。

2. Class-Specific Audio Control Interface Header Descriptor

struct usb_ac_cs_interface_descriptor {

  U8 bLength; /*Size of this descriptor, in bytes: 8+n*/
  U8 bDescriptorType; /*CS_INTERFACE descriptor type*/
  U8 bDescriptorSubtype; /*HEADER descriptor subtype.*/
  U16 bcdADC; /*Audio Device Class Specification Release
              Number in Binary-Coded Decimal.*/
  U16 wTotalLength; /*Total number of bytes returned for the
                    class-specific AudioControl interface
                    descriptor. Includes the combined length
                    of this descriptor header and all Unit and
                    Terminal descriptors.*/
  U8 bInCollection; /*The number of AudioStreaming and
                    MIDIStreaming interfaces in the Audio
                    Interface Collection to which this
                    AudioControl interface belongs: n*/
  U8 *baInterfaceNr; /*Interface number of the first
                      AudioStreaming or MIDIStreaming
                      interface in the Collection.*/

};

bLength = 8+n; bDescriptor = 0x24; 说明这是一个class-specific audio device interface, 注意,不一定是Audio Control interface, 也可能是Audio Streaming interface; 如果是 Audio Streaming interface,则bLength=0x07; bDescriptorSubtype = 0x01; 说明这是head descriptor; bcdADC: BCD编码的class specification Release编号,即版本号,如果是0x100,就是1.00版,0x200,就是2.00版; wTotalLength: 包含Header和所有Unit, Terminal的总和的length; bInCollection:此Audio Control Interface所拥有的Audio Streaming和Audio MidiStreaming的interface集合数量;即bLength = 8+n 中的n baInterfaceNr: Audio Streaming 和MidiStreaming在集合中的索引值;

3. Input Terminal Descriptor

struct usb_input_terminal_descriptor {

  U8 bLength; /*Size of this descriptor, in bytes: 12*/
  U8 bDescriptorType; /*CS_INTERFACE descriptor type.*/
  U8 bDescriptorSubtype; /*INPUT_TERMINAL descriptor subtype.*/
  U8 bTermialID; /*Constant uniquely identifying the
                  Terminal within the audio function. This
                  value is used in all requests to address
                  this Terminal.*/
  U16 wTerminalType; /*Constant characterizing the type of
                      Terminal. See USB Audio Terminal
                      Types.*/
  U8 bAssocTerminal; /*ID of the Output Terminal to which this
                      Input Terminal is associated.*/
  U8 bNrChannels; /*Number of logical output channels in the
                  Terminal’s output audio channel cluster.*/
  U16 wChannelConfig; /*Describes the spatial location of the
                      logical channels.*/
  U8 iChannelNames; /*Index of a string descriptor, describing
                      the name of the first logical channel.*/
  U8 iTerminal; /*Index of a string descriptor, describing
                  the Input Terminal.*/

}

bLength = 12; bDescriptorType = 0x24; 说明这是 class-specific interface; bDescriptorSubtype = 0x02;说明这是 input terminal descriptor; bTerminalID: Terminal ID, 值唯一; wTerminalType: USB streaming (0x101), ……; bAssocTerminal: 与之相关联的output terminal ID,如果为0,则表示此值未使用; bNrChannels: 逻辑输出声道数; wChannelConfig: Describes the spatial location of the logical channels; iChannelNames: logical channel string index; iTerminal: string index;

4. Output Terminal Descriptor

struct usb_output_terminal_descriptor{

  U8 bLength; /*Size of this descriptor, in bytes: 9*/
  U8 bDescriptorType; /*CS_INTERFACE descriptor type.*/
  U8 bDescriptorSubtype; /*OUTPUT_TERMINAL descriptor subtype.*/
  U8 bTerminalID; /*Constant uniquely identifying the
                  Terminal within the audio function. This
                  value is used in all requests to address
                  this Terminal.*/
  U16 wTerminalType; /*Constant characterizing the type of
                      Terminal. See USB Audio Terminal
                      Types.*/
  U8 bAssocTerminal; /*Constant, identifying the Input Terminal
                      to which this Output Terminal is
                      associated.*/
  U8 bSourceID; /*ID of the Unit or Terminal to which this
                  Terminal is connected.*/
  U8 iTerminal; /*Index of a string descriptor, describing
                  the Output Terminal.*/

}; bLength = 0x09; bDescriptorType = 0x24; 说明这是CS_INTERFACE; bDescriptorSubtype = 0x03; 说明这是 output terminal; bTerminalID: terminal ID,值唯一; wTerminalType: Terminal类型,Speaker(0x301), Headphones(0x302), Head Mounted Display Audio(0x303), Desktop speaker(0x304), Room speaker(0x305), Communication speaker(0x306), Low frequency effects speaker(0x307), USB streaming(0x101); bAssocTerminal: 相关的input terminal ID,0代表此值未使用; bSourceID: 与此Terminal相连接的Unit, Terminal 的 ID,需要在Input Terminal, Feature Unit…中查找; iTerminal: string index

5. Feature Unit Descriptor

偏移量 字段名称 长度(字节) 字段值 意义
0 bLength 1 0x07 端点描述符的字节数大小
1 bDescriptorType 1 0x05 端点描述符类型编号
2 bEndpointAddress 1 端点 端点地址及输入输出属性
3 bmAttributes 1 位图 端点的传输类型属性
4 wMaxPacketSize 2 数字 端点收、发的最大包的大小
6 bInterval 1 数字 主机查询端点的时间间隔

struct usb_feature_unit_descriptor {

  U8 bLength; /*Size of this descriptor, in bytes:
              7+(ch+1)*n*/
  U8 bDescriptorType; /*CS_INTERFACE descriptor type.*/
  U8 bDescriptorSubtype; /*FEATURE_UNIT descriptor subtype.*/
  U8 bUnitID; /*Constant uniquely identifying the Unit
              within the audio function. This value is
              used in all requests to address this Unit.*/
  U8 bSourceID; /*ID of the Unit or Terminal to which this
                  Feature Unit is connected.*/
  U8 bControlSize; /*Size in bytes of an element of the
                      bmaControls() array: n*/
  U8 *bmaControls; /* bmaControls+ 0 means A bit set to 1 indicates that the mentioned
                      Control is supported for master channel
                      0:
                      D0: Mute
                      D1: Volume
                      D2: Bass
                      D3: Mid
                      D4: Treble
                      D5: Graphic Equalizer
                      D6: Automatic Gain
                      D7: Delay
                      D8: Bass Boost
                      D9: Loudness
                      D10..(n*8-1): Reserved
                      (bmaControls + n) means A bit set to 1 indicates that the mentioned
                      Control is supported for logical channel ch.*/
  U8 iFeature; /*Index of a string descriptor, describing
              this Feature Unit.*/

}; bLength = 7+(ch+1)*n; bDescriptorType = 0x24; 说明是 class-specific interface; bUnitID: Unit ID, 值唯一; bSourceID: 与之相连的Unit, Terminal ID; bControlSize: bLength中的n值,即一个bmaControls的size; bmaControls[0]: master channel 0 的 control, D0: Mute D1: Volume D2: Bass D3: Mid D4: Treble D5: Graphic Equalizer D6: Automatic Gain D7: Delay D8: Bass Boost D9: Loudness D10..(n*8-1): Reserved; bmaControls[1]: logical channel 1 的control ; …… bmaControls[ch]: logical channel ch的control; iFeature: string index;

6. Class-Specific Audio Streaming Interface Descriptor

struct usb_as_cs_interface_descriptor {

  U8 bLength; /*Size of this descriptor in bytes: 7 */
  U8 bDescriptorType; /*CS_INTERFACE descriptor type.*/
  U8 bDescriptorSubtype; /*GENERAL_SUB_TYPE descriptor subtype.*/
  U8 bTerminalLink; /*The Terminal ID of the Terminal to which
                    the endpoint of this interface is
                    connected.*/
  U8 bDelay; /*Delay (d) introduced by the data path
             (see Section 3.4, “Inter Channel
             Synchronization”). Expressed in number
             of frames.*/
  U16 wFormatTag; /*The Audio Data Format that has to be
                  used to communicate with this interface.*/

}; bLength = 0x07; bDescriptorType = 0x24; 说明是CS_INTERFACE; bDescriptorSubtype = 0x01; 说明是 AS_GENERAL; bTerminalLink: 此interface所连接的endpoint的terminalID,可以通过这个值找到Terminal; bDelay: wFormatTag: 数据格式 FORMAT_TYPE_UNDEFINED 0X00 FORMAT_TYPE_I 0X01 FORMAT_TYPE_II 0X02 FORMAT_TYPE_III 0X03 Format type I支持pcm, pcm8, IEE_FLOAT, ALAW, MULAW; Format type II支持 mpeg, AC-3 Format type III 支持 IEC1937_AC-3, IEC1937_MPEG-1_Layer1, IEC1937_MPEG-1_Layer2/3 / IEC1937_MPEG-2_NOEXT, IEC1937_MPEG-2_EXT, IEC1937_MPEG-2_Layer1_LS, IEC1937_MPEG-2_Layer2/3_LS

7. Standard AS Interface Descriptor

struct usb_as_interface_descriptor {

  U8      bLength;            /* Size of this descriptor in bytes */
  U8      bDescriptorType;        /* INTERFACE descriptor type */
  U8      bInterfaceNumber;   /* Number of interface. A zero-based value

identifying the index in the array of concurrent interfaces supported by this configuration. */

  U8      bAlternateSetting; /*Value used to select an alternate setting

for the interface identified in the prior field.*/

  U8      bNumEndpoints;      /* Number of endpoints in this interface */
  U8      bInterfaceClass;    /* AUDIO Interface class code */
  U8      bInterfaceSubclass; /* AUDIO_STREAMING Interface subclass code */
  U8      bInterfaceProtocol; /* Not used. Must be set to 0. */
  U8      iInterface;         /* Index of a string descriptor that describes

this interface. */ }; bLength = 0x09; bDescriptorType = 0x04; 说明这是一个Interface descriptor; bInterfaceNumber: 此配置所支持的Interface index; bAlternateSetting: 可变更的Interface; bNumEndpoints: 除了endpoint0, 此interface使用的endpoint; bInterfaceClass = 0x01; 说明是 Audio interface class; bInterfaceSubClass = 0x02; 说明是 audio streaming intertface class; bInterfaceProtocol: 未使用,强制设为0; iInterface: 如果有string descriptor, 则此值是 string 的 index;

8. Type I Format Type Descriptor

struct usb_format_type_1 {

  U8 bLength; /*Size of this descriptor, in bytes: 8+(ns*3)*/
  U8 bDescriptorType; /*CS_INTERFACE descriptor type*/
  U8 bDescriptorSubtype; /*FORMAT_TYPE descriptor subtype.*/
  U8 bFormatType; /*FORMAT_TYPE_I. Constant identifying
                  the Format Type the AudioStreaming
                  interface is using.*/
  U8 bNrChannels; /*Indicates the number of physical
                  channels in the audio data stream.*/
  U8 bSubframeSize; /*The number of bytes occupied by one
                      audio subframe. Can be 1, 2, 3 or 4.*/
  U8 bBitResolution; /*The number of effectively used bits from
                      the available bits in an audio subframe.*/
  U8 bSamFreqType; /*Indicates how the sampling frequency
                  can be programmed:
                  0: Continuous sampling frequency
                  1..255: The number of discrete sampling
                  frequencies supported by the
                  isochronous data endpoint of the
                  AudioStreaming interface (ns)*/
  U8 tLowerSamFreq[3]; /*Lower bound in Hz of the sampling
                      frequency range for this isochronous data
                      endpoint.*/
  U8 tUpperSamFreq[3]; /*Upper bound in Hz of the sampling
                      frequency range for this isochronous data
                      endpoint.*/

};

bLength = 8+(ns*3); 当为continous frequecy 时, ns = 2; bDescriptorType = 0x24; class-specific interface; bDescriptorSubtype = 0x02; 同input terminal→bDescriptorSubtype, 此时要通过bLength来区别,input terminal→bLength = 12; bFormatType = 0x01; FORMAT_TYPE_I; bNrChannels: audio streaming 物理声道数; bSubframeSize: 对于一个subframe, 需要多少bytes; bBitResolution: bit resolution,即多少位的pcm数据; bSamFreqType: 0 表示 continuous sampling frequecy; 1…ns(max=255)表示离散的sampling freqency; tLowSamFreq/tUpperSamFreq: Sampling Frequency的高低位;

9. Standard Audio Streaming Isochronous Audio Data Endpoint Descriptor

struct usb_standard_as_isochronous_endpoint_descriptor {

  U8 bLength; /*Size of this descriptor, in bytes : 9*/
  U8 bDescriptorType; /*ENDPOINT descriptor type*/
  U8 bEndpointAddress; /*The address of the endpoint on the USB
                          device described by this descriptor. The
                          address is encoded as follows:
                          D7: Direction.
                          0 = OUT endpoint
                          1 = IN endpoint
                          D6..4: Reserved, reset to zero
                          D3..0: The endpoint number,
                          determined by the designer.*/
  U8 bmAttributes; /*D3..2: Synchronization type
                  01 = Asynchronous
                  10 = Adaptive
                  11 = Synchronous
                  D1..0: Transfer type
                  01 = Isochronous
                  All other bits are reserved.*/
  U16 wMaxPacketSize; /*Maximum packet size this endpoint is
                      capable of sending or receiving when this
                      configuration is selected.
                      This is determined by the audio
                      bandwidth constraints of the endpoint.*/
  U8 bInterval; /*Interval for polling endpoint for data
                  transfers expressed in milliseconds.
                  Must be set to 1.*/
  U8 bRefresh; /*Reset to 0.*/
  U8 bSynchAddress; /*The address of the endpoint used to
                      communicate synchronization information
                      if required by this endpoint. Reset to zero
                      if no synchronization pipe is used.*/

};

bLength = 0x09; bDescriptorType = 0x05; endpoint descriptor; bEndpointAddress: 含义如下 D7: Direction. 0 = OUT endpoint 1 = IN endpoint D6..4: Reserved, reset to zero D3..0: The endpoint number, determined by the designer. bmAttributes: 含义如下 D3..2: 同步类型 01 = Asynchronous 10 = Adaptive 11 = Synchronous D1..0: 传输类型 01 = Isochronous wMaxPacketSize: max packet size, 由带宽决定; bInterval: 数据传输所需时间,单位milliseconds; bRefresh = 0; 未使用; bSynchAddress: 如果用此endpoint进行同步信息交互,则使用此地址,=0则不使用同步信息。

对于Standard Audio Streaming Isochronous Synch Endpoint Descriptor, 结构与此相同,但含义略有不同,不同点如下: bmAttributes: D3..2: Synchronization type 00 = None D1..0: Transfer type 01 = Isochronous bInterval = 1; 未使用,必须为1; bRefresh: 同步管道提供新的同步feedback数据时的速率,必须是2的幂次方,范围是1(2ms)~9(512ms); bSynchAddress = 0; 未使用;

10. Hid Device

struct usb_standard_interface_descriptor {

  U8 bLength; /*Size of this descriptor in bytes*/
  U8 bDescriptorType; /*INTERFACE Descriptor Type*/
  U8 bInterfaceNumber; /*Number of this interface. Zero-based
                      value identifying the index in the array of
                      concurrent interfaces supported by this
                      configuration.*/
  U8 bAlternateSetting; /*Value used to select this alternate setting
                      for the interface identified in the prior field*/
  U8 bNumEndpoints; /*Number of endpoints used by this
                      interface (excluding endpoint zero). If this
                      value is zero, this interface only uses the
                      Default Control Pipe.*/
  U8 bInterfaceClass; /*Class code (assigned by the USB-IF).
                          A value of zero is reserved for future
                          standardization.
                          If this field is set to FFH, the interface
                          class is vendor-specific.
                          All other values are reserved for
                          assignment by the USB-IF.*/
  U8 bInterfaceSubClass; /* **Hid = 0x03** */
                         /*Subclass code (assigned by the USB-IF).
                          These codes are qualified by the value of
                          the bInterfaceClass field.
                          If the bInterfaceClass field is reset to zero,
                          this field must also be reset to zero.
                          If the bInterfaceClass field is not set to
                          FFH, all values are reserved for
                          assignment by the USB-IF.*/
  U8 bInterfaceProtocol; /*Protocol code (assigned by the USB).
                          These codes are qualified by the value of
                          the bInterfaceClass and the
                          bInterfaceSubClass fields. If an interface
                          supports class-specific requests, this code
                          identifies the protocols that the device
                          uses as defined by the specification of the
                          device class.
                          If this field is reset to zero, the device
                          does not use a class-specific protocol on
                          this interface.
                          If this field is set to FFH, the device uses
                          a vendor-specific protocol for this
                          interface.*/
  U8 iInterface; /*Index of string descriptor describing this
                  interface*/

};

在Standard Interface Descriptor后面,会跟着 Hid Descriptor, 如下:

struct hid_descriptor{

  U8 bLength; /*Numeric expression that is the total size of the

HID descriptor.*/

  U8 bDescriptoryType; /*Constant name specifying type of HID

descriptor. USB_DESCRIPTOR_TYPE_INTERFACE = 0x04*/

  U16 bcdHID; /*Numeric expression identifying the HID Class

Specification release.*/

  U8 bCountryCode; /*Numeric expression identifying country code of

the localized hardware.*/

  U8 bNumDescriptor; /*Numeric expression specifying the number of

class descriptors (always at least one i.e. Report descriptor.)*/

  U8 bDescriptorType; /*Constant name identifying type of class

descriptor. See Section 7.1.2: Set_Descriptor Request for a table of class descriptor constants.*/

  U16 wDescriptorLength; /*Numeric expression that is the total size of the

Report descriptor.*/ U8 [bDescriptorType]; /*Constant name specifying type of optional descriptor.*/

  U16 [wDescriptorLength]; /*Numeric expression that is the total size of the

optional descriptor.*/ };

在Standard Interface Descriptor之后可以有Report Descriptor和Physical Descriptor。如图

Physicial Descriptor可选,一般没有,此时bNumDescriptor=1, 并且没有[bDescriptorType]和[wDescriptorLength]。

Report Descriptor没有固定的结构,它的最小单位是Item。从长度分类,Item分为两类,长item和短item。从功能分,Item分为3类Main item, Gobal item和Local item。大部分item都是短item,短Item的第一个字节含有item信息,如下图:

bTag占4bit, bType占2bit,bSize占2bit。由于bSize只有2bit,所以短item的长度只能为0(00),1(01),2(10),4(11),注意:size没有3。 根据第一个字节的信息,Main Item又分为Input, output, feature, collection, end collection; Gobal item又分为Usage Page, logical Minimum, logical Maximum, physical Minimum, physical maximum, Unit Exponent, Unit, Report Size, Report ID, Report Count, Push, Pop; Local Item又分为Usage, Usage Minimum, usage maximum, designator index, designator minimum, designator maximum, string index, string minimum, string maximum, delimiter; 下表为bTag值:

main item bType = 00; global item bType = 01; local item bType = 10; 当main item识别出来时,即后面的数据是一个新的item, 所有的local item数据将被清除,gobal item数据不变。一个report可以包含许多main item。

11. TYPE I描述符(FORMAT_TYPE descriptor)

TYPE I主要针对于音频数据流是按照物理时序以采样为单位的数据格式,每一个采样点由一个数据表示,而最终的音频信号是将这些连续发送的采样数据进行DA转换后得到的波形。在此类型中,使用某些压缩算法并不改变其格式类型,只要该压缩算法不影响数据以样本为单位的基本格式,例如G.711语音编码算法。在TYPE I格式下如果需要传送多个声道的数据,不同声道的数据是交叉传送的。因此,要从TYPE I中恢复多声道数据,只需要将每个簇(Cluster)中依次提取出各个声道的采样值并分别恢复即可,因此,TYPE I在传送过程中,保存了每个声道的独立性,恢复非常方便。典型的TYPE I信号就是标准的PCM码。

Offset Field Size SizeValue Comment
0 bLength 1 Number 0x0B
1 bDescriptorType 1 Constant
2 bDescriptorSubtype 1 Constant
3 bFormatType 1 Constant Type-I(0x01)
4 bNrChannels 1 Number Number of Channel
5 bSubframeSize 1 Number Subframe Size
6 bBitResolution 1 Number
7 bSamFreqType 1 Number
8 tSamFreq 3 Number Sample Rate
bLength=8+(ns*3)
公式中,8为固定字段长度,ns代表该接口的端点支持的不同采样率数量。每种采样率需用3个字节表示。即单一采样率时,描述符总长度为11(8+3),两种采样率时描述符总长度为14(8+3x2).

bDescriptorType 表示该描述符种类为音频类特有的接口

bDescriptorSubtype 表示该描述符为数据格式描述符

bFormatType 指定该接口具体数据格式

bNrChannels 表示该接口支持的物理声道数

bSubframeSize 音频子帧大小

bBitResolution 指定采样量化比特数

bSamFreqType 指定该接口支持频率类型,可选为连续和固定两种

最后一个字段由bSamFreqType决定,目前,采用单一采样率,只需要填入以24位二进制数表示的具体采样率值即可,可选范围为0到16777215Hz。
    //Type 1 Format type descriptor:FORMAT_TYPE(0x02),FORMAT_TYPE_I(0x01),
    //physical channels 0x02,two byte per audio subframe(0x02),16bit,
    //32K(0x007d00)
    0x0b,    //Length                                  
    0x24,    //DescriptorType:audio interface descriptor
    0x02,    //DescriptorSubType:Format_type           
    0x01,    //FormatType:Format type 1                
    0x02,    //NumberOfChanne:2                        
    0x02,    //SubframeSize:2byte                      
    0x10,    //BitsResolution:16bit                    
    0x01,    //SampleFreqType:One sampling frequency.   
    0x00,
    0x7d,
    0x00,    //32K(0x007d00)   

http://makaidong.com/heiyue/279451_1108963.html USB音频类描述符及其说明

Generic Input Terminal Descriptor


wChannelConfig
D0: Left Front (L)
D1: Right Front (R)
D2: Center Front (C)
D3: Low Frequency Enhancement (LFE)
D4: Left Surround (LS)
D5: Right Surround (RS)
D6: Left of Center (LC)
D7: Right of Center (RC)
D8: Surround (S)
D9: Side Left (SL)
D10: Side Right (SR)
D11: Top (T)
D15..12: Reserved
library/usb/audioclass.txt · Last modified: 2022/05/02 00:32 (external edit)