From e58bf6f8cbbada959f7fb2fc75a15b750db699f5 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Sun, 15 Mar 2020 02:09:30 +0100 Subject: [PATCH] Use linearRamp and correct a small bug in lerpFill --- src/sfizz/Curve.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/sfizz/Curve.cpp b/src/sfizz/Curve.cpp index 85d6b5d6..5f6511d9 100644 --- a/src/sfizz/Curve.cpp +++ b/src/sfizz/Curve.cpp @@ -6,6 +6,7 @@ #include "Curve.h" #include "Opcode.h" +#include "SIMDHelpers.h" #include "Debug.h" #include #include @@ -133,13 +134,18 @@ void Curve::fill(Interpolator itp, const bool fillStatus[NumValues]) void Curve::lerpFill(const bool fillStatus[NumValues]) { - for (int iCurr = 1; iCurr < NumValues - 1; ++iCurr) { - int iLeft, iRight; - iLeft = iCurr - 1; - for (iRight = iCurr + 1; iRight < 127 && !fillStatus[iRight]; ++iRight); + int left { 0 }; + int right { 1 }; + auto pointSpan = absl::MakeSpan(_points); - float mu = static_cast(iCurr - iLeft) / (iRight - iLeft); - _points[iCurr] = _points[iLeft] + mu * (_points[iRight] - _points[iLeft]); + while (right < NumValues) { + for (; right < NumValues && !fillStatus[right]; ++right); + const auto length = right - left; + if (length > 1) { + const float mu = (_points[right] - _points[left]) / length; + linearRamp(pointSpan.subspan(left + 1, length - 1), _points[left], mu); + } + left = right++; } }