Support interpolation to nearest

This commit is contained in:
Jean Pierre Cimalando 2020-06-22 06:39:06 +02:00
parent 80736aec99
commit 3cd56b4697
3 changed files with 21 additions and 4 deletions

View file

@ -9,6 +9,8 @@
namespace sfz {
enum InterpolatorModel : int {
// a nearest interpolator
kInterpolatorNearest,
// a linear interpolator
kInterpolatorLinear,
// a Hermite 3rd order interpolator

View file

@ -19,6 +19,19 @@ inline R interpolate(const R* values, R coeff)
return Interpolator<M, R>::process(values, coeff);
}
//------------------------------------------------------------------------------
// Nearest
template <class R>
class Interpolator<kInterpolatorNearest, R>
{
public:
static inline R process(const R* values, R coeff)
{
return values[coeff > static_cast<R>(0.5)];
}
};
//------------------------------------------------------------------------------
// Linear

View file

@ -144,8 +144,9 @@ void WavetableOscillator::process(float frequency, float detuneRatio, float* out
int quality = clamp(_quality, 0, 3);
switch (quality) {
case 0: // supposed to be nearest according to book
// fall through
case 0:
processSingle<kInterpolatorNearest>(frequency, detuneRatio, output, nframes);
break;
case 1:
processSingle<kInterpolatorLinear>(frequency, detuneRatio, output, nframes);
break;
@ -163,8 +164,9 @@ void WavetableOscillator::processModulated(const float* frequencies, float detun
int quality = clamp(_quality, 0, 3);
switch (quality) {
case 0: // supposed to be nearest according to book
// fall through
case 0:
processModulatedSingle<kInterpolatorNearest>(frequencies, detuneRatio, output, nframes);
break;
case 1:
processModulatedSingle<kInterpolatorLinear>(frequencies, detuneRatio, output, nframes);
break;