I think I will just revert the changes in regards to processing
program change events in the helper thread. The problems with program
changes occurring in the synth thread (possible mutex contention and
memory allocation) seem less of an issue in comparison and will only
happen in the case of MIDI events being generated in the synthesis
thread.
I did start thinking along the lines of making the program change
lock/malloc free. Unfortunately the allocation of presets is left up
to the SoundFont loader. But the internal SoundFont loaders could be
modified to assign each preset a pre-allocated fluid_preset_t
structure, so that it does not need to be allocated or freed during
program change. In fact these structures could probably be shared for
an entire SoundFont. This means that the get_preset method would be
marked as a real-time sensitive method. Existing programs that use
the SoundFont loader would likely need to update this method, to
remain real-time safe.
I'm not sure how to resolve the need for the mutex protecting the
SoundFont list though. As far as making sure the SoundFont doesn't
get unloaded while the synth thread is using it, the synth thread
could just hold a reference to all SoundFonts. A remove request could
then be queued to the synth thread, which then queues an event back to
the return queue unref'ing it, at which point it would be removed.
Any ideas how to have a lock free method of accessing the SoundFont
list, when searching for a preset? A secondary shadow SoundFont list
owned by the synth thread, which is synchronized via the queue, might
work. Seems slightly messy though and I know how much you hate those
shadow variables ;)
Maybe its not worth trying to fix now.
Josh
_______________________________________________
fluid-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/fluid-dev