From 69f27e744180fd95f3e2461d34a11a55ca76a003 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 18 Mar 2021 13:52:14 +0100 Subject: [PATCH 1/2] Linear smoother: ensure to get the derivative correct --- src/sfizz/Smoothers.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sfizz/Smoothers.cpp b/src/sfizz/Smoothers.cpp index 9dcd8023..dff32e78 100644 --- a/src/sfizz/Smoothers.cpp +++ b/src/sfizz/Smoothers.cpp @@ -101,8 +101,8 @@ void LinearSmoother::process(absl::Span input, absl::Span ou if (target != nextTarget) { target = nextTarget; //framesToTarget = (framesToTarget > 0) ? framesToTarget : smoothFrames; - //step = (target - current) / max(1, framesToTarget); - step = (target - current) / max(1, smoothFrames); + //step = (target - current) / (16 * max(1, framesToTarget)); + step = (target - current) / (16 * max(1, smoothFrames)); } const simde__m128 targetX4 = simde_mm_set1_ps(target); if (target > current) { @@ -149,8 +149,8 @@ void LinearSmoother::process(absl::Span input, absl::Span ou if (target != nextTarget) { target = nextTarget; // framesToTarget = (framesToTarget > 0) ? framesToTarget : smoothFrames; - // step = (target - current) / max(1, framesToTarget); - step = (target - current) / max(1, smoothFrames); + // step = (target - current) / ((count - i) * max(1, framesToTarget)); + step = (target - current) / ((count - i) * max(1, smoothFrames)); } if (target > current) { for (; i < count; ++i) From 3f5f4ef2c4d37e786df9c4d7bd7ce9d44a0976fb Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 18 Mar 2021 13:54:23 +0100 Subject: [PATCH 2/2] Add the non-SIMD linear smoother (for reference) --- src/sfizz/Smoothers.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/sfizz/Smoothers.cpp b/src/sfizz/Smoothers.cpp index dff32e78..970c05bb 100644 --- a/src/sfizz/Smoothers.cpp +++ b/src/sfizz/Smoothers.cpp @@ -9,7 +9,10 @@ #include "MathHelpers.h" #include "SfzHelpers.h" #include "SIMDHelpers.h" +#include +#if SIMDE_NATURAL_VECTOR_SIZE_GE(128) #include +#endif namespace sfz { @@ -96,6 +99,7 @@ void LinearSmoother::process(absl::Span input, absl::Span ou // int32_t framesToTarget = framesToTarget_; const int32_t smoothFrames = smoothFrames_; +#if SIMDE_NATURAL_VECTOR_SIZE_GE(128) for (; i + 15 < count; i += 16) { const float nextTarget = input[i + 15]; if (target != nextTarget) { @@ -143,6 +147,32 @@ void LinearSmoother::process(absl::Span input, absl::Span ou } //framesToTarget -= 16; } +#else + for (; i + 15 < count; i += 16) { + const float nextTarget = input[i + 15]; + + if (target != nextTarget) { + target = nextTarget; + //framesToTarget = (framesToTarget > 0) ? framesToTarget : smoothFrames; + //step = (target - current) / (16 * max(1, framesToTarget)); + step = (target - current) / (16 * max(1, smoothFrames)); + } + if (target > current) { + for (size_t j = 0; j < 16; ++j) + output[i + j] = current = min(target, current + step); + } + else if (target < current) { + for (size_t j = 0; j < 16; ++j) + output[i + j] = current = max(target, current + step); + } + else { + for (size_t j = 0; j < 16; ++j) + output[i + j] = target; + } + + //framesToTarget -= 16; + } +#endif if (i < count) { const float nextTarget = input[count - 1];