diff --git a/src/sfizz/Config.h b/src/sfizz/Config.h index 60c2f0a2..03f7f378 100644 --- a/src/sfizz/Config.h +++ b/src/sfizz/Config.h @@ -103,6 +103,10 @@ namespace config { Background file loading */ static constexpr int backgroundLoaderPthreadPriority = 50; // expressed in % + /** + @brief Ratio to target under which smoothing is considered as completed + */ + static constexpr float smoothingShortcutThreshold = 5e-3; } // namespace config } // namespace sfz diff --git a/src/sfizz/Smoothers.cpp b/src/sfizz/Smoothers.cpp index 59fcc5b9..fda61be0 100644 --- a/src/sfizz/Smoothers.cpp +++ b/src/sfizz/Smoothers.cpp @@ -31,7 +31,13 @@ void Smoother::process(absl::Span input, absl::Span output, if (input.size() == 0) return; - if (canShortcut && std::abs(input.front() - current()) < config::virtuallyZero) { + if (canShortcut) { + float in = input.front(); + float rel = std::abs(in - current()) / (std::abs(in) + config::virtuallyZero); + canShortcut = rel < config::smoothingShortcutThreshold; + } + + if (canShortcut) { if (input.data() != output.data()) copy(input, output);