Add aging in the voice
This commit is contained in:
parent
a9980f163f
commit
b78a7945ab
3 changed files with 19 additions and 4 deletions
|
|
@ -481,7 +481,7 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept
|
|||
|
||||
// Find voices that can be stolen
|
||||
absl::c_sort(voiceViewArray, [](Voice* lhs, Voice* rhs) {
|
||||
return lhs->getMeanSquaredAverage() < rhs->getMeanSquaredAverage();
|
||||
return lhs->getAverageEnvelope() < rhs->getAverageEnvelope();
|
||||
});
|
||||
|
||||
voiceViewArray.front()->reset();
|
||||
|
|
|
|||
|
|
@ -240,7 +240,13 @@ void sfz::Voice::renderBlock(AudioSpan<float> buffer) noexcept
|
|||
|
||||
updateChannelPowers(buffer);
|
||||
|
||||
this->triggerDelay = absl::nullopt;
|
||||
age += buffer.getNumFrames();
|
||||
if (triggerDelay) {
|
||||
// Should be OK but just in case;
|
||||
age = min(age - *triggerDelay, 0);
|
||||
triggerDelay = absl::nullopt;
|
||||
}
|
||||
|
||||
#if 0
|
||||
ASSERT(!hasNanInf(buffer.getConstSpan(0)));
|
||||
ASSERT(!hasNanInf(buffer.getConstSpan(1)));
|
||||
|
|
@ -629,6 +635,7 @@ void sfz::Voice::reset() noexcept
|
|||
region = nullptr;
|
||||
currentPromise.reset();
|
||||
sourcePosition = 0;
|
||||
age = 0;
|
||||
floatPositionOffset = 0.0f;
|
||||
noteIsOff = false;
|
||||
|
||||
|
|
@ -642,7 +649,7 @@ void sfz::Voice::reset() noexcept
|
|||
equalizers.clear();
|
||||
}
|
||||
|
||||
float sfz::Voice::getMeanSquaredAverage() const noexcept
|
||||
float sfz::Voice::getAverageEnvelope() const noexcept
|
||||
{
|
||||
return max(channelPowers[0], channelPowers[1]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ public:
|
|||
*
|
||||
* @return float
|
||||
*/
|
||||
float getMeanSquaredAverage() const noexcept;
|
||||
float getAverageEnvelope() const noexcept;
|
||||
/**
|
||||
* @brief Get the position of the voice in the source, in samples
|
||||
*
|
||||
|
|
@ -215,6 +215,13 @@ public:
|
|||
*/
|
||||
void release(int delay, bool fastRelease = false) noexcept;
|
||||
|
||||
/**
|
||||
* @brief gets the age of the Voice
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getAge() const noexcept { return age; }
|
||||
|
||||
Duration getLastDataDuration() const noexcept { return dataDuration; }
|
||||
Duration getLastAmplitudeDuration() const noexcept { return amplitudeDuration; }
|
||||
Duration getLastFilterDuration() const noexcept { return filterDuration; }
|
||||
|
|
@ -271,6 +278,7 @@ private:
|
|||
float floatPositionOffset { 0.0f };
|
||||
int sourcePosition { 0 };
|
||||
int initialDelay { 0 };
|
||||
int age { 0 };
|
||||
|
||||
FilePromisePtr currentPromise { nullptr };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue