How To Get The Value Of An Cubic Interp. Curve At Any Given Point?

I suck at math haha… I read the wikipedia article on cubic interpolation and am none the wiser :(

Would it make sense to request this as an API feature? Something like automation[]:value_at(float thingy), where thingy ranges from 1.0 to automation.length (or automation.length + 0.9999?)

Well, if you’re talking about a long sweeping curve (a whole pattern long) then I would click to make another point where I wanted the value. Read the box and delete the point again afterwards. I think that’s about as good as it gets now.

With future releases, automation must surely be the next logical step to be worked on.

I need to automation value at any point (1.0001, 1.0438, etc.), not just on whole pattern lines. And besides, putting a point somewhere changes the curve.

Nah? I just need the pseudocode instead of math formulas, then I’m all set… it’s not like cubic interpolation is a mystery, it’s just to me ^^

first result on google for ‘cubic interpolation pseudocode’ :P

http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/

translated to lua the cubic function is :

  
function cubic(y0,y1,y2,y3,mu)  
 local mu2 = mu*mu;  
 local a0 = y3 - y2 - y0 + y1;  
 local a1 = y0 - y1 - a0;  
 local a2 = y2 - y0;  
  
 return(a0*mu*mu2+a1*mu2+a2*mu+y3);  
end  
  

and the catmull-rom :

  
function cubic(y0,y1,y2,y3,mu)  
 local mu2 = mu*mu;  
 local a0 = -0.5*y0 + 1.5*y1 - 1.5*y2 + 0.5*y3;  
 local a1 = y0 - 2.5*y1 + 2*y2 - 0.5*y3;  
 local a2 = -0.5*y0 + 0.5*y2;  
  
 return(a0*mu*mu2+a1*mu2+a2*mu+y3);  
end  
  

but this code is only for a series of points which are equally spaced along the x-axis.

you’ll have to do some extra work to deal with non-equal distances, oh and for the edge cases.

im sure i had some cubic interpolation code of my own for a few years back, i’ll see if i can dig it out.

ok, i looked at the curve in renoise and it looks like a ‘cubic ease in-out’ type of curve. So I converted some old actionscript easing code to lua :

  
-- t: current time, b: beginning value, c: change in value, d: duration  
function easeInOutCubic (t, b, c, d)  
 t = t / (d/2);  
 if (t < 1) then  
 return (c/2) * (t*t*t) + b;   
 end   
 t = t-2  
 return (c/2) * (t*t*t + 2) + b;  
end  
  

so you only need 2 values either side and the distance between them, then ‘t’ is the time you want the value for.

let me know how it goes :)

why thank you!!

will do.