Move things around
This commit is contained in:
parent
59c25dccf1
commit
e4f0b0c7b0
2 changed files with 17 additions and 5 deletions
|
|
@ -59,6 +59,16 @@ namespace config {
|
||||||
constexpr int maxCurves { 256 };
|
constexpr int maxCurves { 256 };
|
||||||
constexpr int chunkSize { 1024 };
|
constexpr int chunkSize { 1024 };
|
||||||
constexpr int filtersInPool { maxVoices * 2 };
|
constexpr int filtersInPool { maxVoices * 2 };
|
||||||
|
/**
|
||||||
|
* @brief The threshold for age stealing.
|
||||||
|
* In percentage of the voice's max age.
|
||||||
|
*/
|
||||||
|
constexpr float stealingAgeCoeff { 0.5f };
|
||||||
|
/**
|
||||||
|
* @brief The threshold for envelope stealing.
|
||||||
|
* In percentage of the sum of all envelopes.
|
||||||
|
*/
|
||||||
|
constexpr float stealingEnvelopeCoeff { 0.5f };
|
||||||
constexpr int filtersPerVoice { 2 };
|
constexpr int filtersPerVoice { 2 };
|
||||||
constexpr int eqsPerVoice { 3 };
|
constexpr int eqsPerVoice { 3 };
|
||||||
constexpr int oscillatorsPerVoice { 9 };
|
constexpr int oscillatorsPerVoice { 9 };
|
||||||
|
|
|
||||||
|
|
@ -481,14 +481,15 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept
|
||||||
if (freeVoice != voices.end())
|
if (freeVoice != voices.end())
|
||||||
return freeVoice->get();
|
return freeVoice->get();
|
||||||
|
|
||||||
// Find voices that can be stolen
|
// Start of the voice stealing algorithm
|
||||||
absl::c_sort(voiceViewArray, voiceOrdering);
|
absl::c_sort(voiceViewArray, voiceOrdering);
|
||||||
|
|
||||||
const auto sumEnvelope = absl::c_accumulate(voiceViewArray, 0.0f, [](float sum, const Voice* v) {
|
const auto sumEnvelope = absl::c_accumulate(voiceViewArray, 0.0f, [](float sum, const Voice* v) {
|
||||||
return sum + v->getAverageEnvelope();
|
return sum + v->getAverageEnvelope();
|
||||||
});
|
});
|
||||||
const auto envThreshold = sumEnvelope / static_cast<float>(voiceViewArray.size()) * 0.5f;
|
const auto envThreshold = sumEnvelope
|
||||||
const auto ageThreshold = voiceViewArray.front()->getAge() * 0.5f;
|
/ static_cast<float>(voiceViewArray.size()) * config::stealingEnvelopeCoeff;
|
||||||
|
const auto ageThreshold = voiceViewArray.front()->getAge() * config::stealingAgeCoeff;
|
||||||
|
|
||||||
auto tempSpan = resources.bufferPool.getStereoBuffer(samplesPerBlock);
|
auto tempSpan = resources.bufferPool.getStereoBuffer(samplesPerBlock);
|
||||||
const auto killVoice = [&] (Voice* v) {
|
const auto killVoice = [&] (Voice* v) {
|
||||||
|
|
@ -506,7 +507,7 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept
|
||||||
if (ref->getAge() < ageThreshold) {
|
if (ref->getAge() < ageThreshold) {
|
||||||
unsigned killIdx = 1;
|
unsigned killIdx = 1;
|
||||||
while (killIdx < voiceViewArray.size()
|
while (killIdx < voiceViewArray.size()
|
||||||
&& sisterVoices(returnedVoice, voiceViewArray[killIdx])) {
|
&& sisterVoices(returnedVoice, voiceViewArray[killIdx])) {
|
||||||
killVoice(voiceViewArray[killIdx]);
|
killVoice(voiceViewArray[killIdx]);
|
||||||
killIdx++;
|
killIdx++;
|
||||||
}
|
}
|
||||||
|
|
@ -517,7 +518,8 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
float maxEnvelope = ref->getAverageEnvelope();
|
float maxEnvelope = ref->getAverageEnvelope();
|
||||||
while (idx < voiceViewArray.size() && sisterVoices(ref, voiceViewArray[idx])) {
|
while (idx < voiceViewArray.size()
|
||||||
|
&& sisterVoices(ref, voiceViewArray[idx])) {
|
||||||
maxEnvelope = max(maxEnvelope, voiceViewArray[idx]->getAverageEnvelope());
|
maxEnvelope = max(maxEnvelope, voiceViewArray[idx]->getAverageEnvelope());
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue