Skip to content

Commit

Permalink
Interpolator: making x numbering more consistent for None and Nearest…
Browse files Browse the repository at this point in the history
… options. issue #71
  • Loading branch information
nwolek committed Dec 30, 2015
1 parent 6cb55a5 commit 79ad19d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
36 changes: 18 additions & 18 deletions include/core/JamomaInterpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace Jamoma {


/** No interpolation always returns the first sample passed to it
@param x0 Sample value that will be returned
@param x1 Unused sample value
@param x0 Unused sample value
@param x1 Sample value that will be returned
@param x2 Unused sample value
@param x3 Unused sample value
@param delta Unused fractional location
Expand All @@ -41,45 +41,45 @@ namespace Jamoma {
public:
static const int delay = 0;

constexpr T operator()(T x0) noexcept {
return x0;
constexpr T operator()(T x1) noexcept {
return x1;
}

constexpr T operator()(T x0, T x1, double delta) noexcept {
return x0;
constexpr T operator()(T x1, T x2, double delta) noexcept {
return x1;
}

constexpr T operator()(T x0, T x1, T x2, T x3, double delta) noexcept {
return x0;
return x1;
}
};

/** Nearest interpolation returns the closest sample by rounding the delta up or down.
@param x0 Returned sample value when rounding down
@param x1 Returned sample value when rounding up
@param x2 Unused sample value
@param x0 Unused sample value
@param x1 Returned sample value when rounding down
@param x2 Returned sample value when rounding up
@param x3 Unused sample value
@param delta Fractional location between x0 and x1 @n
delta < 0.5 => x0 @n
delta >= 0.5 => x1
@param delta Fractional location between x1 and x2 @n
delta < 0.5 => x1 @n
delta >= 0.5 => x2
@return The interpolated value
*/
template<class T>
class Nearest : Base {
public:
static const int delay = 0;

constexpr T operator()(T x0) noexcept {
return x0;
constexpr T operator()(T x1) noexcept {
return x1;
}

constexpr T operator()(T x0, T x1, double delta) noexcept {
T out = delta < 0.5 ? x0 : x1;
constexpr T operator()(T x1, T x2, double delta) noexcept {
T out = delta < 0.5 ? x1 : x2;
return out;
}

constexpr T operator()(T x0, T x1, T x2, T x3, double delta) noexcept {
T out = delta < 0.5 ? x0 : x1;
T out = delta < 0.5 ? x1 : x2;
return out;
}
};
Expand Down
16 changes: 8 additions & 8 deletions test/Interpolator/Interpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ class InterpolatorTest {
auto x2 = 1.0;
auto x3 = 4.0;

auto out = my_interp(x0);
auto out = my_interp(x1);

mTest->TEST_ASSERT("testNone with 1 sample produced correct output", out == x0);
mTest->TEST_ASSERT("testNone with 1 sample produced correct output", out == x1);

auto out2 = my_interp(x0,x1,0.25);
auto out2 = my_interp(x1,x2,0.25);

mTest->TEST_ASSERT("testNone with 2 samples, low delta produced correct output", out2 == x0);
mTest->TEST_ASSERT("testNone with 2 samples, low delta produced correct output", out2 == x1);

auto out2b = my_interp(x0,x1,0.75);
auto out2b = my_interp(x1,x2,0.75);

mTest->TEST_ASSERT("testNone with 2 samples, high delta produced correct output", out2b == x0);
mTest->TEST_ASSERT("testNone with 2 samples, high delta produced correct output", out2b == x1);

auto out4 = my_interp(x0,x1,x2,x3,0.25);

mTest->TEST_ASSERT("testNone with 4 samples, low delta produced correct output", out4 == x0);
mTest->TEST_ASSERT("testNone with 4 samples, low delta produced correct output", out4 == x1);

auto out4b = my_interp(x0,x1,x2,x3,0.75);

mTest->TEST_ASSERT("testNone with 4 samples, high delta produced correct output", out4b == x0);
mTest->TEST_ASSERT("testNone with 4 samples, high delta produced correct output", out4b == x1);

}

Expand Down

0 comments on commit 79ad19d

Please sign in to comment.