From e574aeb592b2026c742d46e9951ef70b8bf9d214 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Mon, 27 Jul 2020 21:01:07 +0200 Subject: [PATCH] Filter shortcut by relative formula --- src/sfizz/Config.h | 4 ++++ src/sfizz/Smoothers.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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);