Author Topic: USB1.1 24 bits audio stream  (Read 7030 times)

Marc.O

  • Member
  • ***
  • Posts: 3
USB1.1 24 bits audio stream
« on: December 09, 2013, 07:03:24 am »
Hello,

I am working on a demo for an USB headset and I have a question about the audio endpoint descriptors of the USB.
I have a working 8-48kHz 16bit audio stream and I can select any sample frequency in the windows properties of an audio device. I use the following descriptors:

Code: [Select]
// Interface 2: Speaker, alternate setting 1. Type 1 format descriptor.
static const UsbAudioStreamingType1DescriptorType UsbIfd2Format =
{
  sizeof(UsbAudioStreamingType1DescriptorType),                                       // uint8 bLength;
  UDESC_CS_INTERFACE,                                                                 // uint8 bDescriptorType;
  UA_FORMAT_TYPE,                                                                     // uint8 bDescriptorSubtype;
  UA_FORMAT_TYPE_I,                                                                   // uint8 bFormatType;
  AUDIO_LSR_NOC,                                                                      // uint8 bNrChannels;
  AUDIO_LSR_SAMPLE_SIZE,                                                              // uint8 bSubFrameSize;
  AUDIO_LSR_SAMPLE_SIZE << 3,                                                         // uint8 bBitResolution;
  0x00,                                                                               // uint8 bSamFreqType;
  (uint8)((AUDIO_LSR_MIN_SAMPLE_FREQUENCY) & 0xFF),                                   // uint8 first byte minumum sample frequency 
  (uint8)((AUDIO_LSR_MIN_SAMPLE_FREQUENCY >> 8) & 0xFF),                              // uint8 second byte minumum sample frequency                           
  (uint8)(((0x10000000 | AUDIO_LSR_MIN_SAMPLE_FREQUENCY) >> 16) & 0xFF),              // uint8 third byte minumum sample frequency 
  (uint8)((AUDIO_LSR_MAX_SAMPLE_FREQUENCY) & 0xFF),                                   // uint8 first byte maximum sample frequency 
  (uint8)((AUDIO_LSR_MAX_SAMPLE_FREQUENCY >> 8) & 0xFF),                              // uint8 second byte maximum sample frequency 
  (uint8)(((0x10000000 | AUDIO_LSR_MAX_SAMPLE_FREQUENCY) >> 16) & 0xFF),              // uint8 third byte maximum sample frequency 
};

// Interface 2: Speaker, alternate setting 1. Audio endpoint descriptor.
static const UsbAudioEndpointDescriptorType UsbIfd2StdEndpoint =
{
  sizeof(UsbAudioEndpointDescriptorType),                                             // uint8 bLength;
  USB_DT_ENDPOINT,                                                                    // uint8 bDescriptorType;
  USB_DIR_OUT | USB_EP_AUDIO_RX,                                                      // uint8 bEndpointAddress;
  0x01,                                                                               // uint8 bmAttributes;
  ((AUDIO_LSR_MAX_SAMPLE_FREQUENCY / 1000) * AUDIO_LSR_SAMPLE_SIZE) * AUDIO_LSR_NOC,  // uint16 wMaxPacketSize;
  0x01,                                                                               // uint8 bInterval;
  0x00,                                                                               // uint8 bRefresh;
  0x00,                                                                               // uint8 bSynchAddress;
};

With these settings:
// Sample frequencies
#define AUDIO_LSR_MIN_SAMPLE_FREQUENCY 0x01F40  // 8kHz
#define AUDIO_LSR_MAX_SAMPLE_FREQUENCY 0x0BB80  // 48kHz

// Sample size
#define AUDIO_LSR_SAMPLE_SIZE 0x02 // in bytes

// Defines for mono/stereo.
#define AUDIO_LSR_NOC 0x02 // Number Of Channels (stereo)
 
Now I want to change it to a 8-48kHz 24bit stream. By changing the AUDIO_LSR_SAMPLE_SIZE to 0x03. When I do this the sample frequency selection box in the windows properties window is grayed out at 48kHz so I cannot select any other frequency. When I play something to the device the stream is 24bit though.
I already tried uninstalling the drivers but this does not change anything.

Does anyone encounter this problem as well or does anyone have an idea what might cause this problem?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB1.1 24 bits audio stream
« Reply #1 on: December 17, 2013, 10:18:48 am »
This group might have advice:

http://www.wdmaudiodev.com/

Marc.O

  • Member
  • ***
  • Posts: 3
Re: USB1.1 24 bits audio stream
« Reply #2 on: December 19, 2013, 04:32:58 am »
Thank you, I will give it a try.

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: USB1.1 24 bits audio stream
« Reply #3 on: December 22, 2013, 09:50:00 am »
In your isoc endpoint descriptor, bmAttributes specifies just isoc (D1..0), but no synchronization type (D3..2). Assign one of synchronization type, Synchronous, Adaptive or Asynchronous. I believe Synchronous is assumed, when no synchronization type is specified.

Depending on this synchronization type, the way to set sampling frequency differs.

1) Synchronous and Asynchronous (bmAttributes: 0x0D, 0x05, respectively)
Refer to these chapters of USB audio spec (audio10.pdf)

- The capability of sampling frequency control is indicated by bmAttributes (D0) of Class-Specific AS Isochronous Audio Data Endpoint Descriptor, which directly follows the isoc endpoint descriptor.
(4.6.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor)

- The device should respond to Get_Cur/Min/Max/Res of the endpoint control requests,
wValue (CS) = SAMPLING_FREQ_CONTROL (0x0100)
(5.2.3.2.2 Get Endpoint Control Request)
By Get_xxx requests, host knows the Current (Cur), Minimum (Min), Maximum (Max) and setting Resolution (Res) of the device's sampling frequency.

Also, the device should respond to Set_Cur of the endpoint control request
(5.2.3.2.1 Set Endpoint Control Request)
By Set_Cur request, host specifies desired sampling frequency.

These requests exchanges 3 bytes tSampleFreq parameter.
(5.2.3.2.3.1 Sampling Frequency Control)

2) Adaptive (bmAttributes: 0x09)
Sampling frequency is represented by the number of samples on each isoc packet from host.
Optionally, you may apply endpoint control requests for this synchronization type. It'll accelerate device synchronization at the start of streaming.

Tsuneo
« Last Edit: December 22, 2013, 10:18:17 am by Tsuneo »

Marc.O

  • Member
  • ***
  • Posts: 3
Re: USB1.1 24 bits audio stream
« Reply #4 on: January 22, 2014, 06:52:40 am »
It turned out that the problem was not in these descriptors but in the Input Terminal Descriptor where the channel configuration was wrong.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB1.1 24 bits audio stream
« Reply #5 on: January 22, 2014, 10:36:06 am »
Thanks for reporting back. Glad to know it's working.