From 936be2f4d15507f7d1ada45a20eea4f3d57245e1 Mon Sep 17 00:00:00 2001 From: nwolek Date: Wed, 30 Dec 2015 11:11:18 -0500 Subject: [PATCH] Interpolator: separating the None and Nearest ideas into individual options. issue #71 --- include/core/JamomaInterpolator.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/include/core/JamomaInterpolator.h b/include/core/JamomaInterpolator.h index 69e7802..6731dbf 100644 --- a/include/core/JamomaInterpolator.h +++ b/include/core/JamomaInterpolator.h @@ -28,7 +28,7 @@ namespace Jamoma { }; - /** No interpolation */ + /** No interpolation always returns the first sample passed to it */ template class None : Base { public: @@ -38,6 +38,25 @@ namespace Jamoma { return x0; } + constexpr T operator()(T x0, T x1, double delta) noexcept { + return x0; + } + + constexpr T operator()(T x0, T x1, T x2, T x3, double delta) noexcept { + return x0; + } + }; + + /** Nearest interpolation returns the closest sample by rounding the delta up or down. */ + template + class Nearest : Base { + public: + static const int delay = 0; + + constexpr T operator()(T x0) noexcept { + return x0; + } + constexpr T operator()(T x0, T x1, double delta) noexcept { T out = delta < 0.5 ? x0 : x1; return out; @@ -47,9 +66,8 @@ namespace Jamoma { T out = delta < 0.5 ? x0 : x1; return out; } - }; + }; - /** Linear interpolation. @param x0 Sample value at prior integer index @param x1 Sample value at next integer index