MIDI: FluidSynth is now configured to load samples dynamically instead of caching entire banks at once

This commit is contained in:
Christopher Snowhill 2021-05-08 19:41:35 -07:00
parent dffe888124
commit b2a6a67170
2 changed files with 11 additions and 1 deletions

View file

@ -18,6 +18,7 @@ SFPlayer::SFPlayer() : MIDIPlayer()
_synth[1] = 0; _synth[1] = 0;
_synth[2] = 0; _synth[2] = 0;
uInterpolationMethod = FLUID_INTERP_DEFAULT; uInterpolationMethod = FLUID_INTERP_DEFAULT;
bDynamicLoading = true;
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
{ {
@ -26,6 +27,7 @@ SFPlayer::SFPlayer() : MIDIPlayer()
fluid_settings_setnum(_settings[i], "synth.gain", 0.2); fluid_settings_setnum(_settings[i], "synth.gain", 0.2);
fluid_settings_setnum(_settings[i], "synth.sample-rate", 44100); fluid_settings_setnum(_settings[i], "synth.sample-rate", 44100);
fluid_settings_setint(_settings[i], "synth.midi-channels", 16); fluid_settings_setint(_settings[i], "synth.midi-channels", 16);
fluid_settings_setint(_settings[i], "synth.dynamic-sample-loading", bDynamicLoading ? 1 : 0);
fluid_settings_setint(_settings[i], "synth.device-id", 0x10 + i); fluid_settings_setint(_settings[i], "synth.device-id", 0x10 + i);
} }
} }
@ -41,12 +43,17 @@ SFPlayer::~SFPlayer()
void SFPlayer::setInterpolationMethod(unsigned method) void SFPlayer::setInterpolationMethod(unsigned method)
{ {
shutdown();
uInterpolationMethod = method; uInterpolationMethod = method;
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
if ( _synth[i] ) fluid_synth_set_interp_method( _synth[i], -1, method ); if ( _synth[i] ) fluid_synth_set_interp_method( _synth[i], -1, method );
} }
void SFPlayer::setDynamicLoading(bool enabled)
{
shutdown();
bDynamicLoading = enabled;
}
void SFPlayer::send_event(uint32_t b) void SFPlayer::send_event(uint32_t b)
{ {
if (!(b & 0x80000000)) if (!(b & 0x80000000))
@ -157,6 +164,7 @@ bool SFPlayer::startup()
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
{ {
fluid_settings_setnum(_settings[i], "synth.sample-rate", uSampleRate); fluid_settings_setnum(_settings[i], "synth.sample-rate", uSampleRate);
fluid_settings_setint(_settings[i], "synth.dynamic-sample-loading", bDynamicLoading ? 1 : 0);
_synth[i] = new_fluid_synth(_settings[i]); _synth[i] = new_fluid_synth(_settings[i]);
if (!_synth[i]) if (!_synth[i])
{ {

View file

@ -26,6 +26,7 @@ public:
void setSoundFont( const char * in ); void setSoundFont( const char * in );
void setFileSoundFont( const char * in ); void setFileSoundFont( const char * in );
void setInterpolationMethod(unsigned method); void setInterpolationMethod(unsigned method);
void setDynamicLoading(bool enabled);
const char * GetLastError() const; const char * GetLastError() const;
@ -44,6 +45,7 @@ private:
std::string sFileSoundFontName; std::string sFileSoundFontName;
unsigned uInterpolationMethod; unsigned uInterpolationMethod;
bool bDynamicLoading;
}; };
#endif /* SFPlayer_h */ #endif /* SFPlayer_h */