static t_int *headShadow_perform(t_int *w)
{
	t_headShadow *x = (t_headShadow *)(w[1]);
	t_sample *in = (t_sample *)(w[2]);						// what's this?
	t_sample *outL = (t_sample *)(w[3]);
	t_sample *outR = (t_sample *)(w[4]);
	t_headShadowctl *c = (t_headShadowctl *)(w[5]);
	int n = (t_int)(w[6]);									// lenght of the signal vector
	int i;
	t_sample lastL = c->c_x;

	t_sample lastR = c->c_x;
	t_sample coef = c->c_coef;
	//t_sample feedback = 1 - coef;
	//for (i = 0; i < n; i++) last = *out++ = coef * *in++ + feedback * last; if (PD_BIGORSMALL(last)) last = 0; c->c_x = last;
	/* For the left ear */
	t_float b0l = x->x_b0l;
	t_float b1l = x->x_b1l;
	t_float b0r = x->x_b0r;
	t_float b1r = x->x_b1r;
	t_float a0 = x->x_a0;
	t_float a1 = x->x_a1;


	t_sample lastLm1 = 0;
	t_sample lastRm1 = 0;
    t_sample inm1 = 0;


	lastL = 0;
	lastR = 0;





	for (i = 0; i < n; i++) {
		// lastL  = (1/a0) *((b0l * *in++) + (b1l * *in) - (a1 * lastLm1));
		// lastR  = (1/a0) *((b0r * *in++) + (b1r * *in) - (a1 * lastRm1));

        lastL  = (1/a0) * ((b0l * in[i]) + (b1l * inm1) - (a1 * lastLm1));
		lastR  = (1/a0) * ((b0r * in[i]) + (b1r * inm1) - (a1 * lastRm1));

		// update
		lastLm1 = lastL;
		lastRm1 = lastR;
		inm1 = in[i];

		outL[i] = lastL;
		outR[i] = lastR;

		}


		post("LastL:%f y lastLm1: %f. LastR: %f", lastL, lastLm1, lastR);
	
	if (PD_BIGORSMALL(lastL)) lastL = 0; c->c_x = lastL;
	if (PD_BIGORSMALL(lastR)) lastR = 0; c->c_x = lastR;
	return (w+7);
}
Exemple #2
0
/* Run one sample through the SV filter. Filter is by andy@vellocet */
static inline float run_svf(t_svf *sv, float in) {
        float out;
        int i;

        in = sv->qnrm * in ;
        for (i=0; i < F_R; i++) {
                // only needed for pentium chips
                if(PD_BIGORSMALL(in)) in = 0.;
                if(PD_BIGORSMALL(sv->l)) sv->l = 0.;
        // OLD VERSION
        //in = FLUSH_TO_ZERO(in);
        //sv->l = FLUSH_TO_ZERO(sv->l);
	  // new versions, thanks to Damon Chaplin, inserted by Ed Kelly, not yet working!!!
	  //in  = ((int)in & 0x7f800000)==0?0.0f:in;
	   //sv->l = ((int)sv->l & 0x7f800000)==0?0.0f:sv->l;
                // very slight waveshape for extra stability
                sv->b = sv->b - sv->b * sv->b * sv->b * 0.001f;

                // regular state variable code here
                // the notch and peaking outputs are optional
                sv->h = in - sv->l - sv->q * sv->b;
                sv->b = sv->b + sv->f * sv->h;
                sv->l = sv->l + sv->f * sv->b;
                sv->n = sv->l + sv->h;
                sv->p = sv->l - sv->h;

                out = *(sv->op);
                in = out;
        }

        return out;
}
Exemple #3
0
static t_int *headShadow_perform(t_int *w)
{
	t_headShadow *x = (t_headShadow *)(w[1]);
	t_sample *in = (t_sample *)(w[2]);			
	t_sample *outL = (t_sample *)(w[3]);
	t_sample *outR = (t_sample *)(w[4]);
	t_headShadowctl *c = (t_headShadowctl *)(w[5]);
	int n = (t_int)(w[6]);									
	int i;
	t_sample lastL = c->c_x;
	t_sample lastR = c->c_x;
	t_sample coef = c->c_coef;
	t_float b0l = x->x_b0l;
	t_float b1l = x->x_b1l;
	t_float b0r = x->x_b0r;
	t_float b1r = x->x_b1r;
	t_float a0 = x->x_a0;
	t_float a1 = x->x_a1;
	
	for (i = 0; i < n; i++) {
        x->lastL  = (1/a0) * ((b0l * in[i]) + (b1l * x->inm1) - (a1 * x->lastL));
		x->lastR  = (1/a0) * ((b0r * in[i]) + (b1r * x->inm1) - (a1 * x->lastR));
		/* Updating*/
		x->inm1 = in[i];
		outL[i] = x->lastL;
		outR[i] = x->lastR;
	}
	
	if (PD_BIGORSMALL(lastL)) lastL = 0; c->c_x = lastL;
	if (PD_BIGORSMALL(lastR)) lastR = 0; c->c_x = lastR;
	return (w+7);
}
Exemple #4
0
/* this is a true linear ramper */
static t_int *rampsmooth_perform(t_int *w)
{
    t_rampsmooth *x = (t_rampsmooth *)(w[1]);
    int nblock = (int)(w[2]);
    t_float *in = (t_float *)(w[3]);
    t_float *out = (t_float *)(w[4]);
    t_float last = x->x_last;
    t_float target = x->x_target;
    double incr = x->x_incr;
    int nleft = x->x_nleft;
    while (nblock--)
    {
    	t_float f = *in++;
	if (f != target)
	{
	    target = f;
	    if (f > last)
	    {
		if (x->x_nup > 1)
		{
		    incr = (f - last) * x->x_upcoef;
		    nleft = x->x_nup;
		    *out++ = (last += incr);
		    continue;
		}
	    }
	    else if (f < last)
	    {
		if (x->x_ndown > 1)
		{
		    incr = (f - last) * x->x_downcoef;
		    nleft = x->x_ndown;
		    *out++ = (last += incr);
		    continue;
		}
	    }
	    incr = 0.;
	    nleft = 0;
	    *out++ = last = f;
	}
	else if (nleft > 0)
	{
	    *out++ = (last += incr);
	    if (--nleft == 0)
	    {
		incr = 0.;
		last = target;
	    }
	}
	else *out++ = target;
    }
    x->x_last = (PD_BIGORSMALL(last) ? 0. : last);
    x->x_target = (PD_BIGORSMALL(target) ? 0. : target);
    x->x_incr = incr;
    x->x_nleft = nleft;
    return (w + 5);
}
Exemple #5
0
static t_int *vcf_perform(t_int *w)
{
    t_sample *inputsample = (t_sample *)(w[1]);
    t_sample *freqin = (t_sample *)(w[2]);
    t_sample *out1 = (t_sample *)(w[3]);
    t_sample *out2 = (t_sample *)(w[4]);
    t_vcfctl *c = (t_vcfctl *)(w[5]);
    int vectorsize = (t_int)(w[6]);

    t_float real = c->real, real2;
    t_float im = c->im;
    t_float q = c->q;
    t_float *costab = cos_table;
    
    t_float ampcorrect = 2. - 2. / (q + 2.);
    t_float q2radius = (q ? c->oneoversamplerate * TWOPI / q : 0.);         
    t_float tabnorm =  c->oneoversamplerate * COSTABSIZE;                       
    t_float realcoef, imcoef, fraction, insamp;
    t_float tabphase, centerfreq, radius, oneminusr;
    int index;

    while(vectorsize--)
    {
        centerfreq = (*freqin > 0.? *freqin : 0.);
        freqin++;
        
        // radius
        radius = 1. - centerfreq * q2radius - EPSILON;                                      
        if ((radius < 0.) || (q2radius == 0.)) radius = 0.;                               
        oneminusr = 1.0 - radius;
        
        // phase
        tabphase = centerfreq * tabnorm;
        index = (int)tabphase;
        fraction = (GOODINT(index)? tabphase - index : 0.);
        index &= COSTABMASK;
        
        // coefficients
        realcoef = radius * (costab[index] + fraction * (costab[index+1] - costab[index]));
        index -= COSTABSIZE>>2;
        index &= COSTABSIZE-1;
        imcoef = radius * (costab[index] + fraction * (costab[index+1] - costab[index]));
        
        insamp = *inputsample++;
        real2 = real;
        *out1++ = real = ampcorrect * oneminusr * insamp + realcoef * real2 - imcoef * im;
        *out2++ = im = imcoef * real2 + realcoef * im;
    }

    if (PD_BIGORSMALL(real)) real = 0.;
    if (PD_BIGORSMALL(im)) im = 0.;
    c->real = real;
    c->im = im;
    return (w+7);
}
Exemple #6
0
static t_int *line_tilde_perform(t_int *w)
{
    t_line *x = (t_line *)(w[1]);
    t_sample *out = (t_sample *)(w[2]);
    int n = (int)(w[3]);
    t_sample f = x->x_value;

    if (PD_BIGORSMALL(f))
            x->x_value = f = 0;
    if (x->x_retarget)
    {
        int nticks = x->x_inletwas * x->x_dspticktomsec;
        if (!nticks) nticks = 1;
        x->x_ticksleft = nticks;
        x->x_biginc = (x->x_target - x->x_value)/(t_float)nticks;
        x->x_inc = x->x_1overn * x->x_biginc;
        x->x_retarget = 0;
    }
    if (x->x_ticksleft)
    {
        t_sample f = x->x_value;
        while (n--) *out++ = f, f += x->x_inc;
        x->x_value += x->x_biginc;
        x->x_ticksleft--;
    }
    else
    {
        t_sample g = x->x_value = x->x_target;
        while (n--)
            *out++ = g;
    }
    return (w+4);
}
static t_int *sigdelwrite_perform(t_int *w)
{
    t_sample *in = (t_sample *)(w[1]);
    t_delwritectl *c = (t_delwritectl *)(w[2]);
    int n = (int)(w[3]);
    int phase = c->c_phase, nsamps = c->c_n;
    t_sample *vp = c->c_vec, *bp = vp + phase, *ep = vp + (c->c_n + XTRASAMPS);
    phase += n;

    while (n--)
    {
        t_sample f = *in++;
        if (PD_BIGORSMALL(f))
            f = 0;
        *bp++ = f;
        if (bp == ep)
        {
            vp[0] = ep[-4];
            vp[1] = ep[-3];
            vp[2] = ep[-2];
            vp[3] = ep[-1];
            bp = vp + XTRASAMPS;
            phase -= nsamps;
        }
    }
    c->c_phase = phase; 
    return (w+4);
}
Exemple #8
0
/* this ramper generates a geometric series output for a single step input */
static t_int *rampsmooth_perform(t_int *w)
{
    t_rampsmooth *x = (t_rampsmooth *)(w[1]);
    int nblock = (int)(w[2]);
    t_float *in = (t_float *)(w[3]);
    t_float *out = (t_float *)(w[4]);
    t_float last = x->x_last;
    while (nblock--)
    {
    	t_float f = *in++;
	if (f > last)
	{
	    if (x->x_nup > 1)
	    {
		*out++ = (last += (f - last) * x->x_upcoef);
		continue;
	    }
	}
	else if (f < last)
	{
	    if (x->x_ndown > 1)
	    {
		*out++ = (last += (f - last) * x->x_downcoef);
		continue;
	    }
	}
	*out++ = last = f;
    }
    x->x_last = (PD_BIGORSMALL(last) ? 0. : last);
    return (w + 5);
}
Exemple #9
0
static t_int *tabsend_perform(t_int *w)
{
    t_tabsend *x = (t_tabsend *)(w[1]);
    t_sample *in = (t_sample *)(w[2]);
    int n = w[3];
    t_word *dest = x->x_vec;
    int i = x->x_graphcount;
    if (!x->x_vec) goto bad;
    if (n > x->x_npoints)
        n = x->x_npoints;
    while (n--)
    {   
        t_sample f = *in++;
        if (PD_BIGORSMALL(f))
            f = 0;
         (dest++)->w_float = f;
    }
    if (!i--)
    {
        t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
        if (!a)
            bug("tabsend_dsp");
        else garray_redraw(a);
        i = x->x_graphperiod;
    }
    x->x_graphcount = i;
bad:
    return (w+4);
}
Exemple #10
0
static t_int *tabwrite_tilde_perform(t_int *w)
{
    t_tabwrite_tilde *x = (t_tabwrite_tilde *)(w[1]);
    t_sample *in = (t_sample *)(w[2]);
    int n = (int)(w[3]), phase = x->x_phase, endphase = x->x_nsampsintab;
    if (!x->x_vec) goto bad;
    
    if (endphase > phase)
    {
        int nxfer = endphase - phase;
        t_word *wp = x->x_vec + phase;
        if (nxfer > n) nxfer = n;
        phase += nxfer;
        while (nxfer--)
        {
            t_sample f = *in++;
            if (PD_BIGORSMALL(f))
                f = 0;
            (wp++)->w_float = f;
        }
        if (phase >= endphase)
        {
            tabwrite_tilde_redraw(x);
            phase = 0x7fffffff;
        }
        x->x_phase = phase;
    }
    else x->x_phase = 0x7fffffff;
bad:
    return (w+4);
}
Exemple #11
0
static void vline_tilde_float(t_vline *x, t_float f)
{
    double timenow = clock_gettimesince(x->x_referencetime);
    t_float inlet1 = (x->x_inlet1 < 0 ? 0 : x->x_inlet1);
    t_float inlet2 = x->x_inlet2;
    double starttime = timenow + inlet2;
    t_vseg *s1, *s2, *deletefrom = 0, *snew;
    if (PD_BIGORSMALL(f))
        f = 0;

        /* negative delay input means stop and jump immediately to new value */
    if (inlet2 < 0)
    {
        x->x_value = f;
        vline_tilde_stop(x);
        return;
    }
    snew = (t_vseg *)t_getbytes(sizeof(*snew));
        /* check if we supplant the first item in the list.  We supplant
        an item by having an earlier starttime, or an equal starttime unless
        the equal one was instantaneous and the new one isn't (in which case
        we'll do a jump-and-slide starting at that time.) */
    if (!x->x_list || x->x_list->s_starttime > starttime ||
        (x->x_list->s_starttime == starttime &&
            (x->x_list->s_targettime > x->x_list->s_starttime || inlet1 <= 0)))
    {
        deletefrom = x->x_list;
        x->x_list = snew;
    }
    else
    {
        for (s1 = x->x_list; (s2 = s1->s_next); s1 = s2)
        {
            if (s2->s_starttime > starttime ||
                (s2->s_starttime == starttime &&
                    (s2->s_targettime > s2->s_starttime || inlet1 <= 0)))
            {
                deletefrom = s2;
                s1->s_next = snew;
                goto didit;
            }
        }
        s1->s_next = snew;
        deletefrom = 0;
    didit: ;
    }
    while (deletefrom)
    {
        s1 = deletefrom->s_next;
        t_freebytes(deletefrom, sizeof(*deletefrom));
        deletefrom = s1;
    }
    snew->s_next = 0;
    snew->s_target = f;
    snew->s_starttime = starttime;
    snew->s_targettime = starttime + inlet1;
    x->x_inlet1 = x->x_inlet2 = 0;
}
Exemple #12
0
	inline void m_bash_denormals()
	{
		for (int i = 0; i != dimensions; ++i)
		{
#ifndef DOUBLE_PRECISION
			if (PD_BIGORSMALL(m_data[i]))
				m_data[i] = 0;
#endif
		}
	};
Exemple #13
0
/* LATER make ready for optional audio-rate modulation
   (separate scalar case routines, use sic_makecostable(), etc.) */
static t_int *reson_perform(t_int *w)
{
    t_reson *x = (t_reson *)(w[1]);
    int nblock = (int)(w[2]);
    t_float *xin = (t_float *)(w[3]);
    t_float *gin = (t_float *)(w[4]);
    t_float fin0 = *(t_float *)(w[5]);
    t_float qin0 = *(t_float *)(w[6]);
    t_float *out = (t_float *)(w[7]);
    float xnm1 = x->x_xnm1;
    float xnm2 = x->x_xnm2;
    float ynm1 = x->x_ynm1;
    float ynm2 = x->x_ynm2;
    /* CHECKME sampled once per block */
    float qinv = (qin0 > RESON_MINQ ? -1. / qin0 : (-1. / RESON_MINQ));
    float omega = fin0 * x->x_srcoef;
    float radius, c1, c2, scale;
    if (omega < RESON_MINOMEGA)
	omega = RESON_MINOMEGA;
    else if (omega > RESON_MAXOMEGA)
	omega = RESON_MAXOMEGA;
    radius = expf(omega * qinv);  /* radius < 1 (because omega * qinv < 0) */
    c1 = 2. * radius * cosf(omega);
    c2 = radius * radius;
    scale = 1. - radius;
    while (nblock--)
    {
	float yn, xn = *xin++;
	/* CHECKED gain control */
	*out++ = yn =
	    *gin++ * scale * (xn - radius * xnm2) + c1 * ynm1 - c2 * ynm2;
	xnm2 = xnm1;
	xnm1 = xn;
	ynm2 = ynm1;
	ynm1 = yn;
    }
    x->x_xnm1 = xnm1;
    x->x_xnm2 = xnm2;
    /* LATER rethink */
    x->x_ynm1 = (PD_BIGORSMALL(ynm1) ? 0. : ynm1);
    x->x_ynm2 = (PD_BIGORSMALL(ynm2) ? 0. : ynm2);
    return (w + 8);
}
Exemple #14
0
static t_int *delay_performsig(t_int *w)
{
	t_delay *x = (t_delay *)(w[1]);
    int nblock = (int)(w[2]);
    t_float *in1 = (t_float *)(w[3]);
    t_float *in2 = (t_float *)(w[4]);
    t_float *out = (t_float *)(w[5]);
    t_float *buf = x->x_buf;
    t_float *bp = x->x_buf + DELAY_GUARD - 1;
    t_float *ep = x->x_bufend;
    t_float *wp = x->x_whead;
    int maxsize = x->x_maxsize;
    t_float *rp;
    
    while (nblock--)
    {
    	t_sample f, del, frac, a, b, c, d, cminusb;
   		int idel;
    	f = *in1++;
    	if (PD_BIGORSMALL(f))
    		f = 0.;
    	*wp = f;
    	del = *in2++;
    	del = (del > 0. ? del : 0.);
    	del = (del < maxsize ? del : maxsize);
    	idel = (int)del;
    	frac = del - (t_sample)idel;
    	rp = wp - idel;
    	if (rp < bp)
    		rp += (maxsize + DELAY_GUARD);
    	d = rp[-3];
        c = rp[-2];
        b = rp[-1];
        a = rp[0];
        cminusb = c-b;
        *out++ = b + frac * (
            cminusb - 0.1666667f * (1.-frac) * (
                (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
            )
        );
    	if (++wp == ep)
    	{
    		buf[0] = wp[-3];
    		buf[1] = wp[-2];
    		buf[2] = wp[-1];
    		wp = bp;
    	}
    }
    x->x_whead = wp;
    return (w + 6);
}
Exemple #15
0
static t_int *testfilter_tilde_perform(t_int *w)
{
    t_sample *in = (t_sample *)(w[1]);
    t_sample *out = (t_sample *)(w[2]);
    t_testfilterctl *c = (t_testfilterctl *)(w[3]);
    int n = (t_int)(w[4]);
    int i;
    t_sample last = c->c_x;
    t_sample coef = c->c_coef;
    t_sample feedback = 1 - coef;
    for (i = 0; i < n; i++)
        last = *out++ = coef * *in++ + feedback * last;
    if (PD_BIGORSMALL(last))
        last = 0;
    c->c_x = last;
    return (w+5);
}
Exemple #16
0
/* TB: vectorized version */
static t_int *line_tilde_perf8(t_int *w)
{
    t_line *x = (t_line *)(w[1]);
    t_sample *out = (t_sample *)(w[2]);
    int n = (int)(w[3]);
    t_sample f = x->x_value;

    if (PD_BIGORSMALL(f))
        x->x_value = f = 0;
    if (x->x_retarget)
    {
        int nticks = x->x_inletwas * x->x_dspticktomsec;
        if (!nticks) nticks = 1;
        x->x_ticksleft = nticks;
        x->x_biginc = (x->x_target - x->x_value)/(t_sample)nticks;
        x->x_inc = x->x_1overn * x->x_biginc;
        x->x_retarget = 0;
    }
    if (x->x_ticksleft)
    {
        t_sample f = x->x_value;
#if USE_ACCEL_OPTIM
        vDSP_vramp(&f, &x->x_inc, out, 1, n);
#else
        while (n--) *out++ = f, f += x->x_inc;
#endif
        x->x_value += x->x_biginc;
        x->x_ticksleft--;
    }
    else
    {
        t_sample f = x->x_value = x->x_target;
#if USE_ACCEL_OPTIM
        vDSP_vfill(&f, out, 1, n);
#else
        for (; n; n -= 8, out += 8)
        {
            out[0] = f; out[1] = f; out[2] = f; out[3] = f;
            out[4] = f; out[5] = f; out[6] = f; out[7] = f;
        }
#endif
    }
    return (w+4);
}
Exemple #17
0
 t_int *sigthrow13_perform(t_int *w)
{
    t_sigthrow13 *x = (t_sigthrow13 *)(w[1]);
    t_float *in = (t_float *)(w[2]);
    int n = (int)(w[3]);
    t_float *out = x->x_whereto;
    if (out)
    {
    	while (n--)
	{
	/* TB: denormal handling in pd >0.37-2 */
#ifdef PD_BIGORSMALL
	    *out += (PD_BIGORSMALL(*in) ? 0 : *in);
	    out++;
	    in++;
#else
	    *out++ += *in++; 
#endif
	}
    }
    return (w+4);
}
Exemple #18
0
static t_int *envgen_perform(t_int *w){
    t_envgen *x = (t_envgen *)(w[1]);
    t_int n = (int)(w[2]);
    t_float *in = (t_float *)(w[3]);
    t_float *out = (t_float *)(w[4]);
    float lastin = x->x_lastin;
    while(n--){
        t_float f = *in++;
        if(f != 0 && lastin == 0){
            x->x_gain = f;
            envgen_attack(x, &s_list, x->x_ac, x->x_av);
        }
        else if(x->x_release && f == 0 && lastin != 0)
            envgen_release(x, &s_list, x->x_ac_rel, x->x_av_rel);
        if(PD_BIGORSMALL(x->x_value))
            x->x_value = 0;
        *out++ = x->x_value;
        if(!x->x_pause && x->x_status){ // update
            if(x->x_nleft > 0){ // inc
                x->x_value += x->x_inc;
                x->x_nleft--;
            }
            else if(x->x_nleft == 0){ // target
                x->x_value = x->x_target;
                if(x->x_n_lines > 0){ // next
//                    while(x->x_nleft == 0){
                        envgen_retarget(x);
//                    }
                }
                else if(!x->x_release) // off
                    clock_delay(x->x_clock, 0); // over!!!!!
            }
        }
        lastin = f;
    }
    x->x_lastin = lastin;
    return(w + 5);
}
Exemple #19
0
static t_int *phasor_perform(t_int *w)
{
    t_phasor *x = (t_phasor *)(w[1]);
    t_sample *freq = (t_sample *)(w[2]);
    t_sample *phaseout = (t_sample *)(w[3]);
    int vecsize = (int)(w[4]); 

    t_float oneoversamplerate = x->oneoversamplerate;
    double phase = x->phase;
    t_float temp;
    int intphase;
    t_float fraction;
    if(PD_BIGORSMALL(phase)) phase = 0.;   
    
    while (vecsize--)
    {
        // wrap phase within interval 0. - 1.
        if(phase>=1.)
        {
            intphase = (int)phase;
            phase = (GOODINT(intphase)? phase - intphase : 0.);  
        }
        else if(phase<0.) 
        {
            intphase = (int)phase;
            phase = (GOODINT(intphase)? phase - intphase + 1. : 0.);
        }
        
        temp = *freq++;
        *phaseout++ = phase;
        phase += temp * oneoversamplerate;
    }
    
    x->phase = phase;
    return (w+5);
}
Exemple #20
0
static t_int *sigvcf_perform(t_int *w)
{
    float *in1 = (float *)(w[1]);
    float *in2 = (float *)(w[2]);
    float *out1 = (float *)(w[3]);
    float *out2 = (float *)(w[4]);
    t_vcfctl *c = (t_vcfctl *)(w[5]);
    int n = (t_int)(w[6]);
    int i;
    float re = c->c_re, re2;
    float im = c->c_im;
    float q = c->c_q;
    float qinv = (q > 0? 1.0f/q : 0);
    float ampcorrect = 2.0f - 2.0f / (q + 2.0f);
    float isr = c->c_isr;
    float coefr, coefi;
    float *tab = cos_table, *addr, f1, f2, frac;
    double dphase;
    int normhipart, tabindex;
    union tabfudge tf;
    
    tf.tf_d = UNITBIT32;
    normhipart = tf.tf_i[HIOFFSET];

    for (i = 0; i < n; i++)
    {
    	float cf, cfindx, r, oneminusr;
    	cf = *in2++ * isr;
    	if (cf < 0) cf = 0;
    	cfindx = cf * (float)(COSTABSIZE/6.28318f);
    	r = (qinv > 0 ? 1 - cf * qinv : 0);
    	if (r < 0) r = 0;
    	oneminusr = 1.0f - r;
    	dphase = ((double)(cfindx)) + UNITBIT32;
	tf.tf_d = dphase;
	tabindex = tf.tf_i[HIOFFSET] & (COSTABSIZE-1);
	addr = tab + tabindex;
	tf.tf_i[HIOFFSET] = normhipart;
	frac = tf.tf_d - UNITBIT32;
	f1 = addr[0];
	f2 = addr[1];
	coefr = r * (f1 + frac * (f2 - f1));

	addr = tab + ((tabindex - (COSTABSIZE/4)) & (COSTABSIZE-1));
	f1 = addr[0];
	f2 = addr[1];
	coefi = r * (f1 + frac * (f2 - f1));

    	f1 = *in1++;
    	re2 = re;
    	*out1++ = re = ampcorrect * oneminusr * f1 
    	    + coefr * re2 - coefi * im;
    	*out2++ = im = coefi * re2 + coefr * im;
    }
    if (PD_BIGORSMALL(re))
	re = 0;
    if (PD_BIGORSMALL(im))
	im = 0;
    c->c_re = re;
    c->c_im = im;
    return (w+7);
}
Exemple #21
0
static t_int *line_perform(t_int *w)
{
    t_line *x = (t_line *)(w[1]);
    t_float *out = (t_float *)(w[2]);
    int nblock = (int)(w[3]);
    int nxfer = x->x_nleft;
    float curval = x->x_value;
    float inc = x->x_inc;
    float biginc = x->x_biginc;
    
    if (x->x_pause)
    {
	while (nblock--) *out++ = curval;
	return (w + 4);
    }
    if (PD_BIGORSMALL(curval))  /* LATER rethink */
	curval = x->x_value = 0;
retarget:
    if (x->x_retarget)
    {
	float target = x->x_curseg->s_target;
	float delta = x->x_curseg->s_delta;
    	int npoints = delta * x->x_ksr + 0.5;  /* LATER rethink */
/* #ifdef LINE_DEBUG
	x->dbg_nretargets++;
#endif */
	x->x_nsegs--;
	x->x_curseg++;
    	while (npoints <= 0)
	{
	    curval = x->x_value = target;
	    if (x->x_nsegs)
	    {
		target = x->x_curseg->s_target;
		delta = x->x_curseg->s_delta;
		npoints = delta * x->x_ksr + 0.5;  /* LATER rethink */
		x->x_nsegs--;
		x->x_curseg++;
	    }
	    else
	    {
		while (nblock--) *out++ = curval;
		x->x_nleft = 0;
/* #ifdef LINE_DEBUG
		x->dbg_exitpoint = 1;
#endif */
		clock_delay(x->x_clock, 0);
		x->x_retarget = 0;
		return (w + 4);
	    }
	}
    	nxfer = x->x_nleft = npoints;
    	inc = x->x_inc = (target - x->x_value) / (float)npoints;
	x->x_biginc = (int)(w[3]) * inc;
	biginc = nblock * inc;
	x->x_target = target;
    	x->x_retarget = 0;
/* #ifdef LINE_DEBUG
	x->dbg_npoints = npoints;
#endif */
    }
    if (nxfer >= nblock)
    {
	if ((x->x_nleft -= nblock) == 0)
	{
	    if (x->x_nsegs) x->x_retarget = 1;
	    else
	    {
/* #ifdef LINE_DEBUG
		x->dbg_exitpoint = 2;
#endif */
		clock_delay(x->x_clock, 0);
	    }
	    x->x_value = x->x_target;
	}
	else x->x_value += biginc;
    	while (nblock--)
	    *out++ = curval, curval += inc;
    }
    else if (nxfer > 0)
    {
	nblock -= nxfer;
	do
	    *out++ = curval, curval += inc;
	while (--nxfer);
	curval = x->x_value = x->x_target;
	if (x->x_nsegs)
	{
	    x->x_retarget = 1;
	    goto retarget;
	}
	else
	{
	    while (nblock--) *out++ = curval;
	    x->x_nleft = 0;
/* #ifdef LINE_DEBUG
	    x->dbg_exitpoint = 3;
#endif */
	    clock_delay(x->x_clock, 0);
	}
    }
    else while (nblock--) *out++ = curval;
    return (w + 4);
}
Exemple #22
0
static t_int *curve_perform(t_int *w)
{
    t_curve *x = (t_curve *)(w[1]);
    t_float *out = (t_float *)(w[2]);
    int nblock = (int)(w[3]);
    int nxfer = x->x_nleft;
    float curval = x->x_value;
    double vv = x->x_vv;
    double bb = x->x_bb;
    double mm = x->x_mm;
    float dy = x->x_dy;
    float y0 = x->x_y0;
    if (PD_BIGORSMALL(curval))  /* LATER rethink */
	curval = x->x_value = 0;
retarget:
    if (x->x_retarget)
    {
	float target = x->x_curseg->s_target;
	float delta = x->x_curseg->s_delta;
    	int nhops = x->x_curseg->s_nhops;
	bb = x->x_curseg->s_bb;
	mm = x->x_curseg->s_mm;
	if (x->x_curseg->s_ccinput < 0)
	    dy = x->x_value - target;
	else
	    dy = target - x->x_value;
#ifdef CURVE_DEBUG
	x->dbg_nretargets++;
#endif
	x->x_nsegs--;
	x->x_curseg++;
    	while (nhops <= 0)
	{
	    curval = x->x_value = target;
	    if (x->x_nsegs)
	    {
		target = x->x_curseg->s_target;
		delta = x->x_curseg->s_delta;
		nhops = x->x_curseg->s_nhops;
		bb = x->x_curseg->s_bb;
		mm = x->x_curseg->s_mm;
		if (x->x_curseg->s_ccinput < 0)
		    dy = x->x_value - target;
		else
		    dy = target - x->x_value;
		x->x_nsegs--;
		x->x_curseg++;
	    }
	    else
	    {
		while (nblock--) *out++ = curval;
		x->x_nleft = 0;
#ifdef CURVE_DEBUG
		x->dbg_exitpoint = 1;
#endif
		clock_delay(x->x_clock, 0);
		x->x_retarget = 0;
		return (w + 4);
	    }
	}
    	nxfer = x->x_nleft = nhops;
	x->x_vv = vv = bb;
	x->x_bb = bb;
	x->x_mm = mm;
	x->x_dy = dy;
	x->x_y0 = y0 = x->x_value;
	x->x_target = target;
    	x->x_retarget = 0;
#ifdef CURVE_DEBUG
	x->dbg_nhops = nhops;
#endif
    }
    if (nxfer >= nblock)
    {
	int silly = ((x->x_nleft -= nblock) == 0);  /* LATER rethink */
    	while (nblock--)
	{
	    *out++ = curval = (vv - bb) * dy + y0;
	    vv *= mm;
	}
	if (silly)
	{
	    if (x->x_nsegs) x->x_retarget = 1;
	    else
	    {
#ifdef CURVE_DEBUG
		x->dbg_exitpoint = 2;
#endif
		clock_delay(x->x_clock, 0);
	    }
	    x->x_value = x->x_target;
	}
	else
	{
	    x->x_value = curval;
	    x->x_vv = vv;
	}
    }
    else if (nxfer > 0)
    {
	nblock -= nxfer;
	do
	    *out++ = (vv - bb) * dy + y0, vv *= mm;
	while (--nxfer);
	curval = x->x_value = x->x_target;
	if (x->x_nsegs)
	{
	    x->x_retarget = 1;
	    goto retarget;
	}
	else
	{
	    while (nblock--) *out++ = curval;
	    x->x_nleft = 0;
#ifdef CURVE_DEBUG
	    x->dbg_exitpoint = 3;
#endif
	    clock_delay(x->x_clock, 0);
	}
    }
    else while (nblock--) *out++ = curval;
    return (w + 4);
}
Exemple #23
0
static t_int *delay_perform(t_int *w)
{
    t_delay *x = (t_delay *)(w[1]);
    int nblock = (int)(w[2]);
    t_float *in1 = (t_float *)(w[3]);
    t_float *in2 = (t_float *)(w[4]);
    t_float *out = (t_float *)(w[5]);
    t_float *buf = x->x_buf;
    t_float *ep = x->x_bufend;
    t_float *wp = x->x_whead;
    int maxsize = x->x_maxsize;
    
    if (*in2 != x->x_delsize && !x->x_remain)
    {
    	delay_delay(x, *in2);
    }
    
    int nleft = x->x_remain;
    if (nleft)
    {
    	double incr = x->x_rampinc;
    	double currramp = x->x_rampvals[0];
    	double prevramp = x->x_rampvals[1];
    	t_float *prevrp = wp - x->x_prevdelsize;
    	t_float *currrp = wp - x->x_delsize;
    	if (prevrp < buf) prevrp += maxsize + 1;
    	if (currrp < buf) currrp += maxsize + 1;
    	
    	if (nleft > nblock)
    	{
    		nleft -= nblock;
    		while (nblock--)
    		{
    			t_sample f = *in1++;
    			if (PD_BIGORSMALL(f))
    				f = 0.;
    			currramp += incr;
    			prevramp -= incr;*wp = f;
    			*out++ = (t_float)(*prevrp * prevramp + *currrp * currramp);
    			if (prevrp++ == ep) prevrp = buf;
    			if (currrp++ == ep) currrp = buf;
    			if (wp++ == ep) wp = buf;
    		}
    	}
    	else
    	{
    		while (nleft)
    		{
    			nleft--;
    			nblock--;
    			t_sample f = *in1++;
    			if (PD_BIGORSMALL(f))
    				f = 0.;
    			currramp += incr;
    			prevramp -= incr;
    			*wp = f;
    			*out++ = (t_float)(*prevrp * prevramp + *currrp * currramp);
    			if (prevrp++ == ep) prevrp = buf;
				if (currrp++ == ep) currrp = buf;
    			if (wp++ == ep) wp = buf;
    		}
    		while (nblock--)
    		{
    			t_sample f = *in1++;
    			if (PD_BIGORSMALL(f))
    				f = 0.;
    			*wp = f;
    			*out++ = *currrp;
    			if (currrp++ == ep) currrp = buf;
    			if (wp++ == ep) wp = buf;
    		}
    	} /* end else */
    	x->x_rampvals[0] = currramp;
    	x->x_rampvals[1] = prevramp;
    	x->x_remain = nleft;
    }
    else if (x->x_delsize)
    {
    	t_float *rp = wp - x->x_delsize;
    	if (rp < buf) rp += maxsize + 1;
    	while (nblock--)
    	{
    		t_sample f = *in1++;
    		if (PD_BIGORSMALL(f))
    			f = 0.;
    		*out++ = *rp;
    		*wp = f;
    		if (rp++ == ep) rp = buf;
    		if (wp++ == ep) wp = buf;
    	}
    }
    else while (nblock--)
    {
    	t_sample f = *in1++;
    	if (PD_BIGORSMALL(f))
    		f = 0.;
    	*out++ = *wp = f;
    	if (wp++ == ep) wp = buf;
    }
    x->x_whead = wp;
    return (w + 6);
}
Exemple #24
0
static t_int *nrcombf_perform(t_int *w)
{
    t_sample *in = (t_sample *)(w[1]);
    t_sample *time = (t_sample *)(w[2]);
    t_sample *fb = (t_sample *)(w[3]);
    t_sample *norm = (t_sample *)(w[4]);
    t_sample *out = (t_sample *)(w[5]);
    t_nrcombf *x = (t_nrcombf *)(w[6]);
    int n = (int)(w[7]);

    int phase = x->c_phase, nsamps = x->c_n;
    int idelsamps;
    t_sample limit = nsamps - 3;
    t_sample *vp = x->c_vec, *bp, *wp = vp + phase, 
    	*ep = vp + (nsamps + XTRASAMPS);
    phase += n;
    while (n--)
    {
    	t_sample f = *in++;
        if (PD_BIGORSMALL(f))
            f = 0;
        t_sample delsamps = x->x_sr * (*time++), frac;
        
        t_sample a, b, c, d, cminusb;
        if (!(delsamps >= 1.f))    /* too small or NAN */
            delsamps = 1.f;
        if (delsamps > limit)           /* too big */
            delsamps = limit;
        idelsamps = delsamps;
        frac = delsamps - (t_sample)idelsamps;
        bp = wp - idelsamps;
        if (bp < vp + 4) bp += nsamps;
        d = bp[-3];
        c = bp[-2];
        b = bp[-1];
        a = bp[0];
        cminusb = c-b;
        #ifdef FP_FAST_FMA
       delsamps = fma(frac, (
            cminusb - 0.1666667f * (1.-frac) * fma(
                (fma(-3.0f, cminusb, d - a)), frac, fma(-3.0, b, fma(2.0, a, d))
            )
        ), b);
        #else
        delsamps = b + frac * (
            cminusb - 0.1666667f * (1.-frac) * (
                (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)
            )
        );
        #endif
        b = fmax(fmin(*norm++, 1), -1);
        a = fmax(fmin(*fb++, 0x1.fffffp-1), -0x1.fffffp-1);
        #ifdef FP_FAST_FMA
        *out++ = fma(delsamps, a, f)*b;
        #else
        *out++ = (f + delsamps*a)*b;
        #endif
        *wp++ = f;
        if (wp == ep)
        {
            vp[0] = ep[-4];
            vp[1] = ep[-3];
            vp[2] = ep[-2];
            vp[3] = ep[-1];
            wp = vp + XTRASAMPS;
            phase -= nsamps;
        }
    }
    x->c_phase = phase;
    return (w+8);
}