记一次USB声卡设计开发

目前笔者从事音频开发工作,借助公司硬件资源,给自己做了个迷你声卡,接下来让笔者介绍一下相关开发过程。

USB声卡,这里借助度娘的解释:USB声卡是插在USB口的声卡,通过USB总线与计算机系统链接。。。。。。

那么怎么DIY声卡需要些什么硬件资源呢?

1.具有USB和I2S相关外设的MCU    2.Codec(编码解码器)   3.输出输入接口及相关模电电路

如下简图:

记一次USB声卡设计开发_第1张图片

我这里直接选用的MCU资源为NXP的RT1052,当然MCU大可不必选这么好的,选用STM32F1系列基本就可以,笔者主要为了可玩性,加一些算法效果所以选择了这款比较火的跨界处理器。Codec的选择根据自己想做到什么级别的吧,市面上的几块十几块几十块的都可以,我们主要需要了解的一些基本参数:动态范围,信噪比等等。另外模拟运放部分也很关键,总之音质的影响是方方面面的,如:USB Audio 同步问题,Codec选型配置问题,运放设计问题,电源问题都会影响声卡的参数。

如下实物图:

记一次USB声卡设计开发_第2张图片

 硬件配套全了,接下来开搞软件了,核心部分当然是USB Audio啦。这里笔者采用比较古老的Audio1.0标准开发的,主要原因是免驱,开发难度不会很大。对于USB Audio 的开发这里说比较关键的几点:

1.设备接口数量:如果要实现扬声器和录音功能,那么接口数量为:3个  分别为 Control+Recoder+Speaker

2.音频流同步问题(缓冲区的处理方案,反馈端点的使用策略)具体可以参考我之前写的一个博客

https://blog.csdn.net/weixin_38426553/article/details/95383679

3.采样率,采样精度等等

4.每次修改usb audio配置后最好卸载之前的驱动,让PC重新配置相关驱动

下面分享一点点相关配置(一不小心做成了复合设备):

/* Configuration, interface and endpoint. */

#define USB_DEVICE_CONFIGURATION_COUNT (1)

#define USB_DEVICE_STRING_COUNT (3)

#define USB_DEVICE_LANGUAGE_COUNT (1)

#define USB_DEVICE_INTERFACE_COUNT (6) //设备接口数量(Control+Recoder+Speaker+Contrl+ MIDI+HID)

 

#define USB_AUDIO_ENDPOINT_COUNT (1)

 

#define USB_AUDIO_SPEAKER_CONFIGURE_INDEX (1)

#define USB_COMPOSITE_CONFIGURE_INDEX (1)

 

/*接口计数,根据数量依次递增*/

#define USB_AUDIO_CONTROL_INTERFACE_INDEX (0)

#define USB_AUDIO_RECORDER_STREAM_INTERFACE_INDEX (1)

#define USB_AUDIO_SPEAKER_STREAM_INTERFACE_INDEX (2)

/*MIDI 独立拥有一个Contrl接口端点*/

#define USB_AUDIO_MIDI_INDEX (4)

#define USB_HID_INTERFACE_INDEX (5)

 

/*每个接口的端点数量*/

#define USB_AUDIO_CONTROL_ENDPOINT_COUNT (1)

#define USB_AUDIO_RECORDER_STREAM_ENDPOINT_COUNT (1)

#define USB_AUDIO_SPEAKER_STREAM_ENDPOINT_COUNT (2)

#define USB_HID_ENDPOINT_COUNT (2)

#define USB_AUDIO_MIDI_ENDPOINT_COUNT (2)

 

/*分配端点地址*/

#define USB_AUDIO_CONTROL_ENDPOINT (1)

#define USB_AUDIO_SPEAKER_STREAM_ENDPOINT (2)

#define USB_AUDIO_SPEAKER_FEEDBACK_ENDPOINT (2)

#define USB_AUDIO_RECORDER_STREAM_ENDPOINT (3)

#define USB_AUDIO_MIDI_ENDPOINT_IN (4)

#define USB_AUDIO_MIDI_ENDPOINT_OUT (4)

#define USB_HID_ENDPOINT_IN (5)

#define USB_HID_ENDPOINT_OUT (5)

 

/* Audio data format */

#define AUDIO_FORMAT_CHANNELS (0x02) //立体声模式

#define AUDIO_FORMAT_BITS (24) //数据宽度 24bit

#define AUDIO_FORMAT_SIZE (0x03) //数据长度 8*3

#define HS_ISO_IN_ENDP_PACKET_SIZE (AUDIO_SAMPLING_RATE_KHZ * AUDIO_FORMAT_CHANNELS * AUDIO_FORMAT_SIZE)    //包大小,根据采样率,采样精度和通道数量选择

#define FS_ISO_IN_ENDP_PACKET_SIZE (AUDIO_SAMPLING_RATE_KHZ * AUDIO_FORMAT_CHANNELS * AUDIO_FORMAT_SIZE)

Audio描述符相关:

/**********************Audio Interface Descriptor(No.0):0x04**********************/

USB_DESCRIPTOR_LENGTH_INTERFACE, /* Size of this descriptor in bytes */

USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */

USB_AUDIO_CONTROL_INTERFACE_INDEX, /* Number of this interface. */

0x00U, /* Value used to select this alternate setting

for the interface identified in the prior field */

0x01U, /* Number of endpoints used by this

interface (excluding endpoint zero). (0 or 1)*/

USB_AUDIO_CLASS, /*The interface implements the Audio Interface class */

USB_SUBCLASS_AUDIOCONTROL, /*The interface implements the AUDIOCONTROL Subclass */

0x00U, /*The interface doesn't use any class-specific protocols */

0x00U, /* The device doesn't have a string descriptor describing this iInterface */

 

/*******************AC Header of Interface Descriptor:0x24 0x01*************************/

USB_AUDIO_CONTROL_INTERFACE_HEADER_LENGTH, /* Size of the descriptor, in bytes */

    USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_CONTROL_HEADER, /* HEADER descriptor subtype */

0x00U, 0x01U, /* Audio Device version 1.00 */

0x48, 0x00U, /* 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. */

0x02U, /* The number of AudioStreaming and MIDIStreaming interfaces in the Audio Interface Collection to which this

AudioControl interface belongs */

USB_AUDIO_RECORDER_STREAM_INTERFACE_INDEX, /* Recorder interfaces in the Audio Interface baNumber is 0x01 */

USB_AUDIO_SPEAKER_STREAM_INTERFACE_INDEX, /* Speaker interfaces in the Audio Interface baNumber is 0x02 */

 

/******************* AC Specific type of Input Terminal:0x24 0x02*************************/

USB_AUDIO_INPUT_TERMINAL_ONLY_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_CONTROL_INPUT_TERMINAL,

/* INPUT_TERMINAL descriptor subtype */

USB_AUDIO_RECORDER_CONTROL_INPUT_TERMINAL_ID, /* Constant uniquely identifying the Terminal within the audio

function. This value is used in all requests

to address this Terminal. */

0x01U, 0x02, /* A generic microphone that does not fit under any of the other classifications. */

0x00U, /* This Input Terminal has no association */

0x02U, /* This Terminal's output audio channel cluster has 1 logical output channels */

0x03U, 0x00U, /* Spatial locations present in the cluster */

0x00U, /* Index of a string descriptor, describing the name of the first logical channel. */

0x00U, /* Index of a string descriptor, describing the Input Terminal. */

 

/*******************Audio Class Specific type of Feature Unit:0x24 0x06*************************/

USB_AUDIO_FEATURE_UNIT_ONLY_DESC_SIZE(2, 1), /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_CONTROL_FEATURE_UNIT, /* FEATURE_UNIT descriptor subtype */

USB_AUDIO_RECORDER_CONTROL_FEATURE_UNIT_ID, /* Constant uniquely identifying the Unit within the audio function.

This value is used in all requests to

address this Unit. */

USB_AUDIO_RECORDER_CONTROL_INPUT_TERMINAL_ID, /* ID of the Unit or Terminal to which this Feature Unit is connected.

*/

0x01U, /* Size in bytes of an element of the bmaControls() array: */

0x01U, /* Master channel0: Mute */

0x02U, /* Left channel1: Volume*/

0x02U, /* Right channel2: Volume */

0x00U, /* Index of a string descriptor, describing this Feature Unit. */

 

/*******************Audio Class Specific type of Output Terminal:0x24 0x03*************************/

USB_AUDIO_OUTPUT_TERMINAL_ONLY_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_CONTROL_OUTPUT_TERMINAL,

/* OUTPUT_TERMINAL descriptor subtype */

USB_AUDIO_RECORDER_CONTROL_OUTPUT_TERMINAL_ID, /* Constant uniquely identifying the Terminal within the audio

function*/

0x01U, 0x01U, /* A Terminal dealing with a signal carried over an endpoint in an AudioStreaming interface */

0x00U, /* This Output Terminal has no association */

USB_AUDIO_RECORDER_CONTROL_FEATURE_UNIT_ID, /* ID of the Unit or Terminal to which this Terminal is connected. */

0x00U, /* Index of a string descriptor, describing the Output Terminal. */

 

/******************* Audio Class Specific type of Input Terminal:0x24 0x02*************************/

USB_AUDIO_INPUT_TERMINAL_ONLY_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_CONTROL_INPUT_TERMINAL,

/* INPUT_TERMINAL descriptor subtype */

USB_AUDIO_SPEAKER_CONTROL_INPUT_TERMINAL_ID, /* Constant uniquely identifying the Terminal within the audio

function. This value is used in all requests

to address this Terminal. */

0x01U, 0x01, /* A Terminal dealing with a signal carried over an endpoint in an AudioStreaming interface. */

0x00U, /* This Input Terminal has no association */

0x02U, /* This Terminal's output audio channel cluster has 1 logical output channels */

0x03U, 0x00U, /* Spatial locations present in the cluster */

0x00U, /* Index of a string descriptor, describing the name of the first logical channel. */

0x00U, /* Index of a string descriptor, describing the Input Terminal. */


 

/*******************Audio Class Specific type of Feature Unit:0x24 0x06*************************/

USB_AUDIO_FEATURE_UNIT_ONLY_DESC_SIZE(2, 1), /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_CONTROL_FEATURE_UNIT, /* FEATURE_UNIT descriptor subtype */

USB_AUDIO_SPEAKER_CONTROL_FEATURE_UNIT_ID, /* Constant uniquely identifying the Unit within the audio function. This

value is used in all requests to

address this Unit. */

USB_AUDIO_SPEAKER_CONTROL_INPUT_TERMINAL_ID, /* ID of the Unit or Terminal to which this Feature Unit is connected.

*/

0x01U, /* Size in bytes of an element of the bmaControls() array: */

0x01U, /* Master channel0: Mute */

0x02U, /* Left channel1: Volume*/

0x02U, /* Right channel2: Volume */

0x00U, /* Index of a string descriptor, describing this Feature Unit. */

 

/*******************Audio Class Specific type of Output Terminal:0x24 0x03*************************/

USB_AUDIO_OUTPUT_TERMINAL_ONLY_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_CONTROL_OUTPUT_TERMINAL,

/* OUTPUT_TERMINAL descriptor subtype */

USB_AUDIO_SPEAKER_CONTROL_OUTPUT_TERMINAL_ID, /* Constant uniquely identifying the Terminal within the audio

function*/

0x01U, 0x03U, /* A generic speaker or set of speakers that does not fit under any of the other classifications. */

0x00U, /* This Output Terminal has no association */

USB_AUDIO_SPEAKER_CONTROL_FEATURE_UNIT_ID, /* ID of the Unit or Terminal to which this Terminal is connected. */

0x00U, /* Index of a string descriptor, describing the Output Terminal. */

 

/******************************* Audio Control ENDPOINT descriptor: 0x05 *******************************/   

USB_DESCRIPTOR_LENGTH_AC_INTERRUPT_ENDPOINT, /* Size of this descriptor, in bytes: 9U */

USB_DESCRIPTOR_TYPE_ENDPOINT, /* ENDPOINT descriptor type */

USB_AUDIO_CONTROL_ENDPOINT | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),

/* Endpoint address */

USB_ENDPOINT_INTERRUPT, /* Transfer type */

USB_SHORT_GET_LOW(FS_AUDIO_INTERRUPT_IN_PACKET_SIZE), USB_SHORT_GET_HIGH(FS_AUDIO_INTERRUPT_IN_PACKET_SIZE),

/* Max Packet Size */

FS_AUDIO_INTERRUPT_IN_INTERVAL, /* Interval */

0, 0,

        

     /*****************Audio Recorder Interface descriptor(No.1):0x04***********************/

USB_DESCRIPTOR_LENGTH_INTERFACE, /* Descriptor size is 9 bytes */

USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */

USB_AUDIO_RECORDER_STREAM_INTERFACE_INDEX, /* Number of this interface. */

0x00U, /* The value used to select the alternate setting for this interface is 0 */

0x00U, /* The number of endpoints used by this interface is 0 (excluding endpoint zero) */

USB_AUDIO_CLASS, /* The interface implements the Audio Interface class */

USB_SUBCLASS_AUDIOSTREAM, /* The interface implements the AUDIOSTREAMING Subclass */

0x00U, /* The interface doesn't use any class-specific protocols */

0x00U, /* The device doesn't have a string descriptor describing this iInterface */

 

     /*****************Audio Recorder Interface descriptor(No.1):0x04***********************/     

USB_DESCRIPTOR_LENGTH_INTERFACE, /* Descriptor size is 9 bytes */

USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */

USB_AUDIO_RECORDER_STREAM_INTERFACE_INDEX,

0x01U, /* The value used to select the alternate setting for this interface is 1 */

0x01U, /* The number of endpoints used by this interface is 1 (excluding endpoint zero) */

USB_AUDIO_CLASS, /* The interface implements the Audio Interface class */

USB_SUBCLASS_AUDIOSTREAM, /* The interface implements the AUDIOSTREAMING Subclass */

0x00U, /* The interface doesn't use any class-specific protocols */

0x00U, /* The device doesn't have a string descriptor describing this iInterface */

 

/*******************AS descriptor subtype Descriptor:0x24 0x01*************************/

USB_AUDIO_STREAMING_IFACE_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_STREAMING_GENERAL, /* AS_GENERAL descriptor subtype */

USB_AUDIO_RECORDER_CONTROL_OUTPUT_TERMINAL_ID, /* The Terminal ID of the Terminal to which the endpoint of this

interface is connected. */

0x00U, /* Delay introduced by the data path. Expressed in number of frames. */

0x01U, 0x00U, /* PCM */

 

/****************** Audio Class Specific type I format INTERFACE Descriptor: 0x24 0X02 ***********/

USB_AUDIO_STREAMING_TYPE_I_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_STREAMING_FORMAT_TYPE,

/* FORMAT_TYPE descriptor subtype */

USB_AUDIO_FORMAT_TYPE_I, /* FORMAT_TYPE_I */

AUDIO_FORMAT_CHANNELS, /* Indicates the number of physical channels in the audio data stream. */

AUDIO_FORMAT_SIZE, /* The number of bytes occupied by one audio subframe. Can be 1, 2, 3 or 4. */

AUDIO_FORMAT_BITS, /* The number of effectively used bits from the available bits in an audio subframe.*/

0x01U, /* Indicates how the sampling frequency can be programmed: */

AUDIO_SAMPLE_FREQ(44100),

 

/******************************* Audio Recorder IN ENDPOINT descriptor: 0x05 *******************************/

USB_ENDPOINT_AUDIO_DESCRIPTOR_LENGTH, /* Descriptor size is 9 bytes */

USB_DESCRIPTOR_TYPE_ENDPOINT, /* ENDPOINT Descriptor Type */

USB_AUDIO_RECORDER_STREAM_ENDPOINT | (USB_IN << 7), /* This is an IN endpoint with endpoint number 2 */

USB_ENDPOINT_ISOCHRONOUS | 0x04 | (0x2 << 4U), /* Types - Transfer: ISOCHRONOUS

Sync: Async

Usage: Implicit Feedback EP */

USB_SHORT_GET_LOW(FS_ISO_IN_ENDP_PACKET_SIZE + AUDIO_FORMAT_CHANNELS * AUDIO_FORMAT_SIZE),

USB_SHORT_GET_HIGH(FS_ISO_IN_ENDP_PACKET_SIZE +AUDIO_FORMAT_CHANNELS *AUDIO_FORMAT_SIZE),

    

FS_ISO_IN_ENDP_INTERVAL, /* The polling interval value is every 1 Frames. If Hi-Speed, every 1 uFrames */

0x00U, /* Refresh Rate 2^n ms where n = 0 */

0x00U, /* Synchronization Endpoint (if used) is endpoint 0 */

 

/******************************* Audio Class Specific ENDPOINT Descriptor: 0x25 0x01*******************************/

USB_AUDIO_STREAMING_ENDP_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_AUDIO_STREAM_ENDPOINT_DESCRIPTOR, /* CS_ENDPOINT Descriptor Type */

USB_AUDIO_EP_GENERAL_DESCRIPTOR_SUBTYPE, /* AUDIO_EP_GENERAL descriptor subtype */

0x00U, /* Bit 0: Sampling Frequency 0

Bit 1: Pitch 0

Bit 7: MaxPacketsOnly 0 */

0x00U, /* Indicates the units used for the wLockDelay field: 0: Undefined */

0x00U,

0x00U, /* Indicates the time it takes this endpoint to reliably lock its internal clock recovery

circuitry */

 

     /***********************Audio Speaker Interface descriptor(No.2):0x04*****************************/  

USB_DESCRIPTOR_LENGTH_INTERFACE, /* Descriptor size is 9 bytes */

USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */

USB_AUDIO_SPEAKER_STREAM_INTERFACE_INDEX,

0x00U, /* The value used to select the alternate setting for this interface is 0 */

0x00U, /* The number of endpoints used by this interface is 0 (excluding endpoint zero) */

USB_AUDIO_CLASS, /* The interface implements the Audio Interface class */

USB_SUBCLASS_AUDIOSTREAM, /* The interface implements the AUDIOSTREAMING Subclass */

0x00U, /* The interface doesn't use any class-specific protocols */

0x00U, /* The device doesn't have a string descriptor describing this iInterface */

 

     /***********************Audio Speaker Interface descriptor(No.2):0x04*****************************/  

USB_DESCRIPTOR_LENGTH_INTERFACE, /* Descriptor size is 9 bytes */

USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */

USB_AUDIO_SPEAKER_STREAM_INTERFACE_INDEX,

0x01U, /* The value used to select the alternate setting for this interface is 1 */

0x02U, /* The number of endpoints used by this interface is 2 (excluding endpoint zero) */

USB_AUDIO_CLASS, /* The interface implements the Audio Interface class */

USB_SUBCLASS_AUDIOSTREAM, /* The interface implements the AUDIOSTREAMING Subclass */

0x00U, /* The interface doesn't use any class-specific protocols */

0x00U, /* The device doesn't have a string descriptor describing this iInterface */

 

/*******************AS_GENERAL descriptor subtype Descriptor:0x24 0x01*************************/

USB_AUDIO_STREAMING_IFACE_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* CS_INTERFACE Descriptor Type */

USB_DESCRIPTOR_SUBTYPE_AUDIO_STREAMING_GENERAL, /* AS_GENERAL descriptor subtype */

USB_AUDIO_SPEAKER_CONTROL_INPUT_TERMINAL_ID, /* The Terminal ID of the Terminal to which the endpoint of this

interface is connected. */

0x01U, /* Delay introduced by the data path. Expressed in number of frames. */

0x01U,

  0x00U, /* PCM */

 

/****************** Audio Class Specific type I format INTERFACE Descriptor: 0x24 0X02 ***********/

USB_AUDIO_STREAMING_TYPE_I_DESC_SIZE, /* bLength (11) */

USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE, /* bDescriptorType (CS_INTERFACE) */

USB_DESCRIPTOR_SUBTYPE_AUDIO_STREAMING_FORMAT_TYPE, /* DescriptorSubtype: AUDIO STREAMING FORMAT TYPE */

USB_AUDIO_FORMAT_TYPE_I, /* Format Type: Type I */

AUDIO_FORMAT_CHANNELS, /* Number of Channels: one channel */

AUDIO_FORMAT_SIZE, /* SubFrame Size: one byte per audio subframe */

AUDIO_FORMAT_BITS, /* Bit Resolution: 8 bits per sample */

0x01U, /* One frequency supported */

AUDIO_SAMPLE_FREQ(44100),

 

/******************************* Audio Speaker OUT ENDPOINT descriptor: 0x05 *******************************/   

USB_ENDPOINT_AUDIO_DESCRIPTOR_LENGTH, /* Descriptor size is 9 bytes */

USB_DESCRIPTOR_TYPE_ENDPOINT, /* Descriptor type (endpoint descriptor) */

USB_AUDIO_SPEAKER_STREAM_ENDPOINT |

(USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), /* OUT endpoint address 1 */

USB_ENDPOINT_ISOCHRONOUS | 0x04, /* Isochronous endpoint */

USB_SHORT_GET_LOW(FS_ISO_OUT_ENDP_PACKET_SIZE + AUDIO_FORMAT_CHANNELS * AUDIO_FORMAT_SIZE),

USB_SHORT_GET_HIGH(FS_ISO_OUT_ENDP_PACKET_SIZE + AUDIO_FORMAT_CHANNELS * AUDIO_FORMAT_SIZE), /* 16 bytes */

0x01, /* bInterval(0x01U): x ms */

0x00U, /* Unused */

USB_AUDIO_SPEAKER_FEEDBACK_ENDPOINT |

(USB_IN

<< USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),

 

/******************************* Audio Class Specific ENDPOINT Descriptor: 0x25 0x01*******************************/

USB_AUDIO_STREAMING_ENDP_DESC_SIZE, /* Size of the descriptor, in bytes */

USB_AUDIO_STREAM_ENDPOINT_DESCRIPTOR, /* CS_ENDPOINT Descriptor Type */

USB_AUDIO_EP_GENERAL_DESCRIPTOR_SUBTYPE, /* AUDIO_EP_GENERAL descriptor subtype */

0x00U, /* Bit 0: Sampling Frequency 0

Bit 1: Pitch 0

Bit 7: MaxPacketsOnly 0 */

0x00U, /* Indicates the units used for the wLockDelay field: 0: Undefined */

0x00U,

0x00U, /* Indicates the time it takes this endpoint to reliably lock its internal clock recovery circuitry */

 

/******************************* Audio feedback IN ENDPOINT descriptor: 0x05 *******************************/

USB_ENDPOINT_AUDIO_DESCRIPTOR_LENGTH, /* bLength */

USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */

USB_AUDIO_SPEAKER_FEEDBACK_ENDPOINT |

(USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), /* This is an IN endpoint with endpoint number 3 */

USB_ENDPOINT_ISOCHRONOUS | 0x04 | 0x10, /* Types -

Transfer: ISOCHRONOUS

Sync: Async

Usage: Feedback EP */

0x04, //FS_ISO_FEEDBACK_ENDP_PACKET_SIZE

0x00, /* wMaxPacketSize */

0x03, /* interval polling(2^x ms) */

0x05, /* 2^n ms, this fied is from 1(2ms) to 9(512)ms*/

0x00, /* unused */

        

    /***********************Audio Contrl Interface descriptor(No.3):0x04*****************************/

    0x09, /*bLength: Interface Descriptor size*/

    USB_DESCRIPTOR_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/

    USB_AUDIO_CONTRL_MIDI_INDEX, /*bInterfaceNumber: Number of Interface*/

    0x00, /*bAlternateSetting: Alternate setting*/

    0x00, /*bNumEndpoints: no endpoints*/

    0x01, /*bInterfaceClass: Audio device class*/

    0x01, /*bInterfaceSubClass : Audio control*/

    0x00, /*nInterfaceProtocol :*/

    0x00, /*iInterface: Index of string descriptor*/

 

    /*******************AC Header of Interface Descriptor:0x24 0x01*************************/

    0x09,

    USB_DESCRIPTOR_TYPE_AUDIO_CS_INTERFACE,

    USB_DESCRIPTOR_SUBTYPE_AUDIO_CONTROL_HEADER,

    0x00,

    0x01,

    0x09,

    0x00,

    0x01,

    USB_AUDIO_MIDI_INDEX, /* Midi interfaces in the Audio Interface baNumber is 0x04 */

 

戴上我的耳机试试,呦有点意思!!!大功告成

 

 

你可能感兴趣的:(Audio,USB)