diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 9d9c1a21..20714e41 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -1149,7 +1149,7 @@ class AudioReactive : public Usermod { #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) case 5: DEBUGSR_PRINT(F("AR: I2S PDM Microphone - ")); DEBUGSR_PRINTLN(F(I2S_MIC_CHANNEL_TEXT)); - audioSource = new I2SSource(SAMPLE_RATE, BLOCK_SIZE); + audioSource = new I2SSource(SAMPLE_RATE, BLOCK_SIZE, true, 1.0f/4.0f); delay(100); if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin); break; diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index 9637f879..7ceb0760 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -201,11 +201,20 @@ class I2SSource : public AudioSource { return; } } else { + #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) + #if !defined(SOC_I2S_SUPPORTS_PDM_RX) + #warning this MCU does not support PDM microphones + #endif + #endif #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + // example from espressif: https://github.com/espressif/esp-idf/blob/release/v4.4/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c // This is an I2S PDM microphone, these microphones only use a clock and // data line, to make it simpler to debug, use the WS pin as CLK and SD // pin as DATA _config.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); // Change mode to pdm if clock pin not provided. PDM is not supported on ESP32-S2. PDM RX not supported on ESP32-C3 + _config.channel_format =I2S_CHANNEL_FMT_ONLY_LEFT; // seems that PDM mono mode always uses left channel. + //_config.use_apll = true; // experimental - use aPLL clock source to improve sampling quality + //_config.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT; // not needed #endif } @@ -249,9 +258,11 @@ class I2SSource : public AudioSource { DEBUGSR_PRINTF("AR: I2S#0 driver %s aPLL; fixed_mclk=%d.\n", _config.use_apll? "uses":"without", _config.fixed_mclk); DEBUGSR_PRINTF("AR: Sample scaling factor = %6.4f\n", _sampleScale); - if(_config.mode & I2S_MODE_MASTER) - DEBUGSR_PRINTLN(F("AR: I2S#0 driver installed in MASTER mode.")); - else + if(_config.mode & I2S_MODE_MASTER) { + if (_config.mode & I2S_MODE_PDM) + DEBUGSR_PRINTLN(F("AR: I2S#0 driver installed in PDM MASTER mode.")); + else DEBUGSR_PRINTLN(F("AR: I2S#0 driver installed in MASTER mode.")); + } else DEBUGSR_PRINTLN(F("AR: I2S#0 driver installed in SLAVE mode.")); err = i2s_set_pin(I2S_NUM_0, &_pinConfig);