USB Audio Speaker Device
Default mainpageat91libusbdeviceaudio-speakerUSB Audio Speaker Device
Description
audio-speaker.dir::USB Audio Speaker Device
 
This page describes how to use the USB framework to produce a USB Audio Class Device driver.
References

Audio Speaker Driver API

Audio Desktop Speaker Description
The device described here is a USB desktop speaker. It receives a stero audio data stream from the Host over its Audio Streaming interface. The used Audio Data Format is 16-bit 48KHz 2-channel PCM (or mono 16-bit 32KHz PCM for sam7s chips). The following is the internal topology of the speaker.

USBAudioSpeaker.png
USB Desktop Speaker Topology


The audio function contains one Onput Terminal that represents the actual speaker output element, followed by the Digital-to-Analog Converter (DAC). The digital input stream of the host enters the audio function through the single Input Pin of the Output terminal. There is a Feature Unit on the audio stream, to mute or unmute the speaker. The Input Terminal is the representation within the audio fucntion of the USB OUT endpoint that eventually receives the audio data stream from the Host. The internals of the audio function are presented to the Host through the (mandatory) AudioControl interface wheras the USB OUT endpoint resides in the AudioStreaming interface.

Descriptor Hierarchy
This USB Desktop Speaker device includes the AudioControl interface (interface 0) and a single AudioStreaming interface (interface 1). The AudioStreaming interface features two alternate settings. The first alternate setting (Alternate Setting 0) has zero bandwidth associated with it so that switching to this alternate setting effectively frees all allocated bandwidth on the USB for this device. Zero bandwidth is indicated by the lack of a streaming endpoint. Alternate Setting 1 is the operational part of the interface and it has one isochronous OUT endpoint. Figure presents the descriptor hierarchy.

UsbAudioSpeakerDescriptors.png
USB Desktop Speaker Hierarchy


Descriptors
The following sections present all the descriptors that are used to describe the device.

All descriptors are combined into a list and pass to USBDDriver_Initialize invoked in AUDDSpeakerDriver_Initialize.

const USBDDriverDescriptors auddSpeakerDriverDescriptors;


Device Descriptor
const USBDeviceDescriptor deviceDescriptor;

OffsetFieldSizeValueDescription
0bLength10x12Size of this descriptor, in bytes.
1bDescriptorType10x01DEVICE descriptor (USBGenericDescriptor_DEVICE).
2bcdUSB20x02002.00 - current revision of USB specification.
4bDeviceClass10x00Device defined at interface level.
5bDeviceSubClass10x00Unused.
6bDeviceProtocol10x00Unused.
7bMaxPacketSize010x088 bytes (BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0)).
8idVendor20x03EBAtmel Vendor ID (AUDDSpeakerDriverDescriptors_VENDORID).
10idProduct20x6128Product ID (AUDDSpeakerDriverDescriptors_PRODUCTID).
12bcdDevice20x0100Device Release Code
(AUDDSpeakerDriverDescriptors_RELEASE).
14iManufacturer10x01Index to manufacture name in Unicode
(manufacturerDescriptor).
15iProduct10x02Index to product name in Unicode (productDescriptor).
16iSerialNumber10x03Index to serial number in Unicode
(serialNumberDescriptor).
17bNumConfigurations10x01One configuration.

Configuration Descriptor
const AUDDSpeakerDriverConfigurationDescriptors configurationDescriptors;

OffsetFieldSizeValueDescription
0bLength10x09Size of this descriptor, in bytes.
1bDescriptorType10x02CONFIGURATION descriptor
(USBGenericDescriptor_CONFIGURATION).
2wTotalLength20x????Length of the total configuration block in bytes
including this descriptor
(AUDDSpeakerDriverConfigurationDescriptors)
4bNumInterfaces10x02Two interfaces.
5bConfigurationValue10x01ID of this configuration.
6iConfiguration10x00Unused.
7bmAttributes10x??BOARD_USB_BMATTRIBUTES
8bMaxPower10x32100mA Max. power consumption.
USBConfigurationDescriptor_POWER(100)

AudioControl Interface Descriptor
The AudioControl interface describes the device structure (audio function topology) and is used to manipulate the Audio Controls.

Standard AC Interface Descriptor
The AudioControl interface has no dedicated endpoints associated with it. It uses the default pipe (endpoint 0) for all communication purposes. Class- specific AudioControl Requests are sent using the default pipe. There is no Status Interrupt endpoint provided.

See USBInterfaceDescriptor.
OffsetFieldSizeValueDescription
0bLength10x09Size of this descriptor, in bytes.
1bDescriptorType10x04INTERFACE descriptor
(USBGenericDescriptor_INTERFACE).
2bInterfaceNumber10x00Index of this interface.
3bAlternateSetting10x00Index of this setting.
4bNumEndpoints10x000 endpoints.
5bInterfaceClass10x01AUDIO (AUDControlInterfaceDescriptor_CLASS).
6bInterfaceSubClass10x01AUDIO_CONTROL
(AUDControlInterfaceDescriptor_SUBCLASS).
7bInterfaceProtocol10x00Unused.
8iInterface10x00Unused.

Class-specific AC Interface Descriptor
The Class-specific AC interface descriptor is always headed by a Header descriptor that contains general information about the AudioControl interface. It contains all the pointers needed to describe the AudioInterface Collection, associated with the described audio function.
OffsetFieldSizeValueDescription
0bLength10x09Size of this descriptor, in bytes.
1bDescriptorType10x24CS_INTERFACE descriptor
(AUDGenericDescriptor_INTERFACE).
2bDescriptorSubtype10x01HEADER subtype (AUDGenericDescriptor_HEADER).
3bcdADC20x0100Revision of class specification - 1.0
5wTotalLength20x????Total size of class specific descriptors
(AUDDSpeakerDriverAudioControlDescriptors).
7bInCollection10x01Number of streaming interfaces.
8baInterfaceNr(1)10x01AudioStreaming interface 1 belongs to this AudioControl interface.

Input Terminal Descriptor for playback
This descriptor describes the Input Terminal that represents the USB pipe from the Host PC. Its Output Pin is connected to the Input Pin of the Feature Unit ...
OffsetFieldSizeValueDescription
0bLength10x0CSize of this descriptor, in bytes.
1bDescriptorType10x24CS_INTERFACE descriptor
(AUDGenericDescriptor_INTERFACE).
2bDescriptorSubType10x02INPUT_TERMINAL subtype
(AUDGenericDescriptor_INPUTTERMINAL).
3bTerminalID10x00ID of this Input Terminal
(AUDDSpeakerDriverDescriptors_INPUTTERMINAL).
4wTerminalType20x0101Terminal is USB stream
(AUDInputTerminalDescriptor_USBSTREAMING).
6bAssocTerminal10x01Associated to Output Terminal
(AUDDSpeakerDriverDescriptors_OUTPUTTERMINAL).
7bNrChannels10x02Two channel.
8wChannelConfig20x0003Left plus right front channel.
10iChannelNames10x00Unused.
11iTerminal10x00Unused.

Output Terminal Descriptor for playback
...
OffsetFieldSizeValueDescription
0bLength10x09Size of this descriptor, in bytes.
1bDescriptorType10x24CS_INTERFACE descriptor
(AUDGenericDescriptor_INTERFACE).
2bDescriptorSubType10x03OUTPUT_TERMINAL subtype
(AUDGenericDescriptor_OUTPUTTERMINAL).
3bTerminalID10x01ID of this Output Terminal
(AUDDSpeakerDriverDescriptors_OUTPUTTERMINAL).
4wTerminalType20x0301Terminal is Desktop speaker.
6bAssocTerminal10x01Associated to Input Terminal
(AUDDSpeakerDriverDescriptors_INPUTTERMINAL).
7bSourceID10x02From Feature Unit
(AUDDSpeakerDriverDescriptors_FEATUREUNIT).
8iTerminal10x00Unused.

Feature Unit Descriptor for playback
...
OffsetFieldSizeValueDescription
0bLength10x0ASize of this descriptor, in bytes.
1bDescriptorType10x24CS_INTERFACE descriptor
(AUDGenericDescriptor_INTERFACE).
2bDescriptorSubType10x02FEATURE_UNIT subtype
(AUDGenericDescriptor_FEATUREUNIT).
3bUnitID10x02ID of this Feature Unit
(AUDDSpeakerDriverDescriptors_FEATUREUNIT).
4bSourceID10x00From Input Terminal
(AUDDSpeakerDriverDescriptors_INPUTTERMINAL).
5bControlSize10x011 byte per channel for controls
6bmaControls30x000001Master channel mute control, no other controls.
9iFeature10x00Unused.

AudioStreaming Interface Descriptor
The AudioStreaming interface has two possible alternate settings.

Zero-bandwidth Alternate Setting 0
Alternate setting 0 is a zero-bandwidth setting, used to relinquish the claimed bandwidth on the bus when the microphone is not in use. It is the default setting after power-up. The zero bandwidth is implemented by specifying that this alternate setting of the interface has no endpoints associated with it (bNumEndpoints=0). The collection of descriptors for this alternate setting reduces to the standard interface descriptor.

Standard AS Interface Descriptor (USBInterfaceDescriptor)
OffsetFieldSizeValueDescription
0bLength10x09Size of this descriptor, in bytes.
1bDescriptorType10x04INTERFACE descriptor
(USBGenericDescriptor_INTERFACE).
2bInterfaceNumber10x01Index of this interface.
3bAlternateSetting10x00Index of this setting.
4bNumEndpoints10x000 endpoint.
5bInterfaceClass10x01AUDIO (AUDStreamingInterfaceDescriptor_CLASS).
6bInterfaceSubClass10x02AUDIO_STREAMING
(AUDStreamingInterfaceDescriptor_SUBCLASS).
7bInterfaceProtocol10x00Unused (AUDStreamingInterfaceDescriptor_PROTOCOL).
8iInterface10x00Unused.

Operational Alternate Setting 1
Alternate setting 1 is the operational setting of the interface. It contains the standard and class-specific interface and endpoint descriptors.

Standard AS Interface Descriptor (USBInterfaceDescriptor)
OffsetFieldSizeValueDescription
0bLength10x09Size of USBInterfaceDescriptor in bytes.
1bDescriptorType10x04INTERFACE descriptor
(USBGenericDescriptor_INTERFACE).
2bInterfaceNumber10x01Index of this interface.
3bAlternateSetting10x01Index of this setting.
4bNumEndpoints10x011 endpoint.
5bInterfaceClass10x01AUDIO (AUDStreamingInterfaceDescriptor_CLASS).
6bInterfaceSubClass10x02AUDIO_STREAMING
(AUDStreamingInterfaceDescriptor_SUBCLASS).
7bInterfaceProtocol10x00Unused (AUDStreamingInterfaceDescriptor_PROTOCOL).
8iInterface10x00Unused.

Class-specific AS General Interface Descriptor (AUDStreamingInterfaceDescriptor)
OffsetFieldSizeValueDescription
0bLength10x06Size of AUDStreamingInterfaceDescriptor in bytes.
1bDescriptorType10x24CS_INTERFACE descriptor
(AUDGenericDescriptor_INTERFACE).
2bDescriptorSubType10x01GENERAL subtype
(AUDStreamingInterfaceDescriptor_GENERAL).
3bTerminalLink10x02Unit ID of the Input Terminal
(AUDDSpeakerDriverDescriptors_INPUTTERMINAL).
4bDelay10x00No interface delay.
5wFormatTag20x0001PCM Format (AUDFormatTypeOneDescriptor_PCM).

Type I Format Type Descriptor (AUDFormatTypeOneDescriptor1)
OffsetFieldSizeValueDescription
0bLength10x0BSize of AUDFormatTypeOneDescriptor1 in bytes.
1bDescriptorType10x24CS_INTERFACE descriptor\ (AUDGenericDescriptor_INTERFACE).
2bDescriptorSubType10x02FORMAT_TYPE subtype
(AUDStreamingInterfaceDescriptor_FORMATTYPE).
3bFormatType10x01FORMAT_TYPE_I (AUDFormatTypeOneDescriptor_FORMATTYPEONE).
4bNrChannels10x022 channels (AUDDSpeakerDriver_NUMCHANNELS).
5bSubFrameSize10x02Two bytes per audio subframe
(AUDDSpeakerDriver_BYTESPERSAMPLE).
6bBitResolution10x1016 bits per sample
(AUDDSpeakerDriver_BYTESPERSAMPLE * 2).
7bSamFreqType10x01One frequency supported.
8tSamFreq348004800Hz (AUDDSpeakerDriver_SAMPLERATE).

Standard Endpoint Descriptor (AUDEndpointDescriptor)
OffsetFieldSizeValueDescription
0bLength10x09Size of AUDFormatTypeOneDescriptor1 in bytes.
1bDescriptorType10x24ENDPOINT descriptor (USBGenericDescriptor_ENDPOINT).
2bEndpointAddress10x04OUT endpoint 4
See USBEndpointDescriptor_ADDRESS
See AUDDSpeakerDriverDescriptors_DATAOUT.
3bmAttributes10x01Isochronous, not shared
(USBEndpointDescriptor_ISOCHRONOUS).
4wMaxPacketSize20x????BOARD_USB_ENDPOINTS_MAXPACKETSIZE().
6bInterval10x01One packet per frame.
7bRefresh10x00Unused.
8bSynchAddress10x00Unused.

Class-specific Isochronous Audio Data Endpoint Descriptor (AUDDataEndpointDescriptor)
OffsetFieldSizeValueDescription
0bLength10x07Size of AUDDataEndpointDescriptor in bytes.
1bDescriptorType10x25CS_ENDPOINT descriptor
(AUDGenericDescriptor_ENDPOINT).
2bDescriptorSubType10x01GENERAL subtype
(AUDDataEndpointDescriptor_SUBTYPE).
3bmAttributes10x00No sampling frequency control
no pitch control
no packet padding.
4bLockDelayUnits10x00Unused.
5wLockDelay20x0000Unused.

String Descriptors
There are three string descriptors available. The Manufacturer, Product and Serial Number descriptor.

See manufacturerDescriptor, productDescriptor, serialNumberDescriptor.

Requests
The Audio Speaker Driver supports all necessary standard requests, and some class-specific requests.

USBDCallbacks_RequestReceived is used to filter all requests, AUDDSpeakerDriver_RequestHandler is invoked to handle Audio Class requests and forward standard request to AUDDSpeakerDriver_RequestHandler.

Standard requests
Set Interface request should be processed to control bandwidth allocation.

Set Interface
USBDDriverCallbacks_InterfaceSettingChanged is re-implemented to handle the event.
OffsetFieldSizeValueDescription
0bmRequestType10x01D7:0=Host to Device.
D6..5:00=Standard Request.
D4..0:00001=Recipient is interface.
1bRequest10x0BSET_INTERFACE.
2wValue20x0000
or
0x0001
Zero bandwidth or normal isochronous operation.
4wIndex20x0001Interface number of the AudioStreaming interface.
6wLength20x0000No Parameter Block.

Class-specific requests
The only class-specific Request supported is the Set/Get Feature Unit Control Request. For mute control of the Feature Unit.

Set Feature Unit Control Request
OffsetFieldSizeValueDescription
0bmRequestType10x01D7:0=Host to Device.
D6..5:01=Class Request.
D4..0:00001=Recipient is interface.
1bRequest10x01SET_CUR.
2wValue20x0100Mute control (AUDFeatureUnitRequest_MUTE) of
Master channel (AUDDSpeakerDriver_MASTERCHANNEL).
4wIndex20x0200Feature Unit (AUDDSpeakerDriverDescriptors_FEATUREUNIT)
and
AudioControl Interface (AUDDSpeakerDriverDescriptors_CONTROL).
6wLength20x0001Paramter Block Length

The one-byte Parameter Block contains the new bMuted value for Feature Control.

Get Feature Unit Control Request
OffsetFieldSizeValueDescription
0bmRequestType10x01D7:0=Host to Device.
D6..5:01=Class Request.
D4..0:00001=Recipient is interface.
1bRequest10x81GET_CUR.
2wValue20x0100Mute control (AUDFeatureUnitRequest_MUTE) of
Master channel (AUDDSpeakerDriver_MASTERCHANNEL).
4wIndex20x0200Feature Unit (AUDDSpeakerDriverDescriptors_FEATUREUNIT)
and
AudioControl Interface (AUDDSpeakerDriverDescriptors_CONTROL).
6wLength20x0001Paramter Block Length

The one-byte Parameter Block contains the new bMuted value for Feature Control.

Modify the Device Driver
You can modify your project from the USB Audio Demoes:
Change Device ID and Display
All Device ID and Display Strings are in AUDDSpeakerDriverDescriptors.c.

Device IDs
You can find "Audio Speaker Device Codes"
Display Strings
You can modify the string descriptors
Add Recorder Function
See "USB Audio Recorder".
 
Source
The documentation for this Page was generated from the following file:
  • audio-speaker.dir