Support interpolation to nearest
This commit is contained in:
parent
80736aec99
commit
3cd56b4697
3 changed files with 21 additions and 4 deletions
|
|
@ -9,6 +9,8 @@
|
||||||
namespace sfz {
|
namespace sfz {
|
||||||
|
|
||||||
enum InterpolatorModel : int {
|
enum InterpolatorModel : int {
|
||||||
|
// a nearest interpolator
|
||||||
|
kInterpolatorNearest,
|
||||||
// a linear interpolator
|
// a linear interpolator
|
||||||
kInterpolatorLinear,
|
kInterpolatorLinear,
|
||||||
// a Hermite 3rd order interpolator
|
// a Hermite 3rd order interpolator
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,19 @@ inline R interpolate(const R* values, R coeff)
|
||||||
return Interpolator<M, R>::process(values, 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
|
// Linear
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,9 @@ void WavetableOscillator::process(float frequency, float detuneRatio, float* out
|
||||||
int quality = clamp(_quality, 0, 3);
|
int quality = clamp(_quality, 0, 3);
|
||||||
|
|
||||||
switch (quality) {
|
switch (quality) {
|
||||||
case 0: // supposed to be nearest according to book
|
case 0:
|
||||||
// fall through
|
processSingle<kInterpolatorNearest>(frequency, detuneRatio, output, nframes);
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
processSingle<kInterpolatorLinear>(frequency, detuneRatio, output, nframes);
|
processSingle<kInterpolatorLinear>(frequency, detuneRatio, output, nframes);
|
||||||
break;
|
break;
|
||||||
|
|
@ -163,8 +164,9 @@ void WavetableOscillator::processModulated(const float* frequencies, float detun
|
||||||
int quality = clamp(_quality, 0, 3);
|
int quality = clamp(_quality, 0, 3);
|
||||||
|
|
||||||
switch (quality) {
|
switch (quality) {
|
||||||
case 0: // supposed to be nearest according to book
|
case 0:
|
||||||
// fall through
|
processModulatedSingle<kInterpolatorNearest>(frequencies, detuneRatio, output, nframes);
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
processModulatedSingle<kInterpolatorLinear>(frequencies, detuneRatio, output, nframes);
|
processModulatedSingle<kInterpolatorLinear>(frequencies, detuneRatio, output, nframes);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue