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); }
void *stats_new(t_symbol *s, long argc, t_atom *argv) { t_stats *x; x = (t_stats *)object_alloc(this_class); // create the new instance and return a pointer to it if (x) { long attrstart = attr_args_offset(argc, argv); // Create outlets object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL)); // dumpout x->outlet5 = floatout(x); // 5th outlet: standard deviation x->outlet4 = floatout(x); // 4th outlet: mean x->outlet3 = floatout(x); // 3rd outlet: maximum x->outlet2 = floatout(x); // 2nd outlet: minimum x->outlet = intout(x); // 1st outlet: counter // Setting max window size and actual window size x->maxWindowSize = 0; x->windowSize = 0; if (attrstart && argv) x->maxWindowSize = atom_getlong(argv); if ((attrstart==2) && argv) x->windowSize = atom_getlong(argv+1); if (x->maxWindowSize <= 0) x->maxWindowSize = 500; // changing to default value if (x->windowSize <= 0) x->windowSize = x->maxWindowSize; // changing to default value if (x->windowSize > x->maxWindowSize) x->windowSize = x->maxWindowSize; // making sure we do not read outside array // allocate memory for array x->values = (double *)sysmem_newptr(sizeof(double) * x->maxWindowSize); if (x->values == NULL) { error("j.stats: memory allocation error"); // whoops, out of memory... return 0; } x->attr_windowed = 1; // set default attr_args_process(x, argc, argv); // handle attribute args stats_clear(x); // initilaize instance return (x); // return the pointer to our new instantiation } else return 0; }
void *breakpoints_new(t_symbol *s, int argc, t_atom *argv) { t_binbuf* d = binbuf_via_atoms(argc,argv); t_breakpoints *x = (t_breakpoints *)eobj_new(breakpoints_class); if(x && d) { x->f_outline_mode = 0; long flags = 0 | EBOX_GROWINDI ; ebox_new((t_ebox *)x, flags); x->f_out_float = (t_outlet *)floatout(x); x->f_out_list = (t_outlet *)listout(x); x->f_out_function = (t_outlet *)listout(x); x->f_number_of_points = 0; x->f_point_hover = -1; x->f_point_selected = -1; x->f_output_inc = -1; x->f_output_nextprev = 0; x->f_point_last_created = -1; x->f_mouse.x = -666666; x->f_mouse.y = -666666; x->f_clock = clock_new(x, (t_method)breakpoints_inc); ebox_attrprocess_viabinbuf(x, d); breakpoints_init(x, d); ebox_ready((t_ebox *)x); } return (x); }
void* SssNew( long iNN, long iSeed) { tPink* me = NIL; tTaus88DataPtr myTausStuff = NIL; // Run through initialization parameters from right to left, handling defaults if (iSeed != 0) myTausStuff = Taus88New(iSeed); // Default NN value doesn't need massaging // Finished checking intialization parameters // Let Max allocate us, our inlets, and outlets. me = (tPink*) newobject(gObjectClass); intin(me, 1); // NN inlet floatout(me); // Access through me->coreObject.o_outlet // Set up object components me->tausData = myTausStuff; SssNN(me, iNN); me->counter = 0; // This will cause the dice array to be // initialized at the first bang. return me; }
void *number_tilde_new(t_symbol *s, int argc, t_atom *argv) { t_number_tilde *x = NULL; t_binbuf* d; long flags; if (!(d = binbuf_via_atoms(argc,argv))) return NULL; x = (t_number_tilde *)eobj_new(number_tilde_class); flags = 0 | EBOX_GROWINDI | EBOX_IGNORELOCKCLICK ; ebox_new((t_ebox *)x, flags); eobj_dspsetup((t_ebox *)x, 1, 1); x->f_peaks_outlet = floatout(x); x->f_peak_value = 0.; x->f_clock = clock_new(x,(t_method)number_tilde_tick); x->f_startclock = 0; ebox_attrprocess_viabinbuf(x, d); ebox_ready((t_ebox *)x); 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->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 *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); }
void *gain_new(t_symbol *s, int argc, t_atom *argv) { t_gain *x = NULL; t_binbuf* d; long flags; if (!(d = binbuf_via_atoms(argc,argv))) return NULL; x = (t_gain *)eobj_new(gain_class); flags = 0 | EBOX_GROWINDI ; ebox_new((t_ebox *)x, flags); eobj_dspsetup((t_ebox *)x, 1, 1); x->f_out = (t_outlet *)floatout(x); x->f_value = 0.; x->f_amp = 1.; x->f_amp_old = 1.; x->f_amp_step = 0.; x->f_counter = 0; x->f_sample_rate = sys_getsr(); ebox_attrprocess_viabinbuf(x, d); ebox_ready((t_ebox *)x); return (x); }
void *meter_new(t_symbol *s, int argc, t_atom *argv) { t_meter *x = NULL; t_binbuf* d; long flags; if (!(d = binbuf_via_atoms(argc,argv))) return NULL; x = (t_meter *)eobj_new(meter_class); flags = 0 | EBOX_GROWINDI | EBOX_IGNORELOCKCLICK ; ebox_new((t_ebox *)x, flags); eobj_dspsetup((t_ebox *)x, 1, 0); x->f_direction = 0; x->f_peaks_outlet = floatout(x); x->f_peak_value = -90.; x->f_clock = clock_new(x,(t_method)meter_tick); x->f_startclock = 0; x->f_over_led_preserved = 0; ebox_attrprocess_viabinbuf(x, d); ebox_ready((t_ebox *)x); return (x); }
void *sum_new(long n) { t_sum *x; x = (t_sum *)object_alloc(sum_class); if(x){ x->c_outlet = floatout(x); x->c_result = 0; } return x; }
void *cambio_new(void) { t_cambio *x; x = (t_cambio *)object_alloc(cambio_class); if (x==0) return 0; x->prev = -987654321.; // So first sample will always be a change dsp_setup((t_pxobject *)x,1); x->outlet = floatout(x); return x; }
void *plane_new(t_symbol *s, int argc, t_atom *argv) { t_plane *x = NULL; t_binbuf* d; long flags; if (!(d = binbuf_via_atoms(argc,argv))) return NULL; x = (t_plane *)eobj_new(plane_class); flags = 0 | EBOX_GROWLINK ; ebox_new((t_ebox *)x, flags); x->f_out_x = (t_outlet *)floatout(x); x->f_out_y = (t_outlet *)floatout(x); x->f_position.x = 0.; x->f_position.y = 0.; ebox_attrprocess_viabinbuf(x, d); ebox_ready((t_ebox *)x); return (x); }
void *mapparam_new(t_symbol *s, long argc, t_atom *argv) { t_mapparam *x = NULL; // object instantiation, OLD STYLE // if (x = (t_mapparam *)newobject(mapparam_class)) { // ; // } // object instantiation, NEW STYLE if (x = (t_mapparam *)object_alloc(mapparam_class)) { //floatin(x,1); x->outlet_1 = floatout((t_object *)x); /* object_post((t_object *)x, "value is %f", atom_getfloat(&x->val)); object_post((t_object *)x, "a new %s object was instantiated: 0x%X", s->s_name, x); object_post((t_object *)x, "it has %ld arguments - youhouuuuuu je suis nouveau", argc); */ x->scale_value = x->value = x->low = x->mode = x->sine = x->hot = 0; x->factor = x->high = 1; /* if((atom_gettype(argv)==A_FLOAT || atom_gettype(argv)==A_LONG) && atom_gettype(argv+1)!=A_FLOAT && atom_gettype(argv+1)!=A_LONG) { switch (atom_gettype(argv)) { case A_FLOAT: if(atom_getfloat(argv) < 0) x->factor = 0; else x->factor = atom_getfloat(argv); break; case A_LONG: if(atom_getlong(argv) < 0) x->factor = 0; else x->factor = (double)atom_getlong(argv); break; default: break; } } */ } return (x); }
void *logistic_new (Symbol *msg, short argc, Atom *argv) //input the args { logistic *x; int i; x=(logistic *)newobject(logistic_class); x->c_out=floatout(x); x->seed = 0.777f; x->seedinit = 0.777f; x->lambda = 3.9f; x->om = 0; logistic_set(x, msg, argc, argv); return(x); }
void *stein_new (Symbol *msg, short argc, Atom *argv) //input the args { stein *x; int i; x=(stein *)newobject(stein_class); x->c_out=floatout(x); x->seed = 0.777f; x->seedinit = 0.777f; x->lambda = 1.7f; x->om = 0; stein_set(x, msg, argc, argv); return(x); }
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); }
void *toggle_new(t_symbol *s, int argc, t_atom *argv) { t_toggle *x = NULL; t_binbuf* d; long flags; if (!(d = binbuf_via_atoms(argc,argv))) return NULL; x = (t_toggle *)eobj_new(toggle_class); flags = 0 | EBOX_GROWLINK ; ebox_new((t_ebox *)x, flags); x->f_active = 0; x->f_out = (t_outlet *)floatout(x); ebox_attrprocess_viabinbuf(x, d); ebox_ready((t_ebox *)x); return (x); }
void *incdec_new(t_symbol *s, int argc, t_atom *argv) { t_incdec *x = NULL; t_binbuf* d; long flags; if (!(d = binbuf_via_atoms(argc,argv))) return NULL; x = (t_incdec *)eobj_new(incdec_class); flags = 0 | EBOX_GROWINDI ; ebox_new((t_ebox *)x, flags); x->f_value = 0.; x->f_mouse_down = 0; x->f_out = (t_outlet *)floatout(x); ebox_attrprocess_viabinbuf(x, d); x->f_setted = 0; ebox_ready((t_ebox *)x); 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 *randomvals_new() { t_randomvals *x = (t_randomvals *)object_alloc(this_class); t_atom list_atoms[3]; #ifdef MSP_VERSION dsp_setup((t_pxobject *)x, 1); outlet_new((t_object *)x, "signal"); #else x->the_outlet = floatout(x); #endif rand_seed(&x->gen); atom_setfloat(list_atoms + 0, 0.5); atom_setfloat(list_atoms + 1, 1.); atom_setfloat(list_atoms + 2, 1.); randomvals_list(x, gensym("list"), 3, list_atoms); return (x); }
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; }
void *ringdiff_new(t_symbol *s, long argc, t_atom *argv) { t_ringdiff *x = NULL; long i; // object instantiation, NEW STYLE if (x = (t_ringdiff *)object_alloc(ringdiff_class)) { //object_post((t_object *)x, "a new %s object was instantiated: 0x%X", s->s_name, x); //object_post((t_object *)x, "it has %ld argu", argc); intin(x, 1);//inlet 1 //x->m_outlet2 = bangout((t_object *)x); x->m_outlet1 = floatout((t_object *)x); x->counter = 0; x->mod = 1; x->previousVal = 0.0; for (i = 0; i < argc; i++) { if ((argv + i)->a_type == A_LONG) { long tempArg = atom_getlong(argv+i); object_post((t_object *)x, "arg %ld: long (%ld)", i, tempArg); if(i==0 && tempArg > 0 && tempArg <= 1000){ post("initial buffer size set to %ld", tempArg); x->mod = atom_getlong(argv+i); } } else if ((argv + i)->a_type == A_FLOAT) { object_post((t_object *)x, "arg %ld: float (%f)", i, atom_getfloat(argv+i)); } else if ((argv + i)->a_type == A_SYM) { object_post((t_object *)x, "arg %ld: symbol (%s)", i, atom_getsym(argv+i)->s_name); } else { object_error((t_object *)x, "forbidden argument"); } } } return (x); }
void *loadmess_new(t_symbol *s, int argc, t_atom *argv) { int i; t_loadmess *x = NULL; t_binbuf* d; if (!(d = binbuf_via_atoms(argc,argv))) return NULL; x = (t_loadmess *)eobj_new(loadmess_class); x->l_loaded = 0; x->l_time = clock_getsystime(); x->l_argc = argc; x->l_argv = (t_atom *)calloc(x->l_argc, sizeof(t_atom)); for(i = 0; i < argc; i++) x->l_argv[i] = argv[i]; if(!x->l_argc) { x->l_out = (t_outlet *)bangout(x); } else if(x->l_argc == 1) { if(atom_gettype(argv) == A_FLOAT) x->l_out = (t_outlet *)floatout(x); else if (atom_gettype(argv) == A_SYMBOL) x->l_out = (t_outlet *)symbolout(x); } else { if(atom_gettype(argv) == A_FLOAT) x->l_out = (t_outlet *)listout(x); else if (atom_gettype(argv) == A_SYMBOL) x->l_out = (t_outlet *)anythingout(x); } return (x); }
void *bench_new(t_symbol *mode){ t_bench *x; x = (t_bench *)object_alloc(bench_class); if(!x){ return NULL; } if(!strcmp(mode->s_name, "in")){ x->out1 = listout((t_object *)x); x->out0 = outlet_new((t_object *)x, 0L); x->t_objmode = BENCH_IN; }else if(!strcmp(mode->s_name, "out")){ x->proxy[0] = proxy_new(x, 1, &x->inletNumber); x->out0 = floatout((t_object *)x); x->t_objmode = BENCH_OUT; }else { object_error((t_object *)x, "bench~: unrecognized argument %s", mode->s_name); return NULL; } 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; }
static void *rvbap_new(t_symbol *s, int ac, t_atom *av) /* create new instance of object... MUST send it an int even if you do nothing with this int!! */ { t_rvbap *x; #ifdef MAXMSP x = (t_rvbap *)newobject(rvbap_class); t_floatin(x,4); /* takes the distance */ intin(x,3); intin(x,2); /* create a second (int) inlet... remember right-to-left ordering in Max */ intin(x,1); /* create a second (int) inlet... remember right-to-left ordering in Max */ x->x_outlet4 = floatout(x); /* distance */ x->x_outlet3 = intout(x); x->x_outlet2 = intout(x); /* create an (int) outlet - rightmost outlet first... */ x->x_outlet1 = intout(x); /* create an (int) outlet */ x->x_outlet0 = listout(x); /* create a (list) outlet */ #endif #ifdef PD x = (t_rvbap *)pd_new(rvbap_class); floatinlet_new(&x->x_ob, &x->x_azi); floatinlet_new(&x->x_ob, &x->x_ele); floatinlet_new(&x->x_ob, &x->x_spread); floatinlet_new(&x->x_ob, &x->x_dist); x->x_outlet0 = outlet_new(&x->x_ob, gensym("list")); x->x_outlet1 = outlet_new(&x->x_ob, gensym("float")); x->x_outlet2 = outlet_new(&x->x_ob, gensym("float")); x->x_outlet3 = outlet_new(&x->x_ob, gensym("float")); x->x_outlet4 = outlet_new(&x->x_ob, gensym("float")); #endif x->x_azi = 0; x->x_ele = 0; x->x_dist = 1.0; x->x_spread_base[0] = 0.0; x->x_spread_base[1] = 1.0; x->x_spread_base[2] = 0.0; x->x_spread = 0; x->x_lsset_available =0; if (ac>0) { #ifdef MAXMSP if (av[0].a_type == A_LONG) x->x_azi = av[0].a_w.w_long; else #endif if (av[0].a_type == A_FLOAT) x->x_azi = av[0].a_w.w_float; } if (ac>1) { #ifdef MAXMSP if (av[1].a_type == A_LONG) x->x_ele = av[1].a_w.w_long; else #endif if (av[1].a_type == A_FLOAT) x->x_ele = av[1].a_w.w_float; } if (ac>2) { #ifdef MAXMSP if (av[2].a_type == A_LONG) x->x_dist = (float)av[2].a_w.w_long; else #endif if (av[2].a_type == A_FLOAT) x->x_dist = av[2].a_w.w_float; } return(x); /* return a reference to the object instance */ }
void *specFlatness_new(t_symbol *s, long argc, t_atom *argv) { t_specFlatness *x = (t_specFlatness *)object_alloc(specFlatness_class); int i, isPow2; double timef = 0.0; //s=s; if (x) { dsp_setup((t_pxobject *)x, 1); // MSP inlets: arg is # of inlets and is REQUIRED! // use 0 if you don't need inlets //outlet_new(x, "signal"); // signal outlet (note "signal" rather than NULL) //x->offset = 0.0; x->x_flatness = floatout(x); //x->x_flatness = outlet_new(&x->x_obj, &s_float); if(argc > 1) { x->window = atom_getfloat(argv); isPow2 = (int)x->window && !( ((int)x->window-1) & (int)x->window ); if(!isPow2) { error("requested window size is not a power of 2. default value of 1024 used instead"); x->window = 1024; }; } else if(argc > 0) { x->window = atom_getfloat(argv); isPow2 = (int)x->window && !( ((int)x->window-1) & (int)x->window ); if(!isPow2) { error("requested window size is not a power of 2. default value of 1024 used instead"); x->window = 1024; }; } else { x->window = 1024; }; x->sr = 44100.0; x->n = 64.0; x->overlap = 1; x->windowFunction = 4; // 4 is hann window x->powerSpectrum = 0; //x->lastDspTime = clock_getlogicaltime(); clock_getftime(&timef); x->lastDspTime = timef; x->signal_R = (t_sample *)t_getbytes_((x->window+x->n) * sizeof(t_sample)); x->nthRoots = (t_float *)t_getbytes((x->window*0.5+1)*sizeof(t_float)); for(i=0; i<(x->window+x->n); i++) x->signal_R[i] = 0.0; x->blackman = (t_float *)t_getbytes_(x->window*sizeof(t_float)); x->cosine = (t_float *)t_getbytes_(x->window*sizeof(t_float)); x->hamming = (t_float *)t_getbytes_(x->window*sizeof(t_float)); x->hann = (t_float *)t_getbytes_(x->window*sizeof(t_float)); // initialize signal windowing functions tIDLib_blackmanWindow(x->blackman, x->window); tIDLib_cosineWindow(x->cosine, x->window); tIDLib_hammingWindow(x->hamming, x->window); tIDLib_hannWindow(x->hann, x->window); post("specFlatness~: window size: %i", (int)x->window); } return (x); }
void *centroid_new(t_symbol *s, short argc, t_atom *argv) { t_int i; t_int vs = sys_getblksize(); t_centroid *x = (t_centroid *)newobject(centroid_class); t_float ms2samp; dsp_setup((t_pxobject *)x,2); x->c_clock = clock_new(x,(method)centroid_tick); x->c_outcent = floatout((t_centroid *)x); x->c_Fs = sys_getsr(); x->c_centroid = 0.0f; x->BufWritePos = 0; ms2samp = x->c_Fs * 0.001f; if (argv[0].a_type == A_LONG) x->BufSize = argv[0].a_w.w_long; // Samples else if (argv[0].a_type == A_FLOAT) x->BufSize = (int)(argv[0].a_w.w_float * ms2samp); // Time in ms else x->BufSize = DEFBUFSIZE; if (argv[1].a_type == A_LONG) x->c_overlap = argv[1].a_w.w_long; // Samples else if (argv[1].a_type == A_FLOAT) x->c_overlap = (int)(argv[1].a_w.w_float * ms2samp); // Time in ms else x->c_overlap = x->BufSize/2; if (argv[2].a_w.w_sym == ps_rectangular) x->c_window = Recta; else if (argv[2].a_w.w_sym == ps_hanning) x->c_window = Hann; else if (argv[2].a_w.w_sym == ps_hamming) x->c_window = Hamm; else if (argv[2].a_w.w_sym == ps_blackman) x->c_window = Black; else x->c_window = Black; x->FFTSize = x->BufSize; if (x->BufSize < vs) { x->FFTSize = vs; x->BufSize = vs; } else if ((x->BufSize > vs) && (x->BufSize < 128)) x->FFTSize = 128; else if ((x->BufSize > 128) && (x->BufSize < 256)) x->FFTSize = 256; else if ((x->BufSize > 256) && (x->BufSize < 512)) x->FFTSize = 512; else if ((x->BufSize > 512) && (x->BufSize < 1024)) x->FFTSize = 1024; else if ((x->BufSize > 1024) && (x->BufSize < 2048)) x->FFTSize = 2048; else if ((x->BufSize > 2048) && (x->BufSize < 4096)) x->FFTSize = 4096; else if ((x->BufSize > 8192) && (x->BufSize < 16384)) x->FFTSize = 16384; else if ((x->BufSize > 16384) && (x->BufSize < 32768)) x->FFTSize = 32768; else if (x->BufSize > 32768) { post(" Maximum FFT Size is 65536",0); x->FFTSize = 65536; x->BufSize = 65536; } // Overlap case if (x->c_overlap > x->BufSize-vs) { post(" You can't overlap so much...",0); x->c_overlap = x->BufSize-vs; } else if (x->c_overlap < 1) x->c_overlap = 0; // Allocate memory x->Buf1 = t_getbytes(x->BufSize * sizeof(float)); x->Buf2 = t_getbytes(x->BufSize * sizeof(float)); x->BufFFT = t_getbytes(x->FFTSize * sizeof(float)); x->WindFFT = t_getbytes(x->FFTSize * sizeof(float)); x->memFFT = t_getbytes(CMAX * x->FFTSize * sizeof(float)); // memory allocated for fft twiddle // Compute and store Windows if ((x->c_window > Recta) && (x->c_window <= Black)) { switch (x->c_window) { case Hann: for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = HANNING_W(i, x->FFTSize); break; case Hamm: for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = HAMMING_W(i, x->FFTSize); break; case Black: for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = BLACKMAN_W(i, x->FFTSize); break; } } return (x); }
void *getonset_new(t_symbol *s, short argc, t_atom *argv) { t_getonset *x = (t_getonset *)newobject(getonset_class); t_float ms2samp; dsp_setup((t_pxobject *)x,10); x->g_clock = clock_new(x,(method)getonset_tick); x->g_outcent = floatout((t_getonset *)x); x->g_outener = floatout((t_getonset *)x); x->g_outoffset = bangout((t_getonset *)x); x->g_outonset = bangout((t_getonset *)x); x->g_Fs = sys_getsr(); x->g_energy = 0.0f; x->g_lastEner = 0.0f; x->g_centroid = 0.0f; x->g_onset = 0; x->g_offset = 0; x->g_noteOn = 0; x->g_attackReady = 0; x->g_timer = 0; x->BufWritePos = 0; x->BufReadPos = vs; ms2samp = x->g_Fs * 0.001f; // Look at first argument if (argv[0].a_type == A_LONG) x->BufSize = argv[0].a_w.w_long; // Samples else if (argv[0].a_type == A_FLOAT) x->BufSize = (int)(argv[0].a_w.w_float * ms2samp); // Time in ms else x->BufSize = DEFBUFSIZE; x->FFTSize = x->BufSize; // Take a convenient FFT Size if (x->BufSize < vs) { post(" Minimum FFT Size is %i",vs); x->FFTSize = vs; x->BufSize = vs; } else if ((x->BufSize > vs) && (x->BufSize < 128)) x->FFTSize = 128; else if ((x->BufSize > 128) && (x->BufSize < 256)) x->FFTSize = 256; else if ((x->BufSize > 256) && (x->BufSize < 512)) x->FFTSize = 512; else if ((x->BufSize > 512) && (x->BufSize < 1024)) x->FFTSize = 1024; else if ((x->BufSize > 1024) && (x->BufSize < 2048)) x->FFTSize = 2048; else if ((x->BufSize > 2048) && (x->BufSize < 4096)) x->FFTSize = 4096; else if ((x->BufSize > 4096) && (x->BufSize < 8192)) x->FFTSize = 8192; else if ((x->BufSize > 8192) && (x->BufSize < 16384)) x->FFTSize = 16384; else if ((x->BufSize > 16384) && (x->BufSize < 32768)) x->FFTSize = 32768; else if (x->BufSize > 32768) { post(" Maximum FFT Size is 65536",0); x->FFTSize = 65536; x->BufSize = 65536; } // Look at second argument if (argv[1].a_type == A_LONG) x->g_overlap = argv[1].a_w.w_long; // Samples else if (argv[1].a_type == A_FLOAT) x->g_overlap = (int)(argv[0].a_w.w_float * ms2samp); // Time in ms else x->g_overlap = DEFBUFSIZE/2; // Look at third argument if (argv[2].a_w.w_sym == ps_rectangular) x->c_window = Recta; else if (argv[2].a_w.w_sym == ps_hanning) x->c_window = Hann; else if (argv[2].a_w.w_sym == ps_hamming) x->c_window = Hamm; else if (argv[2].a_w.w_sym == ps_blackman) x->c_window = Black; else x->g_window = Hann; if (argv[3].a_type == A_LONG) x->g_deltattack = 44 * argv[3].a_w.w_long; else if (argv[3].a_type == A_FLOAT) x->g_deltattack = 44 * (long)argv[3].a_w.w_float; else x->g_deltattack = DEFATTACKTIME; if (argv[4].a_type == A_FLOAT) x->g_attackthres = argv[4].a_w.w_float; else if (argv[4].a_type == A_LONG) x->g_attackthres = (float)argv[4].a_w.w_long; else x->g_attackthres = DEFATTACKTHRESH; if (argv[5].a_type == A_FLOAT) x->g_decaythres = argv[5].a_w.w_float; else if (argv[5].a_type == A_LONG) x->g_decaythres = (float)argv[5].a_w.w_long; else x->g_decaythres = DEFDECAYTHRESH; if (argv[6].a_type == A_FLOAT) x->g_highthres = argv[6].a_w.w_float; else if (argv[6].a_type == A_LONG) x->g_highthres = (float)argv[6].a_w.w_long; else x->g_highthres = DEFHIGHTHRESH; if (argv[7].a_type == A_FLOAT) x->g_enerthres = argv[7].a_w.w_float; else if (argv[7].a_type == A_LONG) x->g_enerthres = (float)argv[7].a_w.w_long; else x->g_enerthres = DEFENERGYTHRESH; if (argv[8].a_type == A_FLOAT) x->g_lowthres = argv[8].a_w.w_float; else if (argv[8].a_type == A_LONG) x->g_lowthres = (float)argv[8].a_w.w_long; else x->g_lowthres = DEFLOWTHRESH; if (argv[9].a_type == A_FLOAT) x->g_centhres = argv[9].a_w.w_float; else if (argv[9].a_type == A_LONG) x->g_centhres = (float)argv[9].a_w.w_long; else x->g_centhres = DEFCENTHRESH; // Allocate memory x->Buf1 = t_getbytes(x->BufSize * sizeof(float)); x->Buf2 = t_getbytes(x->BufSize * sizeof(float)); x->memFFT = t_getbytes(CMAX * x->FFTSize * sizeof(float)); // memory allocated for fft twiddle x->Window = t_getbytes(x->BufSize * sizeof(float)); if (x->FFTSize != x->BufSize) x->WindFFT = t_getbytes(x->FFTSize * sizeof(float)); else x->WindFFT = x->Window; // Compute and store Windows if ((x->g_window > Recta) && (x->g_window <= Black)) { switch (x->c_window) { case Hann: for (i=0; i<x->BufSize; ++i) x->Window[i] = HANNING_W(i, x->BufSize); if (x->FFTSize != x->BufSize) for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = HANNING_W(i, x->FFTSize); break; case Hamm: for (i=0; i<x->BufSize; ++i) x->Window[i] = HAMMING_W(i, x->BufSize); if (x->FFTSize != x->BufSize) for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = HAMMING_W(i, x->FFTSize); break; case Black: for (i=0; i<x->BufSize; ++i) x->Window[i] = BLACKMAN_W(i, x->BufSize); if (x->FFTSize != x->BufSize) for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = BLACKMAN_W(i, x->FFTSize); break; } } return (x); }
void *noisiness_new(t_symbol *s, short argc, t_atom *argv) { t_int i, j=1, band=0, oldband=0, sizeband=0; t_int vs = sys_getblksize(); // get vector size double freq=0.0f, oldfreq=0.0f; t_noisiness *x = (t_noisiness *)newobject(noisiness_class); dsp_setup((t_pxobject *)x,1); // one inlet x->x_outnois = floatout((t_noisiness *)x); // one outlet x->x_Fs = sys_getsr(); x->BufWritePos = 0; x->x_noisiness = 0.0f; switch (argc) { // Read arguments case 0: x->BufSize = DEFBUFSIZE; x->x_overlap = x->BufSize/2; x->x_hop = x->BufSize/2; x->FFTSize = DEFBUFSIZE; x->x_window = DEFWIN; x->x_delay = 0; break; case 1: readBufSize(x,argv); x->x_overlap = x->BufSize/2; x->x_hop = x->BufSize/2; x->FFTSize = x->BufSize; x->x_window = DEFWIN; x->x_delay = 0; break; case 2: readBufSize(x,argv); readx_overlap(x,argv); x->FFTSize = x->BufSize; x->x_window = DEFWIN; x->x_delay = 0; break; case 3: readBufSize(x,argv); readx_overlap(x,argv); readFFTSize(x,argv); x->x_window = DEFWIN; x->x_delay = 0; break; case 4: readBufSize(x,argv); readx_overlap(x,argv); readFFTSize(x,argv); readx_window(x,argv); x->x_delay = 0; break; default: readBufSize(x,argv); readx_overlap(x,argv); readFFTSize(x,argv); readx_window(x,argv); readx_delay(x,argv); } // Just storing the name of the window switch(x->x_window) { case 0: strcpy(x->x_winName,"rectangular"); break; case 1: strcpy(x->x_winName,"hanning"); break; case 2: strcpy(x->x_winName,"hamming"); break; case 3: strcpy(x->x_winName,"blackman62"); break; case 4: strcpy(x->x_winName,"blackman70"); break; case 5: strcpy(x->x_winName,"blackman74"); break; case 6: strcpy(x->x_winName,"blackman92"); break; default: strcpy(x->x_winName,"blackman70"); } if (x->BufSize < vs) { post("Noisiness~: Buffer size is smaller than the vector size, %d",vs); x->BufSize = vs; } else if (x->BufSize > 65536) { post("Noisiness~: Maximum FFT size is 65536 samples"); x->BufSize = 65536; } if (x->FFTSize < x->BufSize) { post("Noisiness~: FFT size is at least the buffer size, %d",x->BufSize); x->FFTSize = x->BufSize; } if ((x->FFTSize > vs) && (x->FFTSize < 128)) x->FFTSize = 128; else if ((x->FFTSize > 128) && (x->FFTSize < 256)) x->FFTSize = 256; else if ((x->FFTSize > 256) && (x->FFTSize < 512)) x->FFTSize = 512; else if ((x->FFTSize > 512) && (x->FFTSize < 1024)) x->FFTSize = 1024; else if ((x->FFTSize > 1024) && (x->FFTSize < 2048)) x->FFTSize = 2048; else if ((x->FFTSize > 2048) && (x->FFTSize < 4096)) x->FFTSize = 4096; else if ((x->FFTSize > 8192) && (x->FFTSize < 16384)) x->FFTSize = 16384; else if ((x->FFTSize > 16384) && (x->FFTSize < 32768)) x->FFTSize = 32768; else if ((x->FFTSize > 32768) && (x->FFTSize < 65536)) x->FFTSize = 65536; else if (x->FFTSize > 65536) { post("Noisiness~: Maximum FFT size is 65536 samples"); x->FFTSize = 65536; } // Overlap case if (x->x_overlap > x->BufSize-vs) { post("Noisiness~: You can't overlap so much..."); x->x_overlap = x->BufSize-vs; } else if (x->x_overlap < 1) x->x_overlap = 0; x->x_hop = x->BufSize - x->x_overlap; post("--- Noisiness~ ---"); post(" Buffer size = %d",x->BufSize); post(" Hop size = %d",x->x_hop); post(" FFT size = %d",x->FFTSize); post(" Window type = %s",x->x_winName); post(" Initial delay = %d",x->x_delay); // Here comes the choice for altivec optimization or not... if (sys_optimize()) { // note that we DON'T divide the vector size by four here #ifdef __ALTIVEC__ // More code and a new ptr so that x->BufFFT is vector aligned. #pragma altivec_model on x->x_clock = clock_new(x,(method)noisiness_tick_G4); // Call altivec-optimized tick function post(" Using G4-optimized FFT"); // Allocate some memory for the altivec FFT x->x_FFTSizeOver2 = x->FFTSize/2; x->x_A.realp = t_getbytes(x->x_FFTSizeOver2 * sizeof(t_float)); x->x_A.imagp = t_getbytes(x->x_FFTSizeOver2 * sizeof(t_float)); x->x_log2n = log2max(x->FFTSize); x->x_setup = create_fftsetup (x->x_log2n, 0); #pragma altivec_model off #else error(" No G4 optimization available"); #endif } else { // Normal tick function x->x_clock = clock_new(x,(method)noisiness_tick); x->memFFT = (t_float*) NewPtr(CMAX * x->FFTSize * sizeof(t_float)); // memory allocated for normal fft twiddle } post(""); // Allocate memory x->Buf1 = (t_int*) NewPtr(x->BufSize * sizeof(t_float)); // Careful these are pointers to integers but the content is floats x->Buf2 = (t_int*) NewPtr(x->BufSize * sizeof(t_float)); x->BufFFT = (t_float*) NewPtr(x->FFTSize * sizeof(t_float)); x->WindFFT = (t_float*) NewPtr(x->BufSize * sizeof(t_float)); if (x->x_Fs != DEFAULT_FS) { error("Noisiness~: WARNING !!! object set for 44.1 KHz only"); return; } else { x->BufBark = (t_float*) NewPtr(2*NUMBAND * sizeof(t_float)); x->BufSizeBark = (t_int*) NewPtr(NUMBAND * sizeof(t_int)); } // Compute and store Windows if (x->x_window != Recta) { switch (x->x_window) { case Hann: for (i=0; i<x->BufSize; ++i) x->WindFFT[i] = HANNING_W(i,x->BufSize); break; case Hamm: for (i=0; i<x->BufSize; ++i) x->WindFFT[i] = HAMMING_W(i,x->BufSize); break; case Blackman62: for (i=0; i<x->BufSize; ++i) x->WindFFT[i] = BLACKMAN62_W(i,x->BufSize); break; case Blackman70: for (i=0; i<x->BufSize; ++i) x->WindFFT[i] = BLACKMAN70_W(i,x->BufSize); break; case Blackman74: for (i=0; i<x->BufSize; ++i) x->WindFFT[i] = BLACKMAN74_W(i,x->BufSize); break; case Blackman92: for (i=0; i<x->BufSize; ++i) x->WindFFT[i] = BLACKMAN92_W(i,x->BufSize); break; } } else { for (i=0; i<x->BufSize; ++i) { // Just in case x->WindFFT[i] = 1.0f; } } x->BufBark[0] = 0.0f; // Compute and store Bark scale for (i=0; i<x->FFTSize/2; i++) { freq = (i*x->x_Fs)/x->FFTSize; band = floor(13*atan(0.76*freq/1000) + 3.5*atan((freq/7500)*(freq/7500))); if (oldband != band) { x->BufBark[j] = oldfreq; x->BufBark[j+1] = freq; x->BufSizeBark[j/2] = sizeband; j+=2; sizeband = 0; } oldband = band; oldfreq = freq; sizeband++; } x->BufBark[2*NUMBAND-1] = freq; x->BufSizeBark[NUMBAND-1] = sizeband; return (x); }