void *f0ext_new(t_symbol *s, long argc, t_atom *argv) { t_f0ext *x= (t_f0ext *)object_alloc(f0ext_class); if(x) { x->valLeft= 0.0; x->valOut= 0.0; x->valMiddle= 120.0; x->valRight= 20.0; t_atom *ap; ap= argv; ap++; if(argc>2) {post("warning: f0.beats_to_frames %d extra argument(s)", argc-2);} switch(MIN(argc, 2)) { case 2: if(atom_gettype(ap)==A_FLOAT) { x->valRight= (double)atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->valRight= (double)atom_getlong(ap); } case 1: ap--; if(atom_gettype(ap)==A_FLOAT) { x->valMiddle= (double)atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->valMiddle= (double)atom_getlong(ap); } } floatin(x, 2); floatin(x, 1); x->out= floatout(x); } return (x); }
void *lorenz_new(t_symbol *s, long argc, t_atom *argv) { t_lorenz *x; x = (t_lorenz *)object_alloc(lorenz_class); x->l_xyz[0]= x->l_xyz[1] = x->l_xyz[2] = 0.6; x->l_h = 0.01; if (argc) { for (int i = 0; i < argc; ++i) { if (i < 3) { if ((argv+i)->a_type == A_FLOAT) { x->l_xyz[i] = (double)atom_getfloat(argv+i); } else if ((argv+i)->a_type == A_LONG) { x->l_xyz[i] = (double)atom_getlong(argv+i); } } } if (argc > 3){ if (argv[3].a_type == A_FLOAT) { x->l_h = atom_getfloat(argv+3); } else if (argv[3].a_type == A_LONG) { x->l_h = (float)atom_getlong(argv+3); } } } floatin(x,3); floatin(x,2); floatin(x,1); x->l_out2 = floatout(x); x->l_out1 = floatout(x); x->l_out0 = floatout(x); return (x); }
t_gaussdraw *gaussdraw_new(Symbol *sym, short argc, Atom *argv) { t_gaussdraw *x = (t_gaussdraw *)newobject(gaussdraw_class); x->x_outlet = listout((t_gaussdraw *)x); // Create a list outlet floatin(x,2); // Create 1 additional inlets floatin(x,1); // Create 1 additional inlets switch (argc) { // Read arguments case 0: x->x_max = DEFMAX; x->x_min = DEFMIN; x->x_height = DEFHEIGHT; x->x_N = DEF_N; break; case 1: x->x_max = DEFMAX; x->x_min = DEFMIN; x->x_height = DEFHEIGHT; readx_N(x,argv); break; case 2: x->x_max = DEFMAX; x->x_min = DEFMIN; readx_height(x,argv); readx_N(x,argv); break; case 3: x->x_max = DEFMAX; readx_min(x,argv); readx_height(x,argv); readx_N(x,argv); break; case 4: readx_max(x,argv); readx_min(x,argv); readx_height(x,argv); readx_N(x,argv); break; default: post("gaussdraw: too many arguments."); readx_max(x,argv); readx_min(x,argv); readx_height(x,argv); readx_N(x,argv); } if (x->x_max <= x->x_min) { post("gaussdraw: min can't be higher than max. Taking default..."); x->x_max = DEFMAX; x->x_min = DEFMIN; } x->myList = (Atom *) NewPtr(MAXNUMPTS * sizeof(*x->myList)); return x; }
void *f0ext_new(double val) { t_f0ext *x= (t_f0ext *)object_alloc(f0ext_class); if(x) { if(val==0.0) { x->valRight= 7.0; } else { x->valRight= val; } floatin(x, 1); } return (x); }
void *f0ext_new(t_symbol *s, long argc, t_atom *argv) { t_f0ext *x= (t_f0ext *)object_alloc(f0ext_class); if(x) { x->valIn= 0.0; x->intswitch= 1; x->valMin= 0.0; x->valMax= 100.0; if(argc>2) {post("warning: f0.wrap %d extra argument(s)", argc-2);} t_atom *ap; ap= argv; if(argc==1) { if(atom_gettype(ap)==A_FLOAT) { x->intswitch= 0; x->valMax= atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->valMax= atom_getlong(ap); } } if(argc>=2) { if(atom_gettype(ap)==A_FLOAT) { x->intswitch= 0; x->valMin= atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->valMin= atom_getlong(ap); } ap++; if(atom_gettype(ap)==A_FLOAT) { x->intswitch= 0; x->valMax= atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->valMax= atom_getlong(ap); } } floatin(x, 2); floatin(x, 1); x->out= floatout(x); } return (x); }
void *randist_new(long num) { t_randist *x; x = (t_randist *)object_alloc(randist_class); if (num < 2) num = 2; x->b_num = num; x->b_id = 0; x->distType = 0; x->possNum = 2; x->varFlt1 = 0.07; // default standard deviation for gaussian x->varFlt2 = 0.5; //default mean for gaussian x->rand_out = floatout((t_object *)x); x->inVar2 = floatin(x, 2); x->inVar1 = floatin(x, 1); x->inDist = intin(x, 3); x->inPoss = intin(x, 4); return x; }
void *myObj_new(double infreq, long n) { int i; t_myObj *x = object_alloc(myObj_class); dsp_setup((t_pxobject*)x, 1); outlet_new((t_object *)x, "signal"); floatin(x, 1); // // initialize variables if(n<16) x->N = 1024; else x->N = n; x->newN = x->N; if(infreq <= 0) x->freq = 1000; else x->freq = infreq; x->sr = sys_getsr(); if(x->sr<=0) x->sr = 44100.0; x->scale = 2.0 / x->N ; x->count = 0; x->wflag = 0; x->mag = 0; // alloc mem x->wgauss = (double *)sysmem_newptr( x->N * sizeof(double)); if(x->wgauss != NULL) { for(i=0; i<x->N; i++) { // blackman //x->wind[i] = 0.426591 - 0.496561*cos(TWOPI*i/x->N) +.076848*cos(2*TWOPI*i/x->N); //x->wind[i] = 0.54 - 0.46 * cos(TWOPI*i/x->N); // hamming //x->wind[i] = 0.5 - 0.5 * cos(TWOPI*i/x->N); // hanning // gaussian double sigma = 0.4; x->wgauss[i] = exp( -0.5 * pow( (i-(x->N-1)*0.5) / (sigma*(x->N-1)*0.5), 2) ); } } else object_error((t_object*)x, "out of memory!"); init(x); return x; }
void *adsr_new(t_symbol *s, int argc, t_atom *argv) { t_adsr *x = (t_adsr *)object_alloc(adsr_class); dsp_setup((t_pxobject *)x,1); // no inputs outlet_new((t_object *)x, "signal"); x->x_obj.z_misc |= Z_NO_INPLACE; floatin((t_object *)x, 1); floatin((t_object *)x, 2); floatin((t_object *)x, 3); floatin((t_object *)x, 4); floatin((t_object *)x, 5); floatin((t_object *)x, 6); x->srate = sys_getsr(); if(!x->srate){ error("zero sampling rate, setting to 44100"); x->srate = 44100; } x->a = 10; x->d = 50; x->s = 100; x->r = 100; atom_arg_getdouble(&x->a,0,argc,argv); atom_arg_getdouble(&x->d,1,argc,argv); atom_arg_getdouble(&x->s,2,argc,argv); atom_arg_getdouble(&x->r,3,argc,argv); atom_arg_getdouble(&x->egain1,4,argc,argv); atom_arg_getdouble(&x->egain2,5,argc,argv); x->a *= .001; x->d *= .001; x->s *= .001; x->r *= .001; x->asamps = x->a * x->srate; x->dsamps = x->d * x->srate; x->ssamps = x->s * x->srate; x->rsamps = x->r * x->srate; x->tsamps = x->asamps+x->dsamps+x->ssamps+x->rsamps; x->ebreak1 = x->asamps; x->ebreak2 = x->asamps+x->dsamps; x->ebreak3 = x->asamps+x->dsamps+x->ssamps; x->egain1 = .7; x->egain2 = .1; x->counter = 0; x->click_gain = 0.0; x->mute = 0; return (x); }
void* BernieNew( long iNTrials, double iProb, long iSeed) { const long kDefNTrials = 1; const double kDefProb = 0.5; objBernie* me = (objBernie*) newobject(gObjectClass); // Default instantiation // Allocate inlets and outlets floatin(me, 2); // p(1) intin(me, 1); // Number of Trials intout(me); // Access main outlet through me->coreObject.o_outlet; // Set up our own members to defaults me->tausData = NIL; me->prob = kDefProb; me->nTrials = kDefNTrials; me->gen = genUndef; // Don't need to worry about genParams as long as the generator is undefined // Run through initialization parameters from right to left, checking for defaults if (iSeed == 0) Taus88Init(); else me->tausData = Taus88New(iSeed); if (iProb == 0.0) iProb = kDefProb; if (iNTrials == 0) iNTrials = kDefNTrials; // Any changes from defaults? if (iNTrials != kDefNTrials) BernieNTrials(me, iNTrials); if (iProb != kDefProb) BernieProb(me, iProb); return me; }
void *minimum_new(t_symbol *s, long ac, t_atom *av) { t_minimum *x; x = object_alloc(minimum_class); systhread_mutex_new(&x->m_mutex, 0); x->m_count = 0; x->m_args = NULL; minimum_resize(x,2); x->m_out2 = intout(x); if (ac) { x->m_args[1] = *av; if (atom_gettype(av)==A_LONG) { x->m_args[0].a_type = x->m_outtype = A_LONG; x->m_out = intout(x); x->m_args[0].a_w.w_long = 0; intin(x,1); } else if (atom_gettype(av)==A_FLOAT) { x->m_args[0].a_type = x->m_outtype = A_FLOAT; x->m_out = floatout(x); x->m_args[0].a_w.w_float = 0; floatin(x,1); } else { x->m_outtype = A_LONG; intin(x,1); x->m_out = intout(x); atom_setlong(x->m_args+1,0L); atom_setlong(x->m_args,0L); } } else { x->m_outtype = A_LONG; intin(x,1); x->m_out = intout(x); atom_setlong(x->m_args+1,0L); atom_setlong(x->m_args,0L); } return x; }
static void* PfishieNew( double iLambda, long iSeed) { const double kDefLambda = 1.0; objPoisson* me = NIL; tTaus88DataPtr myTausData = NIL; // Run through initialization parameters from right to left, handling defaults if (iSeed == 0) Taus88Init(); // Use Taus88's data pool else { myTausData = Taus88New(iSeed); goto noMoreDefaults; } if (iLambda == 0.0) iLambda = kDefLambda; noMoreDefaults: // Finished checking intialization parameters // Let Max allocate us, our inlets, and outlets me = (objPoisson*) LitterAllocateObject(); floatin(me, 1); // lambda inlet intout(me); // Access through me->coreObject.o_outlet // Store object components me->tausData = myTausData; PfishieLambda(me, iLambda); // Sets up all other members return me; }
void *FMNew (double minfreq, double maxfreq, double minModFreq, double maxModFreq, double dex, double minwin, double maxwin){ fmsynth *x; //VARIABLE FOR CREATING THE OBJECT x = (fmsynth *) object_alloc(myClass); dsp_setup((t_pxobject *)x,0); //No signal inlets floatin((t_object *) x, 6); // Inlet for max grain val floatin((t_object *) x, 5); // Inlet for min grain val floatin((t_object *) x, 4); // Inlet for Modulator Depth floatin((t_object *) x, 3); // Inlet for min Modulator Freq floatin((t_object *) x, 2); // Inlet for max Modulator Freq floatin((t_object *) x, 1); // Inlet for Max Carrier Freq outlet_new((t_pxobject *)x, "signal"); // Add a signal outlet //INITIAL VALUES (A_GIMME seems to require this initialization x->minFreq = minfreq = 220.0; x->maxFreq = maxfreq = 300.0; x->minModFreq = minModFreq = 0.; x->maxModFreq = maxModFreq = 0.; x->modIndex = dex= 1.; x->min = minwin = 0.01; x->max = maxwin = 0.1; x->winFlag = 0; // Allocate memory for wavetables: x->waveTable = (double *)sysmem_newptr(sizeof(double) * kTableLength); x->waveTable2 = (double *)sysmem_newptr(sizeof(double) * kTableLength); x->window = (double *)sysmem_newptr(sizeof(double) * kTableLength); FillSine(x); //Default waveform for Carrier is Sine FillSineMod(x); //Default waveform for Modulator is Sine FillWindow(x); //Default window is Hamming return (x); }
void *f0ext_new(t_symbol *s, long argc, t_atom *argv) { t_f0ext *x= (t_f0ext *)object_alloc(f0ext_class); if(x) { x->step= 1.0; x->loop= 0; x->min= LONG_MIN; x->max = LONG_MAX; x->val= 0.0; t_atom *ap; ap= argv; if(argc>4) {post("warning: f0.ultimate_counter %d extra argument(s)", argc-4);} switch(MIN(argc, 4)) { case 4: ap++; ap++; ap++; if(atom_gettype(ap)==A_FLOAT) { x->max= (double)atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->max= (double)atom_getlong(ap); } ap--; ap--; ap--; case 3: ap++; ap++; if(atom_gettype(ap)==A_FLOAT) { x->min= (double)atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->min= (double)atom_getlong(ap); } ap--; ap--; x->val= x->min; case 2: ap++; if(atom_gettype(ap)==A_FLOAT) { x->loop= (short)atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->loop= (short)atom_getlong(ap); } ap--; case 1: if(atom_gettype(ap)==A_FLOAT) { x->step= (double)atom_getfloat(ap); } else if(atom_gettype(ap)==A_LONG) { x->step= (double)atom_getlong(ap); } } floatin(x, 6); floatin(x, 5); floatin(x, 4); floatin(x, 3); intin(x, 2); floatin(x, 1); x->out3= bangout(x); x->out2= bangout(x); x->out= floatout(x); } return (x); }
void *myObj_new(t_symbol *s, short argc, t_atom *argv) { int i; t_myObj *x = object_alloc(myObj_class); if(x) { x->stages_out = listout(x); dsp_setup((t_pxobject*)x, 1); outlet_new((t_pxobject *)x, "signal"); floatin(x, 1); // cf input // initialize paramters x->xm1 = x->xm2 = x->ym1 = x->ym2 = 0; for(i=0; i<MAXPOLES; i++) { x->a[i] = 0; x->b[i] = 0; x->xms[i] = 0; x->yms[i] = 0; } x->mode = 0; // 0: lowpass, 1: highpass x->ripple = 0.5; x->poles = 4; x->r_sr = 1.0/sys_getsr(); //x->blocksize = sys_getblksize(); memalloc(x, sys_getblksize()); x->cfreq = 4410.; // parse arguments if(argc==1) { switch(argv->a_type) { // test type of argument case A_LONG: x->cfreq = argv->a_w.w_long; break; case A_FLOAT: x->cfreq = argv->a_w.w_float; break; } } else if(argc==2) { switch(argv->a_type) { // test type of argument case A_LONG: x->cfreq = argv->a_w.w_long; break; case A_FLOAT: x->cfreq = argv->a_w.w_float; break; } argv++; switch(argv->a_type) { // test type of argument case A_LONG: myObj_poles(x, argv->a_w.w_long); break; case A_FLOAT: myObj_poles(x, (int)argv->a_w.w_float); break; } } else if(argc==3) { switch(argv->a_type) { // test type of argument case A_LONG: x->cfreq = argv->a_w.w_long; break; case A_FLOAT: x->cfreq = argv->a_w.w_float; break; } argv++; switch(argv->a_type) { // test type of argument case A_LONG: myObj_poles(x, argv->a_w.w_long); break; case A_FLOAT: myObj_poles(x, (int)argv->a_w.w_float); break; } argv++; switch(argv->a_type) { // test type of argument case A_LONG: myObj_mode(x, argv->a_w.w_long); break; case A_FLOAT: myObj_mode(x, (float)argv->a_w.w_float); break; } } else if(argc==4) { switch(argv->a_type) { // test type of argument case A_LONG: x->cfreq = argv->a_w.w_long; break; case A_FLOAT: x->cfreq = argv->a_w.w_float; break; } argv++; switch(argv->a_type) { // test type of argument case A_LONG: myObj_poles(x, argv->a_w.w_long); break; case A_FLOAT: myObj_poles(x, (int)argv->a_w.w_float); break; } argv++; switch(argv->a_type) { // test type of argument case A_LONG: myObj_mode(x, argv->a_w.w_long); break; case A_FLOAT: myObj_mode(x, (float)argv->a_w.w_float); break; } argv++; switch(argv->a_type) { // test type of argument case A_LONG: myObj_ripple(x, argv->a_w.w_long); break; case A_FLOAT: myObj_ripple(x, argv->a_w.w_float); break; } } myObj_cf(x, x->cfreq); } else { object_free(x); x = NULL; } return x; }
bool flext_base::InitInlets() { bool ok = true; // incnt has number of inlets (any type) // insigs should be 0 FLEXT_ASSERT(!insigs && !inlets); // ---------------------------------- // create inlets // ---------------------------------- #if FLEXT_SYS == FLEXT_SYS_MAX // copy inlet descriptions indesc = new char *[incnt]; for(int i = 0; i < incnt; ++i) { xlet &x = inlist[i]; indesc[i] = x.desc; x.desc = NULL; } #endif #if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX inlets = incnt > 1?new px_object *[incnt-1]:NULL; #endif // type info is now in list array #if FLEXT_SYS == FLEXT_SYS_PD { int cnt = 0; if(incnt >= 1) { xlet &xi = inlist[0]; // points to first inlet if(xi.tp == xlet_sig) ++insigs; // else leftmost inlet is already there... ++cnt; #if PD_MINOR_VERSION >= 37 && defined(PD_DEVEL_VERSION) // set tooltip // this is on a per-class basis... we cannot really use it here // if(xi.desc && *xi.desc) class_settip(thisClass(),gensym(xi.desc)); #endif } for(int ix = 1; ix < incnt; ++ix,++cnt) { xlet &xi = inlist[ix]; // points to first inlet t_inlet *in = NULL; switch(xi.tp) { case xlet_float: case xlet_int: { if(ix > 9) { // proxy inlet needed (inlets[ix-1] = (px_object *)pd_new(px_class))->init(this,ix); // proxy for 2nd inlet messages in = inlet_new(&x_obj->obj,&inlets[ix-1]->obj.ob_pd, (t_symbol *)sym_float, (t_symbol *)sym_float); } else { inlets[ix-1] = NULL; static char sym[] = " ft ?"; sym[4] = '0'+ix; in = inlet_new(&x_obj->obj, &x_obj->obj.ob_pd, (t_symbol *)sym_float, gensym(sym)); } break; } case xlet_sym: (inlets[ix-1] = (px_object *)pd_new(px_class))->init(this,ix); // proxy for 2nd inlet messages in = inlet_new(&x_obj->obj,&inlets[ix-1]->obj.ob_pd, (t_symbol *)sym_symbol, (t_symbol *)sym_symbol); break; case xlet_list: (inlets[ix-1] = (px_object *)pd_new(px_class))->init(this,ix); // proxy for 2nd inlet messages in = inlet_new(&x_obj->obj,&inlets[ix-1]->obj.ob_pd, (t_symbol *)sym_list, (t_symbol *)sym_list); break; case xlet_any: (inlets[ix-1] = (px_object *)pd_new(px_class))->init(this,ix); // proxy for 2nd inlet messages in = inlet_new(&x_obj->obj,&inlets[ix-1]->obj.ob_pd, 0, 0); break; case xlet_sig: inlets[ix-1] = NULL; #ifdef FLEXT_COMPATIBLE if(inlist[ix-1].tp != xlet_sig) { post("%s: All signal inlets must be left-aligned in compatibility mode",thisName()); ok = false; } else #endif { // pd is not able to handle signals and messages into the same inlet... in = inlet_new(&x_obj->obj, &x_obj->obj.ob_pd, (t_symbol *)sym_signal, (t_symbol *)sym_signal); ++insigs; } break; default: inlets[ix-1] = NULL; error("%s: Wrong type for inlet #%i: %i",thisName(),ix,(int)inlist[ix].tp); ok = false; } #if PD_MINOR_VERSION >= 37 && defined(PD_DEVEL_VERSION) // set tooltip if(in && xi.desc && *xi.desc) inlet_settip(in,gensym(xi.desc)); #endif } incnt = cnt; } #elif FLEXT_SYS == FLEXT_SYS_MAX { int ix,cnt; // count leftmost signal inlets while(insigs < incnt && inlist[insigs].tp == xlet_sig) ++insigs; for(cnt = 0,ix = incnt-1; ix >= insigs; --ix,++cnt) { xlet &xi = inlist[ix]; if(!ix) { if(xi.tp != xlet_any) { error("%s: Leftmost inlet must be of type signal or anything",thisName()); ok = false; } } else { FLEXT_ASSERT(inlets); switch(xi.tp) { case xlet_sig: inlets[ix-1] = NULL; error("%s: All signal inlets must be left-aligned",thisName()); ok = false; break; case xlet_float: { if(ix < 10) { inlets[ix-1] = NULL; floatin(x_obj,ix); break; } else goto makeproxy; } case xlet_int: { if(ix < 10) { inlets[ix-1] = NULL; intin(x_obj,ix); break; } else goto makeproxy; } makeproxy: case xlet_any: // non-leftmost case xlet_sym: case xlet_list: inlets[ix-1] = (px_object *)proxy_new(x_obj,ix,&((flext_hdr *)x_obj)->curinlet); break; default: inlets[ix-1] = NULL; error("%s: Wrong type for inlet #%i: %i",thisName(),ix,(int)xi.tp); ok = false; } } } if(inlets) while(ix >= 0) inlets[ix--] = NULL; } #else #error #endif return ok; }