Support for I2S microphone to have a sound level meter

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
jbarea
Normal user
Posts: 17
Joined: 24 Jun 2021, 00:21

Support for I2S microphone to have a sound level meter

#1 Post by jbarea » 06 Apr 2023, 17:29

Hi,

Currently I am using a simple microphone with a MAX4466 based module attached to the ADC pin of a ESP8266 to measure the sound intensity. I took the idea from https://blog.yavilevich.com/2016/08/ard ... -analyzer/

Actually I use the Analog Input Plugin to obtain the voltage [adc#v] from the microphone and a dummy device [slm] where the decibels is computed respect the maximum that the signal can reach. Here are the rules to do this job:

On System#Boot do // Cuando se inicia la placa
Let,1,538 // reference value corresponding to silence
Let,2,0 // count the number of samples
Let,3,0 // compute the RMS and the dBs
Let,4,10 // time between samples in msec
Let,5,10 // total number of samples to use
TimerSet_ms,1,[int#4]
endo

On Rules#Timer=1 do
if [int#2] < [int#5]
Let,2,[int#2]+1
TaskRun,adc
Let 3,[var#3]+([adc#v]-[var#1])*([adc#v]-[var#1])
TimerSet_ms,1,[int#4]
else
Let,3,sqrt([var#3]/([var#2])) // compute RMS
TaskValueSet,slm,RMS,[var#3]
TaskValueSet,slm,dB,88+20.0*log([var#3]/[var#1]) // compute dB
Let,2,0
Let,3,0
TimerSet_ms,1,[int#4]
endif
endo

I am in the process of compare the measurements with a professional sound level meter (SLM), but I don't expect miracles. However it would be nice to have a plugin to support a I2S microphone in EspEasy. Here it is explained how to implement a SLM using a ESP32, where also the decibels with the A filter are calculated, and for several I2S microphones:

https://hackaday.io/project/166867-esp32-i2s-slm

Code in https://github.com/ikostoski/esp32-i2s-slm

Maybe it is worthy to explore if it can be implemented as a plugin in Espeasy. A SPL device allows to monitor the environmental noise, something which impacts in human healthy.

Cheers,

Jose.

TD-er
Core team member
Posts: 8752
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Support for I2S microphone to have a sound level meter

#2 Post by TD-er » 06 Apr 2023, 21:14

Looks like a nice project, but I think it will be quite a lot of work to get it to work in ESPEasy.
The simple reason is that we probably need to let this run on the 2nd core as it would otherwise render ESPEasy completely unresponsive.

Since we don't have anything setup for multi-core processing right now, I don't know how much work it will be to implement it as this also will involve quite some testing with locking to sync data between cores and I don't know how much locking will affect operations on "the other core".
I know there are several types of locks/semaphores on the ESP32, so that needs to be tested also.

jbarea
Normal user
Posts: 17
Joined: 24 Jun 2021, 00:21

Re: Support for I2S microphone to have a sound level meter

#3 Post by jbarea » 10 Apr 2023, 19:54

Thanks TD-er for your quick answer. I never imagine that I2S could be so complicated. I just thought that it could be activated only for ESP32 and only when the plugin is enabled (assuming it is available). I didn't know that the I2S libraries needed to build the hypothetical plugin could interfere in the entire firmware, involving a second core and things like that. Thanks again!

TD-er
Core team member
Posts: 8752
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Support for I2S microphone to have a sound level meter

#4 Post by TD-er » 10 Apr 2023, 22:14

Problem with I2S is that it has really hard real-time requirements.
So you need to have some DMA memory reserved which you must either fill (for output) or read (for input) in due time or else you get buffer-underrun or buffer overflow.
If it is just for measuring some volume level, then it is a bit more forgiving as any hickups would not really affect the readings a lot.
However if we make some I2S plugin, you can bet it will be used for other things too.
And it is a bit disappointing to write something which you already know it is not going to work for anything else and also can just wait for others to request that use case you know it will not work for and then have to re-implement it all over.

As a matter of fact we already had some report of a user about a generated sound which isn't tuned well because it is generated in software and being interrupted by other things running on the ESP.
To one it is merely a 'notification beep', but for others it may be unbearable if some notification melody is out of tune :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 130 guests