View Raw SPL
/* sinc interpolation */
ITERATE interplp(y, n, p, attn, edge)
{
        local r, fc, f;

        if (argc < 5)
        {
                if (argc < 4)
                {
                        if (argc < 3)
                        {
                                if (argc < 2)
                                {
                                        if (argc < 1) error("interplp - input series required");

                                        n = 2;
                                }

                                p = 1;
                        }

                        attn = 60.0;
                }

                edge = 0.8125;
        }

        r = rate(y);
        n = int(n);
        p = int(p);

        if (n < 1 || p < 1)
        {
                error("interplp - positive interpolation factor required");
        }

        if (edge <= 0.0 || edge >= 1.0)
        {
                error(sprintf("interplp - edge is %g, must lie between 0.0 and 1.0", edge));
        }
        
        if (attn <= 0.0)
        {
                error("interplp - positive attenuation required");
        }

        if (n == p)
        {
                return(y);
        }

        /* cutoff freq is 1/2 * sample rate unless decimation is lower */
        fc = min(r / 2, (r / 2) * (n / p));

        /* upsample */
        y = upsample(y, n);

        /*
         *  build a Kaiser FIR low pass filter such that we have zero
         *  crossings at the original series samples
         */

        f = firlp(rate(y), edge * fc, fc * (2 - edge), attn);

        /* FIR filter and scale */
        y = firflt(y, f, 0) * n;

        /* normal decimation */
        if (p > 1)
        {
                y = decimate(y, p);
        }

        if (outargc > 1)
        {
                /* return result and filter */
                return(y, f);
        }
        else
        {
                return(y);
        }
}