Browse Source

Fix for the Synthesiser voice-stealing algorithm

tags/2021-05-28
jules 11 years ago
parent
commit
f7e36108f8
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp

+ 6
- 6
modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp View File

@@ -447,7 +447,7 @@ struct VoiceAgeSorter
{
static int compareElements (SynthesiserVoice* v1, SynthesiserVoice* v2) noexcept
{
return v1->wasStartedBefore (*v2) ? 1 : (v2->wasStartedBefore (*v1) ? -1 : 0);
return v1->wasStartedBefore (*v2) ? -1 : (v2->wasStartedBefore (*v1) ? 1 : 0);
}
};
@@ -480,10 +480,10 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay,
}
}
jassert (bottom != nullptr && top != nullptr);
const int stealableVoiceRange = usableVoices.size() - 6;
// The oldest note that's playing with the target pitch playing is ideal..
for (int i = 0; i < usableVoices.size(); ++i)
for (int i = 0; i < stealableVoiceRange; ++i)
{
SynthesiserVoice* const voice = usableVoices.getUnchecked (i);
@@ -492,7 +492,7 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay,
}
// ..otherwise, look for the oldest note that isn't the top or bottom note..
for (int i = 0; i < usableVoices.size(); ++i)
for (int i = 0; i < stealableVoiceRange; ++i)
{
SynthesiserVoice* const voice = usableVoices.getUnchecked (i);
@@ -500,6 +500,6 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay,
return voice;
}
// ..otherwise, there's only one or two voices to choose from - we'll return the top one..
return top;
// ..otherwise, there's only one or two voices to choose from - we'll return the oldest one..
return usableVoices.getFirst();
}

Loading…
Cancel
Save