interpolation-bezier-cubic

cubic bezier interpolation
Author: toneburst
License: BSD
Github: toneburst/math/interpolation bezier cubic.axo

Inlets

frac32.positive input value

Outlets

frac32.positive interpolated output

Parameters

frac32.s.map curve end tension

frac32.u.map curve start tension

Declaration
__attribute__((always_inline)) __STATIC_INLINE float int2f(int32_t val) {
  return val * (float)(1.0f / (1 << 27));
}

__attribute__((always_inline)) __STATIC_INLINE int32_t f2int(float val) {
  return (int)(val * (float)(1 << 27));
}
Control Rate
// Transform inlet val to float in 0 > 1 range
float x = int2f(inlet_in);

// Transform curve a and b params to float in 0 > 1 range
float a = int2f(param_start);
float b = int2f(param_end);

// Cubic Bezier interpolation
// http://blog.demofox.org/2014/08/28/one-dimensional-bezier-curves/
float outf =
    3 * ((1 - x) * (1 - x)) * x * a + 3 * (1 - x) * (x * x) * b + (x * x * x);

// Output int
outlet_out = f2int(outf);

Privacy

© 2024 Zrna Research