Exemple #1
0
int granufm_tilde_setup(void)
{
	t_class *c = class_new(gensym("granufm~"), (t_newmethod)granufm_new, (t_method)grans_free, (long)sizeof(t_grans), CLASS_NOINLET, A_GIMME, 0);
	
    class_addmethod(c, (t_method)grans_clear,   gensym("clear"),     0);
	class_addmethod(c, (t_method)grans_dsp,		gensym("dsp"),	A_CANT, 0);
	
    
    double coefshape[NSHAPINGTABS];
    PowTableFunction(NSHAPINGTABS, coefshape, 1, 0.0001, 1.0, 2.0);
    
    long i;
    for(i = 0; i < NSHAPINGTABS; i++){
        PowTableFunction(STABSZ, granu_exptab[i], 1, 0.0001, 1.0, coefshape[i] * 10.0);
    }
    
    SincFunction(STABSZ, granu_sincwindow, 1, (double)-GRANU_SINCRIPPLES, (double)GRANU_SINCRIPPLES);
    DampedSineFunction(STABSZ, granu_dampedsinetab, 1, 0.0, 5.0, 1.0);
    CosWindowFunction(STABSZ, granu_wind_costab, 1, 0.0, 2.0 * PI);
    SineFunction(STABSZ, granu_sinetab, 1, 0.0, 2.0 * PI);
    ExpDecayFunction(STABSZ, granu_expdecaytab, 1, 0.0, 5.0);
    
    
    granufm_class = c;
	return 0;
}
Exemple #2
0
void *grans_new(t_symbol *s, long argc, t_atom *argv)
{
    int n;
	t_grans *x = (t_grans *)object_alloc(grans_class);

	if (x) {
		dsp_setup((t_pxobject *)x, 8);

        x->maxoscillators = DEFAULTMAXOSCILLATORS;
        
        if( argc > 0)
        {
            int i;
            t_atom *ap;
            for (i = 0, ap = argv; i < argc; i++, ap++) {
                if(atom_gettype(ap) == A_LONG)
                {
                    switch(i){
                        case 0:
                            n = atom_getlong(ap);
                            x->maxoscillators = n;
                           // object_post((t_object *)x, "%d oscillators initialized", n);
                            break;
                        case 1:
                            n = atom_getlong(ap);
                            x->numoutlets = n;
                           // object_post((t_object *)x, "%d outlets?", n);

                            while(n--){
                                outlet_new(x, "signal");
                            }
                        default:
                        break;       
                    }
                }
            }
            
        }
        else
        {
            x->numoutlets = 1;
            outlet_new(x, "signal");
           // outlet_new(x, "signal");
            
        }
		
        x->ob.z_misc |= Z_NO_INPLACE;

        
		x->base = (t_osc *)calloc(x->maxoscillators, sizeof(t_osc));
//		x->modbase = (t_osc *)calloc(x->maxoscillators, sizeof(t_osc));

        x->sinetab = (double *)calloc(STABSZ, sizeof(double));
        x->wind_costab = (double *)calloc(STABSZ, sizeof(double));
        x->expdecaytab = (double *)calloc(STABSZ, sizeof(double));
        x->dampedsinetab = (double *)calloc(STABSZ, sizeof(double));
        x->sincwindow = (double *)calloc(STABSZ, sizeof(double));

        double coefshape[NSHAPINGTABS];
        
        PowTableFunction(NSHAPINGTABS, coefshape, 1, 0.0001, 1.0, 2.0);
        
        
        x->exptab = (double **)calloc(NSHAPINGTABS, sizeof(double *));
        
        long i;
        for(i = 0; i < NSHAPINGTABS; i++){
            x->exptab[i] = (double *)calloc(STABSZ, sizeof(double));
            if(x->exptab[i])
            {
                PowTableFunction(STABSZ, x->exptab[i], 1, 0.0001, 1.0, coefshape[i] * 10.0);
            } else {
                object_error((t_object *)x, "could not allocate memory for lookup table");
            }
        }
        
        x->samplerate =  sys_getsr();
        if(x->samplerate<=0)
            x->samplerate = 44100;
      
        
        x->sampleinterval = 1.0 / x->samplerate;
        x->pkw = ( STABSZ * x->sampleinterval ) ;

        x->maxhz = (x->samplerate / 2) * x->pkw;
        x->nosc = x->next_nosc = 0;
        
        x->prev_in1 = 0.0;
        
        x->sincripples = 5; //could make this an attribute, or maybe compute sinc in realtime...
        
        Makeoscsinetable(x);
        MakeCosWindow(x);
        MakeExpDecaytable(x);
        MakeDampedSineWindow(x);
        MakeSincWindow(x);
        
        grans_clear(x);
        
        x->always_on = 0;
        
        t_dictionary *d = NULL;
        d = dictionary_new();
        
        if (d) {
            attr_args_dictionary(d, argc, argv);
            attr_dictionary_process(x, d);
            object_free(d);
        }
        

        
    } else {
        object_post((t_object *)x, "this is potentially bad!");
    }
    
	return (x);
}