-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enable mp3 output on esp32s3 #9218
Conversation
.. just to prevent background tasks from running
it's the standard i2s format, and what's needed for max98357 breakout.
.. so that the underlying allocations will be freed. This is not important now but will be if the underlying allocator is changed to something else like `port_malloc` in the future.
.. espressif will be able to put the mp3 data in faster RAM this way.
These changes have been requested upstream at adafruit/Adafruit_MP3#21
gcc -fsanitize=undefined reports diagnostics like these: ``` ../../src/bitstream.c:93:36: runtime error: left shift of 177 by 24 places cannot be represented in type 'int' ../../src/imdct.c:86:53: runtime error: left shift of negative value -937 ``` -fwrapv provides implementation-defined behavior that matches the expectations of two's complement arithmetic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question about what boards to enable on. Good otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One obsolete comment. Good otherwise. Thanks!
Co-authored-by: Scott Shawcroft <scott@tannewt.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
With these changes I can successfully play a 48kBit/s, 22.5kHz, mono test file on the Adafruit Feather ESP32-S3 TFT using a max98357 breakout, which takes less than 10% of available CPU times. I have not tried higher bit rates, stereo playback etc., so I don't know the performance limits.
There are occasional audio glitches, which mostly correlate with the feather's charging LED. I think this is a HW problem but it's difficult to be sure.
This also fixes the problem that all I2S output was in a non-standard format since updating esp-idf (to 5.0? 5.1?). Now, the "philips standard" format is used again.
This needs adafruit/Adafruit_MP3#21
I made sure that my test program does not generate garbage while playing. The maximum I2S DMA buffer size is only about 1000 samples, or only about 20ms @ 48kHz. blocking background tasks will make the audio glitch, and garbage collection blocks background tasks. This is a larger problem on microcontrollers with PSRAM, like the feather s3 series, because the collection time is proportional to the size of the GC heap.
This also doesn't work on a debug build, the different optimization flags or additional error checking seemed to just add too much overhead to play back without glitching.