SonaBen
SonaBen

Reputation: 21

USB Audio descriptor for Teensy board

I'm trying to update the Teensy 4 code to increase the number of output channels for the USB audio interface that only supports 2 at the moment. My first mission is to update the Audio descriptors (under #ifdef AUDIO_INTERFACE at https://github.com/PaulStoffregen/cores/blob/master/teensy4/usb_desc.c).

#ifdef AUDIO_INTERFACE
    // configuration for 480 Mbit/sec speed
        // interface association descriptor, USB ECN, Table 9-Z
        8,                                      // bLength
        11,                                     // bDescriptorType
        AUDIO_INTERFACE,                        // bFirstInterface
        3,                                      // bInterfaceCount
        0x01,                                   // bFunctionClass
        0x01,                                   // bFunctionSubClass
        0x00,                                   // bFunctionProtocol
        0,                                      // iFunction
         .......................

However I'm trying to understand why there are so many elements to the audio interface, and I get some issues when updating the number of channels, some softwares seem to understand the descriptor, but others not.

I posted in the Teensy forum but the main developer hasn't got time to explain unfortunately:

[https://forum.pjrc.com/threads/71104-USB-AUDIO_INTERFACE-explanations-please!]

The usb.org documentation should help but is not easy to digest at all...

[https://www.usb.org/sites/default/files/audio10.pdf]

I would really like to be able to understand the main logic behind the descriptors, why we have 3 interfaces, so many elements that seem duplicated and how each element relates to each interface.

I have compared with other similar audio interfaces with a USB descriptor dumper and they are much simpler in general.

Any help to put me in the right direction will be much appreciated thanks!

Here's a dump of the descriptor, why does Windows play fine but not VLC?:

------------------------------
Connection Information:
------------------------------
Device current bus speed: HighSpeed
Device supports USB 1.1 specification
Device supports USB 2.0 specification
Device address: 0x003D
Current configuration value: 0x01
Number of open pipes: 2


------------------------------
Device Descriptor:
------------------------------
0x12    bLength
0x01    bDescriptorType
0x0200  bcdUSB
0x00    bDeviceClass      
0x00    bDeviceSubClass   
0x00    bDeviceProtocol   
0x40    bMaxPacketSize0   (64 bytes)
0x16C0  idVendor
0x04D2  idProduct
0x0279  bcdDevice
0x01    iManufacturer
0x02    iProduct     
0x03    iSerialNumber
0x01    bNumConfigurations

Device Qualifier Descriptor:
------------------------------
0x0A    bLength
0x06    bDescriptorType
0x0200  bcdUSB
0x00    bDeviceClass      
0x00    bDeviceSubClass   
0x00    bDeviceProtocol   
0x40    bMaxPacketSize0   (64 bytes)
0x01    bNumConfigurations 
0x00    bReserved 


-------------------------
Configuration Descriptor:
-------------------------
0x09    bLength
0x02    bDescriptorType
0x00E9  wTotalLength   (233 bytes)
0x04    bNumInterfaces
0x01    bConfigurationValue
0x00    iConfiguration
0xC0    bmAttributes   (Self-powered Device)
0x32    bMaxPower      (100 mA)

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x00    bInterfaceNumber
0x00    bAlternateSetting
0x02    bNumEndPoints
0x03    bInterfaceClass      (Human Interface Device Class)
0x00    bInterfaceSubClass   
0x00    bInterfaceProtocol   
0x00    iInterface

HID Descriptor:
------------------------------
0x09    bLength
0x21    bDescriptorType
0x0111  bcdHID
0x00    bCountryCode
0x01    bNumDescriptors
0x22    bDescriptorType   (Report descriptor)
0x0021  bDescriptorLength

Endpoint Descriptor:
------------------------------
0x07    bLength
0x05    bDescriptorType
0x82    bEndpointAddress  (IN endpoint 2)
0x03    bmAttributes      (Transfer: Interrupt / Synch: None / Usage: Data)
0x0040  wMaxPacketSize    (1 x 64 bytes)
0x01    bInterval         (1 microframes)

Endpoint Descriptor:
------------------------------
0x07    bLength
0x05    bDescriptorType
0x02    bEndpointAddress  (OUT endpoint 2)
0x03    bmAttributes      (Transfer: Interrupt / Synch: None / Usage: Data)
0x0020  wMaxPacketSize    (1 x 32 bytes)
0x02    bInterval         (2 microframes)

Interface Association Descriptor:
------------------------------
0x08    bLength
0x0B    bDescriptorType
0x01    bFirstInterface
0x03    bInterfaceCount
0x01    bFunctionClass      (Audio Device Class)
0x01    bFunctionSubClass   (Audio Control Interface)
0x00    bFunctionProtocol   (Audio Protocol undefined)
0x00    iFunction

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x01    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x01    bInterfaceSubClass   (Audio Control Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

AC Interface Header Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x0100  bcdADC
0x003E  wTotalLength   (62 bytes)
0x02    bInCollection
0x02    baInterfaceNr(1)
0x03    baInterfaceNr(2)

AC Input Terminal Descriptor:
------------------------------
0x0C    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bTerminalID
0x0602  wTerminalType   (Digital audio interface)
0x00    bAssocTerminal
0x02    bNrChannels   (2 channels)
0x0003  wChannelConfig
0x00    iChannelNames
0x00    iTerminal

AC Output Terminal Descriptor:
------------------------------
0x09    bLength
0x24    bDescriptorType
0x03    bDescriptorSubtype
0x02    bTerminalID
0x0101  wTerminalType   (USB Streaming)
0x00    bAssocTerminal
0x01    bSourceID
0x00    iTerminal

AC Input Terminal Descriptor:
------------------------------
0x0C    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x03    bTerminalID
0x0101  wTerminalType   (USB Streaming)
0x00    bAssocTerminal
0x02    bNrChannels   (2 channels)
0x0003  wChannelConfig
0x00    iChannelNames
0x00    iTerminal

AC Feature Unit Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x06    bDescriptorSubtype
0x31    bUnitID
0x03    bSourceID
0x01    bControlSize
bmaControls: 
 0x01   Channel(0) - Mute
 0x02   Channel(1) - Volume
 0x02   Channel(2) - Volume
0x00    iFeature


AC Output Terminal Descriptor:
------------------------------
0x09    bLength
0x24    bDescriptorType
0x03    bDescriptorSubtype
0x04    bTerminalID
0x0602  wTerminalType   (Digital audio interface)
0x00    bAssocTerminal
0x31    bSourceID
0x00    iTerminal

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x02    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x02    bInterfaceNumber
0x01    bAlternateSetting
0x01    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

AS Interface Descriptor:
------------------------------
0x07    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x02    bTerminalLink
0x03    bDelay
0x0001  wFormatTag   (PCM)

AS Format Type 1 Descriptor:
------------------------------
0x0B    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bFormatType   (FORMAT_TYPE_1)
0x02    bNrChannels   (2 channels)
0x02    bSubframeSize
0x10    bBitResolution   (16 bits per sample)
0x01    bSamFreqType   (Discrete sampling frequencies)
0x00AC44    tSamFreq(1)   (44100 Hz)

Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x83    bEndpointAddress  (IN endpoint 3)
0x09    bmAttributes      (Transfer: Isochronous / Synch: Adaptive / Usage: Data)
0x0168  wMaxPacketSize    (1 x 360 bytes)
0x04    bInterval         (8 microframes)
0x00    bRefresh
0x00    bSynchAddress

AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07    bLength
0x25    bDescriptorType
0x01    bDescriptorSubtype
0x00    bmAttributes
0x00    bLockDelayUnits   (undefined)
0x0000  wLockDelay

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x03    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x03    bInterfaceNumber
0x01    bAlternateSetting
0x02    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

AS Interface Descriptor:
------------------------------
0x07    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x03    bTerminalLink
0x03    bDelay
0x0001  wFormatTag   (PCM)

AS Format Type 1 Descriptor:
------------------------------
0x0B    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bFormatType   (FORMAT_TYPE_1)
0x04    bNrChannels   (4 channels)
0x02    bSubframeSize
0x10    bBitResolution   (16 bits per sample)
0x01    bSamFreqType   (Discrete sampling frequencies)
0x00AC44    tSamFreq(1)   (44100 Hz)

Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x03    bEndpointAddress  (OUT endpoint 3)
0x05    bmAttributes      (Transfer: Isochronous / Synch: Asynchronous / Usage: Data)
0x02D0  wMaxPacketSize    (1 x 720 bytes)
0x04    bInterval         (8 microframes)
0x00    bRefresh
0x84    bSynchAddress

AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07    bLength
0x25    bDescriptorType
0x01    bDescriptorSubtype
0x00    bmAttributes
0x00    bLockDelayUnits   (undefined)
0x0000  wLockDelay

Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x84    bEndpointAddress  (IN endpoint 4)
0x11    bmAttributes      (Transfer: Isochronous / Synch: None / Usage: Feedback)
0x0004  wMaxPacketSize    (1 x 4 bytes)
0x04    bInterval         (8 microframes)
0x07    bRefresh
0x00    bSynchAddress


-------------------------------------
Other Speed Configuration Descriptor:
-------------------------------------
0x09    bLength
0x07    bDescriptorType
0x00E9  wTotalLength   (233 bytes)
0x04    bNumInterfaces
0x01    bConfigurationValue
0x00    iConfiguration
0xC0    bmAttributes   (Self-powered Device)
0x32    bMaxPower      (100 mA)

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x00    bInterfaceNumber
0x00    bAlternateSetting
0x02    bNumEndPoints
0x03    bInterfaceClass      (Human Interface Device Class)
0x00    bInterfaceSubClass   
0x00    bInterfaceProtocol   
0x00    iInterface

HID Descriptor:
------------------------------
0x09    bLength
0x21    bDescriptorType
0x0111  bcdHID
0x00    bCountryCode
0x01    bNumDescriptors
0x22    bDescriptorType   (Report descriptor)
0x0021  bDescriptorLength

Endpoint Descriptor:
------------------------------
0x07    bLength
0x05    bDescriptorType
0x82    bEndpointAddress  (IN endpoint 2)
0x03    bmAttributes      (Transfer: Interrupt / Synch: None / Usage: Data)
0x0040  wMaxPacketSize    (1 x 64 bytes)
0x01    bInterval         (1 frames)

Endpoint Descriptor:
------------------------------
0x07    bLength
0x05    bDescriptorType
0x02    bEndpointAddress  (OUT endpoint 2)
0x03    bmAttributes      (Transfer: Interrupt / Synch: None / Usage: Data)
0x0020  wMaxPacketSize    (1 x 32 bytes)
0x02    bInterval         (2 frames)

Interface Association Descriptor:
------------------------------
0x08    bLength
0x0B    bDescriptorType
0x01    bFirstInterface
0x03    bInterfaceCount
0x01    bFunctionClass      (Audio Device Class)
0x01    bFunctionSubClass   (Audio Control Interface)
0x00    bFunctionProtocol   (Audio Protocol undefined)
0x00    iFunction

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x01    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x01    bInterfaceSubClass   (Audio Control Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

AC Interface Header Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x0100  bcdADC
0x003E  wTotalLength   (62 bytes)
0x02    bInCollection
0x02    baInterfaceNr(1)
0x03    baInterfaceNr(2)

AC Input Terminal Descriptor:
------------------------------
0x0C    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bTerminalID
0x0602  wTerminalType   (Digital audio interface)
0x00    bAssocTerminal
0x02    bNrChannels   (2 channels)
0x0003  wChannelConfig
0x00    iChannelNames
0x00    iTerminal

AC Output Terminal Descriptor:
------------------------------
0x09    bLength
0x24    bDescriptorType
0x03    bDescriptorSubtype
0x02    bTerminalID
0x0101  wTerminalType   (USB Streaming)
0x00    bAssocTerminal
0x01    bSourceID
0x00    iTerminal

AC Input Terminal Descriptor:
------------------------------
0x0C    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x03    bTerminalID
0x0101  wTerminalType   (USB Streaming)
0x00    bAssocTerminal
0x02    bNrChannels   (2 channels)
0x0003  wChannelConfig
0x00    iChannelNames
0x00    iTerminal

AC Feature Unit Descriptor:
------------------------------
0x0A    bLength
0x24    bDescriptorType
0x06    bDescriptorSubtype
0x31    bUnitID
0x03    bSourceID
0x01    bControlSize
bmaControls: 
 0x01   Channel(0) - Mute
 0x02   Channel(1) - Volume
 0x02   Channel(2) - Volume
0x00    iFeature


AC Output Terminal Descriptor:
------------------------------
0x09    bLength
0x24    bDescriptorType
0x03    bDescriptorSubtype
0x04    bTerminalID
0x0602  wTerminalType   (Digital audio interface)
0x00    bAssocTerminal
0x31    bSourceID
0x00    iTerminal

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x02    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x02    bInterfaceNumber
0x01    bAlternateSetting
0x01    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

AS Interface Descriptor:
------------------------------
0x07    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x02    bTerminalLink
0x03    bDelay
0x0001  wFormatTag   (PCM)

AS Format Type 1 Descriptor:
------------------------------
0x0B    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bFormatType   (FORMAT_TYPE_1)
0x02    bNrChannels   (2 channels)
0x02    bSubframeSize
0x10    bBitResolution   (16 bits per sample)
0x01    bSamFreqType   (Discrete sampling frequencies)
0x00AC44    tSamFreq(1)   (44100 Hz)

Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x83    bEndpointAddress  (IN endpoint 3)
0x09    bmAttributes      (Transfer: Isochronous / Synch: Adaptive / Usage: Data)
0x0168  wMaxPacketSize    (1 x 360 bytes)
0x01    bInterval         (1 frames)
0x00    bRefresh
0x00    bSynchAddress

AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07    bLength
0x25    bDescriptorType
0x01    bDescriptorSubtype
0x00    bmAttributes
0x00    bLockDelayUnits   (undefined)
0x0000  wLockDelay

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x03    bInterfaceNumber
0x00    bAlternateSetting
0x00    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

Interface Descriptor:
------------------------------
0x09    bLength
0x04    bDescriptorType
0x03    bInterfaceNumber
0x01    bAlternateSetting
0x02    bNumEndPoints
0x01    bInterfaceClass      (Audio Device Class)
0x02    bInterfaceSubClass   (Audio Streaming Interface)
0x00    bInterfaceProtocol   (Audio Protocol undefined)
0x00    iInterface

AS Interface Descriptor:
------------------------------
0x07    bLength
0x24    bDescriptorType
0x01    bDescriptorSubtype
0x03    bTerminalLink
0x03    bDelay
0x0001  wFormatTag   (PCM)

AS Format Type 1 Descriptor:
------------------------------
0x0B    bLength
0x24    bDescriptorType
0x02    bDescriptorSubtype
0x01    bFormatType   (FORMAT_TYPE_1)
0x02    bNrChannels   (2 channels)
0x02    bSubframeSize
0x10    bBitResolution   (16 bits per sample)
0x01    bSamFreqType   (Discrete sampling frequencies)
0x00AC44    tSamFreq(1)   (44100 Hz)

Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x03    bEndpointAddress  (OUT endpoint 3)
0x05    bmAttributes      (Transfer: Isochronous / Synch: Asynchronous / Usage: Data)
0x02D0  wMaxPacketSize    (1 x 720 bytes)
0x01    bInterval         (1 frames)
0x00    bRefresh
0x84    bSynchAddress

AS Isochronous Data Endpoint Descriptor:
------------------------------
0x07    bLength
0x25    bDescriptorType
0x01    bDescriptorSubtype
0x00    bmAttributes
0x00    bLockDelayUnits   (undefined)
0x0000  wLockDelay

Endpoint Descriptor (Audio/MIDI 1.0):
------------------------------
0x09    bLength
0x05    bDescriptorType
0x84    bEndpointAddress  (IN endpoint 4)
0x11    bmAttributes      (Transfer: Isochronous / Synch: None / Usage: Feedback)
0x0003  wMaxPacketSize    (1 x 3 bytes)
0x01    bInterval         (1 frames)
0x05    bRefresh
0x00    bSynchAddress

Microsoft OS Descriptor is not available. Error code: 0x0000001F

Upvotes: 1

Views: 645

Answers (1)

SonaBen
SonaBen

Reputation: 21

In the end I managed to fix the descriptor to work by updating bNrChannels, and also had to change the Volume feature descriptor to add the extra channels:

16,                 // bLength
0x24,               // bDescriptorType = CS_INTERFACE
0x06,               // bDescriptorSubType = FEATURE_UNIT
0x31,               // bUnitID
0x03,               // bSourceID (Input Terminal)
0x01,               // bControlSize (each channel is 1 byte, 3 channels)
0x00,               // bmaControls(0) Master: Mute
  0x03, // Channel(1) - Volume
  0x03, // Channel(2) - Volume
  0x03, // Channel(3) - Mute / Volume
  0x03, // Channel(4) - Mute / Volume
  0x03, // Channel(5) - Mute / Volume
  0x03, // Channel(6) - Mute / Volume
  0x03, // Channel(7) - Mute / Volume
  0x03, // Channel(8) - Mute / Volume
  0x00,             // iFeature

Because of updating bLength from 10 to 16, it meant I also had to increase the wTotalLength of the "Class-specific AC Interface Header Descriptor" from 62 to 68.

Last but not least: I spent hours trying to understand why some changes wouldn't work, when in the end it was Windows caching some properties of the USB device. Uninstalling from Device manager didn't work, but I removed the Teensy Audio device using "USBDeview".

Upvotes: 1

Related Questions