maa
maa

Reputation: 51

USB Microphone descriptor for Windows XP,7,8 application

I am trying to implement a USB microphone on a STM32F103 using the USB-FS library from STMicroelectronics.

My microphone is detected on Windows XP, 7 and 8. When I try to record voice with Audacity, the signal is correct on Windows XP and Windows 8 but for Windows 7 it is amplified.

Does anyone have an idea of what is going on ?

Here is the descriptor:

const uint8_t Mic_ConfigDescriptor[] =
{
/* Configuration 1 */
0x09,                                /* bLength */
USB_CONFIGURATION_DESCRIPTOR_TYPE,   /* bDescriptorType */
0x64,                               /* wTotalLength = 100  bytes */
0x00,
0x02,                                 /* bNumInterfaces */
0x01,                                 /* bConfigurationValue */
0x00,                                 /* iConfiguration */
0x80,                                 /* bmAttributes  BUS Powred*/
0x32,                                 /* bMaxPower = 100 mA*/
/* 09 byte*/
/* Interface 0, Alternate Setting 0, USB Microphone Standard AC Interface Descriptor */
9,  /* bLength */
USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
0x00,                                 /* bInterfaceNumber */
0x00,                                 /* bAlternateSetting */
0x00,                                 /* bNumEndpoints */
USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
AUDIO_SUBCLASS_AUDIOCONTROL,          /* bInterfaceSubClass */
AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
0x00,                                 /* iInterface */
/* 09 byte*/
/* USB Microphone Class-specific AC Interface Descriptor */
9,   /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
AUDIO_CONTROL_HEADER,                 /* bDescriptorSubtype */
0x01,          /* 1.00 */             /* bcdADC */
0x00,
0x1E,                                /* wTotalLength = 30*/
0x00,
0x01,                                 /* bInCollection */
0x01,                                 /* baInterfaceNr */
/* 09 byte*/
/* USB Microphone Input Terminal Descriptor */
AUDIO_INPUT_TERMINAL_DESC_SIZE,       /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
AUDIO_CONTROL_INPUT_TERMINAL,         /* bDescriptorSubtype */
0x01,                                 /* bTerminalID */
0x01,                                 /* wTerminalType: terminal is Micro = 0x0201 */
0x02,
0x00,                                 /* bAssocTerminal */
0x02,                                 /* bNrChannels */
0x00,                                 /* wChannelConfig 0x0000  Mono */
0x00,
0x00,                                 /* iChannelNames */
0x00,                                 /* iTerminal */
/* 12 byte*/
/* USB Microphone Output Terminal Descriptor*/
//AUDIO_OUTPUT_TERMINAL_DESC_SIZE,      /* bLength */

0x09,
AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
AUDIO_CONTROL_OUTPUT_TERMINAL,        /* bDescriptorSubtype */
0x02,                                 /* bTerminalID */
0x01,                                 /* wTerminalType AUDIO_USB_STREAMING.  0x0101*/
0x01,
0x00,                                 /* bAssocTerminal */
0x01,                                 /* bSourceID */
0x00,                                 /* iTerminal */
/* 09 byte*/
/* Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith */
9,    /* bLength */
USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
0x01,                                 /* bInterfaceNumber */
0x00,                                 /* bAlternateSetting */
0x00,                                 /* bNumEndpoints */
USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
AUDIO_SUBCLASS_AUDIOSTREAMING,        /* bInterfaceSubClass */
AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
0x00,                                 /* iInterface */
/* 09 byte*/
/* Interface 1, Alternate Setting 1, Audio Streaming - Operational */
9,    /* bLength */
USB_INTERFACE_DESCRIPTOR_TYPE,        /* bDescriptorType */
0x01,                                 /* bInterfaceNumber */
0x01,                                 /* bAlternateSetting */
0x01,                                 /* bNumEndpoints */
USB_DEVICE_CLASS_AUDIO,               /* bInterfaceClass */
AUDIO_SUBCLASS_AUDIOSTREAMING,        /* bInterfaceSubClass */
AUDIO_PROTOCOL_UNDEFINED,             /* bInterfaceProtocol */
0x00,                                 /* iInterface */
/* 09 byte*/
/* USB Microphone Class-specific AS General Interface Descriptor */
AUDIO_STREAMING_INTERFACE_DESC_SIZE,  /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
AUDIO_STREAMING_GENERAL,              /* bDescriptorSubtype */
0x02,                                 /* bTerminalLink */
0x00,                                 /* bDelay */
0x01,                                 /* wFormatTag AUDIO_FORMAT_PCM8  0x0002*/
0x00,
/* 07 byte*/
/* USB Microphone Type I Format Type Descriptor */
0x0B,                                 /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE,      /* bDescriptorType */
AUDIO_STREAMING_FORMAT_TYPE,          /* bDescriptorSubtype */
AUDIO_FORMAT_TYPE_I,                  /* bFormatType */
0x01,                                 /* bNrChannels */
0x02,                                 /* bSubFrameSize */
16,                                    /* bBitResolution */
0x01,                                 /* bSamFreqType */
0x40,        /* tSamFreq 8KHz = 0x1F40 */
0x1F,
0x00,
/* 11 byte*/
/* USB Microphone Standard Endpoint Descriptor */
AUDIO_STANDARD_ENDPOINT_DESC_SIZE,    /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE,         /* bDescriptorType */
//AUDIO_IN_EP,                                 /* bEndpointAddress 1 IN endpoint*/

0x81, /* bEndpointAddress 1 IN endpoint*/
0x01,//USB_ENDPOINT_TYPE_ISOCHRONOUS,        /* 01: Asynchronous, 10: Adaptive, 11: synchronous. bmAttributes */
16,                                 /* wMaxPacketSize 22 bytes*/
0x00,
0x01,                                 /* bInterval */
0x00,                                 /* bRefresh */
0x00,                                 /* bSynchAddress */
/* 09 byte*/
/* USB Microphone Class-specific Isoc. Audio Data Endpoint Descriptor */
AUDIO_STREAMING_ENDPOINT_DESC_SIZE,   /* bLength */
AUDIO_ENDPOINT_DESCRIPTOR_TYPE,       /* bDescriptorType */
AUDIO_ENDPOINT_GENERAL,               /* bDescriptor */
0x00,                                 /* bmAttributes */
0x00,                                 /* bLockDelayUnits */ 
0x00,                                 /* wLockDelay */
0x00,
/* 07 byte*/
} 

Upvotes: 3

Views: 802

Answers (2)

endolith
endolith

Reputation: 26813

If you don't define a Feature Unit for the input path, Windows 7 and later adds a digital gain control. (Windows XP and macOS just show a grayed-out slider that can't be adjusted.)

However, Windows 7 has a bug that sets this digital control to +30 dB gain by default for Microphones:

Change Windows gain slider display from percentage to decibels

Windows gain slider is set to +30 dB

So either lower the gain to 0 dB after plugging in the mic for the first time, set the Terminal Type to something other than Microphone, or define a Feature Unit.

Upvotes: 0

maa
maa

Reputation: 51

This issue is solved : A feature unit has to be implemented in the descriptor + responses to audio class specific requests.

Upvotes: 2

Related Questions