Skip to content

Commit

Permalink
Interpolator: separating the None and Nearest ideas into individual o…
Browse files Browse the repository at this point in the history
…ptions. issue #71
  • Loading branch information
nwolek committed Dec 30, 2015
1 parent 61e8119 commit 936be2f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions include/core/JamomaInterpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Jamoma {
};


/** No interpolation */
/** No interpolation always returns the first sample passed to it */
template<class T>
class None : Base {
public:
Expand All @@ -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 T>
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;
Expand All @@ -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
Expand Down

0 comments on commit 936be2f

Please sign in to comment.