Skip to content

Commit d542db4

Browse files
committed
Limit internal GM synth to stereo output to prevent glitches
1 parent 88bab24 commit d542db4

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Source/Standalone/InternalSynth.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void InternalSynth::run()
4545
unprepareLock.lock();
4646

4747
// Fluidlite does not like setups with <2 channels
48-
internalBuffer.setSize(std::max(2, lastNumChannels.load()), lastBlockSize);
48+
internalBuffer.setSize(2, lastBlockSize);
4949
internalBuffer.clear();
5050

5151
// Check if soundfont exists to prevent crashing
@@ -57,7 +57,7 @@ void InternalSynth::run()
5757
fluid_settings_setint(settings, "synth.ladspa.active", 0);
5858
fluid_settings_setint(settings, "synth.midi-channels", 16);
5959
fluid_settings_setnum(settings, "synth.gain", 0.9f);
60-
fluid_settings_setnum(settings, "synth.audio-channels", lastNumChannels);
60+
fluid_settings_setnum(settings, "synth.audio-channels", 2);
6161
fluid_settings_setnum(settings, "synth.sample-rate", lastSampleRate);
6262
synth = new_fluid_synth(settings); // Create fluidsynth instance:
6363

@@ -90,7 +90,6 @@ void InternalSynth::unprepare()
9090

9191
lastSampleRate = 0;
9292
lastBlockSize = 0;
93-
lastNumChannels = 0;
9493

9594
ready = false;
9695

@@ -106,15 +105,13 @@ void InternalSynth::unprepare()
106105
void InternalSynth::prepare(int sampleRate, int blockSize, int numChannels)
107106
{
108107
#ifdef PLUGDATA_STANDALONE
109-
if (ready && !isThreadRunning() && sampleRate == lastSampleRate && blockSize == lastBlockSize && numChannels == lastNumChannels) {
108+
if (ready && !isThreadRunning() && sampleRate == lastSampleRate && blockSize == lastBlockSize) {
110109
return;
111110
} else {
112111
waitForThreadToExit(-1);
113112

114113
lastSampleRate = sampleRate;
115114
lastBlockSize = blockSize;
116-
lastNumChannels = numChannels;
117-
118115
startThread();
119116
}
120117

@@ -125,7 +122,7 @@ void InternalSynth::process(AudioBuffer<float>& buffer, MidiBuffer& midiMessages
125122
{
126123
#ifdef PLUGDATA_STANDALONE
127124

128-
if (buffer.getNumChannels() != lastNumChannels || buffer.getNumSamples() > lastBlockSize) {
125+
if (buffer.getNumSamples() > lastBlockSize) {
129126
unprepare();
130127
return;
131128
}
@@ -169,7 +166,7 @@ void InternalSynth::process(AudioBuffer<float>& buffer, MidiBuffer& midiMessages
169166
// Run audio through fluidsynth
170167
fluid_synth_process(synth, internalBuffer.getNumSamples(), internalBuffer.getNumChannels(), const_cast<float**>(internalBuffer.getArrayOfReadPointers()), internalBuffer.getNumChannels(), const_cast<float**>(internalBuffer.getArrayOfWritePointers()));
171168

172-
int numChannelsToProcess = std::min(buffer.getNumChannels(), internalBuffer.getNumChannels());
169+
int numChannelsToProcess = std::min(buffer.getNumChannels(), 2);
173170
for (int ch = 0; ch < numChannelsToProcess; ch++) {
174171
buffer.addFrom(ch, 0, internalBuffer, ch, 0, buffer.getNumSamples());
175172
}

0 commit comments

Comments
 (0)