MIDI: Fix FluidSynth device-id setting, which requires unique settings objects

CQTexperiment
Christopher Snowhill 2021-05-06 19:02:25 -07:00
parent 81aca83940
commit 37aa36f9f4
2 changed files with 14 additions and 10 deletions

View File

@ -19,18 +19,24 @@ SFPlayer::SFPlayer() : MIDIPlayer()
_synth[2] = 0; _synth[2] = 0;
uInterpolationMethod = FLUID_INTERP_DEFAULT; uInterpolationMethod = FLUID_INTERP_DEFAULT;
_settings = new_fluid_settings(); for (unsigned int i = 0; i < 3; ++i)
{
_settings[i] = new_fluid_settings();
fluid_settings_setnum(_settings, "synth.gain", 0.2); fluid_settings_setnum(_settings[i], "synth.gain", 0.2);
fluid_settings_setnum(_settings, "synth.sample-rate", 44100); fluid_settings_setnum(_settings[i], "synth.sample-rate", 44100);
fluid_settings_setint(_settings, "synth.midi-channels", 16); fluid_settings_setint(_settings[i], "synth.midi-channels", 16);
fluid_settings_setint(_settings[i], "synth.device-id", 0x10 + i);
}
} }
SFPlayer::~SFPlayer() SFPlayer::~SFPlayer()
{ {
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
{
if (_synth[i]) delete_fluid_synth(_synth[i]); if (_synth[i]) delete_fluid_synth(_synth[i]);
if (_settings) delete_fluid_settings(_settings); if (_settings[i]) delete_fluid_settings(_settings[i]);
}
} }
void SFPlayer::setInterpolationMethod(unsigned method) void SFPlayer::setInterpolationMethod(unsigned method)
@ -148,12 +154,10 @@ bool SFPlayer::startup()
{ {
if ( _synth[0] && _synth[1] && _synth[2] ) return true; if ( _synth[0] && _synth[1] && _synth[2] ) return true;
fluid_settings_setnum(_settings, "synth.sample-rate", uSampleRate);
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
{ {
fluid_settings_setint(_settings, "synth.device-id", i); fluid_settings_setnum(_settings[i], "synth.sample-rate", uSampleRate);
_synth[i] = new_fluid_synth(_settings); _synth[i] = new_fluid_synth(_settings[i]);
if (!_synth[i]) if (!_synth[i])
{ {
_last_error = "Out of memory"; _last_error = "Out of memory";

View File

@ -38,7 +38,7 @@ private:
std::string _last_error; std::string _last_error;
fluid_settings_t * _settings; fluid_settings_t * _settings[3];
fluid_synth_t * _synth[3]; fluid_synth_t * _synth[3];
std::string sSoundFontName; std::string sSoundFontName;
std::string sFileSoundFontName; std::string sFileSoundFontName;