make sample rate changeable, probably

This commit is contained in:
Alex Birch 2018-04-15 21:32:26 +01:00
parent a82e7e450b
commit b5a807fe91
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
3 changed files with 16 additions and 0 deletions

View File

@ -12,6 +12,7 @@ FluidSynthModel::FluidSynthModel(SharesParams& p)
synth(nullptr),
settings(nullptr),
currentSoundFontAbsPath(),
currentSampleRate(44100),
initialised(false),
sfont_id(0),
channel(0)
@ -38,6 +39,7 @@ void FluidSynthModel::initialise() {
fluid_settings_setstr(settings, "synth.verbose", "yes");
synth = new_fluid_synth(settings);
fluid_synth_set_sample_rate(synth, currentSampleRate);
if (sharesParams.getSoundFontPath().isNotEmpty()) {
loadFont(sharesParams.getSoundFontPath());
@ -202,4 +204,13 @@ void FluidSynthModel::addListener (FluidSynthModel::Listener* const newListener)
void FluidSynthModel::removeListener (FluidSynthModel::Listener* const listener)
{
eventListeners.remove(listener);
}
void FluidSynthModel::setSampleRate(float sampleRate) {
currentSampleRate = sampleRate;
if (!initialised) {
// don't worry; we'll do this in initialise phase regardless
return;
}
fluid_synth_set_sample_rate(synth, sampleRate);
}

View File

@ -59,6 +59,8 @@ public:
*/
void removeListener (Listener* listener);
void setSampleRate(float sampleRate);
const String& getCurrentSoundFontAbsPath();
private:
@ -70,6 +72,8 @@ private:
String currentSoundFontAbsPath;
float currentSampleRate;
const fluid_preset_t getFirstPreset();
void selectFirstPreset();
unique_ptr<BankAndPreset> getFirstBankAndPreset();

View File

@ -111,6 +111,7 @@ void JuicySFAudioProcessor::prepareToPlay (double sampleRate, int /*samplesPerBl
// initialisation that you need..
synth.setCurrentPlaybackSampleRate (sampleRate);
keyboardState.reset();
fluidSynthModel.setSampleRate(static_cast<float>(sampleRate));
reset();
}