Read audio sample from 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 Input block reads audio samples from the audio device (Microphone, Line In) connected to the processor on the STM32F746G/STM32F769I–Discovery™ boards. The audio samples are either in Pulse Density Modulation (PDM) format or Pulse Code Modulated (PCM) format. The format of the audio samples depends on the device from which the block acquires audio.
The block emits PCM audio frames. For STM32F746G, these frames are
int16 matrix. For STM32F769I, these frames are
[Nx2] for Line In input, and
[Nx4] for Microphone input, depending on the number of channels
N is the number of samples per frame, and
4 are the number of audio channels per
You can read 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 frame sizes.
Using the parameters of this block, you specify the device from which you acquire audio. For STM32F746G, you can also specify the volume level at which the block emits audio frames.
The output of this block connects to audio devices such as headphones or speakers.
Read Audio from Microphone or LineIn
The STM32F746G/STM32F769I–Discovery board acquires audio from either of the two audio devices, Dual MEMS Microphones (MP34DT01), or Line In that connect to the board.
The dual MEMS microphones (MP34DT01) on the STM32F746G–Discovery board outputs a PDM signal, which is then sent to the WM8994 codec. The WM8994 codec converts the PDM signal to 16-bit PCM format and sends it to the ARM Cortex M7 processor.
The two dual MEMS microphones on the STM32F769I–Discovery board outputs PDM signals, which are then sent to the digital filter for sigma delta modulation (DFSDM) peripheral. The DFSDM peripheral converts the PDM signals to 16-bit PCM format and sends it to the ARM-Cortex M7 processor.
LineIn outputs a PCM signal. The output signal is sent to the WM8994 codec, which is then sent to the ARM Cortex M7 processor. These frames are then sent to the connected audio devices.
Audio data between audio devices, WM8994 codec, and the ARM Cortex M7 processor are transferred by using I2S line.
The 16-bit PCM audio frames from LineIn, which are streamed through the WM8994 codec and ARM Cortex M7 processor, do not undergo any conversion.
Read Audio Data with Double Buffering
The Audio Input block uses a double buffering mechanism to read the audio data from the audio device.
With double buffering, the DMA uses one buffer to read an audio PCM signal from the audio device while the other buffer sends audio frames to the audio processing algorithm. When the audio algorithm uses the buffer, this mechanism helps to prevent overwriting of the buffer.
With the double buffering mechanism in the Audio Input block:
In the first iteration, when the Audio In buffer1 sends the data for audio processing, the DMA fills Audio In buffer0.
In the first iteration, the Audio In buffer1 does not contain the audio samples. Therefore, the audio samples from the Audio Input block are delayed by one audio frame.
After the DMA completes filling Audio In buffer0, an interrupt is triggered.
In the second iteration, when the Audio In buffer0 sends the data for audio processing, the DMA fills Audio In buffer1.
Port_1 — Output port containing PCM audio samples in frames
The block emits PCM audio frames. For STM32F746G, the output frames
int16 matrix. For STM32F769I, the output frames are
N is the number of
samples per frame specified in the Samples per frame
(N) parameter, and
2 is the number of
audio channels per frame.
The block interprets
2 matrix as
a multichannel signal with
N samples per channel. For example,
if you specify Samples per frame (N) as
5, the block interprets the following sequence of
2 matrices as a
two-channel signal with a frame size of 5.
Device — Device from which to acquire audio
Microphone (default) |
Select the device from which the block reads audio data.
Audio sampling frequency (Hz) — Sampling frequency to read audio signal from the audio device
44100 (default for STM32F769I) |
48000 (default for STM32F746G) |
Specify the number of samples per second to read from the audio device that you specify in the Device parameter.
Number of Channels — Number of audio channels (STM32F769I only)
2 (default) |
If the Device is Microphone, you can select 2 or 4 audio channels. This parameter is not available for Line In.
To use four microphones in the Audio Input block, you must have an Audio Toolbox license.
Samples per frame (N) — Number of samples per frame at the output
48(default for STM32F746G) |
1024(default for STM32F769I) |
integer between 1 and 65535
Specify the number of samples per frame that the block emits.
Volume — Loudness of the audio signal at the output (STM32F746G only)
90 (default) |
integer between 0 and 100
The block applies gain to the value that you specify in this parameter. The gain is calculated as:
Pulse Density Modulation (PDM) uses the density of a pulse to represent a signal. The relative density of the pulses in PDM corresponds to the analog signal amplitude. In PDM bit stream, 1 corresponds to a pulse of positive polarity. 0 corresponds to a pulse of negative polarity. PDM uses a single bit to convey the audio.
Some of the advantages of PDM processing are:
Simple in concept and execution
Low-cost audio transmission in digital form
Efficient systems with good design
Low noise and less signal interference
The block sample time is calculated as: Samples per frame (N)/Audio sampling frequency (Hz).
For example, the sample time of the block with 48 kHz sampling frequency and 96 samples frame size is equal to 2 ms (96/48000).
To receive audio with no breaks, set the sample time of the block instance 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 Input block. This setting ensures that the processing algorithm is synchronized with the Audio Input block interrupt.
After you run the simulation, if the Audio Input 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.
Introduced in R2016b