Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2S Audio not fully working (devel branch) #21205

Open
Jason2866 opened this issue Apr 17, 2024 · 26 comments
Open

I2S Audio not fully working (devel branch) #21205

Jason2866 opened this issue Apr 17, 2024 · 26 comments
Assignees
Labels
enhancement Type - Enhancement that will be worked on work in progress Action - Work in progress

Comments

@Jason2866
Copy link
Collaborator

Jason2866 commented Apr 17, 2024

Follow up of #16074 (reply in thread)

Did some short tests.
- I2S micro not working (INMP441)
- mp3 stream not working

Crahes happened too.

EDIT: Working now with ESP32. ESP32-S3 i2s play issue left.
Migration status: Completed. S3 was not supported before.

@s-hadinger @gemu2015

@Jason2866 Jason2866 changed the title Core I2S Audio not working I2S Audio not working Apr 17, 2024
@Jason2866 Jason2866 changed the title I2S Audio not working I2S Audio not working (devel branch) Apr 17, 2024
@rug1024
Copy link

rug1024 commented Apr 18, 2024

Thanks to @Staars for giving the hint on i2sconfig. And yes, I am using INMP441.
With "RxMode=0" and "Mp3Preallocate=1" the error in the console is gone, but still getting the issue that
IP:81/stream.mp3 does not load.

@s-hadinger
Copy link
Collaborator

Will investigate in a couple of days

@Staars
Copy link
Contributor

Staars commented Apr 18, 2024

Meanwhile @rug1024 could try the following things (with seriallog 3):

  1. Check general microphone functionality with i2srec, e.g.:
    i2srec /test.mp3
    (then after a few seconds)
    i2srec (to stop recording and finish writing)
    Download and test MP3 file.

  2. Provide console output while accessing http://IP:81/stream.mp3 from your browser.
    Please also check output of i2sstream and test behaviour of switching stream server on/off with i2sstream 0/i2sstream 1.

@rug1024
Copy link

rug1024 commented Apr 18, 2024

On executing i2srec the device instantly crashed and does not reboot anymore.
Power cycle also not successfull, think it needs to be reflashed with Esptool.

@Jason2866 Jason2866 added work in progress Action - Work in progress migration (breaking) changes -> new concept / function labels Apr 18, 2024
@Staars
Copy link
Contributor

Staars commented Apr 19, 2024

Okay, I have found my INMP441 and could fix the crashes with i2srec.
It was possible to record raw audio in Berry, but the MP3 encoder ist totally broken at the moment, so no luck with i2srec for now. This makes it impossible to stream MP3 for obvious reasons too, although there was another bug that would crash the ESP before the start of the (non working) stream.
There are a few more glitches.

@s-hadinger
Copy link
Collaborator

s-hadinger commented Apr 21, 2024

Can you guys describe your configuration (especially template) when the crash happens?

Also the output of command I2SConfig

@Staars
Copy link
Contributor

Staars commented Apr 21, 2024

The crashes in i2srec will happen in every mic-only-configuration at the moment, because these calls can not work without an output instance.


The i2sstream does not start the mic at the moment and crashes without starting it by hand withi2smic 1.

But I still only get garbage MP3 data from the encoder ... which I do not understand yet.

@Staars
Copy link
Contributor

Staars commented Apr 25, 2024

After more bugfixing I have the driver working including MP3 streaming, but the INMP441 is a special animal, that seems to need an unusual I2S configuration. ATM this microphone produces garbled/distorted sound, but at least it works somehow. I have found more infos in other projects, but need to test this myself.

The good thing is, that the new driver is very flexible and can be extented quite easily to reflect very different configurations with one firmware image. You can already exchange the connected microphone (i.e. from Standard to PDM), reconfigure it and use it without reflashing the ESP32.
IMHO it is a huge step forward.

@rug1024
Copy link

rug1024 commented Apr 25, 2024

Great news! Thanks for the effort!
The distortion you report has occurred here too, also in previous Tasmota-builds (afaik since 12.x).
Found out just yet: It's only there when streaming live, when recording via i2srec it's not.
I attached a sample of what it sounds like (recorded with my mobile in front of the speaker).
audio.zip
Next thing: the distortion is only with my ESP32S3, on two other ESP32S2 the stream is clean (Tasmota 13.4.0 Master, Core/SDK Version: 2.0.14 / 4.4.6.240105).
Since these mics don't cost much, what other types can you recommend? Willing to buy and test.

@Staars
Copy link
Contributor

Staars commented Apr 25, 2024

Interesting point about the different behavior of different SOC's.

I will have to check this too as currently the INMP441 is connected to a S3. In theory it should not matter, but I would not be too surprised to find the same.

My PDM micro is a cheap clone of this:
https://learn.adafruit.com/adafruit-pdm-microphone-breakout/overview

But is not extensively tested by me so far. Initial impression is good.

@Staars
Copy link
Contributor

Staars commented Apr 25, 2024

INMP441 works here now for MP3 audio recording and streaming on the S3 without distortion and the expected (mediocre) sound quality.
I hope this is repeatable on other platforms too.

Please allow some time for testing and code refactoring as we need some new variables in the driver setting.

@rug1024
Copy link

rug1024 commented Apr 25, 2024

Great news! Ordered myself 2 of these PDM Mics for testing (like the JST-SH plug).
Will compare to INMP441 and report.

@rug1024
Copy link

rug1024 commented Apr 26, 2024

@Staars
Can you please post your compiler options?
Not quite getting the PDM Mic working yet.

@Staars
Copy link
Contributor

Staars commented Apr 26, 2024

Current state of changes here:
https://github.com/Staars/Tasmota/tree/i2s

There are more refactoring steps ahead, but with the next PR I would like to change as few things as possible.

[env:tasmota32s3-i2s]
extends                     = env:tasmota32_base
board                       = esp32s3-qio_opi
build_flags                 = ${env:tasmota32_base.build_flags}
                              -DFIRMWARE_TASMOTA32
                              -DUSE_I2S
                              -DUSE_I2S_AUDIO
                              -DUSE_I2S_MIC
                              -DUSE_SHINE
                              -DMP3_MIC_STREAM
                              -DUSE_I2S_AUDIO_BERRY
                              -DOTA_URL='""'
lib_extra_dirs              = lib/libesp32, lib/libesp32_div, lib/lib_basic, lib/lib_ssl, lib/lib_i2c, lib/lib_audio
lib_ignore                  = Micro-RTSP

Out of the box this should work with an PDM microphone.
i2sconfig {"Rx":{"Mode":0}} would change to standard mode with default settings for INMP441 with left channel.
i2sconfig {"Rx":{"SlotMask":2}} would change this to right channel.

I2smgain should be set to something like 30-60.

i2sconfig {"Sys":{"Mp3Preallocate":1}} is needed for both. Correct pin settings are of course needed too.

@rug1024
Copy link

rug1024 commented Apr 27, 2024

Will need some time for testing and trying to get this running.
Just wondering what that is for:
grafik

@Staars
Copy link
Contributor

Staars commented Apr 27, 2024

Forget the current docs, the aim for the new driver was to configure "everything" at runtime.

So things like PDM, left/right, mono/stereo, ... do not need a different firmware. You will be even able to swap out the microphone to a total different type later or back and forth without reflashing.

@rug1024
Copy link

rug1024 commented Apr 27, 2024

I tried to compile with Gitpod using your fork, unfortunately this does not work very well.
Since I also use ESP32S3 for testing, could you send me compiled binary just to find out if my mic is working at all?

@Staars
Copy link
Contributor

Staars commented Apr 27, 2024

Then please head over to Discord and find me there or use Tasmotas compiling-development channel.

@Jason2866
Copy link
Collaborator Author

Tested with M5stack core 2 and i2rec works. saytime does work too.

@Jason2866
Copy link
Collaborator Author

@Staars Can we close this? Everything I tested is working.

@gemu2015
Copy link
Contributor

gemu2015 commented May 6, 2024

i currently focus on other things,

but after a short test on 2 esp32s3 devices i2splay does only produce some noise while it works on an esp32. i2ssay and i2stime works on all devices, so the i2s channel seems to be ok.

i have a couple of problems with core 3 with several devices such that i will stay at core2 for some more weeks.
e.g. jpeg decoder crashes, (now in rom, used to be in flash)
par8 and par16 display does no longer work. (currently no time to investigate)

@Jason2866
Copy link
Collaborator Author

Jason2866 commented May 6, 2024

@gemu2015 not related to i2s but parallel display do work with core 3.0.0 and uDisplay driver.

EDIT: RGB Display is working. Don't have a parallel display to test.

@s-hadinger
Copy link
Collaborator

Unfortunately I don't have any PAR8/PAR16 display... So I can't help

@Jason2866 Jason2866 changed the title I2S Audio not working (devel branch) I2S Audio not fully working (devel branch) May 10, 2024
@Jason2866 Jason2866 added the enhancement Type - Enhancement that will be worked on label May 10, 2024
@Jason2866 Jason2866 removed the migration (breaking) changes -> new concept / function label May 10, 2024
@sfromis
Copy link
Contributor

sfromis commented May 17, 2024

I was trying to get I2S audio to work with small 8Ω speaker connected to a board having a MAX98357A. Configured the I2S gpios for BCLK, WS and DOUT to match, and left the SD and GAIN pins unconnected, as indicated on the external DAC wiring suggestions in the docs. The board schematics indicate that GAIN is pulled down, and SD connected directly to the ESP32-S3, no pull-up/down, so unconfigured would be floating.

No luck with commands I2SSay or I2STime.

As MAX98357A specs says that SD_MODE pulled low means shutdown, I decided to config the ESP32-S3 pin as Output Hi and now the test cases worked (not great voice quality, but I'm not very demanding).

Not knowing much about I2S audio, I'm wondering if this suggestion should just be made part of the docs, or if there are complications needing extra considerations.

@Jason2866
Copy link
Collaborator Author

@sfromis imho mentioning SD_MODE needs a defined state should be in the docs.

@sfromis
Copy link
Contributor

sfromis commented May 17, 2024

Did a small test getting a WebRadio MP3 stream to play. Got a few seconds of garbled sound first, but then normal audio. Next step was interrupting it with the command I2STime (saw no clean way of stopping a stream), and got:

[14:34:11.626] 14:34:11.037 CMD: I2SWr http://listen.livestreamingservice.com/181-jazzmix_128k.mp3
[14:34:12.517] 14:34:11.928 I2S: Tx i2s_channel_enable err=0x0000
[14:34:13.041] 14:34:11.934 MQT: t337blng/stat/I2SWR = {"I2SWR":"http://listen.livestreamingservice.com/181-jazzmix_128k.mp3"}
[14:34:13.041] 14:34:12.452 I2S: updateClockConfig i2s_channel_disable err=0x0000
[14:34:13.043] 14:34:12.454 I2S: updateClockConfig i2s_channel_reconfig_std_clock err=0x0000
[14:34:13.044] 14:34:12.455 I2S: updateClockConfig i2s_channel_enable err=0x0000
[14:34:57.870] 14:34:57.282 CMD: i2stime
[14:34:57.880] 14:34:57.290 I2S: updateClockConfig i2s_channel_disable err=0x0000
[14:34:57.880] 14:34:57.291 I2S: Could not write samples (count=1): 259
[14:34:57.880] 14:34:57.292 I2S: Could not write samples (count=1): 259
[14:34:57.881] 14:34:57.293 I2S: Could not write samples (count=1): 259
[14:34:57.883] 14:34:57.294 I2S: Could not write samples (count=1): 259

Last message in a loop until I killed it (power off). First set of time stamps from my terminal program.

(Found how to stop the stream, just the command I2SWr without URL).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type - Enhancement that will be worked on work in progress Action - Work in progress
Projects
None yet
Development

No branches or pull requests

6 participants