Clamp the tracking factors to avoid blowups
This commit is contained in:
parent
afc9d72c89
commit
dd8134277c
2 changed files with 16 additions and 2 deletions
|
|
@ -237,6 +237,14 @@ void sfz::Voice::registerTempo(int delay, float secondsPerQuarter) noexcept
|
||||||
UNUSED(secondsPerQuarter);
|
UNUSED(secondsPerQuarter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sfz::Voice::updateTrackingFactor() noexcept
|
||||||
|
{
|
||||||
|
// Protect the envelope follower against blowups
|
||||||
|
const auto maxTrackingFactor = sampleRate / samplesPerBlock;
|
||||||
|
attackTrackingFactor = min(config::powerFollowerAttackFactor, maxTrackingFactor) / sampleRate;
|
||||||
|
releaseTrackingFactor = min(config::powerFollowerReleaseFactor, maxTrackingFactor) / sampleRate;
|
||||||
|
}
|
||||||
|
|
||||||
void sfz::Voice::setSampleRate(float sampleRate) noexcept
|
void sfz::Voice::setSampleRate(float sampleRate) noexcept
|
||||||
{
|
{
|
||||||
this->sampleRate = sampleRate;
|
this->sampleRate = sampleRate;
|
||||||
|
|
@ -249,13 +257,13 @@ void sfz::Voice::setSampleRate(float sampleRate) noexcept
|
||||||
for (auto& lfo : lfos)
|
for (auto& lfo : lfos)
|
||||||
lfo->setSampleRate(sampleRate);
|
lfo->setSampleRate(sampleRate);
|
||||||
|
|
||||||
attackTrackingFactor = config::powerFollowerAttackFactor / sampleRate;
|
updateTrackingFactor();
|
||||||
releaseTrackingFactor = config::powerFollowerReleaseFactor / sampleRate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Voice::setSamplesPerBlock(int samplesPerBlock) noexcept
|
void sfz::Voice::setSamplesPerBlock(int samplesPerBlock) noexcept
|
||||||
{
|
{
|
||||||
this->samplesPerBlock = samplesPerBlock;
|
this->samplesPerBlock = samplesPerBlock;
|
||||||
|
updateTrackingFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Voice::renderBlock(AudioSpan<float> buffer) noexcept
|
void sfz::Voice::renderBlock(AudioSpan<float> buffer) noexcept
|
||||||
|
|
|
||||||
|
|
@ -485,6 +485,12 @@ private:
|
||||||
Smoother xfadeSmoother;
|
Smoother xfadeSmoother;
|
||||||
void resetSmoothers() noexcept;
|
void resetSmoothers() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Update and clamp the tracking factors to ensure the power
|
||||||
|
* follower does not blow up.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void updateTrackingFactor() noexcept;
|
||||||
float attackTrackingFactor { config::powerFollowerAttackFactor / config::defaultSampleRate };
|
float attackTrackingFactor { config::powerFollowerAttackFactor / config::defaultSampleRate };
|
||||||
float releaseTrackingFactor { config::powerFollowerReleaseFactor / config::defaultSampleRate };
|
float releaseTrackingFactor { config::powerFollowerReleaseFactor / config::defaultSampleRate };
|
||||||
float meanChannelPower;
|
float meanChannelPower;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue