Beispiel #1
0
void *HoaEncode_new(t_symbol *s, long argc, t_atom *argv)
{
	t_HoaEncode *x = NULL;
	int	order = 4;
	std::string mode = "basic";
    x = (t_HoaEncode *)object_alloc(HoaEncode_class);
	if (x)
	{		
		if(atom_gettype(argv) == A_LONG)
			order = atom_getlong(argv);
		
		if(atom_gettype(argv + 1) == A_SYM)
			mode = atom_getsym(argv + 1)->s_name;
		
		x->f_ambiEncoder = new AmbisonicEncoder(order, mode, sys_getblksize());
		
		dsp_setup((t_pxobject *)x, x->f_ambiEncoder->getNumberOfInputs());
		for (int i = 0; i < x->f_ambiEncoder->getNumberOfOutputs(); i++)
			outlet_new(x, "signal");
		
		x->f_ob.z_misc = Z_NO_INPLACE;
	}
	return (x);
}
Beispiel #2
0
void *HoaTool_new(t_symbol *s, long argc, t_atom *argv)
{
	t_HoaTool *x = NULL;
	int order = 4;
    int numberOfSources = 1;
    
    x = (t_HoaTool *)object_alloc((t_class*)HoaTool_class);
	if (x)
	{
		if(atom_gettype(argv) == A_LONG)
			order = atom_getlong(argv);
		if(atom_gettype(argv+1) == A_LONG)
			numberOfSources = atom_getlong(argv+1);
        
		x->f_AmbisonicPolyEase	= new AmbisonicPolyEase(order, numberOfSources, sys_getblksize());
        dsp_setup((t_pxobject *)x, x->f_AmbisonicPolyEase->getNumberOfInputs());
        
		for (int i = 0; i < x->f_AmbisonicPolyEase->getNumberOfOutputs(); i++) 
			outlet_new(x, "signal");
		
		x->f_ob.z_misc = Z_NO_INPLACE;
	}
	return (x);
}
Beispiel #3
0
void *HoaFilter_new(t_symbol *s, long argc, t_atom *argv)
{
	t_HoaFilter *x = NULL;
	int	order = 4;
	int mode = Hoa_Basic;
    x = (t_HoaFilter *)object_alloc(HoaFilter_class);
	if (x)
	{		
		if(atom_gettype(argv) == A_LONG)
			order = atom_getlong(argv);
		
		if(atom_gettype(argv + 1) == A_SYM && atom_getsym(argv + 1) == gensym("split"))
			mode = Hoa_Split;
		
		x->f_ambiFilter = new AmbisonicsFilter(order, sys_getblksize(), sys_getsr());
		
		dsp_setup((t_pxobject *)x, x->f_ambiFilter->getNumberOfInputs());
		for (int i = 0; i < x->f_ambiFilter->getNumberOfOutputs(); i++)
			outlet_new(x, "signal");
		
		x->f_ob.z_misc = Z_NO_INPLACE;
	}
	return (x);
}
Beispiel #4
0
void *hoa_grain_new(t_symbol *s, long argc, t_atom *argv)
{
    t_hoa_grain *x = NULL;
	int	order = 4;
    bool mode = 1;
    
    x = (t_hoa_grain *)eobj_new(hoa_grain_class);
    
    order = atom_getint(argv);
    if(atom_getsym(argv+1) == gensym("no"))
        mode = 0;
    
    x->f_ambi_grain = new AmbisonicsGrain(order, mode, 5000, sys_getblksize(), sys_getsr());
    eobj_dspsetup(x, x->f_ambi_grain->getNumberOfInputs(), x->f_ambi_grain->getNumberOfOutputs());
    hoa_grain_buffer_set(x, atom_getsymbol(argv+2));
    x->f_ambi_grain->setGrainSize(20.);
    x->f_ambi_grain->setDelayTime(100.);
    x->f_ambi_grain->setRarefaction(0.);
    x->f_ambi_grain->setFeedback(0.95);
    
	x->f_ob.d_misc = E_NO_INPLACE;
    
    return (x);
}
Beispiel #5
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);
}
Beispiel #6
0
void stringpitch_dsp(t_stringpitch *x, t_signal **sp, short *connect) {
	int vs = sys_getblksize();

	if (vs > x->BufSize) post(" You need to use a smaller signal vector size...",0);
	else if (connect[0]) dsp_add(stringpitch_perform, 3, sp[0]->s_vec, x, sp[0]->s_n);
}
Beispiel #7
0
void *samm_new(t_symbol *msg, short argc, t_atom *argv)
{
	int i,j;
	double divisor;
	t_samm *x;
	
	if(argc < 2){
		error("%s: there must be at least 1 beat stream",OBJECT_NAME);
		return (void *)NULL;
	}
	if(argc > MAXBEATS + 1)
    {
		error("%s: exceeded maximum of %d beat values",OBJECT_NAME, MAXBEATS);
		return (void *)NULL;
    }
    	
    
    
#if MSP
	x = (t_samm *)newobject(samm_class);
	x->metro_count = argc - 1;
	dsp_setup((t_pxobject *)x,1);
	for(i=0;i< x->metro_count ;i++)
		outlet_new((t_pxobject *)x, "signal");  	
	x->x_obj.z_misc |= Z_NO_INPLACE;
#endif
#if PD
    x = (t_samm *)pd_new(samm_class);
    x->metro_count = argc - 1;
    for(i=0;i< x->metro_count;i++)
        outlet_new(&x->x_obj, gensym("signal"));
#endif
	
	x->sr = sys_getsr();
	x->vs = sys_getblksize();

  x->pause = 0;
  x->mute = 0;
  
	x->beats = (double *) calloc(x->metro_count, sizeof(double));
	x->metro_samps = (double *) calloc(x->metro_count, sizeof(double));
	x->metro_beatdurs = (double *) calloc(x->metro_count, sizeof(double));
	x->metro = (double *) calloc(x->metro_count, sizeof(double));
		
	if(! x->sr ){
		x->sr = 44100;
		post("sr autoset to 44100");
	}
	
	if(argc > 0) {
		x->tempo = (double) atom_getfloatarg(0,argc,argv);
	}

	if( x->tempo <= 0.0 ){
		x->tempo = 120;
		post("tempo autoset to 120 BPM");
	}
	
	x->onebeat_samps = (60.0/x->tempo) * x->sr;
	



	for(i = 1,j = 0; i < argc; i++, j++){
		  divisor = (double)atom_getfloatarg(i,argc,argv);
    	if(!divisor){
			error("%s: zero divisor given for beat stream %d",OBJECT_NAME,i);
			divisor = 1.0;
		}
	
		x->metro_beatdurs[j] = 1.0 / divisor; // argument is now DIVISOR of beat 
		x->metro_samps[j] = x->metro_beatdurs[j] * x->onebeat_samps;
		x->metro[j] = 1.0; // initialize for instantaneous beat
		
	}
//    post("there are %d beat streams",x->metro_count);
   samm_init(x,0); 

  return (x);
}
Beispiel #8
0
void *HoaBinaural_new(t_symbol *s, long argc, t_atom *argv)
{
	t_HoaBinaural *x = NULL;
	int order = 3;
    std::string pinnaSize = "small";
    std::string filePath = "HrtfDatabase/";
    std::string absoluteHrtfFilePath = "";
    
    x = (t_HoaBinaural *)object_alloc(HoaBinaural_class);
	if (x)
	{
        
		if(atom_gettype(argv) == A_LONG)
			order = atom_getlong(argv);
        
		if(atom_gettype(argv+1) == A_SYM)
			pinnaSize = atom_getsym(argv+1)->s_name;
        
        if (pinnaSize == "small")
        {
            pinnaSize = "Small";
        }
        else
        {
            pinnaSize = "Large";
        }
        
#ifdef __APPLE__
        // OSX only : access to the hoa.binaural~ bundle
        CFBundleRef hoaBinaural_bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.cycling74.hoa-binaural-"));
        CFURLRef hoaBinaural_ref = CFBundleCopyBundleURL(hoaBinaural_bundle);
        UInt8 bundle_path[512];
        Boolean res = CFURLGetFileSystemRepresentation(hoaBinaural_ref, true, bundle_path, 512);
        assert(res);
        // Built the complete resource path
        absoluteHrtfFilePath = std::string((const char*)bundle_path) + std::string("/Contents/Resources/") + std::string(filePath);
#endif
        
#ifdef WIN32
        HMODULE handle = LoadLibrary("hoa.binaural~.mxe");
        if (handle) {
            // Get hoa.binaural~.mxe path
            char name[512];
            GetModuleFileName(handle, name, 512);
            string str_name = string(name);
            str_name = str_name.substr(0, str_name.find_last_of("\\"));
            // Built the complete resource path
            absoluteHrtfFilePath = string(str_name) + string("/Contents/Resources/") + string(filePath);
            FreeLibrary(handle);
        } else {
            post("Error : cannot locate hoa.binaural~.mxe...");
            absoluteHrtfFilePath = "";
        }
#endif
		x->f_ambiBinaural = new AmbisonicsBinaural(order, absoluteHrtfFilePath, pinnaSize, sys_getsr(), sys_getblksize());
		
		dsp_setup((t_pxobject *)x, x->f_ambiBinaural->getNumberOfInputs());
		for (int i = 0; i < x->f_ambiBinaural->getNumberOfOutputs(); i++)
			outlet_new(x, "signal");
    
        x->f_ob.z_misc = Z_NO_INPLACE;
        attr_args_process(x, argc, argv);
	}
	return (x);
}
Beispiel #9
0
static void *matrix_new(t_symbol *s, int ac, t_atom *av)
{
    t_pd *z;
    if (!fittermax_get() &&
	(z = fragile_class_mutate(matrixps_matrixtilde,
				  (t_newmethod)matrix_new, ac, av)))
	return (z);
    else if (ac < 2)
    {
	loud_error(0, "bad creation arguments for class '%s'",
		   matrixps_matrixtilde->s_name);
	loud_errand(0, "missing number of %s", (ac ? "outlets" : "inlets"));
	return (0);  /* CHECKED */
    }
    else
    {
	t_matrix *x = (t_matrix *)pd_new(matrix_class);
	int i;
	if (av[0].a_type == A_FLOAT)
	{
	    if ((x->x_ninlets = (int)av[0].a_w.w_float) < 1)
		x->x_ninlets = 1;
	}
	else x->x_ninlets = 1;  /* CHECKED */
	if (av[1].a_type == A_FLOAT)
	{
	    if ((x->x_noutlets = (int)av[1].a_w.w_float) < 1)
		x->x_noutlets = 1;
	}
	else x->x_noutlets = 1;  /* CHECKED */
	x->x_ncells = x->x_ninlets * x->x_noutlets;
	x->x_ivecs = getbytes(x->x_ninlets * sizeof(*x->x_ivecs));
	x->x_ovecs = getbytes(x->x_noutlets * sizeof(*x->x_ovecs));
	x->x_nblock = x->x_maxblock = sys_getblksize();
	x->x_osums = getbytes(x->x_noutlets * sizeof(*x->x_osums));
	for (i = 0; i < x->x_noutlets; i++)
	    x->x_osums[i] = getbytes(x->x_maxblock * sizeof(*x->x_osums[i]));
	x->x_cells = getbytes(x->x_ncells * sizeof(*x->x_cells));
	matrix_clear(x);
	if (ac >= 3)
	{
	    if (av[2].a_type == A_FLOAT)
		x->x_defgain = av[2].a_w.w_float;
	    else
		x->x_defgain = MATRIX_DEFGAIN;
	    x->x_gains = getbytes(x->x_ncells * sizeof(*x->x_gains));
	    for (i = 0; i < x->x_ncells; i++)
		x->x_gains[i] = x->x_defgain;
	    x->x_ramps = getbytes(x->x_ncells * sizeof(*x->x_ramps));
	    matrix_ramp(x, MATRIX_DEFRAMP);
	    x->x_coefs = getbytes(x->x_ncells * sizeof(*x->x_coefs));
	    for (i = 0; i < x->x_ncells; i++)
		x->x_coefs[i] = 0.;
	    x->x_ksr = sys_getsr() * .001;
	    x->x_incrs = getbytes(x->x_ncells * sizeof(*x->x_incrs));
	    x->x_bigincrs = getbytes(x->x_ncells * sizeof(*x->x_bigincrs));
	    x->x_remains = getbytes(x->x_ncells * sizeof(*x->x_remains));
	    for (i = 0; i < x->x_ncells; i++)
		x->x_remains[i] = 0;
	}
	else
	{
	    x->x_gains = 0;
	    x->x_ramps = 0;
	    x->x_coefs = 0;
	    x->x_incrs = 0;
	    x->x_bigincrs = 0;
	    x->x_remains = 0;
	}
	for (i = 1; i < x->x_ninlets; i++)
	    sic_newinlet((t_sic *)x, 0.);
	for (i = 0; i < x->x_noutlets; i++)
	    outlet_new((t_object *)x, &s_signal);
	x->x_dumpout = outlet_new((t_object *)x, &s_list);
	return (x);
    }
}
Beispiel #10
0
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);
}
Beispiel #11
0
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;
}
Beispiel #12
0
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);
}
Beispiel #13
0
void k_jackd_tilde_setup(void)
{
  static struct aipc_receiver *main_receiver=NULL;

  // jack-server init
  {
    char *homedir=getenv("HOME");
    char temp[500];
    DIR *dir;

    {
      sprintf(temp,"%s/.k_jackd",homedir);
      dir=opendir(temp);

      if(dir==NULL){
	sprintf(temp,"mkdir %s/.k_jackd",homedir);
	system(temp);
      }else{
	closedir(dir);
      }
    }
    
    sprintf(temp,"%s/.k_jackd/main_socket",homedir);
    main_receiver=aipc_receiver_new(temp);
    if(main_receiver==NULL){
      fprintf(stderr,"k_jackd_init: Unable to open socket \"%s\".\n",temp);
      fprintf(stderr,"Unless k_jackd is allready running, just delete that file.\n");
      return;
    }
    
    sprintf(temp,"rm -f %s/.k_jackd/datadir_*",homedir);
    system(temp);

    sprintf(temp,"%s/.k_jackd/sample_rate",homedir); 
    aipc_variable_create_float(temp,sys_getsr());

    sprintf(temp,"%s/.k_jackd/buffer_size",homedir);    
    aipc_variable_create_int(temp,sys_getblksize());
  }


    k_jackd_class = class_new(
			      gensym("k_jackd~"),
			      (t_newmethod)k_jackd_new,
			      (t_method)k_jackd_free,
			      sizeof(t_k_jackd),
			      0,
			      A_GIMME,
			      0
			      );

    class_addmethod(k_jackd_class, (t_method)k_jackd_dsp, gensym("dsp"), 0);

    class_addmethod (k_jackd_class,
		     nullfn,
		     gensym ("signal"),
		     0);


    class_sethelpsymbol(k_jackd_class, gensym("help-k_jackd~.pd"));

    pthread_create(&pthread,NULL,k_jackd_inputthread,main_receiver);

}
Beispiel #14
0
static void *matrix_new(t_symbol *s, int argc, t_atom *argv)
{
	t_matrix *x = (t_matrix *)pd_new(matrix_class);

	t_float rampval = MATRIX_DEFRAMP;
	x->x_numinlets = (int)MATRIX_MININLETS;
	x->x_numoutlets = (int)MATRIX_MINOUTLETS;
	x->x_defgain = MATRIX_DEFGAIN;

	int i;
	int argnum = 0;
	while(argc > 0){
		if(argv -> a_type == A_FLOAT){
			t_float argval = atom_getfloatarg(0, argc, argv);
			switch(argnum){
				case 0:
					if(argval < MATRIX_MININLETS){
						x->x_numinlets = (int)MATRIX_MININLETS;
					}
					else if (argval > MATRIX_MAXINLETS){
						x->x_numinlets = (int)MATRIX_MAXINLETS;
						post("matrix~: resizing to %d signal inlets", (int)MATRIX_MAXINLETS);
					}
					else{
						x->x_numinlets = (int)argval;
					};
					break;
				case 1:
					if(argval < MATRIX_MINOUTLETS){
						x->x_numoutlets = (int)MATRIX_MINOUTLETS;
					}
					else if (argval > MATRIX_MAXOUTLETS){
						x->x_numoutlets = (int)MATRIX_MAXOUTLETS;
						post("matrix~: resizing to %d signal outlets", (int)MATRIX_MAXOUTLETS);
					}
					else{
						x->x_numoutlets = (int)argval;
					};
					break;
				case 2:
					x->x_defgain = argval;
					break;
				default:
					break;
			};
			argc--;
			argv++;
			argnum++;
		}
		else if(argv -> a_type == A_SYMBOL){
			t_symbol *argname = atom_getsymbolarg(0, argc, argv);
			if(strcmp(argname->s_name, "@ramp")==0){
				if(argc >= 2){
					t_float argval = atom_getfloatarg(1, argc, argv);
					if(argval < MATRIX_MINRAMP){
						rampval = MATRIX_MINRAMP;
					}
					else{
						rampval = argval;
					};
					argc -= 2;
					argv += 2;
				}
				else{
					goto errstate;
				};
			}
			else{
				goto errstate;
			};
		}
		else{
			goto errstate;
		};
	};

	int gaingiven = argnum >= 3; //if >=  3 args given, then gain is given, binary mode is off

	x->x_ncells = x->x_numinlets * x->x_numoutlets;
	x->x_ivecs = getbytes(x->x_numinlets * sizeof(*x->x_ivecs));
	x->x_ovecs = getbytes(x->x_numoutlets * sizeof(*x->x_ovecs));
	x->x_nblock = x->x_maxblock = sys_getblksize();
	x->x_osums = getbytes(x->x_numoutlets * sizeof(*x->x_osums));
	for (i = 0; i < x->x_numoutlets; i++){
	    x->x_osums[i] = getbytes(x->x_maxblock * sizeof(*x->x_osums[i]));
	};
	x->x_cells = getbytes(x->x_ncells * sizeof(*x->x_cells));
	/* zerovec for filtering float inputs*/
	x->x_zerovec = getbytes(x->x_maxblock * sizeof(*x->x_zerovec));
	matrix_clear(x);

	if (gaingiven){
	    x->x_gains = getbytes(x->x_ncells * sizeof(*x->x_gains));
	    for (i = 0; i < x->x_ncells; i++){
            x->x_gains[i] = x->x_defgain;
		};
        
	    x->x_ramps = getbytes(x->x_ncells * sizeof(*x->x_ramps));
	    matrix_ramp(x, rampval);
	    x->x_coefs = getbytes(x->x_ncells * sizeof(*x->x_coefs));
	    
		for (i = 0; i < x->x_ncells; i++){
			x->x_coefs[i] = 0.;
		};
	    x->x_ksr = sys_getsr() * .001;
	    x->x_incrs = getbytes(x->x_ncells * sizeof(*x->x_incrs));
	    x->x_bigincrs = getbytes(x->x_ncells * sizeof(*x->x_bigincrs));
	    x->x_remains = getbytes(x->x_ncells * sizeof(*x->x_remains));
	    for (i = 0; i < x->x_ncells; i++){
			x->x_remains[i] = 0;
		};
	}
	else{
	    x->x_gains = 0;
	    x->x_ramps = 0;
	    x->x_coefs = 0;
	    x->x_incrs = 0;
	    x->x_bigincrs = 0;
	    x->x_remains = 0;
	};
	for (i = 1; i < x->x_numinlets; i++){
		pd_float( (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal), -0.);
		x->x_signalscalars[i] = obj_findsignalscalar((t_object *)x, i);
	};
	for (i = 0; i < x->x_numoutlets; i++){
	 	outlet_new(&x->x_obj, gensym("signal"));
	};
	x->x_dumpout = outlet_new((t_object *)x, &s_list);
	x->x_glist = canvas_getcurrent();
	return (x);
	errstate:
		pd_error(x, "matrix~: improper args");
		return NULL;
}
Beispiel #15
0
static void *riddle_new(t_symbol *s, int ac, t_atom *av)
{
    /* IFBUILTIN remove: this is a bad hack */
    t_pd *en = riddle_getenvironment();
    t_newgimme newfn = (t_newgimme)zgetfn(en, s);
    if (!newfn)
    {
        loudbug_bug("riddle_new 1");
        return (0);
    }
    else
    {
        t_riddle *rd = (t_riddle *)newfn(s, ac, av);
        int i, nslots;
        t_rdsource *inslot;
        t_rdsink *outslot;
        t_rdremote *re;
        if (!rd)
            return (0);

        rd->rd_private = getbytes(sizeof(*rd->rd_private));

        rd->rd_disabled = 0;
        rd->rd_wasdisabled = 0;
        rd->rd_blockfn = (t_rdblockfn)zgetfn((t_pd *)rd, gensym("dspblock"));
        rd->rd_dspfn = (t_rddspfn)zgetfn((t_pd *)rd, gensym("_dsp"));
        if (!rd->rd_dspfn)
            loudbug_bug("riddle_new 2");

        rd->rd_graphsr = (int)sys_getsr();
        rd->rd_graphblock = sys_getblksize();
        rd->rd_nsiginlets = obj_nsiginlets((t_object *)rd);
        rd->rd_nsigoutlets = obj_nsigoutlets((t_object *)rd);

        /* currently, rd_nremoteslots is incremented in rdbuffer_newreader(),
           which relies on calloc in pd_new(), LATER rethink */

        nslots = rd->rd_nsiginlets + rd->rd_nremoteslots;
        rd->rd_inslots = getbytes(nslots * sizeof(*rd->rd_inslots));
        for (i = 0, inslot = rd->rd_inslots; i < nslots; i++, inslot++)
        {
            inslot->so_riddle = rd;
            inslot->so_remote = 0;
            inslot->so_sourcecount = 0;
            inslot->so_pattern = 0;
            inslot->so_newpattern = 0;
            inslot->so_block = 0;
            inslot->so_newblock = 0;
            inslot->so_flags = 0;
        }
        rd->rd_remoteslots = rd->rd_inslots + rd->rd_nsiginlets;

        for (i = 0, inslot = rd->rd_remoteslots, re = rd->rd_remoteports;
                i < rd->rd_nremoteslots; i++, inslot++)
        {
            if (re = rdremote_nextreader(re))
                inslot->so_remote = re;
            else
            {
                loudbug_bug("riddle_new 3");
                break;  /* FIXME this is fatal */
            }
        }

        rd->rd_outslots =
            getbytes(rd->rd_nsigoutlets * sizeof(*rd->rd_outslots));
        for (i = 0, outslot = rd->rd_outslots;
                i < rd->rd_nsigoutlets; i++, outslot++)
        {
            outslot->si_riddle = rd;
            outslot->si_outno = -1;
            outslot->si_pattern = 0;
            outslot->si_block = 0;
            outslot->si_flags = 0;
            outslot->si_outbuf[0].a_type = A_FLOAT;
            outslot->si_outbuf[1].a_type = A_SYMBOL;
            outslot->si_outbuf[1].a_w.w_symbol = rdps__;
            outslot->si_outbuf[2].a_type = A_FLOAT;
            outslot->si_outbuf[3].a_type = A_FLOAT;
            outslot->si_outbuf[3].a_w.w_float = 0.;
            outslot->si_feedchain = 0;
            outslot->si_isready = 0;
        }

        riddle_validatesinks(rd);

        for (i = 0, outslot = rd->rd_outslots;
                i < rd->rd_nsigoutlets; i++, outslot++)
            if (outslot->si_outno >= 0)
                outslot->si_feedchain = rdfeedchain_new(outslot->si_outno);

        rd->rd_idlepicker = rdpicker_attach(rd, gensym("_idle"));

        return (rd);
    }
}
Beispiel #16
0
void *fft_new(Symbol *s, short ac, Atom *av)
{
	t_fft *x;
	float *buf;
	long i;
	long bs = sys_getblksize();
	
	long fftsize, hop;
	
	if ((ac > 0) && (av[0].a_type == A_LONG))
		fftsize = av[0].a_w.w_long;
	else
		fftsize = FFT_DEFAULT_POINTS;
		
	if (fftsize != (1 << ilog2(fftsize))) {
		fftsize = 1 << ilog2(fftsize);
		error("fftÅ: power of two required for fft size - using %ld", fftsize);
	}
	
	if ((ac > 1) && (av[1].a_type == A_LONG))
		hop = av[1].a_w.w_long;
	else
		hop = 2;
	
	if ( hop != 2 ) {
		error("fftÅ: overlap must be 2 or 4 right now - setting to 2");
		hop = 2;
	}
	
	if (fftsize < FFT_MIN_POINTS)
		error("fftÅ: minimum size %ld", fftsize = FFT_MIN_POINTS);
	else if (fftsize > FFT_MAX_POINTS)
		error("fftÅ: maximum size %ld", fftsize = FFT_MAX_POINTS);

	hop = fftsize / hop; // hop is now defined in samples instead of x overlap
	
	// this is not very good well done because overlap should be 2 4 or 8
	if (hop < bs){
		hop = bs;
		error("fftÅ: HOP must be multiple of %ld, setting to %ld", bs,hop);
	}
	
	x = (t_fft *)newobject(fft_class);
	x->x_fftsize = fftsize;
	x->x_hop = hop;
	
	dsp_setup((t_pxobject *)x,2);
	x->x_obj.z_misc = Z_NO_INPLACE;
	x->x_realin = t_getbytes(fftsize * sizeof(float));
	x->x_imagin = t_getbytes(fftsize * sizeof(float));
	x->x_realout = t_getbytes(fftsize * sizeof(float));
	x->x_imagout = t_getbytes(fftsize * sizeof(float));
	x->x_window = t_getbytes(fftsize * sizeof(float));
	
	for (i=0; i < fftsize; i++) {
		x->x_realin[i] = 0;
		x->x_realout[i] = 0;
		x->x_imagin[i] = 0;
		x->x_imagout[i] = 0;
	}
	for (i=0; i < fftsize; i++) { 
		// hanning window with sqrt for two overlap
		x->x_window[i] = sqrt(0.5 * (1. + cos(3.14159 + 3.14159 * 2.* i/fftsize)));
	}
	x->x_realinptr = x->x_realin;
	x->x_realoutptr = x->x_realout;
	x->x_imaginptr = x->x_imagin;
	x->x_imagoutptr = x->x_imagout;

	x->x_1overpts = 1. / x->x_fftsize;
	
	//x->x_outlet2 = outlet_new((t_pxobject *)x, 0L);
	x->x_outlet1 = outlet_new(x, "signal");
	x->x_outlet = outlet_new(x, "signal");
	
	return (x);
}
Beispiel #17
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);
}
Beispiel #18
0
void *stft_new(Symbol *s, short ac, Atom *av)
{
	t_stft *x;
	float *buf;
	long i;
	long bs = sys_getblksize();
	
	long fftsize, hop;
	
	x = (t_stft *)newobject(stft_class);
	
	if ((ac > 0) && (av[0].a_type == A_SYM)) {
		x->x_sdifbufname = av[0].a_w.w_sym;
	}
	else {
		x->x_sdifbufname = 0L;
		post("SDIF-stft~: need a SDIF buffer name as 1st arg",0);
	}
		
	if ((ac > 1) && (av[1].a_type == A_LONG))
		fftsize = av[1].a_w.w_long;
	else
		fftsize = stft_DEFAULT_POINTS;
		
	if (fftsize != (1 << ilog2(fftsize))) {
		fftsize = 1 << ilog2(fftsize);
		error("SDIF-stft~: power of two required for fft size - using %ld", fftsize);
	}
	
	if ((ac > 2) && (av[2].a_type == A_LONG))
		hop = av[2].a_w.w_long;
	else
		hop = 2;
	
	if ( hop != 2 ) {
		error("SDIF-stft~: overlap must be 2 or 4 right now - setting to 2");
		hop = 2;
	}
	
	if (fftsize < stft_MIN_POINTS)
		error("SDIF-stft~: minimum size %ld", fftsize = stft_MIN_POINTS);
	else if (fftsize > stft_MAX_POINTS)
		error("SDIF-stft~: maximum size %ld", fftsize = stft_MAX_POINTS);

	hop = fftsize / hop; // hop is now defined in samples instead of x overlap
	
	// this is not very good well done because overlap should be 2 4 or 8
	if (hop < bs){
		hop = bs;
		error("SDIF-stft~: HOP must be multiple of %ld, setting to %ld", bs,hop);
	}
	
	x->x_fftsize = fftsize;
	x->x_sdifbufsize = (fftsize/2) +1;
	x->x_hop = hop;
	
	dsp_setup((t_pxobject *)x,1);
	x->x_outlet = outlet_new(x, "signal");
	
	x->x_obj.z_misc = Z_NO_INPLACE;
	x->x_in = t_getbytes(fftsize * sizeof(float));
	x->x_out = t_getbytes(fftsize * sizeof(float));
	x->x_window = t_getbytes(fftsize * sizeof(float));
	x->x_sdifbuf = t_getbytes(x->x_sdifbufsize * sizeof(t_complex));
	//x->x_twiddle = t_getbytes(CMAX * fftsize * sizeof(float));
	
	for (i=0; i < fftsize; i++) {
		x->x_in[i] = 0;
		x->x_out[i] = 0;
	}
	for (i=0; i < fftsize; i++) { 
		// hanning window
		x->x_window[i] = sqrt(0.5 * (1. + cos(3.14159 + 3.14159 * 2.* i/fftsize)));
	}
	x->x_inptr = x->x_in;
	x->x_outptr = x->x_out;

	x->x_1overpts = 1. / x->x_fftsize;
	
	return (x);
}
Beispiel #19
0
void *HoaDecode_new(t_symbol *s, long argc, t_atom *argv)
{
	t_HoaDecode *x = NULL;
	int order = 4;
    
    x = (t_HoaDecode *)object_alloc((t_class*)HoaDecode_class);
	if(x)
	{
		if(atom_gettype(argv) == A_LONG || atom_gettype(argv) == A_FLOAT)
			order	= atom_getfloat(argv);
		
        /* Base Attributes */
		x->f_mode = gensym("ambisonics");
        x->f_number_of_loudspeakers =  order * 2 + 2;
        x->f_pinna_size = gensym("small");
        x->f_resitution_mode = gensym("panning");
        x->f_send_config =1;
#ifdef MAC_VERSION
        // OSX only : access to the hoa.binaural~ bundle
        CFBundleRef hoaBinaural_bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.cicm.hoa-decoder-"));
        CFURLRef hoaBinaural_ref = CFBundleCopyBundleURL(hoaBinaural_bundle);
        UInt8 bundle_path[512];
        Boolean res = CFURLGetFileSystemRepresentation(hoaBinaural_ref, true, bundle_path, 512);
        assert(res);
        // Built the complete resource path
        std::string absoluteHrtfFilePath = std::string((const char*)bundle_path) + std::string("/Contents/Resources/") + std::string("HrtfDatabase/");
#endif
#ifdef WIN_VERSION

#ifdef WIN64
		HMODULE handle = LoadLibrary("hoa.decoder~.mxe64");
		char bundle_path[512];
		GetModuleFileName(handle, bundle_path, 512);
        std::string absoluteHrtfFilePath = std::string((const char*)bundle_path);
		absoluteHrtfFilePath.erase(absoluteHrtfFilePath.size()-18, 18);
		absoluteHrtfFilePath.append("HrtfDatabase/");
		FreeLibrary(handle);

#else
		HMODULE handle = LoadLibrary("hoa.decoder~.mxe");
		char bundle_path[512];
		GetModuleFileName(handle, bundle_path, 512);
        std::string absoluteHrtfFilePath = std::string((const char*)bundle_path);
		absoluteHrtfFilePath.erase(absoluteHrtfFilePath.size()-16, 16);
		absoluteHrtfFilePath.append("HrtfDatabase/");
		FreeLibrary(handle);
		
#endif
#endif
		x->f_AmbisonicsDecoder	= new AmbisonicsMultiDecoder(order, x->f_number_of_loudspeakers, Hoa_Dec_Ambisonic, Hoa_Small, absoluteHrtfFilePath, sys_getblksize(), sys_getsr());

		for(int i = 0; i < x->f_AmbisonicsDecoder->getNumberOfLoudspeakers(); i++)
            x->f_angles_of_loudspeakers[i] = x->f_AmbisonicsDecoder->getLoudspeakerAngle(i);
		
        object_attr_setdisabled((t_object *)x, gensym("angles"), 1);
        object_attr_setdisabled((t_object *)x, gensym("pinnaesize"), 1);
        object_attr_setdisabled((t_object *)x, gensym("loudspeakers"), 0);
        object_attr_setdisabled((t_object *)x, gensym("restitution"), 1);
        
        /* DSP Setup */
		dsp_setup((t_pxobject *)x, x->f_AmbisonicsDecoder->getNumberOfInputs());
		for (int i = 0; i < x->f_AmbisonicsDecoder->getNumberOfOutputs(); i++) 
			outlet_new(x, "signal");
		
        attr_args_process(x, argc, argv);
		x->f_ob.z_misc = Z_NO_INPLACE;
	}
    
	return (x);
}