Exemplo n.º 1
0
void guiro_perform64(t_guiro *x, t_object *dsp64, double **ins, long numins, double **outs, long numouts, long sampleframes, long flags, void *userparam)
{
	double num_objects	= x->num_objectsConnected	? 	*(double *)(ins[0]) : x->num_objects;
	double shake_damp 	= x->shake_dampConnected	? 	*(double *)(ins[1]) : x->shake_damp;
	double shake_max 	= x->shake_maxConnected		? 	*(double *)(ins[2]) : x->shake_max;
	double res_freq 	= x->res_freqConnected		? 	*(double *)(ins[3]) : x->res_freq;
	double res_freq2 	= x->res_freq2Connected		? 	*(double *)(ins[4]) : x->res_freq2;
	
	double *out = (double *)(outs[0]);
	long n = sampleframes;
    
	double lastOutput;
    
    if(num_objects != x->num_objectsSave) {
        if(num_objects < 1.) num_objects = 1.;
        x->num_objects = (long)num_objects;
        x->num_objectsSave = (long)num_objects;
        x->gain = log(num_objects) * 30.0 / (double) num_objects;
    }
    
    if(res_freq != x->res_freqSave) {
        x->res_freqSave = x->res_freq = res_freq;
        x->coeffs[0] = -GUIR_GOURD_RESON * 2.0 * cos(res_freq * TWO_PI / x->srate);
    }
    
    if(shake_damp != x->shake_dampSave) {
        x->shake_dampSave = x->shake_damp = shake_damp;
        //x->systemDecay = .998 + (shake_damp * .002);
        //x->ratchetDelta = shake_damp;
        x->scrapeVel = shake_damp;
    }
    
    if(shake_max != x->shake_maxSave) {
        x->shake_maxSave = x->shake_max = shake_max;
        //x->shakeEnergy += shake_max * MAX_SHAKE * 0.1;
        //if (x->shakeEnergy > MAX_SHAKE) x->shakeEnergy = MAX_SHAKE;
        x->guiroScrape = shake_max;
    }
    
    if(res_freq2 != x->res_freq2Save) {
        x->res_freq2Save = x->res_freq2 = res_freq2;
        x->coeffs2[0] = -GUIR_GOURD_RESON2 * 2.0 * cos(res_freq2 * TWO_PI / x->srate);
    }
    
    
    while(n--) {
        if (x->guiroScrape < 1.0)      {
	      	x->guiroScrape += x->scrapeVel;
	      	x->totalEnergy = x->guiroScrape;
	      	x->ratchet -= (x->ratchetDelta + (0.002*x->totalEnergy));
	      	if (x->ratchet<0.0) x->ratchet = 1.0;
	      	lastOutput = guiro_tick(x);
        }
        else lastOutput = 0.0;
        *out++ = lastOutput;
    }
}
Exemplo n.º 2
0
t_int *guiro_perform(t_int *w)
{
	t_guiro *x = (t_guiro *)(w[1]);
	
	float num_objects	= x->num_objectsConnected	? 	*(float *)(w[2]) : x->num_objects;
	float shake_damp 	= x->shake_dampConnected	? 	*(float *)(w[3]) : x->shake_damp;
	float shake_max 	= x->shake_maxConnected		? 	*(float *)(w[4]) : x->shake_max;
	float res_freq 		= x->res_freqConnected		? 	*(float *)(w[5]) : x->res_freq;
	float res_freq2 	= x->res_freq2Connected		? 	*(float *)(w[6]) : x->res_freq2;
	
	float *out = (float *)(w[7]);
	long n = w[8];

	float lastOutput, temp;
	long temp2;

		if(num_objects != x->num_objectsSave) {
			if(num_objects < 1.) num_objects = 1.;
			x->num_objects = (long)num_objects;
			x->num_objectsSave = (long)num_objects;
			x->gain = log(num_objects) * 30.0 / (float) num_objects;
		}
		
		if(res_freq != x->res_freqSave) {
			x->res_freqSave = x->res_freq = res_freq;
			x->coeffs[0] = -GUIR_GOURD_RESON * 2.0 * cos(res_freq * TWO_PI / x->srate);
		}
		
		if(shake_damp != x->shake_dampSave) {
			x->shake_dampSave = x->shake_damp = shake_damp;
			//x->systemDecay = .998 + (shake_damp * .002);
			//x->ratchetDelta = shake_damp;
			x->scrapeVel = shake_damp;
		}
		
		if(shake_max != x->shake_maxSave) {
			x->shake_maxSave = x->shake_max = shake_max;
		 	//x->shakeEnergy += shake_max * MAX_SHAKE * 0.1;
	    	//if (x->shakeEnergy > MAX_SHAKE) x->shakeEnergy = MAX_SHAKE;
	    	x->guiroScrape = shake_max;
		}	

		if(res_freq2 != x->res_freq2Save) {
			x->res_freq2Save = x->res_freq2 = res_freq2;
			x->coeffs2[0] = -GUIR_GOURD_RESON2 * 2.0 * cos(res_freq2 * TWO_PI / x->srate);
		}	
		
		
		while(n--) {
		  if (x->guiroScrape < 1.0)      {
	      	x->guiroScrape += x->scrapeVel;
	      	x->totalEnergy = x->guiroScrape;
	      	x->ratchet -= (x->ratchetDelta + (0.002*x->totalEnergy));
	      	if (x->ratchet<0.0) x->ratchet = 1.0;
	      	lastOutput = guiro_tick(x);
	    	}
	      else lastOutput = 0.0;
	      *out++ = lastOutput;
		}
	return w + 9;
}