Interpolation for DSCH
curves
A workbench for checking the interpolation behind DSCH's multi-point dynamic and duration ramps. It started with B-splines and ended up applying Lagrange interpolation.
source private · ask me about it
/// Lagrange interpolation
pub fn L(x: f32, points: Vec<Vec2>) -> f32 {
points
.iter()
.cloned()
.map(|pt| {
let others = points.iter().filter(|q| q.x != pt.x);
pt.y * others.fold(1.0, |fac, q| fac * ((x - q.x) / (pt.x - q.x)))
})
.sum()
}DSCH's dynamics and durations can ramp across several points (mf > pp), so the compiler has to interpolate between them. curves is where I checked those calculations: working the maths through by hand, then in code, with a WebAssembly build to see the curves drawn.
It began with B-splines, worked out from the knot vector up, and ended up applying Lagrange interpolation: a polynomial that passes exactly through every point it's given.