From 87e4b4ed900548ac1e36803aab255e7d058f84d6 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Tue, 5 May 2020 23:43:32 +0200 Subject: [PATCH] Voice are unilateraly stolen now depending on their average power over the last 10 blocks. --- src/sfizz/Config.h | 1 - src/sfizz/Synth.cpp | 21 +++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/sfizz/Config.h b/src/sfizz/Config.h index c73600ec..8a1443ac 100644 --- a/src/sfizz/Config.h +++ b/src/sfizz/Config.h @@ -54,7 +54,6 @@ namespace config { constexpr Oversampling defaultOversamplingFactor { Oversampling::x1 }; constexpr float A440 { 440.0 }; constexpr size_t powerHistoryLength { 16 }; - constexpr float voiceStealingThreshold { 0.00001f }; constexpr uint16_t numCCs { 512 }; constexpr int maxCurves { 256 }; constexpr int chunkSize { 1024 }; diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index e9797e8a..90c23c70 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -480,20 +480,12 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept return freeVoice->get(); // Find voices that can be stolen - voiceViewArray.clear(); - for (auto& voice : voices) - if (voice->canBeStolen()) - voiceViewArray.push_back(voice.get()); - absl::c_sort(voiceViewArray, [](Voice* lhs, Voice* rhs) { return lhs->getSourcePosition() > rhs->getSourcePosition(); }); + absl::c_sort(voiceViewArray, [](Voice* lhs, Voice* rhs) { + return lhs->getMeanSquaredAverage() < rhs->getMeanSquaredAverage(); + }); - for (auto* voice : voiceViewArray) { - if (voice->getMeanSquaredAverage() < config::voiceStealingThreshold) { - voice->reset(); - return voice; - } - } - - return {}; + voiceViewArray.front()->reset(); + return voiceViewArray.front(); } int sfz::Synth::getNumActiveVoices() const noexcept @@ -992,12 +984,13 @@ void sfz::Synth::resetVoices(int numVoices) for (int i = 0; i < numVoices; ++i) voices.push_back(absl::make_unique(resources)); + voiceViewArray.clear(); for (auto& voice : voices) { voice->setSampleRate(this->sampleRate); voice->setSamplesPerBlock(this->samplesPerBlock); + voiceViewArray.push_back(voice.get()); } - voiceViewArray.reserve(numVoices); this->numVoices = numVoices; }