Coder Social home page Coder Social logo

ikostoski / esp32-i2s-slm Goto Github PK

View Code? Open in Web Editor NEW
218.0 9.0 52.0 193 KB

Sound Level Meter with ESP32 and I2S MEMS microphone

License: GNU General Public License v3.0

C++ 56.45% MATLAB 43.55%
esp32 sound level meter i2s mems iir-filter a-weighting arduino

esp32-i2s-slm's Introduction

Sound Level Meter with Arduino IDE, ESP32 and I2S MEMS microphone

Arduino/ESP32 Sound Level Meter (SLM) using inexpensive, factory calibrated, digital I2S MEMS microphone and digital IIR filters (vs. FFT) for equalization and A-weighting.

The basic idea is:

Basic principle

And the microphone response after equalization should look like:

Adjusted frequency response

Theoretically, i.e. with factory calibrated ICS-4343x, this should get you ยฑ1dB(A) measurement within 20Hz-20KHz range.

The code in this repository is mostly intended as example how you can integrate resonable noise measurement (i.e. LAeq, Equivalent Continuous Sound Level) in your projects.

You can find a bit more information in my hackday.io project.

esp32-i2s-slm's People

Contributors

ikostoski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32-i2s-slm's Issues

Compilation issue

Hello,

I have this issue when i try your code.

Do you know why please ?

Best,

Charles

esp32-i2s-slm:108:1: error: could not convert '{1.0e+0, {{-1.0e+0, 0.0, 9.9919999999999998e-1, 0}}}' from '' to 'SOS_IIR_Filter'
};
^
esp32-i2s-slm:132:1: error: could not convert '{4.7732641883680299e-1, {{9.6986791463971267e-1, 2.3515976355743193e-1, -6.6819480047699276e-2, -1.1152199068812799e-3}, {-1.9890593174362445e+0, 9.8908924206960169e-1, 1.9975533185390604e+0, -9.9755481510122113e-1}}}' from '' to 'SOS_IIR_Filter'
};
^
esp32-i2s-slm:145:1: error: could not convert '{-4.5733702338341298e-1, {{-5.4404793191685896e-1, -2.4836175932179999e-1, 4.0329889166229799e-1, -2.0734618635184299e-1}, {-1.909911869441421e+0, 9.10830292683527e-1, 1.790285722826743e+0, -8.0408581236913401e-1}, {0.0, 0.0, 1.148493493802252e+0, -1.50599527756651e-1}}}' from '' to 'SOS_IIR_Filter'
};
^
esp32-i2s-slm:156:1: error: could not convert '{1.0019783465469601e+0, {{-1.9869204583444511e+0, 9.8696322694661598e-1, 1.9951785105041659e+0, -9.9518432219409103e-1}}}' from '' to 'SOS_IIR_Filter'
};
^
esp32-i2s-slm:169:1: error: could not convert '{1.0012406849675299e+0, {{-1.0e+0, 0.0, 9.9919999999999998e-1, 0}, {-1.994461610298131e+0, 9.9446927873820801e-1, 1.997675693595542e+0, -9.9767704419556302e-1}}}' from '' to 'SOS_IIR_Filter'
};
^
esp32-i2s-slm:182:1: error: could not convert '{1.00123377961525e+0, {{-1.0e+0, 0.0, 9.9919999999999998e-1, 0}, {-1.988897663539382e+0, 9.8892847900809899e-1, 1.9938533761834909e+0, -9.9386282142957205e-1}}}' from '' to 'SOS_IIR_Filter'
};
^
esp32-i2s-slm:200:1: error: could not convert '{1.6999494814742999e-1, {{-2.0002699613310599e+0, 1.0002705614271901e+0, -1.0608684385092779e+0, -1.6398744588592601e-1}, {4.3591238420314404e+0, 3.0912026578388399e+0, 1.2084199263635931e+0, -2.7316699842833198e-1}, {-7.0930303489758995e-1, -2.9071868393580003e-1, 1.982242159753048e+0, -9.8229859492898897e-1}}}' from '' to 'SOS_IIR_Filter'
};
^
esp32-i2s-slm:214:1: error: could not convert '{-4.9164716933713998e-1, {{1.4604385758204708e+0, 5.275070373815286e-1, 1.9946144559930252e+0, -9.9462170701408825e-1}, {2.3762224049395089e-1, 1.40411206016894e-2, -1.3396585608422749e+0, -4.4214578076945588e-1}, {-2.0e+0, 1.0e+0, 3.7758000474208181e-1, -3.5636575668043e-2}}}' from '' to 'SOS_IIR_Filter'
};
^
esp32-i2s-slm:237:1: error: 'QueueHandle_t' does not name a type
QueueHandle_t samples_queue;
^
C:\Users\neouf\Downloads\esp32-i2s-slm-master\esp32-i2s-slm-master\esp32-i2s-slm\esp32-i2s-slm.ino: In function 'void mic_i2s_init()':
esp32-i2s-slm:249:9: error: 'i2s_config_t' does not name a type
const i2s_config_t i2s_config = {
^
esp32-i2s-slm:263:9: error: 'i2s_pin_config_t' does not name a type
const i2s_pin_config_t pin_config = {
^
esp32-i2s-slm:82:27: error: 'I2S_NUM_0' was not declared in this scope
#define I2S_PORT I2S_NUM_0
^
C:\Users\neouf\Downloads\esp32-i2s-slm-master\esp32-i2s-slm-master\esp32-i2s-slm\esp32-i2s-slm.ino:270:22: note: in expansion of macro 'I2S_PORT'
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
^
esp32-i2s-slm:270:33: error: 'i2s_config' was not declared in this scope
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
^
esp32-i2s-slm:270:52: error: 'i2s_driver_install' was not declared in this scope
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
^
esp32-i2s-slm:279:26: error: 'pin_config' was not declared in this scope
i2s_set_pin(I2S_PORT, &pin_config);
^
esp32-i2s-slm:279:36: error: 'i2s_set_pin' was not declared in this scope
i2s_set_pin(I2S_PORT, &pin_config);
^
C:\Users\neouf\Downloads\esp32-i2s-slm-master\esp32-i2s-slm-master\esp32-i2s-slm\esp32-i2s-slm.ino: In function 'void mic_i2s_reader_task(void*)':
esp32-i2s-slm:82:27: error: 'I2S_NUM_0' was not declared in this scope
#define I2S_PORT I2S_NUM_0
^
C:\Users\neouf\Downloads\esp32-i2s-slm-master\esp32-i2s-slm-master\esp32-i2s-slm\esp32-i2s-slm.ino:312:12: note: in expansion of macro 'I2S_PORT'
i2s_read(I2S_PORT, &samples, SAMPLES_SHORT * sizeof(int32_t), &bytes_read, portMAX_DELAY);
^
esp32-i2s-slm:312:78: error: 'portMAX_DELAY' was not declared in this scope
i2s_read(I2S_PORT, &samples, SAMPLES_SHORT * sizeof(int32_t), &bytes_read, portMAX_DELAY);
^
esp32-i2s-slm:312:91: error: 'i2s_read' was not declared in this scope
i2s_read(I2S_PORT, &samples, SAMPLES_SHORT * sizeof(int32_t), &bytes_read, portMAX_DELAY);
^
esp32-i2s-slm:324:5: error: 'TickType_t' was not declared in this scope
TickType_t start_tick = xTaskGetTickCount();
^
esp32-i2s-slm:324:16: error: expected ';' before 'start_tick'
TickType_t start_tick = xTaskGetTickCount();
^
esp32-i2s-slm:341:38: error: 'xTaskGetTickCount' was not declared in this scope
q.proc_ticks = xTaskGetTickCount() - start_tick;
^
esp32-i2s-slm:341:42: error: 'start_tick' was not declared in this scope
q.proc_ticks = xTaskGetTickCount() - start_tick;
^
esp32-i2s-slm:345:16: error: 'samples_queue' was not declared in this scope
xQueueSend(samples_queue, &q, portMAX_DELAY);
^
esp32-i2s-slm:345:48: error: 'xQueueSend' was not declared in this scope
xQueueSend(samples_queue, &q, portMAX_DELAY);
^
C:\Users\neouf\Downloads\esp32-i2s-slm-master\esp32-i2s-slm-master\esp32-i2s-slm\esp32-i2s-slm.ino: In function 'void setup()':
esp32-i2s-slm:359:24: error: 'setCpuFrequencyMhz' was not declared in this scope
setCpuFrequencyMhz(80); // It should run as low as 80MHz
^
esp32-i2s-slm:374:3: error: 'samples_queue' was not declared in this scope
samples_queue = xQueueCreate(8, sizeof(sum_queue_t));
^
esp32-i2s-slm:374:54: error: 'xQueueCreate' was not declared in this scope
samples_queue = xQueueCreate(8, sizeof(sum_queue_t));
^
esp32-i2s-slm:381:94: error: 'xTaskCreate' was not declared in this scope
xTaskCreate(mic_i2s_reader_task, "Mic I2S Reader", I2S_TASK_STACK, NULL, I2S_TASK_PRI, NULL);
^
esp32-i2s-slm:389:43: error: 'portMAX_DELAY' was not declared in this scope
while (xQueueReceive(samples_queue, &q, portMAX_DELAY)) {
^
esp32-i2s-slm:389:56: error: 'xQueueReceive' was not declared in this scope
while (xQueueReceive(samples_queue, &q, portMAX_DELAY)) {
^
exit status 1
could not convert '{1.0e+0, {{-1.0e+0, 0.0, 9.9919999999999998e-1, 0}}}' from '' to 'SOS_IIR_Filter'

[Solution] INMP441 - values fluctuate or are zero

I would like to briefly present a SOLUTION when the calculated dB values fluctuate or are permanently 0 with an INMP411 microphone. This may be due to the wrong selection of the microphone channel.

  1. If the pin L/R is tied to GND, then the channel "I2S_CHANNEL_FMT_ONLY_RIGHT" must be used in the initialisation of the I2S.
  2. If the pin L/R is tied to VCC, then the channel "I2S_CHANNEL_FMT_ONLY_LEFT" must be used in the initialisation of the I2S.
    (see picture)

Note: If the L/R pin is left open, the values will fluctuate incorrectly - if the L/R pin is not set to the appropriate channel, the values will be permanently 0.

INMP441_ValuesZero

Not getting proper dB(A) values.

Hello,
I am using ESP32-WROOM-32D and using ICS43434 as a mic. In the schematic, I have set the LR to HIGH so it is set in the right channel mode. Rest pins of the ICS are connected as followed.
SCK-> GPIO5
SD -> GPIO18
WS -> GPIO19
I only want to read the noise level in dB(A) with the ICS. Therefore, I tried the example code given here. And I have changed the configuration as per the ICS43434 datasheet.
I am attaching the code that I used with my configuration. Also, I am not using any display so I have set USE_DISPLAY to 0.
After uploading the code, in the serial monitor, I am getting the negative values and they are not properly changing with respect to the sound.
I think I have done some wrong configurations or I have missed some configurations not sure how to procede.
It will be very helpful If you can point out the solution to this.
Thank You,
Dharmik Patel
esp32-i2s-slm.zip
image

MIC_CONVERT

Hi,

First of all, let me thank you for this project, which has helped me greatly in my own project. I am adapting your code to a project to check the noise of a street, and I think I've found a problem in your code, although I may be wrong.

When you configure the I2S driver you set the bits_per_sample to 32:

void mic_i2s_init() {
  // Setup I2S to sample mono channel for SAMPLE_RATE * SAMPLE_BITS
  // NOTE: Recent update to Arduino_esp32 (1.0.2 -> 1.0.3)
  //       seems to have swapped ONLY_LEFT and ONLY_RIGHT channels
  const i2s_config_t i2s_config = {
    mode: i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
    sample_rate: SAMPLE_RATE,
    bits_per_sample: i2s_bits_per_sample_t(SAMPLE_BITS),
    channel_format: I2S_CHANNEL_FMT_ONLY_LEFT,

Where SAMPLE_BITS = 32.

After reading data with i2s, you shift the samples with the MIC_CONVERTmacro:

#define MIC_BITS          24          // valid number of bits in I2S data
#define MIC_CONVERT(s)    (s >> (SAMPLE_BITS - MIC_BITS))
    i2s_read(I2S_PORT, &samples, SAMPLES_SHORT * sizeof(SAMPLE_T), &bytes_read, portMAX_DELAY);

    TickType_t start_tick = xTaskGetTickCount();
    
    // Convert (including shifting) integer microphone values to floats, 
    // using the same buffer (assumed sample size is same as size of float), 
    // to save a bit of memory
    SAMPLE_T* int_samples = (SAMPLE_T*)&samples;
    for(int i=0; i<SAMPLES_SHORT; i++) samples[i] = MIC_CONVERT(int_samples[i]);

The problem is that in my setup (with an INMP441) when I set the sample bits to 32, the values are already right aligned. If I print some samples with #define SAMPLE_BITS 32:

ffa92dfc ffa5ebfc ffa3e9fc ffac6400 ffb067fc ffb4de00 ffc0d3fc ffcf2c00 
ffd65400 ffdb7800 ffe39200 ffead1fc fff199fc fffb6ffc 0003ec00 000e3bfc 
00191200 001d07fc 0025c9fc 0029c9fc 00313c00 00344e00 00370c00 003d5dfc 
003f6800 003c97fc 003821fc 0036b400 0033f800 0037b400 003c4ffc 00439c00 
0047f5fc 00478800 0044b800 00437600 004245fc 003a5e00 00313c00 00315200 
002f5c00 002895fc 002711fc 0023ec00 00225e00 001f2400 002131fc 001bd200 
00114ffc 00052dfc fffdd9fc fff4b9fc ffe841fc ffdb25fc ffd5de00 ffd4b7fc 
ffd139fc ffcae200 ffc695fc ffc36bfc ffbdb800 ffbddffc ffbc5400 ffb78bfc 
ffb5d5fc ffb8a3fc ffbe0800 ffbe59fc ffc30ffc ffc775fc ffcd9a00 ffd58c00 
ffd96000 ffd08c00 ffce3000 ffd155fc ffd23c00 ffd051fc ffd25c00 ffd89a00 
ffdef9fc ffe8cc00 fff11200 fff575fc fff55ffc fff9c5fc fffc9200 fffc0ffc 
fffd7e00 0000fbfc 0009d000 0011ac00 001743fc 0020f600 0024b200 00280e00 
002c8bfc 00297bfc 002b29fc 00266600 00236400 00220400 00228e00 00201800

If I set #define SAMPLE_BITS 24 then values output by the mic are left shifted 8 bits:

ffe97400 ffe97400 fff0c300 fffd5300 000acc00 000acc00 0012fc00 001a5f00 
00225f00 00225f00 00321000 00436b00 0058f700 0058f700 00740400 00930b00 
00b59b00 00b59b00 00d0f000 00e54400 00ef9400 00ef9400 00e7d400 00d56b00 
00ae3300 00ae3300 007fbc00 0049e000 00071000 00071000 ffb95f00 ff691c00 
ff1a2300 ff1a2300 fecbbc00 fe85af00 fe590000 fe590000 fe432800 fe418000 
fe5c7b00 fe5c7b00 fe8c8f00 fed64800 ff2fc000 ff2fc000 ff8ee400 fff0bc00 
004a1800 004a1800 009dd400 00df4700 010b1b00 010b1b00 01223800 01224300 
0108af00 0108af00 00db4b00 00a35000 005c0400 005c0400 001bd300 ffd71400 
ff9e5c00 ff9e5c00 ff73ac00 ff588000 ff51af00 ff51af00 ff655800 ff950300 
ffcb2800 ffcb2800 00169400 00673f00 00c08000 00c08000 01111300 015f2800 
01a0ef00 01a0ef00 01cb1000 01dea400 01d29f00 01d29f00 01a41c00 01579300 
00eccb00 00eccb00 00783f00 fffba800 ff833300 ff833300 ff147300 feb52800 
fe67bf00 fe67bf00 fe30d300 fe16c300 fe163700 fe163700 fe31fc00 fe668700 

So you should shift the samples if you set SAMPLE_BITS to 24 only.

It seems that the LSbits are crappy (either 00 or FC only) when SAMPLE_BITS is set to 32, and might be losing resolution.

The problem is that you might be working with 16 bits samples and not 24 if you set SAMPLE_BITSto 32 and shift the samples by 8 bits. This made me think that the way to calculate short_SPL_dB could be wrong, as you count the reference as 24 bits, not 16 bits:

    // Calculate dB values relative to MIC_REF_AMPL and adjust for microphone reference
    double short_RMS = sqrt(double(q.sum_sqr_SPL) / SAMPLES_SHORT);
    double short_SPL_dB = MIC_OFFSET_DB + MIC_REF_DB + 20 * log10(short_RMS / MIC_REF_AMPL);
// Calculate reference amplitude value at compile time
constexpr double MIC_REF_AMPL = pow(10, double(MIC_SENSITIVITY)/20) * ((1<<(MIC_BITS-1))-1);

In my opinion, at least with an INMP441, the way to operate should be: initialize the driver with #define SAMPLE_BITS 24 and shift samples 8 bits to the right:

for(int i=0; i<ACQ_PACK_SAMPLES; i++) samples[i] = (float) (int_samples[i] >> 8);

This implementation breaks your solution for several MEMS, but as I only have INMP441 sensors I do not know if this happens in all of them or just on the INMP441.

Thank you for your time

Could you please support B-weighting?

I can calculate sos and gain of b-weighting through the similar way of calculating a&c weighting. but the high freq part is not perfect, and descending too fast.
could you please upload a matlab file for b-weighting, Thanks a lot!!!

Poblem with i2s_config_t

Hello! I woukd like to know if by any chance, you know if it is possible to do the same on an ESP8266 Wemos D1 mini. I understand that i would need to change some libraries but i cannot find wichones would work for me.

Apreciate the help.

dBC Support

What would be required to support a dBC filter?

Constant dB(A) level even though microphone data changes

I am trying to get your standard code working with a ICS43434 microphone connected as follows:

#define I2S_WS 22
#define I2S_SCK 23
#define I2S_SD 5

I can see the I2S CLK, I2S_WS going into the microphone and I2S_SD data coming out, using a logic analyser, but the reported dBA value just sits at between 51.0 and 53.0 and when the microphone audio level increases nothing happens, the level remains the same.
I am using Arduino IDE 1.8.10 and esp32 v1.0.4 to compile.

Is there anything I can add in the code to see if the microphone data is being read and processed correctly ?

Meaning of MIC_OFFSET_DB constant

Hi, Thank you for the excellent work you put into frequency compensation and frequency weighting. Due to availability, I'd like to use your code with the INMP441 microphone. Unfortunately, I don't fully understand the purpose of the constant MIC_OFFSET_DB.
Is it some value calculated from the manufacturer's specifications. Or is it some offset set by comparing the measurements with a calibrated device? I'd appreciate it if you could provide some clarification.

#define MIC_OFFSET_DB 3.0103 // Default offset (sine-wave RMS vs. dBFS). Modify this value for linear calibration

I2s to i2s converter (format)

Hello, great idea with this project.
I have question,is it possible to make some conventer i2s to i2s with volume correction? Or other futures (equalizer??).
Regards

Stuck reading Led_dB

Hello there! Thank you so much for this project, its amaizing!

I've been trying to incorporate the code to a multisensor I'm creating but when the ESP reads
Serial.printf("%.1f\n", Leq_dB);
Serial.println("dB");

it gets stucks reading forever and won't go back to the loop (see attached picture)

any thoughts?

extra:
what does ("%.1f\n", Leq_dB); means?
I tried reading a Serial.print(Leq_dB); but i get an error

my code is:

void readNoise()
{

// Create FreeRTOS queue
samples_queue = xQueueCreate(8, sizeof(sum_queue_t));

// Create the I2S reader FreeRTOS task
// NOTE: Current version of ESP-IDF will pin the task
// automatically to the first core it happens to run on
// (due to using the hardware FPU instructions).
// For manual control see: xTaskCreatePinnedToCore
xTaskCreate(mic_i2s_reader_task, "Mic I2S Reader", I2S_TASK_STACK, NULL, I2S_TASK_PRI, NULL);

sum_queue_t q;
uint32_t Leq_samples = 0;
double Leq_sum_sqr = 0;
double Leq_dB = 0;

// Read sum of samaples, calculated by 'i2s_reader_task'
while (xQueueReceive(samples_queue, &q, portMAX_DELAY)) {

// Calculate dB values relative to MIC_REF_AMPL and adjust for microphone reference
double short_RMS = sqrt(double(q.sum_sqr_SPL) / SAMPLES_SHORT);
double short_SPL_dB = MIC_OFFSET_DB + MIC_REF_DB + 20 * log10(short_RMS / MIC_REF_AMPL);

// In case of acoustic overload or below noise floor measurement, report infinty Leq value
if (short_SPL_dB > MIC_OVERLOAD_DB) {
  Leq_sum_sqr = INFINITY;
} else if (isnan(short_SPL_dB) || (short_SPL_dB < MIC_NOISE_DB)) {
  Leq_sum_sqr = -INFINITY;
}

// Accumulate Leq sum
Leq_sum_sqr += q.sum_sqr_weighted;
Leq_samples += SAMPLES_SHORT;

// When we gather enough samples, calculate new Leq value
if (Leq_samples >= SAMPLE_RATE * LEQ_PERIOD) {
  double Leq_RMS = sqrt(Leq_sum_sqr / Leq_samples);
  Leq_dB = MIC_OFFSET_DB + MIC_REF_DB + 20 * log10(Leq_RMS / MIC_REF_AMPL);
  Leq_sum_sqr = 0;
  Leq_samples = 0;
  
  // Serial output, customize (or remove) as needed

 noise = ("%.1f\n", Leq_dB);
  Serial.print("Decibeles: ");  
  Serial.printf("%.1f\n", Leq_dB);
  Serial.println("dB");


  // Debug only
  //Serial.printf("%u processing ticks\n", q.proc_ticks);
}
}    

}

thanks!!!

WiFi Implementation

Everything is working fine but when i implement wifi i get constantly this error
Guru Meditation Error: Core 0 panic'ed (Unhandled debug exception).
Debug exception reason: Stack canary watchpoint triggered (Mic I2S Reader)
Core 0 register dump:
PC : 0x4008f75b PS : 0x00060736 A0 : 0x8008589a A1 : 0x3ffe89d0
A2 : 0x3ffbf6b0 A3 : 0xb33fffff A4 : 0x0000abab A5 : 0x00060723
A6 : 0x00060720 A7 : 0x0000cdcd A8 : 0xb33fffff A9 : 0xffffffff
A10 : 0x3ffe923c A11 : 0x3ffb6884 A12 : 0x3ffb6af8 A13 : 0x00000042
A14 : 0x007bf6b0 A15 : 0x003fffff SAR : 0x00000004 EXCCAUSE: 0x00000001
EXCVADDR: 0x00000000 LBEG : 0x4008a505 LEND : 0x4008a515 LCOUNT : 0xfffffffa

Backtrace: 0x4008f758:0x3ffe89d0 0x40085897:0x3ffe8a10 0x400858d2:0x3ffe8a30 0x40085a49:0x3ffe8a60 0x400eb161:0x3ffe8a80 0x400ea45f:0x3ffe8aa0 0x400e9e55:0x3ffe8ac0 0x4008a201:0x3ffe8ae0 0x40089696:0x3ffe8b00 0x40089720:0x3ffe8b20 0x40089c0d:0x3ffe8b50 0x40152d0f:0x3ffe8b80 0x4014e87b:0x3ffe8ba0 0x4014e9f9:0x3ffe8eb0 0x4015ea29:0x3ffe8ee0 0x401089aa:0x3ffe8f10 0x40108a47:0x3ffe8f40 0x400dd51d:0x3ffe8fc0 0x400de5e4:0x3ffe9000 0x400decdd:0x3ffe9050 0x400d3355:0x3ffe9090 0x400d374f:0x3ffe9120

or sometimes i get this error that i2s driver doesn't installed
E (23978) I2S: i2s_alloc_dma_buffer(740): Error malloc dma buffer
E (23979) I2S: i2s_realloc_dma_buffer(787): Failed to allocate dma buffer
E (23982) I2S: i2s_set_clk(1748): I2S0 rx DMA buffer malloc failed
E (23988) I2S: i2s_driver_install(2026): I2S set clock failed
[ 11906][E][Microphone.cpp:25] mic_init(): [I2S Protocol] Failed to install I2S driver: 257

I don't have any clue why it is not working when i am implementing wifi but everything works fine when i test wifi alone and slm code alone

does anyone have an idea how can i fix it

Can you support integrating these filters into another project.

Hi,
I have used the following repo esp32_sdcard_audio to build an rotary phone to store voice messages on an SD card.
It's work quite good now and I will publish the source code soon on GitHub.

One "issue" is, that the sound quality is okay, but not perfect. I hope it could become better with the usage of your filters. Main pain point is, that if you speak "too" loud, the voice is breaking on the recording.

I was wondering if I could integrate these filters into this project.
The project ist based on sample rate of 16000. Also 1 Channel and 32bits/sample
Also the data is streamed from the recording directly into the SD Card in a batch of 1024 samples.

What do you think? Would it be still "fast" enough to filter the data on the fly?

Best,
Johannes

Error in SOS_IIR_Filter

Hello,

I'm working on the ICS-43434 sensor. I want to run this code on STM32 IDE but struck over the file SOS_IIR_Filter.h and the line is struct SOS_IIR_Filter. since I'm new to C++. so, I don't know the struct constructor, can you please tell me the logic that how to convert the noise into dB?

Please reply to me as soon as possible.
Thank you.

Porting to rp2040?

How hard would it be to port this code to rp2040? I just got a few of those to setup such an application before I found this code.

Varying microphone self noise (INMP441) after restarts

Hi, thanks for the great project!

This is probably not your issue, but I just would like to share my experience with this mic for measuring environment noise.

While doing some experiments I noticed a few issues:

  1. Even in quite room, the lowest sound level I could get was only 36 dBA, although according to specs it should be 33 dBA
  2. But really confusing was that self noise could change +-5 dBFS after each restart. Though if applying A-weighting it is less noticeable, but anyway.

My setup is quite simple:

I tried quite a lot of things trying to investigate and/or fix it:

  1. Powering ESP32 from usb or battery
  2. Turning WiFi on/off or lowering its power
  3. Trying IDF 4.4.3 or IDF 5.0/5.1, micropython
  4. Trying different ESP32 boards (including S3)
  5. Trying different INMP441 instances (I have only 2). They actually vary a bit and with one mic I could get lower dBA overall than with other. However they both have the same issue of changing self-noise frequencies/level after restarts.
  6. Trying different wires/pins.
  7. Trying different sample rates/bits per sample. Actually some combinations work better than others.

Unfortunately I don't have other mics to compare. ICS 43434 should work better, but it is quite hard to get it here.

Also I found a few ways to reproduce the issue:

  1. By completely powering on/off
  2. By pressing Reset button
  3. By removing mic from the breadboard and reinserting it again
  4. By calling i2s_driver_uninstall and then i2s_driver_install again
  5. By calling i2s_stop/i2s_start

To investigate it further I made a sketch that does i2s_driver_install/i2s_driver_uninstall every minute and randomly changes sample rate/bits per sample every 5 minutes, and run it for a few hours.

Although it was quite quiet environment (night time), you can see from the chart below, that changing sample rate/bits per channel affects self-noise quite a bit, which might be understandable, but what's more frustrating is that if sample rate and bits per sample doesn't change, noise levels could change after just driver re-installation.

image

Running it for 10 hours and faceting the chart by sample rate/bits per channel and removing gaps inside one chart we can get this:

image

From it we can see, that some sample rates/bits per sample doing better than others:

  1. 10000 samples expectable performs quite bad
  2. 24/32 bits with 44100/48000 sample rate also has quite bad variability.
  3. 16 bit with 44100/48000 seems to be quite stable.
  4. 32 bit with 22050 rate also seems to be OK (surprisingly)

Here is how different noise waves looks like. Those are just two samples with same rate/bits (32 bit@48K), but one is before restart, another - after:
image

Here are a few self-noise spectrums (1024 point FFT):
image

Looks like it is quite similar at high frequencies, but it could vary quite a lot at lower/mid.

TBH, I'm not sure what is the best way to deal with this issue (except buying a better mic). Actually, I don't know for sure if this is a hardware or software issue. And if it is fixable or not. Probably would go for now with 16 bit@48KHz for better stability, albeit loosing some precision. Would be thankful for any advice/explanation why this happens, as I'm quite new to electronics/audio domain.

Update:

However seems like there is another weird issue when using bit depth < 32, see atomic14/esp32-tft-audio-monitor#2

Support for PDM microphone TDK T3902 ?

Trying to use esp32-i2s-slm with a PDM microphone TDK T3902. Changed the interface config to PDM mode, however still some issues remain and getting just inf response.

Would you be able to specify what needs to be change in order to get T3902 working ?

Measuring Infinity dB with SPH0645

Hello,

I try to get this example to run with the SPH0645 I2S mic. I'm using an ESP32 NodeMCU Board.
The pins are mapped correctly, as I can read raw samples and plot them.
But the dB reading says Inf, and I don't know what I did wrong? I didn't change anything besides the pin map.

The value for short_SPL_dB is calculated at 123.1 which is obviously greater than MIC_OVERLOAD_DB at 116, hence the Inf value. But why do I get wrong readings and how can I find the problem?

Thank you for any help.

Modify code for longer LEQ_PERIOD

Hi,

The current program calculates and displays the LEQ every 1 second. How can I modify the code to display the LEQ every 5 minutes instead?

If I were to change LED_PERIOD to 300, then SAMPLES_LEQ will become 14,400,000, and the accumulated Leq sum would probably overflow?

I am not familar with calculating LEQ, but I presume I can't just add up the LEQs for every one second and divide it by 300 (after 5 minutes) to get the average LEQ for 5 minutes right?

I get constantly nan as output

I am doing my BENG project, which i should design a noise detector using I2S microphone. I am using an INMP441 microphone with an ESP32-Devkitc-32E.
I have found out that I2S communication is only working for me with 16 bit resolution and only with left channel. I am using your code but i constantly get nan as output. what could be the issue. I have also set bits_per_sample to 16 bits.
Problem is that i have none experience with I2S protocol and can't solve it. Is it anyone that can help me with that. I would really appericiate it
Thanks alot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.