Send processed audio samples to audio devices on STMicroelectronics STM32F746G/STM32F769I–Discovery board
Embedded Coder Support Package for STMicroelectronics Discovery Boards/STM32F746G-Discovery / Embedded Coder Support Package for STMicroelectronics Discovery Boards/STM32F769I-Discovery
The Audio Output block writes the processed audio data to the audio device (headphones or speakers) that are connected to the processor on the STM32F746G/STM32F769I–Discovery™ board.
The block accepts
int16 Pulse Code Modulated (PCM) audio frames. For
STM32F746G, these frames are either mono: (
[Nx1]) or stereo: (
int16 matrix. For STM32F769I, these
frames are quad:
N is the number of samples per frame from the input signal, and
4 are the number of audio channels per
You can send audio samples at different rates, such as 8 kHz, 11 kHz, 16 kHz, 22 kHz, 32 kHz, 44 kHz, 48 kHz, 96 kHz, and 192 kHz (STM32F746G only), with different sampling frequencies.
Using the parameters of this block, you specify the device to which you want to send the audio. You also specify the volume level at which the block emits audio frames.
Write Audio to Headphone or Speaker
The STM32F746G–Discovery board sends audio to audio devices, headphones or speakers, or both, that are connected to it.
int16 PCM audio frames from the input
port of the Audio Output block instance are streamed
through the ARM Cortex M7 processor and WM8994 codec. These frames
are then sent to the connected audio devices.
The audio data between the ARM Cortex M7 processor, WM8994 codec, and the audio devices are transferred by using I2S line.
The audio frames streamed through the ARM Cortex M7 processor and WM8994 codec do not undergo any conversion.
Send Processed Audio Samples with Double Buffering
The Audio Output block uses a double buffering mechanism to send data to the audio device.
With double buffering, the DMA uses one buffer to transfer an audio frame from the processor to the audio device while the other buffer receives the processed audio frame from your audio algorithm. When sending the data to the audio device, doing so helps to prevent overwriting the buffer.
When you send an audio frame of length
N samples, the block creates two
buffers of length
With the double buffering mechanism in theAudio Output block:
In the first iteration, when the processed audio signal is sent out to the audio device from Audio out buffer1, the Audio out buffer0 is filled with audio signal from the audio processing algorithm.
In the first iteration, the Audio out buffer1 does not contain the audio samples. Therefore, the audio samples from the Audio Output block are delayed by one audio frame. If your model has Audio Input and Audio Output blocks, there is a time delay of two audio frames. This delay occurs because the Audio Input block also uses the same double buffering technique.
After the DMA completes sending out the processed data from Audio out buffer1, an interrupt is generated.
In the second iteration, when the processed audio signal is sent out to the audio device from Audio out buffer0, the Audio out buffer1 is filled with the audio data from the audio processing algorithm.
Port_1 — Input port containing PCM audio samples in frames
The block accepts
N is the number of samples per frame.
the number of audio channels in the signal.
The maximum number of audio channels supported is 2 for STM32F746G and 4 for STM32F769I. For
STM32F746G, the block supports audio frames in mono:
[1xN]) format and
For STM32F769I, the block supports audio frames in quad:
[Nx4]. The values of
N are determined from
the incoming audio frames at the input port.
The block interprets an
2 matrix as a
multichannel signal with
N samples per channel. For example,
the block interprets a sequence of
2 matrices as a
two-channel signal with a frame size of 5.
Device — Device to send the audio data to
Headphone (default) |
Select the audio device to which the block sends audio data.
Sampling frequency (Hz) — Sampling frequency to write audio signal to the audio device
44100 (default for STM32F769I) |
48000 (default for STM32F746G) |
Specify the number of samples per second to write to the audio device that you specify in the Device parameter.
Volume — Loudness of the audio signal at the output
90 (default for STM32F746G) |
80 (default for STM32F769I) |
integer between 0 and 100
The block applies gain to the value that you specify in this parameter. The gain is calculated as:
To send audio with no breaks, the sample time of the block instance is set equal to the model base rate. To ensure that both the values are equal, the base rate trigger is set to the DMA interrupt of the Audio Output block. This setting ensures that the processing algorithm is synchronized with the Audio Output block interrupt.
After you run the simulation, if the Audio Output block instance appears red, it indicates that the sample time of the block instance and the model base rate are equal.
You can view the model base rate from Display > Sample Time > All. In the Sample Time Legend dialog box, the value corresponding to the red box is the model base rate.
In STM32F746G, if your model has Audio Input and Audio Output blocks, the model base rate is set to the sample time of the Audio Input block. The model base rate of the Audio Input block is considered because it is the higher priority for synchronization.
In STM32F769I, if both Audio Input and Audio Output blocks are present, the base rate trigger is set to the DMA interrupt of the Audio Input or Audio Output block, based on the block that has the faster sample rate.
Introduced in R2016b