I've finished the first draft of the dynamic sample loading. You can see the change in this pull request:
If you want to try out the changes, please check out the dynamic-sample-loading branch:
The implementation is actually quite simple and follows the approach that I've outlined earlier. When loading a Soundfont, everything apart from the sample data is loaded. As soon as a preset is selected for a channel, all samples of all instrument zones in that preset are individually loaded into memory. And when a preset is unselected again, all samples of all instrument zones of that preset are unloaded from memory again, unless they are still in use by another selected preset. The loading and unloading is triggered by the fluid_preset_t::notify and fluid_sample_t::notify callbacks.
What I haven't implemented yet is the parsing of a MIID file before playback to pre-load all used presets in the file. I think that can be added later, once the overall idea and implementation of dynamic loading has been finalised.
I've done a fair amount of testing of the code with both SF2 and SF3 files, but I would be very grateful if some of you could also give it a spin. To enable the feature, please use the
new "synth.dynamic-sample-loading" setting.
I'm looking forward to your feedback!