1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-29 23:29:41 +02:00

Clamp attack/release times at 1/sample_rate.

Otherwise, numerical instability could occur.

Signed-off-by: Max Maisel <max.maisel@posteo.de>
This commit is contained in:
Max Maisel 2021-02-12 15:10:14 +01:00
parent 3d4e504bc3
commit fd4276e3f2

View File

@ -313,6 +313,8 @@ void ExpFitEnvelopeDetector::Reset(float value)
void ExpFitEnvelopeDetector::SetParams(
float sampleRate, float attackTime, float releaseTime)
{
attackTime = std::max(attackTime, 1.0f / sampleRate);
releaseTime = std::max(releaseTime, 1.0f / sampleRate);
mAttackFactor = exp(-1.0 / (sampleRate * attackTime));
mReleaseFactor = exp(-1.0 / (sampleRate * releaseTime));
}
@ -428,6 +430,9 @@ void Pt1EnvelopeDetector::Reset(float value)
void Pt1EnvelopeDetector::SetParams(
float sampleRate, float attackTime, float releaseTime)
{
attackTime = std::max(attackTime, 1.0f / sampleRate);
releaseTime = std::max(releaseTime, 1.0f / sampleRate);
// Approximate peak amplitude correction factor.
if(mCorrectGain)
mGainCorrection = 1.0 + exp(attackTime / 30.0);