Tasmota
Tasmota copied to clipboard
I2S Audio not fully working (devel branch)
Follow up of https://github.com/arendst/Tasmota/discussions/16074#discussioncomment-9143268
~~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
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.
Will investigate in a couple of days
Meanwhile @rug1024 could try the following things (with seriallog 3
):
-
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. -
Provide console output while accessing
http://IP:81/stream.mp3
from your browser. Please also check output ofi2sstream
and test behaviour of switching stream server on/off withi2sstream 0
/i2sstream 1
.
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.
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.
Can you guys describe your configuration (especially template) when the crash happens?
Also the output of command I2SConfig
The crashes in i2srec
will happen in every mic-only-configuration at the moment, because these calls can not work without an output instance.
https://github.com/arendst/Tasmota/blob/cb70ff7a778e2e38416faefd49575144e9edb9c7/tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_audio_idf51.ino#L436 https://github.com/arendst/Tasmota/blob/cb70ff7a778e2e38416faefd49575144e9edb9c7/tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_audio_idf51.ino#L462
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.
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.
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.
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.
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.
Great news! Ordered myself 2 of these PDM Mics for testing (like the JST-SH plug). Will compare to INMP441 and report.
@Staars Can you please post your compiler options? Not quite getting the PDM Mic working yet.
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.
Will need some time for testing and trying to get this running.
Just wondering what that is for:
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.
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?
Then please head over to Discord and find me there or use Tasmotas compiling-development channel.
Tested with M5stack core 2 and i2rec works. saytime does work too.
@Staars Can we close this? Everything I tested is working.
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)
@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.
Unfortunately I don't have any PAR8/PAR16 display... So I can't help
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.
@sfromis imho mentioning SD_MODE
needs a defined state should be in the docs.
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).
I ordered some cheap I2S stuff („the usual suspects from Ali“) to be able to do more tests myself. This includes the MAX98357A. I still was not able to find a failing configuration with the hardware I own.
The webradio does work now much more robust than with core 2.x, but you will always run into trouble with non optimal network conditions - which may happen outside your home.
Hopefully I can do more tests in the next 1-2 weeks to confirm, what works and how to configure it.
I'm indeed experiencing I2SWr
working better now.
Next step is trying to get the microphone to work. Schematics shows that my board has a MEMS microphone, ICS-43434 with this pinout:
39: Select (pulled down, 10K)
40: WS
41: Data
42: BCLK
No select pin in Tasmota gpio configs, I let it be for now.
And my Tasmota template includes:
Gpio.00 IO 1 User
Gpio.01 AO 7840 I2S WS1
Gpio.02 AO 7808 I2S BCLK1
Gpio.03 AO 7776 I2S DOUT1
Gpio.04 AO 3840 Output Hi That's the mentioned SD_MODE
Gpio.40 IO 7841 I2S WS2
Gpio.41 IO 7873 I2S DIN2
Gpio.42 IO 7809 I2S BCLK2
This means that I have a I2S DIN2
without having I2S DIN1
, I was not assuming this to be bad?
At boot, I have these messages:
I2S: config loaded from file '/.drvset042'
I2S: Tx i2s_channel_enable err=0x0000
Is error code 0 an error?
Where it gets "annoying" is when doing a test with I2SRec /test.mp3
, without having changed any I2SConfig
settings:
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x420fdf1e PS : 0x00060930 A0 : 0x820fdfae A1 : 0x3fcac490
A2 : 0x00000000 A3 : 0x3c1afb13 A4 : 0x00000016 A5 : 0x00000001
A6 : 0x0000004c A7 : 0x3fcac407 A8 : 0x820fdf1e A9 : 0x3fcac430
A10 : 0x00000003 A11 : 0x3fcb36f0 A12 : 0x00000000 A13 : 0x00000000
A14 : 0x3fce9a70 A15 : 0x3c2c0000 SAR : 0x00000018 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000036 LBEG : 0x400556d5 LEND : 0x400556e5 LCOUNT : 0xfffffffc
Backtrace: 0x420fdf1b:0x3fcac490 0x420fdfab:0x3fcac4b0 0x42030292:0x3fcac4e0 0x420071e3:0x3fcac500 0x4202f9bc:0x3fcac530 0x42064cef:0x3fcac590 0x42009a3f:0x3fcac5b0 0x42009b1e:0x3fcac6a0 0x42019679:0x3fcac6f0 0x42063599:0x3fcac740 0x42072319:0x3fcac760 0x42072e99:0x3fcac780 0x420748fe:0x3fcac7b0 0x42016f78:0x3fcac830 0x42064cef:0x3fcac880 0x4200f030:0x3fcac8a0 0x42009ce5:0x3fcac8c0 0x420daab2:0x3fcac930
Any noob errors?
Your microphone seems to need "standard mode", which requires i2sconfig {"Rx":{"Mode":0}}
.
Error code 0 means no error.
Is this a S3? You may try your luck with full duplex mode, which would share BCLK1 and WS1 for DIN1 and DOUT1. As you have such a setup (I do not), you can share your findings with both modes (duplex and two separate I2S channels).
Yes, same S3 Bling from UnexpectedMaker as when testing audio output. As it has completely separate I2S pins for amplifier and microphone, it does not sound like full duplex makes sense?
Anyway, tried setting I2SConfig {"Sys":{"Duplex":1}}
, (only place where I saw duplex on the docs page) which would not "stick", presumably due to having separate pins configured?
Trying to record after having set I2SConfig {"Rx":{"Mode":0}}
I'm still seeing a crash with LoadProhibited.
"Rx":{"SampleRate":32000,"Gain":30,"Mode":0,"SlotMask":1,"SlotWidth":32,"Channels":1,"DCFilterAlpha":32511,"LowpassAlpha":17719,"APLL":1,"WsWidth":32,"WsPol":0,"BitShift":1,"LeftAlign":1,"BigEndian":0,"LsbOrder":0,"DMAFrame":512,"DMADesc":3}}
(All configs are unchanged from first boot, except now for Rx:Mode).