View Raw SPL
/* sinx / sin interpolation */
ITERATE sinxinterp(y, rate, rational)
{
        local r, up, dn, ratein, yr, yi;

        if (argc < 3)
        {
                if (argc < 2)
                {
                        if (argc < 1) error(sprintf("%s - Y input series required", __FUNC__));

                        /* default to double original rate */
                        rate = rate(y) * 2;
                }

                rational = 1;
        }

        if (isxy(y))
        {
                y = sinxinterpxy(xvals(y), yvals(y), rate);
        }
        else if (iscomplex(y))
        {
                yr = sinxinterp(real(y), rate, rational);
                yi = sinxinterp(imag(y), rate, rational);

                y = yr + i * yi;
        }
        else
        {
                /* ratio of new rate to current rate */
                ratein = rate(y);
                r      = rate / ratein;

                if (rational || r < 1.0)
                {
                        /* check if we can use zinterp without decimation */
                        (up, dn) = rat(r * length(y), 1e-12);
                }
                else
                {
                        dn = 1;
                }

                if (dn == 1)
                {
                        up = r;
                }
                else
                {
                        /* integer factors for interpolation and decimation */
                        (up, dn) = rat(r, 1e-12);
                }

                /* interpolate */
                if (up > 1)
                {
                        y = zinterp(y, up * ratein);
                }

                if (dn > 1)
                {
                        /* decimate */
                        y = decilp(y, dn);
                }
        }

        return(y);
}