iiwusynth-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iiwusynth-devel] Re: unloading a soundfont


From: Peter Hanappe
Subject: [iiwusynth-devel] Re: unloading a soundfont
Date: Thu, 28 Nov 2002 15:12:49 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1


Markus wrote:

some thoughts about unloading sound fonts, This has been on my mind now
for a while.

- The unload routine has to wait, until the DSP loop in the DSP thread
has run through one buffer. Otherwise there is no way to stop a voice,
which uses the soundfont in question and is just in the middle of a
buffer.
- The unload routine could terminate all voices using the soundfont, and
block until the DSP thread has finished the current block. Don't like
that. Not at all.

I agree. We can do better.


The best I came up with so far:
- The unload routine flags the sound font as unloaded, so that no new
voice processes may use it.
Then we keep the old soundfont in memory and only unload it when the
next sound font is loaded (triggered by the 'load' function), assuming
that all voices have finished in the meantime.

Also, remove all presets of that soundfont from the MIDI channels.

We could add a 'reference count' into a soundfont: every time a voice
uses a preset from a soundfont, the reference count of that soundfont
is incremented. When the voice is finished, we decrement the refcount
again. When an unload request comes and the soundfont has a refcount
equal to zero, we unload it immediately otherwise we try to do it later.
When? At the next load request? That might not be good enough, because
the risk exists that soundfont stays in memory for a long time. At every
'noteon' and 'noteoff' event? That may not be good, too. That means that
real-time threads can no longer call this function!

Antoine wrote:
> Why not using the timer functions (in iiwu_sys.h) to schedule a
> callback
> sometime after the current buffer is done, that will do the cleanup ?
> This way, there is no need for the iiwu_idle function.

Yes, we could spin off a timer thread to do the work. It checks every N
msec (~1000 msec) if the soundfont is no longer used (refcount=0) and
frees it if possible.
This doesn't work on macos 9, though (can't free memory in interupt).


Cheers
Peter





reply via email to

[Prev in Thread] Current Thread [Next in Thread]