Main Content

I2S Mic In

Read audio sample from MEMS microphone available on the STM32F4xx based board

Since R2023a

Add-On Required: This feature requires the Embedded Coder Support Package for STMicroelectronics STM32 Processors add-on.

  • Mic In block

Libraries:
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32F4xx Based Boards

Description

The I2S Mic In block reads the audio samples collected from the MEMS microphone (MP45DT02, ST MEMS audio sensor, omnidirectional digital microphone), available on STM32F4xx based board. The MEMS microphone produces a Pulse Density Modulated (PDM) signal.

The block outputs int16 or int32 Pulse Code Modulated audio frame with the size specified in Frame size (samples) field from the block mask.

The block sample rate is calculated as: Sample frequency/ Frame size.

For example, the Mic in block sample time with 48 kHz sampling frequency and 96 samples frame size is equal to 2 ms (96/48000). The minimum allowed sampling rate for the Mic in block is 1ms.

Note

  • As the Mic In block always outputs 1ms of int16 PCM audio frame data, the values in Frame Size and Sample Time are calculated based on the Sample Rate that you select. The values in these parameters are for display purposes only. You cannot edit these values.

  • The PDM filter option in STM32CubeMX project is available only for STM32F4xx and STM32F7xx based boards.

PDM Processing

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 and ‘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

Read Audio Data Using Double Buffering

The Mic In block uses a double buffering to read the audio data from the MEMS microphone.

With double buffering, one buffer is used by the DMA to read audio PDM signal from the MEMS microphone while the other buffer is used to send audio frames to the audio processing algorithm. This helps to prevent overwriting of the buffer while being used by the audio algorithm.

The following describes the double buffering mechanism in the Mic In block.

  • In the first iteration, when the ‘Mic in buffer1’ sends the data for audio processing, the DMA fills ‘Mic in buffer0’.

    In the first iteration, the ‘Mic in buffer1’ does not contain the audio samples. Therefore, the audio samples from the Mic In block are delayed by one audio frame.

  • After the DMA completes filling Mic in buffer0, an interrupt is triggered.

  • In the second iteration, when the ‘Mic in buffer0’ sends the data for audio processing and the DMA fills ‘Mic in buffer1’.

Ports

Output

expand all

The output port containing audio samples from MEMS microphone on the STM32F4xx based board.

Data Types: int16 | int32

Parameters

expand all

Select the I2S mic in module.

Select to enable the conversion of PDM audio frame to PCM audio frame conversion.

Select the I2S mic in signal format in bits.

  • Stereo - select stereo to record and play using 2 different audio channels.

  • Mono - select mono to record and play using single audio channel.

Dependencies

To set the parameter Number of channels to Mono, enable the Enable PDM audio frame to PCM audio frame conversion parameter. Disable the Enable PDM audio frame to PCM audio frame conversion parameter, when Stereo is selected.

Select a audio sample rate. It is the sampling frequency to read audio signal from the MEMS microphone.

The audio signal frame size is based on the sample rate that you select.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2023a

See Also

|