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#
Initializes the I2S module and enables the mic.
Deinitializes the mic and disables the I2S module.
Retrieves the specified number of samples from the mic.
Starts streaming audio data from the mic.
Starts recording from the mic.
Stops the mic from capturing or streaming audio data.
Checks if the mic sample buffer is ready.
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.
[in] | mic_sampling_frequency | The sampling frequency for the microphone to ensure accurate audio capture. |
[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.
43
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/mic/inc/sl_si91x_mic.h
sl_si91x_mic_deinit#
sl_status_t sl_si91x_mic_deinit (void )
Deinitializes the mic and disables the I2S module.
N/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.
55
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/mic/inc/sl_si91x_mic.h
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.
[in] | buffer | Pointer to the buffer to store the samples. |
[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.
69
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/mic/inc/sl_si91x_mic.h
sl_si91x_mic_start_streaming#
sl_status_t sl_si91x_mic_start_streaming (void * buffer)
Starts streaming audio data from the mic.
[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.
82
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/mic/inc/sl_si91x_mic.h
sl_si91x_mic_start#
sl_status_t sl_si91x_mic_start (void * buffer)
Starts recording from the mic.
[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.
95
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/mic/inc/sl_si91x_mic.h
sl_si91x_mic_stop#
sl_status_t sl_si91x_mic_stop (void )
Stops the mic from capturing or streaming audio data.
N/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.
106
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/mic/inc/sl_si91x_mic.h
sl_si91x_mic_sample_buffer_ready#
bool sl_si91x_mic_sample_buffer_ready (void )
Checks if the mic sample buffer is ready.
N/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.
117
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/mic/inc/sl_si91x_mic.h
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.
[out] | sound_level_dB | Pointer to a variable that will store the calculated sound level. |
[in] | audio_samples | Pointer to the buffer containing audio samples. |
[in] | n_frames | The number of samples in the buffer. |
[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
.
134
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/mic/inc/sl_si91x_mic.h