Re: Inputting audio to an ESP32 from an INMP441 I2S microphone: success
Posted: Mon Oct 02, 2023 6:47 pm
I had the same problems a few weeks ago. And finally solved it in a different thread.
ESP32 Official Forum
https://esp32.com/
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);
}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]);
}
}Can you tell me... those samples you end up with, are they R,L,R,L,R,L...And that's it! You've got an array of 16-bit signed samples that are good to go.
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.Has anyone ever encountered this problem? If yes and solved the problem please help me.