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

Enable mp3 output on esp32s3 #9218

Merged
merged 15 commits into from
May 2, 2024
Merged

Enable mp3 output on esp32s3 #9218

merged 15 commits into from
May 2, 2024

Conversation

jepler
Copy link
Member

@jepler jepler commented May 1, 2024

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.

jepler added 12 commits May 1, 2024 10:07
.. 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.
@tannewt tannewt self-requested a review May 1, 2024 20:52
Copy link
Member

@tannewt tannewt left a 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.

ports/espressif/mpconfigport.mk Outdated Show resolved Hide resolved
Copy link
Member

@tannewt tannewt left a 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!

ports/espressif/mpconfigport.mk Outdated Show resolved Hide resolved
Co-authored-by: Scott Shawcroft <scott@tannewt.org>
@jepler jepler requested a review from tannewt May 2, 2024 19:37
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt tannewt merged commit 9ab8831 into adafruit:main May 2, 2024
194 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants