Hi, I am trying to use the Sound service's microphone to turn on every 1000 ms, check if the audio input is above a certain decibel level and turns on the LED if it is and turns of the LED if it isn't. After this, I am looking to turn off the microphone after this check.
Right now, I perform both the conversion to decibels and check in the drv_mic_data_handler function in m_sound.c. In my main.c, I have a timer running to execute this function every 1000ms.
static void mic_in_handler(void * p_context)
{
uint32_t err_code;
err_code = drv_mic_start();
APP_ERROR_CHECK(err_code);
nrf_delay_ms(100);
err_code = drv_mic_stop();
APP_ERROR_CHECK(err_code);
}
If I remove the last 3 lines of the function, then the LED lights up whenever the audio input is loud enough and turns off whenever the audio input is quiet enough since the mic is constantly active, as expected. However, I want to only check the decibel levels every 1000ms, and when the last 3 lines are included, the LED lights do not light up even if I am feeding loud enough input constantly for 5000ms. Does anyone know how to fix this?
I'm wondering if there is any way to use a fixed sample size for each m_audio_frame_t's data. Perhaps this could help me solve this problem.
Any help would be appreciated. Thanks in advance!