Exemple #1
0
// Create
void *init_new(t_symbol *s, long argc, t_atom *argv)
{
	long 		attrstart = attr_args_offset(argc, argv);						// support normal arguments
	t_init 		*x = (t_init *)object_alloc(g_init_class);
	t_symbol	*relativeAddress = _sym_nothing;											// could be used to binds on a sub level j.hub

	if (attrstart && argv)
		atom_arg_getsym(&relativeAddress, 0, attrstart, argv);
	
	if (x) {
		
        x->outlets = (TTHandle)sysmem_newptr(sizeof(TTPtr) * 2);
        x->outlets[end_out] = bangout(x);
		x->outlets[start_out] = bangout(x);

		x->patcherNode = NULL;
		x->address = TTAddress(jamoma_parse_dieze((t_object*)x, relativeAddress)->s_name);
		
		attr_args_process(x, argc, argv);										// handle attribute args				

		// The following must be deferred because we have to interrogate our box,
		// and our box is not yet valid until we have finished instantiating the object.
		// Trying to use a loadbang method instead is also not fully successful (as of Max 5.0.6)
		defer_low((t_object*)x, (method)init_subscribe, NULL, 0, 0);
	}
	
	return (x);																	// Return the pointer
}
Exemple #2
0
/*------------------------------------ spaceballCreate ---*/
static void *
spaceballCreate(t_symbol * addOrDelta,
                const long pollRate)
{
    SpaceballData * xx = static_cast<SpaceballData *>(object_alloc(gClass));
    
    if (xx)
    {
        xx->fPollClock = NULL;
        xx->fPollQueue = NULL;
        xx->fBufferPos = xx->fDelayCounter = 0;
        xx->fButtons = 0;
        xx->fChunkPulseSent = xx->fInited = xx->fNextCharEscaped = xx->fOutputBlocked = false;
        xx->fReset = xx->fSkipping = xx->fModeDelta = xx->fStopping = false;
        if ((0 > pollRate) || (MAX_POLL_RATE < pollRate))
        {
            LOG_ERROR_2(xx, OUTPUT_PREFIX "invalid polling rate (%ld) for device", pollRate)
            xx->fPollRate = SER_SAMPLE_RATE;
        }
        else
        {
            xx->fPollRate = (pollRate ? pollRate : SER_SAMPLE_RATE);
        }
        /* Set up our connections and private data */
        xx->fProxy = proxy_new(xx, 1L, &xx->fInletNumber);
        xx->fErrorBangOut = static_cast<t_outlet *>(bangout(xx));
        xx->fChunkSendOut = static_cast<t_outlet *>(bangout(xx));
        xx->fDataSendOut = static_cast<t_outlet *>(outlet_new(xx, 0L));  /* list, int */
        xx->fSampleBangOut = static_cast<t_outlet *>(bangout(xx));
        xx->fDataOut = static_cast<t_outlet *>(outlet_new(xx, 0L));   /* normally just a list */
        xx->fPollClock = MAKE_CLOCK(xx, spaceballProcessClock);
        xx->fPollQueue = MAKE_QELEM(xx, spaceballProcessQueue);
        if (! (xx->fProxy && xx->fErrorBangOut && xx->fDataSendOut && xx->fChunkSendOut &&
               xx->fSampleBangOut && xx->fDataOut && xx->fPollClock && xx->fPollQueue))
        {
            LOG_ERROR_1(xx, OUTPUT_PREFIX "unable to create port or clock for device")
            freeobject(reinterpret_cast<t_object *>(xx));
            xx = NULL;
        }
        else
        {
            xx->fResetDuration = ((2000 + xx->fPollRate - 1) / xx->fPollRate);
            xx->fInitDuration = ((1000 + xx->fPollRate - 1) / xx->fPollRate);
            if (addOrDelta != gEmptySymbol)
            {
                spaceballSetMode(xx, addOrDelta);
            }
            clock_delay(xx->fPollClock, xx->fPollRate);
        }
    }
    return xx;
} // spaceballCreate
Exemple #3
0
void *bezier_new(t_symbol *s, short ac, t_atom *av)
{
//	t_bezier *x;
//	x = (t_bezier *)newobject(bezier_class);
	
	t_bezier *x;
	x = (t_bezier *)object_alloc(bezier_class);
	
	if(x){
		x->b_outletRight = bangout(x);
		x->b_outlet = outlet_new(x, 0); 		
		x->b_mode = 0;
		x->b_last = 1;
		x->b_steps = 32;
		
		attr_args_process(x, ac, av); // process attributes
		
//		if ((arg1)&&(arg1 <= 2)){
//			x->b_steps = 2;
//		}
//		else if(arg1){
//			x->b_steps = arg1;
//		}
//		if ((arg2)&&(arg2 == 0)){
//			x->b_last = 0;
//		}
//		else if((arg2)&&(arg2 != 0)){
//			x->b_last = 1;
//		}
	}
	return x;
}
void *irextract_new (t_symbol *s, short argc, t_atom *argv)
{
    t_irextract *x = (t_irextract *)object_alloc (this_class);

	x->process_done = bangout(x);
	
	init_HIRT_common_attributes(x);
	
	x->bandlimit = 1;
	x->amp = -1;
	x->inv_amp = 0;
	
	x->fft_size = 0;
	x->sample_rate = 0;
	x->out_length_samps = 0;
	x->out_length = 0;
	x->gen_length = 0;
	
	alloc_mem_swap(&x->out_mem, 0, 0);
	
	x->measure_mode = SWEEP;

	attr_args_process(x, argc, argv);

	return(x);
}
Exemple #5
0
void *dict_recurse_new(t_symbol *sym, long argc, t_atom *argv)
{
  t_dict_recurse *x = NULL;

  x = (t_dict_recurse *)object_alloc(dict_recurse_class);

  if (x == NULL) {
    MY_ERR("Object allocation failed.");
    return NULL; }

  x->outl_bang = bangout(x);                      // Outler 1: Bang on completion
  x->outl_mess = outlet_new((t_object*)x, NULL);  // Outlet 0: General messages

  x->path_len_max = MAX_LEN_PATH;
  
  x->path = NULL;
  x->path = (char *)sysmem_newptr(sizeof(char) * x->path_len_max);
  if (!x->path) { MY_ERR("new:  Allocation error for \"path\"."); }

  x->search_key_expr = regexpr_new();
  x->search_val_expr = regexpr_new();
  if (!x->search_key_expr || !x->search_val_expr) {
    MY_ERR("new:  Allocation error for the search expressions."); }

  _dict_recurse_reset(x);

  re_set_object(x);
  
  x->re2 = re_new(254);
  if (!x->re2) { return NULL; }

  return(x);
}
Exemple #6
0
void *myobject_new(long n)

{

	MyObject *x;

	

	EnterCallback();

	x = newobject(myobject_class);		// get memory for a new object & initialize

	x->m_value = n;						// store value (default is 0)

	x->m_out = intout(x);				// create an int outlet

	x->m_out_b = bangout(x);

	x->m_out_s = outlet_new(x,0L)

	ExitCallback();

	return (x);							// return newly created object to caller

}
Exemple #7
0
void *past_new(t_symbol *s, short ac, t_atom *av)
{
	t_past *x;
	
	x = object_alloc(past_class);
	x->p_out = bangout((t_object *)x);
	past_assign(x,ac,av);
	x->p_set = 0;
	return x;
}			
void *bufreverse_new()
{
    t_bufreverse *x = (t_bufreverse *)object_alloc (this_class);

    x->process_done = bangout(x);

    init_HIRT_common_attributes(x);

    return(x);
}
void *simpleNeuron_new(t_symbol *s, long argc, t_atom *argv)
{
	t_simpleNeuron *x = NULL;
    long i;

	// object instantiation
	if (x = (t_simpleNeuron *)object_alloc(simpleNeuron_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 arguments", argc);
		x = (t_simpleNeuron *)object_alloc(simpleNeuron_class);
		x->m_outlet1 = bangout((t_simpleNeuron *)x);
		x->m_clock1 = clock_new((t_simpleNeuron *)x, (method)delayedReset);
		x->m_clock2 = clock_new((t_simpleNeuron *)x, (method)leak);
		x->m_clock3 = clock_new((t_simpleNeuron *)x, (method)delayedBang);
        
        for (i = 0; i < argc; i++) {
            if ((argv + i)->a_type == A_LONG) {
                object_post((t_object *)x, "arg %ld: long (%ld)", i, 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");
            }
        }
	}
	
	// default settings
	
	x->d_V = 0;
	x->d_Vth = 5;
	x->d_C = 1;
	x->d_R = 100;
	
	// Fitzhugh
	x->d_W = 0;
	x->d_Wth = 1.5;
	x->d_Wr  = 1.3;
	x->d_a = -0.7;  // http://www.scholarpedia.org/article/FitzHugh-Nagumo_model
	x->d_b = 0.8;
	x->d_tao = 12.5;
	x->d_stepSize = 0.3; // this needs to be
	x->l_bangFlag = 0;
	
	x->l_mode = 0;
	x->l_ref = 0;
	
	x->d_absRef = 100;
	x->d_leakPer = 100;
	x->d_bangD = 10;
	
	return (x);
}
void *ircropfade_new()
{
    t_ircropfade *x = (t_ircropfade *)object_alloc (this_class);

    x->process_done = bangout(x);

    x->read_chan = 1;
    x->write_chan = 1;
    x->resize = 1;

    return(x);
}
void *bufconvolve_new  (t_symbol *s, short argc, t_atom *argv)

{
    t_bufconvolve *x = (t_bufconvolve *)object_alloc (this_class);
	
	x->process_done = bangout(x);
	
	init_HIRT_common_attributes(x);
	attr_args_process(x, argc, argv);
	
	return(x);
}
Exemple #12
0
void *posit_new(t_symbol *s, long argc, t_atom *argv)
{
	t_posit *x = NULL;
    
	if ((x = (t_posit *)object_alloc(posit_class))) {
	
        x->p_outlet3 = intout(x);
        x->p_outlet2 = bangout(x);
        x->p_outlet = listout(x);
	}
	return (x);
}
void *irreference_new (t_symbol *s, short argc, t_atom *argv)
{
    t_irreference *x = (t_irreference *)object_alloc (this_class);
    t_atom_long num_in_chans = 1;

    if (argc && atom_gettype(argv) == A_LONG)
    {
        num_in_chans = atom_getlong(argv++);
        num_in_chans = num_in_chans < 1 ? 1 : num_in_chans;
        num_in_chans = num_in_chans > HIRT_MAX_MEASURE_CHANS ? HIRT_MAX_MEASURE_CHANS : num_in_chans;
        argc--;
    }

    dsp_setup((t_pxobject *)x, (long) (num_in_chans + 1));

    x->process_done = bangout(x);
    outlet_new(x, "signal");

    init_HIRT_common_attributes(x);

    x->abs_progress = 0;

    x->T = 0;
    x->current_t = 0;
    x->fft_size = 0;
    x->start_rec = 0;
    x->stop_rec = 0;
    x->sample_rate = sys_getsr();

    if (!x->sample_rate)
        x->sample_rate = 44100;

    alloc_mem_swap(&x->rec_mem, 0, 0);
    alloc_mem_swap(&x->out_mem, 0, 0);

    x->current_length = 0;
    x->current_out_length = 0;
    x->out_length = 0;
    x->num_in_chans = (long) num_in_chans;
    x->num_active_ins = (long) num_in_chans;
    x->current_num_active_ins = (long) num_in_chans;

    x->smooth_mode = 1;

    atom_setlong(&x->deconvolve_delay, 10);

    attr_args_process(x, argc, argv);

    return(x);
}
Exemple #14
0
void *filein_new(t_symbol *fn, t_symbol *spoolFlag)
{
	t_filein *x;
	
	x = object_alloc(filein_class);
	x->f_readdone = bangout(x);
	x->f_eof = bangout(x);
	x->f_out = intout(x);
	intin(x,2);
	intin(x,1);
	x->f_open = FALSE;
	x->f_fh = 0;
	x->f_spool = 0;
	x->f_data = 0;
	if (fn != ps_nothing) {
		if (spoolFlag==ps_spool)
			x->f_spool = TRUE;
		else
			x->f_spool = FALSE;
		filein_doread(x,fn);
	}
	return (x);
}			
Exemple #15
0
void *filesys_new(t_symbol *sym, long argc, t_atom *argv)
{
  t_filesys *x = NULL;

  x = (t_filesys *)object_alloc(filesys_class);

  MY_ASSERT(!x, NULL, "Object allocation failed.");

  x->outl_return = bangout((t_object*)x);         // Outlet 1: 0 or 1 for failure or success (int)
  x->outl_mess = outlet_new((t_object*)x, NULL);  // Outlet 0: General messages

  _filesys_cd_patcher(x);

  POST("New object created:  directory:  %s", x->dir_s);

  return(x);
}
Exemple #16
0
void *carray_new(t_symbol *s, int argc, t_atom *argv)
{
	t_carray *x =  NULL;
	t_binbuf* d;
    long flags;
	if (!(d = binbuf_via_atoms(argc,argv)))
		return NULL;
    
	x = (t_carray *)eobj_new(carray_class);
    flags = 0
    | EBOX_GROWINDI
    ;
	ebox_new((t_ebox *)x, flags);
    x->f_out = (t_outlet *)bangout((t_object *)x);
	ebox_attrprocess_viabinbuf(x, d);
	ebox_ready((t_ebox *)x);
	return (x);
}
void *irphase_new (t_symbol *s, short argc, t_atom *argv)
{
    t_irphase *x = (t_irphase *)object_alloc (this_class);
	
	x->process_done = bangout(x);
	
	init_HIRT_common_attributes(x);
	
	// Change filter specifier to more appropriate default
	
	atom_setlong(x->deconvolve_filter_specifier + 0, -1000);
	atom_setlong(&x->deconvolve_delay, 0);
	x->deconvolve_num_filter_specifiers = 1;
	
	attr_args_process(x, argc, argv);

	return(x);
}
Exemple #18
0
void *bang_new(t_symbol *s, int argc, t_atom *argv)
{
	t_bang *x =  NULL;
	t_binbuf* d;
    long flags;
	if (!(d = binbuf_via_atoms(argc,argv)))
		return NULL;
    
	x = (t_bang *)eobj_new(bang_class);
    flags = 0
    | EBOX_GROWLINK
    ;
	ebox_new((t_ebox *)x, flags);
    x->f_out = (t_outlet *)bangout((t_object *)x);
    x->f_active = 0;
    x->f_clock          = clock_new(x,(t_method)bang_mouseup);
	ebox_attrprocess_viabinbuf(x, d);
	ebox_ready((t_ebox *)x);
	return (x);
}
Exemple #19
0
void *change_new(void)
{
	short i;
	t_change *x;									// Declare an object (based on our struct)
	x = (t_change *)object_alloc(change_class);		// Create object, store pointer to it (get 1 inlet free)
	if(x){
		object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL));	// dumpout	
		x->change_Out[1] = bangout(x);				// Create Outlets (right to left order)
	    x->change_Out[0] = outlet_new(x, 0);		//	...

	// Create Right Inlet (inletnum is 1)
		x->inlet_right = proxy_new(x, 1, 0L);

	// Init the temp storage
	for(i=0; i<MAX_LIST_SIZE; i++)
		atom_setsym(&(x->last_input_list[i]), _sym_nothing);			
	}
	x->last_input_type = msg_new;					// Makes sure that first message receive goes to left outlet
	return (x);										// Return pointer to our instance
}
Exemple #20
0
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 *irmeasure_new(t_symbol *s, short argc, t_atom *argv)
{
    t_irmeasure *x = (t_irmeasure *)object_alloc(this_class);
    t_atom_long num_out_chans = 1;
    t_atom_long num_in_chans = 1;
    long i;

    if (argc && atom_gettype(argv) == A_LONG)
    {
        num_in_chans = atom_getlong(argv++);
        num_in_chans = num_in_chans < 1 ? 1 : num_in_chans;
        num_in_chans = num_in_chans > HIRT_MAX_MEASURE_CHANS ? HIRT_MAX_MEASURE_CHANS : num_in_chans;
        argc--;
    }

    if (argc && atom_gettype(argv) == A_LONG)
    {
        num_out_chans = atom_getlong(argv++);
        num_out_chans = num_out_chans < 1 ? 1 : num_out_chans;
        num_out_chans = num_out_chans > HIRT_MAX_MEASURE_CHANS ? HIRT_MAX_MEASURE_CHANS : num_out_chans;
        argc--;
    }

    x->process_done = bangout(x);

    for (i = 0; i < num_out_chans + 1; i++)
        outlet_new(x, "signal");
    dsp_setup((t_pxobject *)x, (long) num_in_chans);

    init_HIRT_common_attributes(x);

    x->bandlimit = 1;
    x->abs_progress = 0;
    x->amp = -1.0;
    x->inv_amp = 0;

    x->T2 = 0;
    x->current_t = 0;
    x->fft_size = 0;
    x->start_measurement = 0;
    x->stop_measurement = 0;
    x->test_tone = 0;
    x->no_dsp = 1;
    x->sample_rate = sys_getsr();

    if (!x->sample_rate)
        x->sample_rate = 44100.0;


    alloc_mem_swap(&x->rec_mem, 0, 0);
    alloc_mem_swap(&x->out_mem, 0, 0);

    x->num_in_chans = (long) num_in_chans;
    x->num_out_chans = (long) num_out_chans;
    x->num_active_ins = (long) num_in_chans;
    x->num_active_outs = (long) num_out_chans;
    x->current_num_active_ins = (long) num_in_chans;
    x->current_num_active_outs = (long) num_out_chans;

    x->measure_mode = SWEEP;
    x->phase = 0.0;

    attr_args_process(x, argc, argv);

    return(x);
}
void *aubioOnset_new(t_symbol *s, long argc, t_atom *argv)
{
    t_aubioOnset *x = (t_aubioOnset *)object_alloc(aubioOnset_class);
    t_atom *ap;
    int i, isPow2, argcount=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->onsetbang = bangout(x);

        x->sr = 44100.0;
        x->n = 64.0;

        x->threshold = 0.3;
        x->silence = -70;
        x->minioi = 4;
        x->bufsize = 1024;
        x->hopsize = 512;
        x->detectionFunction = "complex";

        // increment ap each time to get to the next atom
        for (i = 0, ap = argv; i < argc; i++, ap++)
        {
            switch (atom_gettype(ap)) {
            case A_LONG:
                if (atom_getlong(ap)<0)
                {
                    post("%ld: silence threshold %ld",i+1,atom_getlong(ap));
                    x->silence = (atom_getlong(ap) < -120) ? -120 : (atom_getlong(ap) > 0) ? 0 : atom_getlong(ap);
                }
                else
                {
                    if (argcount == 0) {
                        post("%ld: bufsize %ld",i+1,atom_getlong(ap));
                        x->bufsize = atom_getlong(ap);
                        argcount = argcount + 1;
                    }
                    else {
                        post("%ld: hopsize %ld",i+1,atom_getlong(ap));
                        x->hopsize = atom_getlong(ap);
                    }
                }
                break;
            case A_FLOAT:
                post("%ld: threshold %.2f",i+1,atom_getfloat(ap));
                x->threshold = (atom_getfloat(ap) < 1e-5) ? 0.1 : (atom_getfloat(ap) > 0.999) ? 0.999 : atom_getfloat(ap);
                break;
            case A_SYM:
                post("%ld: onset detection function %s",i+1, atom_getsym(ap)->s_name);
                x->detectionFunction = atom_getsym(ap)->s_name;
                break;
            default:
                post("%ld: unknown atom type (%ld)", i+1, atom_gettype(ap));
                break;
            }
        }

        isPow2 = (int)x->bufsize && !( ((int)x->bufsize-1) & (int)x->bufsize );
        if(!isPow2)
        {
            error("requested buffer size is not a power of 2. default value of 1024 used instead");
            x->bufsize = 1024;
        }
        isPow2 = (int)x->hopsize && !( ((int)x->hopsize-1) & (int)x->hopsize );
        if(!isPow2)
        {
            error("requested hop size is not a power of 2. default value of 1024 used instead");
            x->hopsize = x->bufsize / 4;
        }


        if (strcmp(x->detectionFunction,"hfc") == 0) x->o=new_aubio_onset(aubio_onset_hfc,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"energy") == 0) x->o=new_aubio_onset(aubio_onset_energy,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"phase") == 0) x->o=new_aubio_onset(aubio_onset_phase,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"complex") == 0) x->o=new_aubio_onset(aubio_onset_complex,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"specdiff") == 0) x->o=new_aubio_onset(aubio_onset_specdiff,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"kl") == 0) x->o=new_aubio_onset(aubio_onset_kl,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"mkl") == 0) x->o=new_aubio_onset(aubio_onset_mkl,x->bufsize, x->hopsize, 1);
        else x->o=new_aubio_onset(aubio_onset_complex,x->bufsize, x->hopsize, 1);


        x->in = (fvec_t *) new_fvec (x->hopsize, 1);
        x->out = (fvec_t *) new_fvec (1, 1);

        aubio_onset_set_threshold(x->o,x->threshold);
        aubio_onset_set_silence(x->o,x->silence);
        aubio_onset_set_minioi(x->o,x->minioi);

        post("aubioOnset~: version 0.3");

    }
    return (x);
}
Exemple #23
0
void *pitch_new(t_symbol *s, short argc, t_atom *argv) {
	t_int i, j;
	t_int vs = sys_getblksize(); // get vector size
    t_pitch *x = (t_pitch *)object_alloc(pitch_class);
	if(!x){
		return NULL;
	}

    dsp_setup((t_pxobject *)x,1); // one signal inlet	
	x->x_Fs = sys_getsr();
	x->BufWritePos = 0;
	
	// From fiddle~
    x->x_histphase = 0;
    x->x_dbage = 0;
    x->x_peaked = 0;
    x->x_amplo = DEFAMPLO;
    x->x_amphi = DEFAMPHI;
    x->x_attacktime = DEFATTACKTIME;
    x->x_attackbins = 1; // real value calculated afterward
    x->x_attackthresh = DEFATTACKTHRESH;
    x->x_vibtime = DEFVIBTIME;
    x->x_vibbins = 1;	 // real value calculated afterward
    x->x_vibdepth = DEFVIBDEPTH;
    x->x_npartial = DEFNPARTIAL;
    x->x_attackvalue = 0;

	// More initializations from Fiddle~
    for (i=0; i<MAXNPITCH; i++) {
		x->x_hist[i].h_pitch = x->x_hist[i].h_noted = 0.0f;
		x->x_hist[i].h_age = 0;
		x->x_hist[i].h_wherefrom = NULL;
		
		for (j=0; j<HISTORY; j++)
	    	x->x_hist[i].h_amps[j] = x->x_hist[i].h_pitches[j] = 0.0f;
    }
        
    for (i=0; i<HISTORY; i++) 
    	x->x_dbs[i] = 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 = DEFDELAY;
			x->x_npitch = DEFNPITCH;
			x->x_npeakanal = DEFNPEAKANAL;
			x->x_npeakout = DEFNPEAKOUT;
			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 = DEFDELAY;
			x->x_npitch = DEFNPITCH;
			x->x_npeakanal = DEFNPEAKANAL;
			x->x_npeakout = DEFNPEAKOUT;
			break;
		case 2:
			readBufSize(x,argv);
			readx_overlap(x,argv);		
			x->FFTSize = x->BufSize;
			x->x_window = DEFWIN;
			x->x_delay = DEFDELAY;
			x->x_npitch = DEFNPITCH;
			x->x_npeakanal = DEFNPEAKANAL;
			x->x_npeakout = DEFNPEAKOUT;
			break;
		case 3:
			readBufSize(x,argv);
			readx_overlap(x,argv);		
			readFFTSize(x,argv);
			x->x_window = DEFWIN;
			x->x_delay = DEFDELAY;
			x->x_npitch = DEFNPITCH;
			x->x_npeakanal = DEFNPEAKANAL;
			x->x_npeakout = DEFNPEAKOUT;
			break;
		case 4:
			readBufSize(x,argv);
			readx_overlap(x,argv);		
			readFFTSize(x,argv);
			readx_window(x,argv);
			x->x_delay = DEFDELAY;
			x->x_npitch = DEFNPITCH;
			x->x_npeakanal = DEFNPEAKANAL;
			x->x_npeakout = DEFNPEAKOUT;
			break;
		case 5:
			readBufSize(x,argv);
			readx_overlap(x,argv);			
			readFFTSize(x,argv);
			readx_window(x,argv);
			readx_delay(x,argv);
			x->x_npitch = DEFNPITCH;
			x->x_npeakanal = DEFNPEAKANAL;
			x->x_npeakout = DEFNPEAKOUT;
			break;
		case 6:
			readBufSize(x,argv);
			readx_overlap(x,argv);			
			readFFTSize(x,argv);
			readx_window(x,argv);
			readx_delay(x,argv);
			readx_npitch(x,argv);
			x->x_npeakanal = DEFNPEAKANAL;
			x->x_npeakout = DEFNPEAKOUT;
			break;
		case 7:
			readBufSize(x,argv);
			readx_overlap(x,argv);			
			readFFTSize(x,argv);
			readx_window(x,argv);
			readx_delay(x,argv);
			readx_npitch(x,argv);
			readx_npeakanal(x,argv);
			x->x_npeakout = DEFNPEAKOUT;
			break;
		default:
			readBufSize(x,argv);
			readx_overlap(x,argv);			
			readFFTSize(x,argv);
			readx_window(x,argv);
			readx_delay(x,argv);
			readx_npitch(x,argv);
			readx_npeakanal(x,argv);
			readx_npeakout(x,argv);
	}		
	
	if (x->x_npeakout > x->x_npeakanal) {
		object_post((t_object *)x, "Pitch~: You can't output more peaks than you pick...");
		x->x_npeakout = x->x_npeakanal;
	}
	
	// Make an outlet for peaks out
	if (x->x_npeakout)
    	x->x_peakout = listout((t_object *)x); // one list out

	// Make an outlet for Amplitude in dB
	x->x_envout = floatout((t_object *)x);

 	// One outlet for fundamental & amplitude raw values
	if (x->x_npitch)
		x->x_pitchout = listout((t_object *)x);

 	// One outlet for MIDI & frequency cooked pitch
	x->x_noteout = listout((t_object *)x);

	// Make bang outlet for onset detection
	x->x_attackout = bangout((t_object *)x);

	// 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,"blackman62");
	}
	
	if (x->BufSize < vs) { 
		object_post((t_object *)x, "Pitch~: Buffer size is smaller than the vector size, %d",vs);
		x->BufSize = vs;
	} else if (x->BufSize > 65536) {
		object_post((t_object *)x, "Pitch~: Maximum FFT size is 65536 samples");
		x->BufSize = 65536;
	}
		
	if (x->FFTSize < x->BufSize) {
		object_post((t_object *)x, "Pitch~: 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) {
		object_post((t_object *)x, "Pitch~: Maximum FFT size is 65536 samples");
		x->FFTSize = 65536;
	}
	
	// Overlap case
	if (x->x_overlap > x->BufSize-vs) {
		object_post((t_object *)x, "Pitch~: 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;
	x->x_FFTSizeOver2 = x->FFTSize/2;		

	object_post((t_object *)x, "--- Pitch~ ---");	
	object_post((t_object *)x, "	Buffer size = %d",x->BufSize);
	object_post((t_object *)x, "	Hop size = %d",x->x_hop);
	object_post((t_object *)x, "	FFT size = %d",x->FFTSize);
	object_post((t_object *)x, "	Window type = %s",x->x_winName);
	object_post((t_object *)x, "	Initial delay = %d",x->x_delay);
	object_post((t_object *)x, "	Number of pitches = %d",x->x_npitch);
	object_post((t_object *)x, "	Number of peaks to search = %d",x->x_npeakanal);
	object_post((t_object *)x, "	Number of peaks to output = %d",x->x_npeakout);

	// 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)pitch_tick_G4); // Call altivec-optimized tick function
		object_post((t_object *)x, "	Using G4-optimized FFT");	
		// Allocate some memory for the altivec FFT
		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);
    	x->x_scaleFactor = (t_float)1.0/(2.0*x->FFTSize);
#pragma altivec_model off
#else
		object_error((t_object *)x, "  No G4 optimization available");
#endif

	} else { // Normal tick function
		x->x_clock = clock_new(x,(method)pitch_tick);
		x->memFFT = (t_float*) sysmem_newptr(CMAX * x->FFTSize * sizeof(t_float)); // memory allocated for normal fft twiddle
	}
	object_post((t_object *)x, "");

	// Allocate memory
	x->Buf1 = (t_int*) sysmem_newptr(x->BufSize * sizeof(t_float)); // Careful these are pointers to integers but the content is floats
	x->Buf2 = (t_int*) sysmem_newptr(x->BufSize * sizeof(t_float));
	x->BufFFT = (t_float*) sysmem_newptr(x->FFTSize * sizeof(t_float));
	x->BufPower = (t_float*) sysmem_newptr((x->FFTSize/2) * sizeof(t_float));
	x->WindFFT = (t_float*) sysmem_newptr(x->BufSize * sizeof(t_float));
	x->peakBuf = (t_peakout*) sysmem_newptr(x->x_npeakout * sizeof(t_peakout)); // from Fiddle~
	x->histBuf = (t_float*) sysmem_newptr((x->FFTSize + BINGUARD) * sizeof(t_float)); // for Fiddle~
		
	// 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;
		}
	}
	
	// More initializations from Fiddle~
	for (i=0; i<x->x_npeakout; i++)
		x->peakBuf[i].po_freq = x->peakBuf[i].po_amp = 0.0f;
		
    return (x);
}
Exemple #24
0
/*------------------------------------ x10Create ---*/
static void *
x10Create(t_symbol * kind,
          const long pollRate)
{
    X10ControlData * xx = static_cast<X10ControlData *>(object_alloc(gClass));
    
    if (xx)
    {
        xx->fHouseCodeChar = 0;
        xx->fFunctionChar = x10CM11FunctionUnitsOff;
        xx->fDimLevel = 0;
        xx->fDeviceMap = 0;
        xx->fCompletedWhenStatus = xx->fIgnoreChecksum = xx->fStopping = false;
        xx->fOutCmd = xx->fOutArea = NULL;
        if ((kind == gCM11Symbol) || (kind == gEmptySymbol))
        {
            xx->fKind = X10KindCM11;
        }
        else if (kind == gCP290Symbol)
        {
            xx->fKind = X10KindCP290;
        }
        else
        {
            LOG_ERROR_2(xx, OUTPUT_PREFIX "invalid kind '%s' for device", kind->s_name)
            xx->fKind = X10KindCM11;
        }
        if ((0 > pollRate) || (MAX_POLL_RATE < pollRate))
        {
            LOG_ERROR_2(xx, OUTPUT_PREFIX "invalid polling rate (%ld) for device", pollRate)
            xx->fPollRate = SER_SAMPLE_RATE;
        }
        else
        {
            xx->fPollRate = (pollRate ? pollRate : SER_SAMPLE_RATE);
        }
        /* Set up our connections and private data */
        intin(xx, 1);
        xx->fErrorBangOut = static_cast<t_outlet *>(bangout(xx));
        xx->fMinuteOut = static_cast<t_outlet *>(intout(xx));
        xx->fHourOut = static_cast<t_outlet *>(intout(xx));
        xx->fDayOut = static_cast<t_outlet *>(intout(xx));
        xx->fDeviceStatus = static_cast<t_outlet *>(intout(xx));
        xx->fCommandComplete = static_cast<t_outlet *>(bangout(xx));
        xx->fHouseCode = static_cast<t_outlet *>(intout(xx));
        xx->fPollerOut = static_cast<t_outlet *>(bangout(xx));
        xx->fCommandsOut = static_cast<t_outlet *>(intout(xx));
        xx->fPollClock = MAKE_CLOCK(xx, x10ProcessClock);
        xx->fPollQueue = MAKE_QELEM(xx, x10ProcessQueue);
        xx->fOutBuffer = GET_BYTES(OUTBUFF_SIZE, unsigned char);
        switch (xx->fKind)
        {
            case X10KindCM11:
                xx->fMinorState = x10CM11MinorIdle;
                xx->fMajorState = x10CM11MajorIdle;
                break;
                
            case X10KindCP290:
                xx->fMinorState = x10CP290MinorIdle;
                xx->fMajorState = x10CP290MajorIdle;
                break;
                
            default:
                break;
                
        }
        xx->fAllOnCount = xx->fEntryCount = xx->fEventByteCount = 0;
        if (xx->fErrorBangOut && xx->fMinuteOut && xx->fHourOut && xx->fDayOut &&
            xx->fDeviceStatus && xx->fCommandComplete && xx->fHouseCode &&
            xx->fPollerOut && xx->fCommandsOut && xx->fPollClock && xx->fPollQueue &&
            xx->fOutBuffer)
        {
            for (short ii = 0; ii < COMMAND_PREFIX_SIZE; ++ii)
            {
                *(xx->fOutBuffer + ii) = ALL_ON;
            }
            xx->fOutCmd = xx->fOutBuffer + COMMAND_PREFIX_SIZE;
            xx->fOutArea = xx->fOutBuffer + COMMAND_PREFIX_SIZE + 1;
            clock_delay(xx->fPollClock, xx->fPollRate);
        }
        else
        {
            LOG_ERROR_1(xx, OUTPUT_PREFIX "unable to create port or clock for device")
            freeobject(reinterpret_cast<t_object *>(xx));
            xx = NULL;
        }
    }
    return xx;
} // x10Create
Exemple #25
0
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);
}
Exemple #26
0
/*------------------------------------ initObject ---*/
bool
initObject(UdpObjectData * xx,
           const long      port,
           const long      numBuffers)
{
    bool okSoFar = true;

    if (xx)
    {
        long buffSize = static_cast<long>(BUFF_MEMORY_TO_ALLOC * (numBuffers + 2));

        xx->fSelfPort = static_cast<unsigned short>(port ? port : DEFAULT_PORT);
        memset(&xx->fPartnerAddress, 0, sizeof(xx->fPartnerAddress));
        xx->fPartnerPort = 0;
        xx->fPartnerKnown = false;
        xx->fErrorBangOut = static_cast<t_outlet *>(bangout(xx));
        xx->fResultOut = static_cast<t_outlet *>(outlet_new(xx, NULL));
        setObjectState(xx, kUdpStateUnbound);
        xx->fSocket = NULL;
        xx->fErrorQueue = MAKE_QELEM(xx, processErrorQueue);
        xx->fReceiveQueue = MAKE_QELEM(xx, processReceiveQueue);
        xx->fBufferBase = reinterpret_cast<DataBuffer **>(sysmem_newhandle(buffSize));
        if (xx->fBufferBase)
        {
            sysmem_lockhandle(reinterpret_cast<t_handle>(xx->fBufferBase), 1);
            xx->fSendBuffer = *xx->fBufferBase;
            xx->fReceiveBuffer = reinterpret_cast<DataBuffer *>(ADD_TO_ADDRESS(xx->fSendBuffer,
                                                                           BUFF_MEMORY_TO_ALLOC));
        }
        xx->fLinkBase = MAKE_TYPED_HANDLE(UdpBufferLink, numBuffers);
        if (xx->fLinkBase)
        {
            DataBuffer *    this_buffer =
                                reinterpret_cast<DataBuffer *>(ADD_TO_ADDRESS(xx->fReceiveBuffer,
                                                               BUFF_MEMORY_TO_ALLOC));
            UdpBufferLink * prev_link = NULL;
            UdpBufferLink * this_link = NULL;

            sysmem_lockhandle(reinterpret_cast<t_handle>(xx->fLinkBase), 1);
            xx->fPoolHead = *xx->fLinkBase;
            this_link = xx->fPoolHead;
            for (long link_count = 0; link_count < numBuffers; ++link_count)
            {
                this_link->fPrevious = prev_link;
                this_link->fData = this_buffer;
                this_buffer = reinterpret_cast<DataBuffer *>(ADD_TO_ADDRESS(this_buffer,
                                                                            BUFF_MEMORY_TO_ALLOC));
                this_link->fNext = NULL;
                if (prev_link)
                {
                    prev_link->fNext = this_link;
                }
                prev_link = this_link;
                this_link = reinterpret_cast<UdpBufferLink *>(ADD_TO_ADDRESS(this_link,
                                                                             sizeof(UdpBufferLink)));
            }
            xx->fPoolTail = prev_link;
        }
        xx->fClosing = xx->fRawMode = false;
        if (! (xx->fResultOut && xx->fErrorBangOut && xx->fErrorQueue && xx->fBufferBase &&
               xx->fReceiveQueue && xx->fLinkBase))
        {
            LOG_ERROR_1(xx, OUTPUT_PREFIX "unable to create port or buffer for object")
            okSoFar = false;
        }
    }
    return okSoFar;
} // initObject
Exemple #27
0
void *fft_donew(long points, long interval, long phase, long inverse)
{
	t_fft *x;
	float *buf;
	long bad = 0,i;
	long bs = sys_getblksize();
	
	if (!points)
		points = FFT_DEFAULT_POINTS;
	if (!interval)
		interval = points;
	if (points != (1 << ilog2(points)) || interval != (1 << ilog2(interval))) {
		error("fft: power of two required for size and interval");
		points = 1 << ilog2(points);
		interval = 1 << ilog2(interval);
	}
	if (points < FFT_MIN_POINTS)
		error("fft~: minimum size %ld", points = FFT_MIN_POINTS);
	else if (points > FFT_MAX_POINTS)
		error("fft~: maximum size %ld", points = FFT_MAX_POINTS);
	if (points > interval) {
		error("fft~: interval must be at least one frame, setting to %ld",points);
		interval = points;
	}
	phase %= interval;
	if (phase % bs) {
		if (phase > bs)
			phase -= (phase % bs);
		else
			phase = bs;
		error("fft~: phase must be multiple of %ld, setting to %ld", bs,phase);
	}
	x = (t_fft *)newobject(fft_class);
	x->f_points = points;
	x->f_interval = interval;
	x->f_phase = phase;
	x->f_inverse = inverse;
	dsp_setup((t_pxobject *)x,2);
	x->f_obj.z_misc = Z_NO_INPLACE;
	x->f_realin = t_getbytes(points * sizeof(float));
	x->f_imagin = t_getbytes(points * sizeof(float));
	x->f_realout = t_getbytes(points * sizeof(float));
	x->f_imagout = t_getbytes(points * sizeof(float));
	for (i=0; i < points; i++) {
		x->f_realin[i] = 0;
		x->f_realout[i] = 0;
		x->f_imagin[i] = 0;
		x->f_imagout[i] = 0;
	}
	x->f_realinptr = x->f_realin;
	x->f_realoutptr = x->f_realout;
	x->f_imaginptr = x->f_imagin;
	x->f_imagoutptr = x->f_imagout;
	x->f_countdown = 0;
	if (!fts_mode)
		outlet_new(x, "signal");
	else {
		x->f_clock = clock_new(x, (method)fft_tick);
		x->f_bangout = bangout((t_object *)x);
	}
	x->f_1overpts = 1. / x->f_points;
	outlet_new(x, "signal");
	outlet_new(x, "signal");
	return (x);
}
Exemple #28
0
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);
}