Mic#

Introduction#

The Mic module provides APIs to initialize, deinitialize, and interact with the microphone using the I2S interface. It supports functionalities such as starting and stopping audio capture, streaming audio data, and calculating sound levels from the captured audio samples.

Configuration#

To configure the Mic module, you need to initialize it with the desired sampling frequency and number of channels. This can be done using the sl_si91x_mic_init API. Ensure that the I2S module is properly configured before initializing the mic.

Functions#

sl_status_t
sl_si91x_mic_init(uint16_t mic_sampling_frequency, uint8_t n_channels)

Initializes the I2S module and enables the mic.

sl_status_t

Deinitializes the mic and disables the I2S module.

sl_status_t
sl_si91x_mic_get_n_samples(void *buffer, uint32_t buffer_size)

Retrieves the specified number of samples from the mic.

sl_status_t

Starts streaming audio data from the mic.

sl_status_t
sl_si91x_mic_start(void *buffer)

Starts recording from the mic.

sl_status_t

Stops the mic from capturing or streaming audio data.

bool

Checks if the mic sample buffer is ready.

sl_status_t
sl_si91x_mic_calculate_sound_level(float *sound_level_dB, const int32_t *audio_samples, uint32_t n_frames, uint8_t channel)

Calculates the sound level from the mic data.

Function Documentation#

sl_si91x_mic_init#

sl_status_t sl_si91x_mic_init (uint16_t mic_sampling_frequency, uint8_t n_channels)

Initializes the I2S module and enables the mic.

Parameters
TypeDirectionArgument NameDescription
uint16_t[in]mic_sampling_frequency

The sampling frequency for the microphone to ensure accurate audio capture.

uint8_t[in]n_channels

The number of channels for I2S mic.

This API initializes the I2S module, sets the operation modes, and enables the microphone.

  • The I2S module will be initialized.

  • The mic will be enabled along with the I2S module.


sl_si91x_mic_deinit#

sl_status_t sl_si91x_mic_deinit (void )

Deinitializes the mic and disables the I2S module.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This API disables the microphone and deinitializes the I2S module, freeing up any resources used by it.

  • The mic and I2S module must be initialized before calling this function.

  • The mic and I2S module will be deinitialized and disabled.


sl_si91x_mic_get_n_samples#

sl_status_t sl_si91x_mic_get_n_samples (void * buffer, uint32_t buffer_size)

Retrieves the specified number of samples from the mic.

Parameters
TypeDirectionArgument NameDescription
void *[in]buffer

Pointer to the buffer to store the samples.

uint32_t[in]buffer_size

Size of the buffer in bytes.

This API retrieves 'n' samples from the microphone and stores them in the provided buffer.

  • The mic must be initialized and started before calling this API.

  • The buffer will be filled with the specified number of samples.


sl_si91x_mic_start_streaming#

sl_status_t sl_si91x_mic_start_streaming (void * buffer)

Starts streaming audio data from the mic.

Parameters
TypeDirectionArgument NameDescription
void *[in]buffer

Pointer to the buffer where audio data will be stored.

This API begins streaming audio data and writes the samples to the provided buffer continuously.

  • The mic must be initialized before streaming.

  • Audio streaming from the mic will begin, and the buffer will be continuously updated.


sl_si91x_mic_start#

sl_status_t sl_si91x_mic_start (void * buffer)

Starts recording from the mic.

Parameters
TypeDirectionArgument NameDescription
void *[in]buffer

Pointer to the buffer where captured data will be stored.

This API begins the process of capturing audio from the microphone and writes the captured data into the provided buffer.

  • The mic must be initialized and ready before starting.

  • Audio data will be recorded and stored in the buffer.


sl_si91x_mic_stop#

sl_status_t sl_si91x_mic_stop (void )

Stops the mic from capturing or streaming audio data.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This API halts the current audio capture or streaming process and stops the mic.

  • The mic must be started before calling this API.

  • The mic will stop capturing or streaming audio data.


sl_si91x_mic_sample_buffer_ready#

bool sl_si91x_mic_sample_buffer_ready (void )

Checks if the mic sample buffer is ready.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This API checks if the sample buffer contains enough data or if it is ready for processing.

  • The mic must be streaming or capturing data.

  • Returns true if the sample buffer is ready, otherwise returns false.


sl_si91x_mic_calculate_sound_level#

sl_status_t sl_si91x_mic_calculate_sound_level (float * sound_level_dB, const int32_t * audio_samples, uint32_t n_frames, uint8_t channel)

Calculates the sound level from the mic data.

Parameters
TypeDirectionArgument NameDescription
float *[out]sound_level_dB

Pointer to a variable that will store the calculated sound level.

const int32_t *[in]audio_samples

Pointer to the buffer containing audio samples.

uint32_t[in]n_frames

The number of samples in the buffer.

uint8_t[in]channel

The I2S channel

This API computes the sound level based on the samples stored in the provided buffer.

  • The buffer must contain valid audio samples captured from the mic.

  • The calculated sound level will be stored in the variable pointed by sound_level.