From 287832e2004f41be6ade99cd43e99ab8cd6803f8 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Fri, 19 Mar 2021 21:26:14 +0100 Subject: [PATCH] Free-run the envelope if the sustain value is low enough Value taken from Sforzando --- src/sfizz/ADSREnvelope.cpp | 2 +- src/sfizz/Config.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sfizz/ADSREnvelope.cpp b/src/sfizz/ADSREnvelope.cpp index be5b3199..b0c10d6e 100644 --- a/src/sfizz/ADSREnvelope.cpp +++ b/src/sfizz/ADSREnvelope.cpp @@ -52,7 +52,7 @@ void ADSREnvelope::reset(const EGDescription& desc, const Region& region, const sustainThreshold = this->sustain + config::virtuallyZero; shouldRelease = false; freeRunning = ( - (this->sustain == Float(0.0)) + (this->sustain <= Float(config::sustainFreeRunningThreshold)) || (region.loopMode == LoopMode::one_shot && region.isOscillator()) ); currentValue = this->start; diff --git a/src/sfizz/Config.h b/src/sfizz/Config.h index 97061613..ac25d3e5 100644 --- a/src/sfizz/Config.h +++ b/src/sfizz/Config.h @@ -167,6 +167,11 @@ namespace config { * @brief The smoothing time constant per "smooth" steps */ constexpr float smoothTauPerStep { 3e-3 }; + /** + * @brief If a value below this threshold is given to `ampeg_sustain`, the envelope will free-run + * and the voice will release itself at the end of the decay stage. + */ + constexpr float sustainFreeRunningThreshold { 0.0032f }; } // namespace config } // namespace sfz