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 {};