Inputting audio to an ESP32 from an INMP441 I2S microphone: success

walinsky
Posts: 3
Joined: Wed Sep 20, 2023 2:42 pm

Re: Inputting audio to an ESP32 from an INMP441 I2S microphone: success

Postby walinsky » Mon Oct 02, 2023 6:47 pm

I had the same problems a few weeks ago. And finally solved it in a different thread.

khanhbkisp
Posts: 3
Joined: Fri Oct 27, 2023 2:46 pm

Re: Inputting audio to an ESP32 from an INMP441 I2S microphone: success

Postby khanhbkisp » Mon Oct 30, 2023 4:41 pm

Hi, I do exactly the same as chris_oz but in IDF 4.4.3. But after read I2S, my buffer32 is all zero. When I change to 16 bits per sample, it works. But with 16 bits per sample, when I test with 500Hz, it seems like it's not working correctly. I just really want to know why 32 bits per sample not working in this case.
This is my i2s configuration:

Code: Select all

// Set up I2S Processor configuration
void i2s_install() {
  // Set up I2S Processor configuration
  i2s_config_t i2s_config = {
    .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
    .sample_rate = 4000, // or 44100 if you like
    .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // Ground the L/R pin on the INMP441.
    .communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S),
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count = bufferCount,
    .dma_buf_len = bufferLen,
    .use_apll = false,
    .tx_desc_auto_clear = false,
    .fixed_mclk = 0,
  };

  i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
}
And this is how I read I2S:

Code: Select all

while (1)
    {
        vTaskDelay(1); // Feed for watchdog, if not watchdog timer will be triggered!

        i2s_read(I2S_PORT, &buffer32, sizeof(buffer32), &bytesRead, 100);
        int samplesRead = bytesRead / 4;

        for (uint8_t i = 0; i < samplesRead; i++) {
            uint8_t mid = buffer32[i * 4 + 2];
            uint8_t msb = buffer32[i * 4 + 3];
            uint16_t raw = (((uint32_t)msb) << 8) + ((uint32_t)mid);
            memcpy(&buffer16[i], &raw, sizeof(raw)); // Copy so sign bits aren't interfered with somehow.
            printf("%d %d %d\n", 3000, -3000, buffer16[i]);
        }
    }
Is there any problem with I2S protocol in this version of IDF ? Has anyone ever encountered this problem? If yes and solved the problem please help me.

bstolk
Posts: 23
Joined: Fri Jan 07, 2022 6:44 am

Re: Inputting audio to an ESP32 from an INMP441 I2S microphone: success

Postby bstolk » Sat Dec 09, 2023 7:13 pm

chris_oz wrote:
Wed Apr 15, 2020 9:15 am
And that's it! You've got an array of 16-bit signed samples that are good to go.
Can you tell me... those samples you end up with, are they R,L,R,L,R,L...

Or only L?

Thanks!

wangnick
Posts: 5
Joined: Tue Dec 12, 2023 6:27 pm

Re: Inputting audio to an ESP32 from an INMP441 I2S microphone: success

Postby wangnick » Tue Dec 12, 2023 6:38 pm

Has anyone ever encountered this problem? If yes and solved the problem please help me.
Try I2S_CHANNEL_FMT_ONLY_RIGHT to receive the data from the "left" INMP441 channel (i.e. the data that the INMP441 provides in the first half of the sampling period when WS is LOW and the L/R pin is tied to GND). For me that does the trick.

KR, Sebastian

Who is online

Users browsing this forum: No registered users and 114 guests