Esempio n. 1
0
void *radians_new(t_symbol *msg, short argc, t_atom *argv)
{
	t_atom_long myArg = 0;
	long attrstart;	
	t_radians *x;
	
	attrstart = attr_args_offset(argc, argv);
	if(attrstart && argv)
		atom_arg_getlong(&myArg, 0, attrstart, argv);	// support a normal int argument for bwc	
	
	x = (t_radians *)object_alloc(radians_class);;
	if(x){
		object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL));	// dumpout
		dsp_setup((t_pxobject *)x,1);
		x->radians_out = floatout(x);					// Create a floating-point Outlet
		outlet_new((t_object *)x, "signal");
		
		x->tt = new tt_audio_base;				// Create object for performing radian conversions
		x->tt->set_sr(sys_getsr());
		
		x->radians_mode = myArg;					// default mode

		attr_args_process(x, argc, argv); 			//handle attribute args			
		
	}
	return (x);
}
Esempio n. 2
0
void *decibels_new(t_symbol *msg, short argc, t_atom *argv)
{
	t_decibels *x;
	long attrstart;
	t_atom_long argument = 0;

	attrstart = attr_args_offset(argc, argv);
	if (attrstart && argv)
		atom_arg_getlong(&argument, 0, attrstart, argv);	// support a normal int argument for bwc

	if (x = (t_decibels *)object_alloc(decibels_class)) {
		object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL));	// dumpout
		dsp_setup((t_pxobject *)x,1);
		
    	x->decibels_out = floatout(x);						// Create a floating-point Outlet
		outlet_new((t_object *)x, "signal");
		
		
		// Handle Arguments...		
		if (msg == gensym("tap.atodb~")){
			x->moden = 0;
			object_post((t_object *)x, "     tap.decibels~ initialized in mode 0");
		}
		else if (msg == gensym("tap.dbtoa~")){
			x->moden = 1;
			object_post((t_object *)x, "     tap.decibels~ initialized in mode 1");
		}
		else x->moden = argument;

		switch(x->moden){
			case 0:	x->attr_mode = ps_amp2db; break;
			case 1: x->attr_mode = ps_db2amp; break;
			case 2: x->attr_mode = ps_mm2db; break;
			case 3: x->attr_mode = ps_db2mm; break;
			case 4: x->attr_mode = ps_mm2amp; break;
			case 5: x->attr_mode = ps_amp2mm; break;
			case 6: x->attr_mode = ps_db2midi; break;
			case 7: x->attr_mode = ps_midi2db; break;
		}
		attr_args_process(x,argc,argv); //handle attribute args	
	}
	return (x);
}
Esempio n. 3
0
// function to create new instance and initialise its parameters
void *drag_new(t_symbol *s, short argc, t_atom *argv)
{
    t_double bound_lo = -1.0, bound_hi = 1.0;
    t_int i = 0, dir = -1;
    t_drag *x = object_alloc(drag_class); // set aside memory for the struct for the object

    x->mode = 0;
    x->drag = DRAG_DEFAULT;
    x->dragCurve = DRAGCURVE;
    x->maxcrash = log(CRASHMAX);
    x->fmax = FMAX * 0.5;
    x->bound_lo = bound_lo;
    x->bound_hi = bound_hi;
    atom_arg_getlong(&(x->voice_count), 0, argc, argv);
    atom_arg_getdouble(&(x->bound_lo), 1, argc, argv);
    atom_arg_getdouble(&(x->bound_hi), 2, argc, argv);
    x->mode = atom_getintarg(3,argc,argv);
    if(x->mode < 0) x->mode = 0;
    else if (x->mode > 4) x->mode = 4;
    atom_arg_getdouble(&(x->drag), 4, argc, argv);

    //protect against invalid parameters
    if(x->voice_count > MAX_VOICES) {
        x->voice_count = MAX_VOICES;
    } else if (x->voice_count < 1) {
        x->voice_count = 1;
    }
    if (x->bound_lo < BOUND_L_MIN) x->bound_lo = BOUND_L_MIN;
    if (x->bound_hi > BOUND_H_MAX) x->bound_lo = BOUND_H_MAX;
    if(x->bound_lo >= x->bound_hi) {
        x->bound_lo = BOUND_L_MIN;
        x->bound_hi = BOUND_H_MAX;
        post("invalid args for bounds, set to %f, %f", BOUND_L_MIN, BOUND_H_MAX);
    }
    x->drag = DRAG_DEFAULT;

    // add to dsp chain, set up inlets
    dsp_setup((t_pxobject *)x, 2*x->voice_count + 2); // upper and lower bounds, plus hz and symm per voice
    x->obj.z_misc |= Z_NO_INPLACE; // force independent signal vectors

    // allocate memory for variable arrays
    x->hz = (t_double **) t_getbytes(x->voice_count * sizeof(t_double *));
    x->symm = (t_double **) t_getbytes(x->voice_count * sizeof(t_double *));
    x->out = (t_double **) t_getbytes(x->voice_count * sizeof(t_double *));
    x->hzFloat = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->hzActual = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->grad = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->ball_loc = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->crash = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->lastcrash = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->direction = (t_int *) t_getbytes(x->voice_count * sizeof(t_int));
    x->hz_conn = (t_int *) t_getbytes(x->voice_count * sizeof(t_int));
    x->symm_conn = (t_int *) t_getbytes(x->voice_count * sizeof(t_int));
    x->dcblock_on = (t_bool *) t_getbytes(x->voice_count * sizeof(t_bool));
    x->dc_prev_in = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->dc_prev_out = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->shape = (t_double *) t_getbytes(x->voice_count * sizeof(t_double));
    x->sin = (t_double *)  t_getbytes(LKTBL_LNGTH * sizeof(t_double));
    x->sinh = (t_double *)  t_getbytes(LKTBL_LNGTH * sizeof(t_double));
    x->isfree = (t_bool *) t_getbytes(x->voice_count * sizeof(t_bool));

    setup_lktables(x,0); // build lookup tables for waveshaper

    //set up outlets & and get rate for each voice from args
    x->ball_loc[0] = bound_lo + THINNESTPIPE;
    x->direction[0] = 1;
    for(i=0; i < x->voice_count; i++) {
        outlet_new((t_object *)x, "signal");

        x->shape[i] = 0.1f;
        x->grad[i] = 2;
        x->hzActual[i] = x->hzFloat[i] = 100;
        x->ball_loc[i] =  (x->ball_loc[i-1] + THINNESTPIPE); // begin near bottom of current bound
        dir *= -1,  x->direction[i] = dir;	// alternate up and down
        x->dcblock_on[i] = 0;
        x->dc_prev_in[i] = x->dc_prev_out[i] = 0.f;

    }

    // initialize remaining parameters
    x->srate = (t_double)sys_getsr();

#if DEBUG_ON == 1|| DEBUG_ON == 2
    x->poll_count = POLL_NO_SAMPLES-1;
    x->stopdebug = x->debug_count = 0;
#endif

    return x;
}