This repository was archived by the owner on Oct 31, 2026. It is now read-only.
Repository navigation
SoundFont instruments make their voices before opening the bank - #250
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
audioinstruments.create("soundfont", ...)andcreate("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()raisedMemoryError allocating 16384 bytesand 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_poolis 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
Voicespool first and pass it to both, as theVoicesdocstring shows.Tests:
VoicesBeforeBankTestintests/test_cpython_soundfont.pychecks 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.