-
Notifications
You must be signed in to change notification settings - Fork 267
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
SoundFonts cannot be unloaded if polyphony is ever exceeded #727
Comments
Yeah, I know. That bug already exists since at least fluidsynth 1.1.6. The problem is that the call to During all this time I haven't come up with an idea... this is not trivial to solve. The timer unloading mechanism is garbage as well. And I'm afraid I don't really have motiviation to look into this. @jjceresa is that something for you? |
Understood - yes; normally I like to try and provide a patch/PR but this one looked very tricky (and I don't know much about Fluid internals). My apologies if you already knew about it - I can work around the problem for my use case in the meantime. 🙂 |
@dwhinham Thanks for reporting this bug. This should be fixed in next PR. |
@jjceresa Thankyou! I just tested your PR and it does indeed appear to fix this bug. The SoundFont is now unloaded as expected and Thankyou for addressing it so quickly! 😀 |
It looks better, yes. But I'm observing that I have to send two NoteOffs to make fluidsynth unload the font: $ fluidsynth -v -la alsa -o synth.polyphony=2 /usr/share/sounds/sf2/FluidR3_GM.sf2
> noteon 0 60 127 # voice count is 2
> unload 1
> noteoff 0 60 # voice count is still 2
> noteoff 0 60 # voice count is 0
fluidsynth: debug: Unloaded SoundFont
fluidsynth: debug: Timer thread finished It works fine when the unload comes after the noteoff:
|
Using FluidR3_GM.sf2 and other sfonts I cannot reproduce this here. After noteoff the voice count is always 0. Did your observations always true at each try or is it random ? |
Your are right, and this is normal. Please remember, after sending the first So the sequence: |
Indeed, you're correct. Client apps will most likely make another call to the synth API, so this would be acceptable. But, let's assume that this "next API call" never happens and instead
This topic seems important enough to construct some unit tests. I'll see what can be done. ... In an ideal world, we would put all the soundfonts which have been requested for unloading to a |
yes, understood. There is another solution that is to make Inside Do you see another way to pass the synth variable via the parameter |
No. The |
Ok, I've set up two unit tests on the For now, I've added two test-cases:
The second test case is So, JJC if you want to continue with this, you may do so on the |
Yes, of course. Stupid of me! |
Sorry I have problem trying to pull fix-sfunload branches locally. I got $ git pull Same problems trying to pull I don't know how to do to obtain the 2 unit tests |
I have some some changes on branch |
git pull performs a merge. Perhaps you've chosen the wrong base branch (master instead of 2.1.x). It's ok, just keep working with the branches you have. To apply my unit test, just execute the following command on your branch git fetch origin
git cherry-pick e67f23eb11e926dadaefc51090f8b5940a1ef7e2 |
yes, I made the wrong git commands. Thanks for your advise.
Thanks for these useful units tests. Indeed I've added these unit tests into |
Looks good, thanks JJC! I'll sleep over it again, maybe I'll come up with another test case. But at the moment it looks safe to me. |
Perhaps, we should add 2 tests case to complete the ones you already provided ?:
|
Done, see PR #735. I also found another use-after-free bug, which I've fixed as well. I found that the patch from issue #151 introduced this particular unloading bug when polyphony has been exceeded: 2f3a1a9, that was your patch, JJC :) However, the "missing next API call issue" from my comment above seems to date back much longer. Looking at the code, even fluidsynth 1.1.4 had a @dwhinham Thanks for the report! |
@derselbst My pleasure, I appreciate you and @jjceresa looking into this so quickly. Thanks again and Happy New Year! 😃 |
Apply fixes for FluidSynth/fluidsynth#727 via patch until a new version is released. This should clear up some memory leaks related to SoundFont unloading.
This PR adds regression tests for FluidSynth#727, ensuring that soundfonts are correctly unloaded via the lazy-timer-unloading mechanism.
FluidSynth version
v2.1.5
Describe the bug
If polyphony is exceeded and FluidSynth has to allocate a voice by calling
fluid_synth_free_voice_by_kill_LOCAL()
, two problems occur:fluid_synth_get_active_voice_count()
becomes inaccurate - the active voice count never returns back to 0 because the counter is not decremented in the usual way.fluid_synth_sfunload_callback()
unsuccessfully tries to unload the SoundFont forever.Expected behavior
fluid_synth_get_active_voice_count()
should provide an accurate value even if polyphony was exceeded during the session.Steps to reproduce
fluid_synth_sfunload_callback()
and notice that it continues to be called repeatedly long after the request was made, even though all voices may be idle.Additional context
As a quick hack to monitor the active voice count, I added the following code just before the call to
fluid_istream_readline()
, near line 510 offluid_cmd.c
:This is just so I could hit enter and see the result. After polyphony is exceeded, this value never returns to zero.
Thanks for your hard work on FluidSynth!
The text was updated successfully, but these errors were encountered: