Audio Class Configuration
General Configuration
Some constants are available to customize the class. These constants are located in the USB device configuration file, usbd_cfg.h
. Table - Audio Class Configuration Constants shows their description.
Constant | Description | Possible Values |
---|---|---|
USBD_AUDIO_CFG_PLAYBACK_EN | Enables or disables playback. |
DEF_ENABLED
or DEF_DISABLED |
USBD_AUDIO_CFG_RECORD_EN | Enables or disables record.
|
DEF_ENABLED
or DEF_DISABLED |
USBD_AUDIO_CFG_FU_MAX_CTRL | Enables all Feature Unit controls or disables all optional controls. When disabled, only the mute and volume controls are kept. | DEF_ENABLED or
DEF_DISABLED
|
USBD_AUDIO_CFG_MAX_NBR_AIC | Configures the maximum number of class instances. Unless you plan on having multiple configurations or interfaces using different class instances, this can be set to 1. | From 1 to 254. Default value is 1 . |
USBD_AUDIO_CFG_MAX_NBR_CFG | Configures the maximum number of configurations in which audio class is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. | From 1 (full-speed) or 2 (high-speed) to 254. Default value is 2. |
USBD_AUDIO_CFG_MAX_NBR_IT | Configures the maximum number of input terminals. | From 1 to 255. Default value is 2. |
USBD_AUDIO_CFG_MAX_NBR_OT | Configures the maximum number of output terminals. | From 1 to 255. Default value is 2 . |
USBD_AUDIO_CFG_MAX_NBR_FU | Configures the maximum number of feature units. | From 1 to 255. Default value is 2 . |
USBD_AUDIO_CFG_MAX_NBR_MU | Configures the maximum number of mixer units. A Mixer Unit is optional. | From 0 to 255. Default value is 0 . |
USBD_AUDIO_CFG_MAX_NBR_SU | Configures the maximum number of selector units. A Selector Unit is optional. | From 0 to 255. Default value is 0 . |
USBD_AUDIO_CFG_MAX_NBR_AS_IF_PLAYBACK | Configures the maximum number of playback AudioStreaming interfaces per class instance. | From 1 to 255. Default value is 1 . |
USBD_AUDIO_CFG_MAX_NBR_AS_IF_RECORD
| Configures the maximum number of record AudioStreaming interfaces per class instance. | From 1 to 255. Default value is 1 . |
USBD_AUDIO_CFG_MAX_NBR_IF_ALT | Configures the maximum number of operational alternate setting interfaces per AudioStreaming interface. | From 1 to 255. Default value is 2 . |
USBD_AUDIO_CFG_CLASS_REQ_MAX_LEN | Configures the maximum class-specific request playload length in bytes. Among all class-specific requests supported by Audio 1.0 class, the Graphic Equalizer control of the Feature Unit use the longest payload size for the SET_CUR request. The payload for the Graphic Equalizer control can take up to 34 bytes depending of the number of frequency bands present. If the Graphical Equalizer control is not used by any feature unit, this constant can be set to 4. Refer to audio 1.0 specification, Table 5-27 for more details about Graphic Equalizer control. | From 1 to 34. Default value is 4 . |
USBD_AUDIO_CFG_BUF_ALIGN_OCTETS | Configures the alignment in octets that audio buffers allocated for each AudioStreaming interface will use. The alignment is dependent of the peripheral used to move data between the memory and the audio peripheral. Note that this buffer alignment should be a multiple of the internal stack's buffer alignment set with the constant If the CPU cache is used with the audio buffers,
If all above requirements must be taken into account, | Typically 1, 2, 4 or 8. Default value is
USBD_CFG_BUF_ALIGN_OCTETS
. |
USBD_AUDIO_CFG_PLAYBACK_FEEDBACK_EN | Enables or disables the playback feedback support. If an isochronous OUT endpoint using the asynchronous synchronization is associated to an AudioStreaming interface, you need to set
DEF_ENABLED
to enable the feedback support. Refer to section Playback Feedback Correction for more details about the audio feedback. | DEF_ENABLED or
DEF_DISABLED
|
USBD_AUDIO_CFG_PLAYBACK_CORR_EN | Enables or disables built-in playback stream correction. | DEF_ENABLED or
DEF_DISABLED
|
USBD_AUDIO_CFG_RECORD_CORR_EN | Enables or disables built-in record stream correction. | DEF_ENABLED or
DEF_DISABLED
|
USBD_AUDIO_CFG_STAT_EN | Enables or disables audio statistics for playback and record. | DEF_ENABLED or
DEF_DISABLED
|
The audio class uses two internal tasks to manage playback and record streams. The task priority and stack size shown in Table - Audio Internal Tasks' Configuration Constants are defined in the application configuration file, app_cfg.h
. Refer to section Audio Class Stream Data Flow for more details about the audio internal tasks.
Constant | Description | Possible Values | |
---|---|---|---|
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_PRIO | Configures the priority of the audio playback task. | From the lowest to the highest priority supported by the OS used. | |
USBD_AUDIO_CFG_OS_RECORD_TASK_STK_SIZE
| Configures the stack size of the audio playback task. The required size of the stack can greatly vary depending on the OS used, the CPU architecture, the type of application, etc. Refer to the documentation of the OS for more details about tasks and stack size calculation. | From the minimal to the maximal stack size supported by the OS used. The default value can be set for instance to 512. | |
USBD_AUDIO_CFG_OS_RECORD_TASK_PRIO | Configures the priority of the audio record task. | From the lowest to the highest priority supported by the OS used. | |
USBD_AUDIO_CFG_OS_PLAYBACK_TASK_STK_SIZE | Configures the stack size of the audio record task. The required size of the stack can greatly vary depending on the OS used, the CPU architecture, the type of application, etc. Refer to the documentation of the OS for more details about tasks and stack size calculation. | From the minimal to the maximal stack size supported by the OS used. The default value can be set for instance to 512. |
When configuring audio tasks, you should pay attention to their priority. Indeed, audio tasks runs against the internal core task responsible for control transfers and asynchronous transfers. In general, it is recommended to set the core task's priority higher than the audio tasks priority. It will ensure that control transfers carrying standard and class-specific requests will be processed in a timely fashion. Also, audio tasks rely on asynchronous implementation of isochronous transfers. Thus, prioritizing the core task guarantees that isochronous transfers completion is processed fast enough. Even if streams are open, control transfers are occasional. They won't really disturb the stream processing.
The audio class has two internal tasks: playback and record. There is no recommendation about if playback task should have higher priority than record task or the opposite. You just need to ensure that these internal tasks have a higher priority than any of your application tasks. Audio data are considered as real-time data. Thus, you should prioritize the audio streams processing over other functionalities of your application whenever possible.