From f874ad3db56a7bc0556c766f944d4e3fd4081d30 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 5 Jul 2020 15:25:24 +0200 Subject: [PATCH] Add short paths for the smoothers When the input is basically constant in particular --- src/sfizz/OnePoleFilter.h | 2 ++ src/sfizz/Smoothers.cpp | 19 +++++++++++++++++-- src/sfizz/Smoothers.h | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/sfizz/OnePoleFilter.h b/src/sfizz/OnePoleFilter.h index 9781b39e..603363a5 100644 --- a/src/sfizz/OnePoleFilter.h +++ b/src/sfizz/OnePoleFilter.h @@ -25,6 +25,8 @@ class OnePoleFilter { public: OnePoleFilter() = default; + Type current() const { return state; } + void setGain(Type gain) { G = gain / (1 + gain); diff --git a/src/sfizz/Smoothers.cpp b/src/sfizz/Smoothers.cpp index 252d1f50..c94d670a 100644 --- a/src/sfizz/Smoothers.cpp +++ b/src/sfizz/Smoothers.cpp @@ -27,10 +27,25 @@ void Smoother::reset(float value) void Smoother::process(absl::Span input, absl::Span output) { - if (smoothing) + CHECK_SPAN_SIZES(input, output); + if (input.size() == 0) + return; + + const auto midValue = input[input.size() / 2]; + const bool shortcut = ( + input.front() == input.back() + && input.front() == midValue + && input.front() == current() + ); + + if (smoothing && !shortcut) { filter.processLowpass(input, output); - else + } + else if (input.data() != output.data()) { copy(input, output); + } else { + // Nothing to do + } } } diff --git a/src/sfizz/Smoothers.h b/src/sfizz/Smoothers.h index 20eb4e3a..e2dadb8b 100644 --- a/src/sfizz/Smoothers.h +++ b/src/sfizz/Smoothers.h @@ -45,6 +45,7 @@ public: */ void process(absl::Span input, absl::Span output); + float current() const { return filter.current(); } private: bool smoothing { false }; OnePoleFilter filter {};