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
|
// Find voices that can be stolen
|
||||||
absl::c_sort(voiceViewArray, [](Voice* lhs, Voice* rhs) {
|
absl::c_sort(voiceViewArray, [](Voice* lhs, Voice* rhs) {
|
||||||
return lhs->getMeanSquaredAverage() < rhs->getMeanSquaredAverage();
|
return lhs->getAverageEnvelope() < rhs->getAverageEnvelope();
|
||||||
});
|
});
|
||||||
|
|
||||||
voiceViewArray.front()->reset();
|
voiceViewArray.front()->reset();
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,13 @@ void sfz::Voice::renderBlock(AudioSpan<float> buffer) noexcept
|
||||||
|
|
||||||
updateChannelPowers(buffer);
|
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
|
#if 0
|
||||||
ASSERT(!hasNanInf(buffer.getConstSpan(0)));
|
ASSERT(!hasNanInf(buffer.getConstSpan(0)));
|
||||||
ASSERT(!hasNanInf(buffer.getConstSpan(1)));
|
ASSERT(!hasNanInf(buffer.getConstSpan(1)));
|
||||||
|
|
@ -629,6 +635,7 @@ void sfz::Voice::reset() noexcept
|
||||||
region = nullptr;
|
region = nullptr;
|
||||||
currentPromise.reset();
|
currentPromise.reset();
|
||||||
sourcePosition = 0;
|
sourcePosition = 0;
|
||||||
|
age = 0;
|
||||||
floatPositionOffset = 0.0f;
|
floatPositionOffset = 0.0f;
|
||||||
noteIsOff = false;
|
noteIsOff = false;
|
||||||
|
|
||||||
|
|
@ -642,7 +649,7 @@ void sfz::Voice::reset() noexcept
|
||||||
equalizers.clear();
|
equalizers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
float sfz::Voice::getMeanSquaredAverage() const noexcept
|
float sfz::Voice::getAverageEnvelope() const noexcept
|
||||||
{
|
{
|
||||||
return max(channelPowers[0], channelPowers[1]);
|
return max(channelPowers[0], channelPowers[1]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
float getMeanSquaredAverage() const noexcept;
|
float getAverageEnvelope() const noexcept;
|
||||||
/**
|
/**
|
||||||
* @brief Get the position of the voice in the source, in samples
|
* @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;
|
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 getLastDataDuration() const noexcept { return dataDuration; }
|
||||||
Duration getLastAmplitudeDuration() const noexcept { return amplitudeDuration; }
|
Duration getLastAmplitudeDuration() const noexcept { return amplitudeDuration; }
|
||||||
Duration getLastFilterDuration() const noexcept { return filterDuration; }
|
Duration getLastFilterDuration() const noexcept { return filterDuration; }
|
||||||
|
|
@ -271,6 +278,7 @@ private:
|
||||||
float floatPositionOffset { 0.0f };
|
float floatPositionOffset { 0.0f };
|
||||||
int sourcePosition { 0 };
|
int sourcePosition { 0 };
|
||||||
int initialDelay { 0 };
|
int initialDelay { 0 };
|
||||||
|
int age { 0 };
|
||||||
|
|
||||||
FilePromisePtr currentPromise { nullptr };
|
FilePromisePtr currentPromise { nullptr };
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue