desc:a handful of interpolation algorithms
@init
function interpolate_linear(x1,x2,mu)
instance(out)
(
out = x1*(1-mu) + x2*mu;
);
function interpolate_cosine(x1,x2,mu)
instance(mu2,out)
(
mu2 = (1 - cos(mu * $pi))/2;
out = x1*(1-mu2) + x2*mu2;
);
function interpolate_smooth(x1,x2,mu)
instance(out)
(
mu = mu * mu * (3 - (2 * mu));
out = x1 + ((x2 - x1) * mu);
);
function interpolate_hermite(x0,x1,x2,x3,mu)
instance(a,b,c,d,out)
(
a = ((3 * (x1- x2)) - x0 + x3) * 0.5;
b = x2 + x2 + x0 - (5*x1 + x3) * 0.5;
c = (x2 - x0) * 0.5;
d = mu;
out = ((a*d+b)*d+c)*d+x1;
);
function interpolate_allpass_init(d)
instance(a,x1,y1)
(
a = (1-d)/(1+d);
a = min(max(a,0),1);
x1 = y1 = 0;
);
function interpolate_allpass(in)
instance(out,x1,y1,a)
(
out = a * in + x1 - a * y1;
x1 = in;
y1 = out;
out;
);
function interpolate_allpass2_init(d)
(
this.a1 = -(d-2)/(d+1);
this.a2 = ((d-1)*(d-2))/((d+1)*(d+2));
this.x1 = this.x2 = this.y1 = this.y2 = 0;
);
function interpolate_allpass2(in)
instance(out,y1,y2,x1,x2,a1,a2)
(
out = a2*in + a1*x1 + x2;
out -= (a1*y1 + a2*y2);
y2 = y1;
y1 = out;
x2 = x1;
x1 = in;
out;
);
function interpolate_rbj_ap_init(frac)
instance(w0, cosw0, sinw0, alpha, a1)
(
w0 = 2 * $pi * frac/srate;
cosw0 = cos(w0);
sinw0 = sin(w0);
alpha = sinw0 / 2;
this.b01 = 1 - alpha;
this.b11 = -2 *cosw0;
this.b21 = 1 + alpha;
this.a01 = 1 + alpha;
this.a11 = -2 * cosw0;
this.a21 = 1 - alpha;
this.b01 /= this.a01;
this.b11 /= this.a01;
this.b21 /= this.a01;
this.a11 /= this.a01;
this.a21 /= this.a01;
this.x11 = this.x21 = 0;
this.y11 = this.y21 = 0;
this.oin = this.in = 0;
);
function interpolate_rbj_ap(in)
instance(oin, out)
(
oin = in;
out = this.b01 * in + this.b11 * this.x11 + this.b21 * this.x21;
out += -this.a11 * this.y11 - this.a21 * this.y21;
this.x21 = this.x11;
this.x11 = this.oin;
this.y21 = this.y11;
this.y11 = out;
out;
);
function interpolate_fir_init(frac)
instance(b0,b1,b2,t,d,g,a)
(
d = frac;
t = (1-d)/(1+d);
g = 10^(-6/(srate*1));
b0 = 0.5 * g * t;
b1 = 0.5 * (t + 1);
b2 = 0.5 * g;
a = t;
);
function interpolate_fir(in)
instance(out,x1,x2)
(
out = this.b0 * in + x1;
x1 = this.b1 * in + x2 - this.a * out;
x2 = this.b2 * in;
out;
);
function interpolate_lagrange2_init(frac)
instance(h0,h1,h2)
(
h0 = 0.5 * (frac-1) * (frac-2);
h1 = -frac * (frac-2);
h2 = 0.5 * frac * (frac-1);
);
function interpolate_lagrange2(in)
instance(out,x1,x2)
(
out = this.h0 * in + this.h1 * x1 + this.h2 * x2;
x2 = x1;
x1 = in;
out;
);
function interpolate_lagrange3_init(frac)
instance(h0,h1,h2,h3)
(
h0 = (frac-1) * (frac-2) * (frac-3)/-6;
h1 = 0.5 * frac * (frac-2) * (frac-3);
h2 = -0.5 * frac * (frac-1) * (frac-3);
h3 = (frac * (frac-1) * (frac-2))/6;
);
function interpolate_lagrange3(in)
instance(out,x1,x2,x3)
(
out = this.h0 * in + this.h1 * x1 + this.h2 * x2 + this.h3 * x3;
x3 = x2;
x2 = x1;
x1 = in;
out;
);