Romkabouter / ESP32-Rhasspy-Satellite

The repo has implementing an esp32 standalone MQTT audio streamer. Is is desinged to work as a satellite for Rhasspy (https://rhasspy.readthedocs.io/en/latest/). It supports multiple devices
GNU General Public License v3.0
351 stars 63 forks source link

Distorted mic signal with Inmp441Max98357a device #134

Open requireiot opened 7 months ago

requireiot commented 7 months ago

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 ...

Romkabouter commented 7 months ago

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

requireiot commented 7 months ago

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