Пример #1
0
void *grans_new(t_symbol *s, long argc, t_atom *argv)
{
	t_grans *x = (t_grans *)object_alloc(grans_class);

	if (x) {
		dsp_setup((t_pxobject *)x, 3);
								
		outlet_new(x, "signal");
		outlet_new(x, "signal");
		outlet_new(x, "signal");
        
        x->ob.z_misc |= Z_NO_INPLACE;

		x->base = (t_osc *)calloc(MAXOSCILLATORS, sizeof(t_osc));
        x->stack = (t_osc **)calloc(MAXOSCILLATORS, sizeof(t_osc *));
        
        x->sinetab = (double *)calloc(STABSZ, sizeof(double));
        
        x->offset = 0.0;

        x->samplerate =  sys_getsr();
        if(x->samplerate<=0)
            x->samplerate = 44100;
      
        
        x->sampleinterval = 1.0 / x->samplerate;
        x->pk = ( STABSZ * x->sampleinterval ) * ( 1l << ( 32 - TPOW )) ;

        x->nosc = x->next_nosc = 0;
        
        x->verbose = 0;
        x->prev_in1 = 0.0;
        
        Makeoscsinetable(x);
        
        grans_clear(x);

    } else {
        object_post((t_object *)x, "could not make object!");
        
    }
    
	return (x);
}
Пример #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);
}
Пример #3
0
void *granufm_new(t_symbol *s, long argc, t_atom *argv)
{
    int n;
	t_grans *x = (t_grans *)pd_new(granufm_class);
    
	if (x) {
        
        x->numinlets = 8;
        for(n = 0; n < x->numinlets; n++)
            inlet_new(&x->ob, &x->ob.ob_pd, &s_signal, &s_signal);
        
        x->maxoscillators = DEFAULTMAXOSCILLATORS;
        
        
        x->x_arrayname = NULL;
        x->x_npoints = 0;
        x->x_vec = 0;
        
        if( argc > 0)
        {
            int i;
            t_atom *ap;
            for (i = 0, ap = argv; i < argc; i++, ap++) {
                if(ap->a_type == A_FLOAT)
                {
                    switch(i){
                        case 0:
                            n = atom_getfloat(ap);
                            x->maxoscillators = (int)n;
                            // object_post((t_object *)x, "%d oscillators initialized", n);
                            break;
                        case 1:
                            n = atom_getfloat(ap);
                            x->numoutlets = n;
                            // object_post((t_object *)x, "%d outlets?", n);
                            
                            while(n--){
                                outlet_new(&x->ob, &s_signal);
                            }
                        default:
                            break;
                    }
                }
                else if(ap->a_type == A_SYMBOL)
                {
                    //pseudo attributes here
                    //@envbuffer
                    //(@buffer for granubuf)
                
                }

            }
            
        }
        else
        {
            x->numoutlets = 1;
            outlet_new(&x->ob, &s_signal);
            
        }
		
    //    x->ob.z_misc |= Z_NO_INPLACE;
        
        x->w = (t_int **)malloc((x->numoutlets + x->numinlets + 2) * sizeof(t_int *)); //DSP vector array
        
		x->base = (t_osc *)calloc(x->maxoscillators, sizeof(t_osc));

        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...
       // I just made it a #define macro in the pd rev
        
        grans_clear(x);
        
        x->always_on = 0;
        
        
    } else {
        post("this is potentially bad!");
    }
    
	return (x);
}