Skip to content

Instantly share code, notes, and snippets.

@mtytel
Created June 3, 2018 19:06
Show Gist options
  • Save mtytel/d09b23fa03b32e392bc9f34ab002f80f to your computer and use it in GitHub Desktop.
Save mtytel/d09b23fa03b32e392bc9f34ab002f80f to your computer and use it in GitHub Desktop.
Cubic Interpolation - part 1
static const poly_float kCubicOne(0.0f, 1.0f, 0.0f, 0.0f);
static const poly_float kCubicTwo(-1.0f, -1.0f, 1.0f, 1.0f);
static const poly_float kCubicThree(-2.0f, -2.0f, -2.0f, -1.0f);
static const poly_float kCubicMult(-1.0f / 6.0f, 1.0f / 2.0f, -1.0f / 2.0f, 1.0f / 6.0f);
forcedinline poly_float getCubicInterpolationValues(poly_float t) {
return kCubicMult * (t + kCubicOne) * (t + kCubicTwo) * (t + kCubicThree);
}
forcedinline poly_float interpolateBuffers(const mono_float* const* buffers,
const poly_int indices) {
poly_int start_index = utils::shiftRight(indices, kIntermediateBits);
poly_float result;
poly_float t = utils::toFloat(indices & kIntermediateMask) * (1.0f / kIntermediateMult);
for (int i = 0; i < poly_float::size(); ++i) {
poly_float mult = utils::getCubicInterpolationValues(t[i]);
poly_float sample = mult * utils::toPolyFloatFromUnaligned(buffers[i] + start_index[i]);
result[i] = sample.sum();
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment