Table of Contents |
---|
There are many audio codecs available on the market and each requires a driver to work with the audio class. The driver is referred as the Audio Peripheral Driver in the general audio class architecture. The amount of code necessary to port a specific audio codec to the audio class greatly depends on the codec’s complexity.
...
Tip |
---|
It is highly recommended to use a DMA implementation of the driver as it will offload the CPU and ensure better overall audio performances. |
...
The audio peripheral driver functions can be divided into three API groups as shown in the Table - Audio Peripheral Driver API Groups.
Anchor | ||||
---|---|---|---|---|
|
Panel | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Optional functions can be declared as null pointers if the audio chip does not support the associated functionality.
...
The audio peripheral driver has access to stream API offered by the Audio Processing module presented in Table - Audio Processing Module Stream API 106070237. Basically, this stream API allows the audio peripheral driver to get buffers to transfer audio data to/from an audio codec or any other types of audio chip.
...
Panel | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
|
In order to better understand the use of this stream API, we will consider the typical audio stereo codec configuration shown by Figure - Typical Audio Codec Interfacing a MCU106070237. Moreover, a DMA controller used by the I2S controller will be assumed. Figure - Playback Stream Functions 106070237 summarizes the use of stream functions for a playback stream. Please refer to Figure - Playback Stream Dataflow as a complement to know what is happening in the Audio Processing module.
...
Panel | ||||
---|---|---|---|---|
| ||||
(1) The host has opened the stream by selecting the operational AS interface. It then sets the sampling frequency (for instance, 48 kHz). The function (2) Once the playback stream priming is completed within the Audio Processing module, that is a certain number of audio buffers has been accumulated, the function
(3) The playback task will receive an AudioStreaming interface handle and will submit to the audio peripheral driver a ready buffer by calling Depending on the DMA controller, you may have to configure some registers and/or a DMA descriptor in order to describe the transfer. The DMA controller moves the audio data from the memory to the I 2 S controller. This one will forward the data to the codec that will play audio data to the speaker. (4) A DMA interrupt will be fired upon transfer completion. An ISR associated to this interrupt is called. This ISR processes the DMA transfer completion by freeing the consumed buffer. For that, the function
(5) The host decides to stop the stream. The function |
Figure - Record Stream Functions summarizes the use of stream functions for a record stream. Please refer to Figure - Record Stream Dataflow as a complement to know that is happening in the Audio Processing module.
...
As described in the section Audio Statistics, the audio class offered some stream statistics that may be useful during your development. An audio statistics structure ( USBD_AUDIO_STAT
) specific to each AS interface can be retrieved by the application and consulted during debugging. Table - USBD_AUDIO_STAT Structure Fields Description106070237 describes all the fields of USBD_AUDIO_STAT
. Among them, there are four interesting for the driver:
...
You can use the macro AUDIO_DRV_STAT_INC()
by specifying an AS handle and the name of the field to update statistics. Listing - AUDIO_DRV_STAT_INC() Usage 106070237 shows an example of AUDIO_DRV_STAT_INC()
usage.
...