Skip to content
This repository was archived by the owner on Oct 31, 2026. It is now read-only.

SoundFont instruments make their voices before opening the bank - #250

Merged
bdbarnett merged 1 commit into
mainfrom
fix/soundfont-sampler-first
Oct 31, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
fix/soundfont-sampler-first

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

audioinstruments.create("soundfont", ...) and create("soundfont_drums", ...) opened and parsed the bank before making the instrument's own voices. A sampler's voices are one block of memory, and after a large bank (FluidR3_GM, for one) is parsed the heap can have megabytes free in small pieces with no gap big enough. On an 8 MB MicroPython heap with the current audiodsp sampler, whose voices are larger, create() raised MemoryError allocating 16384 bytes and the instrument never played.

Both instruments now make their own pool before opening the bank, and free it again if the bank won't open. A pool you pass in as voice_pool is untouched either way.

On an 8 MB heap with FluidR3_GM, each instrument created alone now plays where it raised before. A second instrument with its own pool, created after a large bank is already open in the same interpreter, can still hit the same wall; make one Voices pool first and pass it to both, as the Voices docstring shows.

Tests: VoicesBeforeBankTest in tests/test_cpython_soundfont.py checks the order for both instruments and that an own pool is freed when the bank fails to open; three of its four tests fail without the change.

A sampler's voices are one block of memory. Opening a large bank first
can leave plenty free but no single gap that big, so create() failed
with MemoryError on an 8 MB heap once the sampler's voices grew. Both
soundfont and soundfont_drums now make their own pool first, and free
it again if the bank won't open.
@bdbarnett
bdbarnett merged commit 1515562 into main Oct 31, 2026
7 checks passed
@bdbarnett
bdbarnett deleted the fix/soundfont-sampler-first branch October 31, 2026 02:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant