[PD] better tabread4~

Matt Barber brbrofsvl at gmail.com
Wed Jun 25 19:48:35 CEST 2008


PS -- also for what it's worth, a formula which seems equivalent to
the one used in [tabread4c~] is described here:

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

it gives the following piece of code:


double CubicInterpolate(
   double y0,double y1,
   double y2,double y3,
   double mu)
{
   double a0,a1,a2,a3,mu2;

   mu2 = mu*mu;
   a0 = y3 - y2 - y0 + y1;
   a1 = y0 - y1 - a0;
   a2 = y2 - y0;
   a3 = y1;

   return(a0*mu*mu2+a1*mu2+a2*mu+a3);
}




Here's from tabread4c~, in case someone wants to see but couldn't find the file:

        a = wp[-1].w_float;
        b = wp[0].w_float;
        c = wp[1].w_float;
        d = wp[2].w_float;

		a0 = d - c - a + b;
		a1 = a - b - a0;
		a2 = c - a;
		*out++ = ((a0*frac+a1)*frac+a2)*frac+b;


Matt

On Wed, Jun 25, 2008 at 12:06 PM, Charles Henry <czhenry at gmail.com> wrote:
> On Wed, Jun 25, 2008 at 10:32 AM, Matt Barber <brbrofsvl at gmail.com> wrote:
>> For what it's worth, here's supercollider's cubic interpolation
>> function, which differs from csound's and Pd's, which I believe are
>> equivalent:
>>
>> static float cubicinterp(float x, float y0, float y1, float y2, float y3)
>> {
>>        // 4-point, 3rd-order Hermite (x-form)
>>        float c0 = y1;
>>        float c1 = 0.5f * (y2 - y0);
>>        float c2 = y0 - 2.5f * y1 + 2.f * y2 - 0.5f * y3;
>>        float c3 = 0.5f * (y3 - y0) + 1.5f * (y1 - y2);
>>
>>        return ((c3 * x + c2) * x + c1) * x + c0;
>> }
>>
>>
>> Matt
>
>
> a0=(3b-a-3c+d)/2            (same as c3)
> a1=a-5b/2+2c-d/2           (same as c2)
> a2=(c-a)/2                      (same as c1)
>
> (b is c0)
>
> f(x)=(((a0*x+a1)*x+a2)*x-+b
>
> Actually that's just the same set of coefficients that I named in a
> previous post... just in a different form.  So, that's just the sort
> of thing we could add to pd-extended....
> It's good to know what other people are doing in their software too
>
> Chuck
>




More information about the Pd-list mailing list