Skip to content

CMake builds: MP3 decoder buffers from the heap, not static .bss - #299

Merged
bdbarnett merged 1 commit into
mainfrom
fix/mp3-heap-bss
Oct 21, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
fix/mp3-heap-bss

Conversation

@bdbarnett

@bdbarnett bdbarnett commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

On an ESP32-S3 the MP3 decoder's eight Helix buffers sat in internal RAM as static .bss, 23.8 kB of the 25.3 kB audiodsp holds there. micropython.cmake already asked for them from the heap, but the setting was a set_source_files_properties() on buffers.c. That property belongs to the directory that sets it, and the ESP32 build compiles every module source again from the project's directory, which is the copy that gets linked. That copy used the static fallback.

src/audiomp3/mp3_buffers.c now defines the allocator macros and includes buffers.c, so every compile of it gets them, in any directory. buffers.c and the other Helix sources are unchanged, and the Make build is as before.

Measured on an ESP32-S3 (ESP32_GENERIC_S3, SPIRAM_OCT) with the whole module set:

  • audiodsp .bss: 25,296 B before, 1,480 B after.
  • Free internal heap at boot on a Waveshare ESP32-S3-Touch-LCD-4.3: 176,851 B before, 200,819 B after.
  • A 3 s stereo MP3 decodes to the same bytes (same checksum, 117 buffers) and the rewind probe passes. Making an MP3Decoder now takes about 35.5 kB from the GC heap (PSRAM here), where it took 11.6 kB before, because the buffers are no longer static, and two decoders no longer share buffers.

… heap

micropython.cmake set the allocator macros on buffers.c with
set_source_files_properties(), which belongs to the directory that sets it. The
ESP32 build compiles each module source a second time from the project's
directory, and that is the copy that gets linked, so it had the static fallback:
23.8 kB of .bss, internal RAM on an S3. Define the macros in
src/audiomp3/mp3_buffers.c and include buffers.c from there, so every compile
of it gets them. On an ESP32-S3 audiodsp's .bss goes from 25,296 to 1,480 bytes,
and each MP3Decoder has buffers of its own.
@bdbarnett
bdbarnett merged commit 6f6dd03 into main Oct 21, 2026
31 checks passed
@bdbarnett
bdbarnett deleted the fix/mp3-heap-bss branch October 21, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant