Romkabouter/ESP32-Rhasspy-Satellite

Distorted mic signal with Inmp441Max98357a device

requireiot opened this issue · 2 comments

With the Inmp441Max98357a device, the audio input (microphone signal) is distorted, because each sample is sent twice (apparently, this is what the ESP32 API will do, when 16 bit resolution is requested).

To illustrate, I recorded the streamed signal while playing a loud 440 Hz tone through a PC speaker, the read the resulting WAV file in Audacity. Below are screenshots from Audacity, from the zoomed WAV signal, amplified by 6 dB for clarity.

This was compiled with platform Espressif 32 (4.2.0) for an "Espressif ESP32 Dev Module", framework framework-arduinoespressif32 @ 3.20002.220503 (2.0.2)

With the original code
old-code

With modified code, using 32 bit samples
new-code

The modified code is in my fork of the original code. I'm not a Github expert, I guess I'll have to figure out how to do a pull request ...

Nice fix, I will check your fork.
Thank you for the effort!

The code in my fork has 2 changes compared to the original, which maybe I shouldn't have checked in together, but too late now:

  1. a functional change to implement the duplicated 16-bit words as described above
  2. a cosmetic change, making the definitions at the top of Inmp441Max98357a.hpp more consistent: all pin numbers etc. pertaining to the microphone I2S port start with MIC_, all pin numbers etc. pertaining to the speaker I2S port start with SPK_, and the config structs in Inmp441Max98357a::init() end with _mic or _spk, resp. -- just made it easier for me to wrap my head about what pertains to what