/*-------------------------------------------------------------------- * flite_synth : synthesize current text-buffer *--------------------------------------------------------------------*/ void flite_synth(t_flite *x) { cst_wave *wave; int i,vecsize; t_garray *a; t_float *vec; # ifdef FLITE_DEBUG post("flite: got message 'synth'"); # endif // -- sanity checks if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { pd_error(x,"flite: no such array '%s'", x->x_arrayname->s_name); return; } if (!x->textbuf) { pd_error(x,"flite: attempt to synthesize empty text-buffer!"); return; } # ifdef FLITE_DEBUG post("flite: flite_text_to_wave()"); # endif wave = flite_text_to_wave(x->textbuf,voice); if (!wave) { pd_error(x,"flite: synthesis failed for text '%s'", x->textbuf); return; } // -- resample # ifdef FLITE_DEBUG post("flite: cst_wave_resample()"); # endif cst_wave_resample(wave,sys_getsr()); // -- resize & write to our array # ifdef FLITE_DEBUG post("flite: garray_resize(%d)", wave->num_samples); # endif garray_resize(a, wave->num_samples); if (!garray_getfloatarray(a, &vecsize, &vec)) pd_error(x,"flite: bad template for write to array '%s'", x->x_arrayname->s_name); # ifdef FLITE_DEBUG post("flite: ->write to garray loop<-"); # endif for (i = 0; i < wave->num_samples; i++) { *vec++ = wave->samples[i]/32767.0; } // -- outlet synth-done-bang outlet_bang(x->x_obj.ob_outlet); // -- cleanup delete_wave(wave); // -- redraw garray_redraw(a); }
void maxfreq(t_gendyn *x, double l){ if(l < 0) l = 0; if(l > sys_getsr()) l = sys_getsr(); x->g_maxfreq = l; }
static void pique_doit(int npts, t_word *fpreal, t_word *fpimag, int npeak, int *nfound, t_float *fpfreq, t_float *fpamp, t_float *fpampre, t_float *fpampim, t_float errthresh) { t_float srate = sys_getsr(); /* not sure how to get this correctly */ t_float oneovern = 1.0/ (t_float)npts; t_float fperbin = srate * oneovern; t_float pow1, pow2 = 0, pow3 = 0, pow4 = 0, pow5 = 0; t_float re1, re2 = 0, re3 = fpreal->w_float; t_float im1, im2 = 0, im3 = 0, powthresh, relativeerror; int count, peakcount = 0, n2 = (npts >> 1); t_float *fp1, *fp2; t_word *wp1, *wp2; for (count = n2, wp1 = fpreal, wp2 = fpimag, powthresh = 0; count--; wp1++, wp2++) powthresh += (wp1->w_float) * (wp1->w_float) + (wp2->w_float) * (wp2->w_float) ; powthresh *= 0.00001; for (count = 1; count < n2; count++) { t_float windreal, windimag, pi = 3.14159; t_float detune, pidetune, sinpidetune, cospidetune, ampcorrect, freqout, ampout, ampoutreal, ampoutimag; t_float rpeak, rpeaknext, rpeakprev; t_float ipeak, ipeaknext, ipeakprev; t_float errleft, errright; fpreal++; fpimag++; re1 = re2; re2 = re3; re3 = fpreal->w_float; im1 = im2; im2 = im3; im3 = fpimag->w_float; if (count < 2) continue; pow1 = pow2; pow2 = pow3; pow3 = pow4; pow4 = pow5; /* get Hanning-windowed spectrum by convolution */ windreal = re2 - 0.5 * (re1 + re3); windimag = im2 - 0.5 * (im1 + im3); pow5 = windreal * windreal + windimag * windimag; /* if (count < 30) post("power %f", pow5); */ if (count < 5) continue; /* check for a peak. The actual bin is count-3. */ if (pow3 <= pow2 || pow3 <= pow4 || pow3 <= pow1 || pow3 <= pow5 || pow3 < powthresh) continue; /* go back for the raw FFT values around the peak. */ rpeak = fpreal[-3].w_float; rpeaknext = fpreal[-2].w_float; rpeakprev = fpreal[-4].w_float; ipeak = fpimag[-3].w_float; ipeaknext = fpimag[-2].w_float; ipeakprev = fpimag[-4].w_float; /* recalculate Hanning-windowed spectrum by convolution */ windreal = rpeak - 0.5 * (rpeaknext + rpeakprev); windimag = ipeak - 0.5 * (ipeaknext + ipeakprev); detune = ((rpeakprev - rpeaknext) * (2.0 * rpeak - rpeakprev - rpeaknext) + (ipeakprev - ipeaknext) * (2.0 * ipeak - ipeakprev - ipeaknext)) / (4.0 * pow3); /* if (count < 30) post("detune %f", detune); */ if (detune > 0.7 || detune < -0.7) continue; /* the frequency is the sum of the bin frequency and detuning */ freqout = fperbin * ((t_float)(count-3) + detune); pidetune = pi * detune; sinpidetune = sin(pidetune); cospidetune = cos(pidetune); ampcorrect = 1.0 / hanning(pidetune, sinpidetune); /* Multiply by 2 to get real-sinusoid peak amplitude and divide by N to normalize FFT */ ampcorrect *= 2. * oneovern; /* amplitude is peak height, corrected for Hanning window shape */ ampout = ampcorrect * sqrt(pow3); ampoutreal = ampcorrect * (windreal * cospidetune - windimag * sinpidetune); ampoutimag = ampcorrect * (windreal * sinpidetune + windimag * cospidetune); if (errthresh > 0) { /* post("peak %f %f", freqout, ampout); */ errleft = peakerror(fpreal-4, fpimag-4, pidetune+pi, 2. * oneovern, ampoutreal, ampoutimag); errright = peakerror(fpreal-2, fpimag-2, pidetune-pi, 2. * oneovern, ampoutreal, ampoutimag); relativeerror = (errleft + errright)/(ampout * ampout); if (relativeerror > errthresh) continue; } /* post("power %f, error %f, relative %f", pow3, errleft + errright, relativeerror); */ *fpfreq++ = freqout; *fpamp++ = ampout; *fpampre++ = ampoutreal; *fpampim++ = ampoutimag; if (++peakcount == npeak) break; } *nfound = peakcount; }
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); }
// Create - Contruction of signal inlets and outlets void *autotune_new(t_symbol *s, int argc, t_atom *argv) { unsigned long sr; int fft_window = 0; int fft_hop = 0; t_autotune *x = (t_autotune *)pd_new(autotune_class); if (argc && argv->a_type == A_FLOAT) // got FFT window { fft_window = (int)atom_getint(argv); if (fft_window < 0) fft_window = 0; if (!autotune_power_of_two(fft_window)) fft_window = 0; argv++; argc--; } if (argc && argv->a_type == A_FLOAT) // got hop number { fft_hop = (int)atom_getint(argv); if (fft_hop < 2 || fft_hop > 32) fft_hop = 0; argv++; argc--; } if (fft_window != 0) x->cbsize = fft_window; if (fft_hop != 0) x->noverlap = fft_hop; if(sys_getsr()) sr = sys_getsr(); else sr = 44100; autotune_init(x , sr); // second argument = number of signal inlets //dsp_setup((t_object *)x, 1); //inlet_new(&x->x_obj, &x->x_obj.ob_pd,gensym("signal")); //inlet_new(&x->x_obj, &x->x_obj.ob_pd,gensym("signal"), gensym("signal")); //floatinlet_new (&x->x_obj, &x->fAmount); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("correct")); //floatinlet_new (&x->x_obj, &x->fGlide); //floatinlet_new (&x->x_obj, &x->fSmooth); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("smooth")); //floatinlet_new (&x->x_obj, &x->fMix); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("mix")); //floatinlet_new (&x->x_obj, &x->fShift); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("shift")); //floatinlet_new (&x->x_obj, &x->fTune); //inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("tune")); //floatinlet_new (&x->x_obj, &x->fPersist); //symbolinlet_new (&x->x_obj, &x->fAmount); outlet_new(&x->x_obj, gensym("signal")); //x->f_out = outlet_new(&x->x_obj, &s_float); x->confout = outlet_new(&x->x_obj, &s_float); x->periodout = outlet_new(&x->x_obj, &s_float); //x->confout = outlet_new(x, "float"); //x->periodout = outlet_new(x, "float"); x->clock = clock_new(x,(t_method)autotune_processclock); x->clockinterval = 10.; return (x); // Return the pointer }
void gendy_dsp(t_gendy *x, t_signal **sp, short *count){ x->mFreqMul = (float) 1.f/sys_getsr(); dsp_add(gendy_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); }
void *pitcher_new(Symbol *s, short argc, Atom *argv) { /* Lowest pitch to allow from the pitch detector. Lower pitches are interpreted * as a "don't know." A "don't know" causes the input signal to pass through * this external unmodified. */ float min_pitch; /* approx. input-output delay, in samples. */ int delay_samps; int i; t_pitcher *x; if (argc == 0) { min_pitch = MINIMUM_PITCH; delay_samps = OUTPUT_BUFFER_DELAY; } else if (argc == 1) { if (argv[0].a_type == A_FLOAT) { min_pitch = (float)argv[0].a_w.w_float; } else if (argv[0].a_type == A_LONG) { min_pitch = (float)argv[0].a_w.w_long; } else { goto argerror; } } else if (argc == 2) { if (argv[0].a_type == A_FLOAT) { min_pitch = (float)argv[0].a_w.w_float; } else if (argv[0].a_type == A_LONG) { min_pitch = (float)argv[0].a_w.w_long; } else { goto argerror; } if (argv[1].a_type == A_FLOAT) { delay_samps = (int)argv[1].a_w.w_float; } else if (argv[1].a_type == A_LONG) { delay_samps = (int)argv[1].a_w.w_long; } else { goto argerror; } } else { goto argerror; } if ((min_pitch <= 0) || (delay_samps <= 0) ){ error("pitcher~: Minimum pitch and Delay samples must be positive!"); goto argerror; } post ("*** pitcher~: Minimum pitch %f Hz, %ld delay samples", min_pitch, delay_samps); post ("*** pitcher~: latency = minimum pitch (in samples) + delay samples"); x = (t_pitcher *)newobject(pitcher_class); /* x->outlet = listout(x); x->outputQelem = qelem_new(x, OutputProcedure); */ dsp_setup((t_pxobject *)x,3); // The object has 3 signal inlets: audio in, pitch scale factor, pitch in outlet_new((t_object *)x, "signal"); // Add a signal outlet. x->sampleRate = sys_getsr(); // Set the sampling rate. x->outputDelay = delay_samps; x->ringBufSize = (int) (2*delay_samps); x->minimumPitch = min_pitch; x->minimumPitchSamps =(int)((1/x->minimumPitch)*x->sampleRate); /* Initialize input ring buffer */ x->inputRingBuf = 0; x->inputRingBufWritePos = 0; // Allocate memory for the input circular buffer. x->inputRingBuf = (float *)t_getbytes((long) (x->ringBufSize* sizeof(float))); // Check if the allocation suceeded. if (x->inputRingBuf == NULL) { ouchstring("pitcher~: out of memory!"); x->ringBufSize = 0; return; } // Initiallize the input circular buffer to a zero value in each element. for (i = 0; i<x->ringBufSize; i++) { x->inputRingBuf[i] = 0.0f; } /* Initialize output ring buffer */ x->outputRingBuf = 0; x->outputRingBufPitchMarkerPos = 0; // Allocate memory for the output circular buffer. x->outputRingBuf = (float *)t_getbytes((long) (x->ringBufSize* sizeof(float))); // Check if the allocation suceeded. if (x->outputRingBuf == NULL) { ouchstring("pitcher~: out of memory!"); x->ringBufSize = 0; return; } // Initiallize the output circular buffer to a zero value in each element. for (i = 0; i<x->ringBufSize; i++) { x->outputRingBuf[i] = 0.0f; } /* Initialize the current output ring buffer read postition. * Maybe need to add ringBuffSize because % does not like negative numbers? */ x->readPos = (x->inputRingBufWritePos - x->outputDelay + x->ringBufSize) % x->ringBufSize; //x->readPos = 98000; // FOR DEBUG /* Initialize this to 0 so that the <inputPeriodLength> parameter will be updated in the first * call to the perform method. */ x->samplesLeftInPeriod = 0; x->inputPeriodLength = 100; x->isUnvoiced = 1; // Set unvoiced until we get a pitch to use. return (x); argerror: error("pitcher~: usage: pitcher~ [Minimum input pitch] [Delay samples]"); post("If only 1 arg, it sets minimum input pitch."); post("If no args, minimum pitch and delay samples use default of %f Hz, %ld delay samples.", (float) MINIMUM_PITCH, (long) OUTPUT_BUFFER_DELAY); return 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); }
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); }
static t_int *voicing_detector_tilde_perform(t_int *w) { t_voicing_detector_tilde *x = (t_voicing_detector_tilde *)(w[1]); t_voicing_control *ctl = (t_voicing_control *)(w[2]); t_int n = (int)(w[3]); t_float *in = ctl->c_input; if (x->f_high < x->f_low) { float tmp = x->f_low; x->f_low = x->f_high; x->f_high = tmp; } t_float current, previous, next, temp0, temp1, avg, max, peak0; current = previous = next = temp0 = temp1 = avg = max = peak0 = 0; t_float min = 1000; t_float samplerate = sys_getsr(); t_float start = samplerate / x->f_high; start = start > 1 ? start : 1; t_float end = samplerate / x->f_low; end = end < (n-1) ? end : n-1; t_float result, prob, diff, diff2; t_int i = 0; int j; int l = n; int maxp = 0; int maxi = 0; float temp[n]; ctl->f_sum_abs = 0.0; for (i=0;i<l;i++) { ctl->f_sum_abs += fabs(in[i]); /* I have to calculate f_sum_abs for the whole block before I can calculate amdf */ temp[i] = 0.0; SETFLOAT(&ctl->otemp[i], 0.0); } for (i=1;i<l;i++) { temp1 = 0; for (j=start;j<=end;j++) /* the Average Magnitude Difference Function */ { temp[j] = i + j < l ? in[i+j] : 0.0; temp0 = atom_getfloatarg(i, 4096, ctl->otemp); temp1 += fabs(in[j] - temp[j]); } temp1 += ((float)i / (float)l) * ctl->f_sum_abs; SETFLOAT(&ctl->otemp[i], temp1); } for (i=start+1;i<end;i++) { previous= atom_getfloatarg(i-1, 2048, ctl->otemp); current = atom_getfloatarg(i, 2048, ctl->otemp); next = atom_getfloatarg(i+1, 2048, ctl->otemp); max = current > max ? current : max; min = current < min ? current : min; avg += current; } avg = avg / (end-start); diff = avg - min; diff2 = max - min; result = ctl->method == 0 ? ((avg - min) > (x->f_thresh) ? 1 : 0) : ((max - min) > x->f_thresh ? 1 : 0); prob = diff2 / max; outlet_float(x->prob, prob); outlet_float(x->voiced, result); return(w+4); }
/* open method. Called as: open [args] filename with args as in ambixwrite_argparse(). */ static void ambix_write_open(t_ambix_write *x, t_symbol *s, int argc, t_atom *argv) { t_symbol *filesym; t_float samplerate; ambix_fileformat_t fileformat; ambix_sampleformat_t sampleformat; if (x->x_state != STATE_IDLE) { ambix_write_stop(x); } if (ambixwrite_argparse(x, &argc, &argv, &filesym, &fileformat, &sampleformat, &samplerate)) { pd_error(x, "ambix_write~: usage: open [-bytes [234]] [-rate ####] filename"); return; } if (argc) pd_error(x, "extra argument(s) to ambix_write~: ignored"); pthread_mutex_lock(&x->x_mutex); while (x->x_requestcode != REQUEST_NOTHING) { pthread_cond_signal(&x->x_requestcondition); pthread_cond_wait(&x->x_answercondition, &x->x_mutex); } //x->x_bytespersample = bytespersamp; x->x_filename = filesym->s_name; x->x_fileformat = fileformat; x->x_requestcode = REQUEST_OPEN; x->x_sampleformat = sampleformat; x->x_fifotail = 0; x->x_fifohead = 0; x->x_eof = 0; x->x_fileerror = 0; x->x_state = STATE_STARTUP; if(0){} #if 0 else if (samplerate > 0) x->x_samplerate = samplerate; #endif else if (x->x_insamplerate > 0) x->x_samplerate = x->x_insamplerate; else x->x_samplerate = sys_getsr(); /* set fifosize from bufsize. fifosize must be a multiple of the number of bytes eaten for each DSP tick. */ x->x_fifosize = x->x_bufframes-(x->x_bufframes%x->x_vecsize); /* arrange for the "request" condition to be signalled 16 times per buffer */ x->x_sigcountdown = x->x_sigperiod = (x->x_fifosize / (16 * x->x_vecsize)); pthread_cond_signal(&x->x_requestcondition); pthread_mutex_unlock(&x->x_mutex); }
static t_float calc_coa(t_float hlife) { return (exp(LN2 * 1000 / (((hlife > 0)?hlife:15) * sys_getsr()))); }
/* calcs */ static t_float calc_holdsamples(t_float htime, int buf) { /* hold_time must be greater than buffer_time to make sure that any peak_sample is amplified with its own factor */ t_float min_hold = buf / sys_getsr(); return (0.001 * sys_getsr() * ((htime > min_hold)?htime:((min_hold > 50)?min_hold:50))); }
void *ambipan_tilde_new(t_symbol *s, int argc, t_atom *argv ) { int i, hp, newVersion; char car = 'c'; //--------- Allocation de la dataspace ---------------------------// t_ambipan_tilde *x = (t_ambipan_tilde*)object_alloc(ambipan_tilde_class); /*********************************************************/ /*R�cup�ration du nombre de sorties et de haut-parleurs. */ if( argc >= 1 ){ if( argv[0].a_type == A_LONG ) x->N = argv[0].a_w.w_long; else x->N = 0; } else x->N = Ndefaut; if( Nmax < x->N || 2 > x->N ){ x->N = Ndefaut; object_error((t_object *)x, "Bad number of loudspeaker setup, %d by default", Ndefaut); } x->Nout = x->N; //M�me nombre de sorties et d'haut-parleur. /*R�cup�ration du type rep�re ************************/ if( argc >=2 ){ if( argv[1].a_type == A_SYM ) car = (char)(atom_getsym(argv+1)->s_name[0]); if( car == 'c' ) x->base=1; else if( car == 'p' ) x->base=0; else { x->base=1; object_error((t_object *)x, "Unknown type of coordinates, cartesian by default"); } } else x->base = 1; //Cart�sienne par d�faut. /*R�cup�ration du type des entr�es (pour des questions de compatibilit� avec l'ancienne version) *******************/ if( argc >=3 && argv[2].a_type == A_SYM){ object_error((t_object *)x, "The signal/control argument has no effect in this version"); newVersion = 0; } else newVersion = 1; if (!newVersion) { // si ancienne version : arg 4 = offset, arg 5 = interp time : /*R�cup�ration de l'offset ***************************/ if( argc >= 4 && (atom_gettype(argv+3) == A_FLOAT || atom_gettype(argv+3) == A_LONG) ) x->offset = fabs(atom_getfloat(argv+3)); else x->offset = (float)OFFSET; if( x->offset <= EPSILON ){ object_error((t_object *)x, "No negative offset please"); x->offset = (float)OFFSET;; } /*R�cup�ration du temps d'interpolation **************/ if( argc >= 5 && argv[4].a_type == A_LONG ) x->dtime = (int)(argv[4].a_w.w_long*sys_getsr()/1000.); else x->dtime = DTIME*sys_getsr()/1000.; if( x->dtime <= 0 ) //Pas de temps d'interpolation nul ou n�gatif. x->dtime = 1; } else { // si ancienne version : arg 3 = offset, arg 4 = interp time : /*R�cup�ration de l'offset ***************************/ if( argc >= 3 && (atom_gettype(argv+2) == A_FLOAT || atom_gettype(argv+2) == A_LONG) ) x->offset = fabs(atom_getfloat(argv+2)); else x->offset = (float)OFFSET; if( x->offset <= EPSILON ){ object_error((t_object *)x, "No negative offset please"); x->offset = (float)OFFSET;; } /*R�cup�ration du temps d'interpolation **************/ if( argc >= 4 && argv[3].a_type == A_LONG ) x->dtime = (int)(argv[3].a_w.w_long*sys_getsr()/1000.); else x->dtime = DTIME*sys_getsr()/1000.; if( x->dtime <= 0 ) //Pas de temps d'interpolation nul ou negatif. x->dtime = 1; } /*********************************************************/ /*Initialisation des donn�es de la classe. ***************/ for( hp = x->N-1; hp >= 0; hp--) //Initialisation des P x->P[hp] = 0; x->mute= 0; //entr�es signal non mut�es x->y = Ydefaut; //initialisation de y x->phi = Phidefaut; //initialisation de phi //Initialisation des angles des haut-parleurs et des rayons, for( hp=0; hp<x->N; hp++) { x->teta[hp] = (float)( Pi*( .5 + (1 - 2*hp )/(float)x->N) ); x->dist[hp] = 1; } /*********************************************************/ /* Cr�ation des tableaux cosinus, cos_teta et sin_teta. */ /* pour l'audio. */ x->cos_teta = (float*)getbytes( (short)((T_COS+2*x->N)*sizeof(float)) ); x->sin_teta = x->cos_teta+x->N; //Pr�calculs des cos et sin des haut-parleurs. for( hp=0; hp<x->N; hp++){ x->cos_teta[hp] = (float)cos( x->teta[hp] ); x->sin_teta[hp] = (float)sin( x->teta[hp] ); } //Remplissage du tableau cosinus, x->cosin = x->sin_teta+x->N; /*Pour avoir besoin de cos( phi ), on cherche: cos(phi) = cosin[ (int)( phi*T_COS/360 ))&(((int)T_COS-1) ] */ for( i=0; i<T_COS; i++) x->cosin[i] = (float)cos( i*2*Pi/T_COS ); /*********************************************************/ //initialisation de x, X, Y, W et Pn par la m�thode recoit x. if(x->base) ambipan_tilde_recoit_x( x, Xdefaut); else ambipan_tilde_recoit_x( x, Rdefaut); /*********************************************************/ /*Cr�ation des nouvelles entr�es. ************************/ dsp_setup((t_pxobject *)x, 3); /*Cr�ation des sorties************************************/ for(i=0; i < x->N; i++) outlet_new((t_object *)x, "signal"); return (void *)x; }
static void *dkfm_tilde_new(t_symbol *s, int argc, t_atom * argv){ int i,j; t_dkfm_tilde *x = (t_dkfm_tilde *)pd_new(dkfm_tilde_class); //setting defaults t_float freq = 0.; t_float carharm = 1; x->x_carphs = 0.f; //init mod arrays for(i=0; i<FMMMOD; i++){ x->x_modharm[i] = 0.f; x->x_modidx[i] = 0.; x->x_modphs[i] = 0.; }; //now parse args int curarg = 0; //current arg number int nummod = 0; //number of modulators while(argc){ if(argv->a_type == A_FLOAT){ t_float curfloat = atom_getfloatarg(0, argc, argv); if(curarg == 0){ //first arg is freq freq = curfloat; } else if(curarg == 1){ carharm=harmbounds(curfloat); } else{ int idx = (int)(curarg/2) - 1; //index for arrays if(curarg % 2 == 0){ //even args = harmonics x->x_modharm[idx] = harmbounds(curfloat); nummod++; } else{ //odd indices = indices x->x_modidx[idx] = (double)curfloat; }; }; } else{ goto errstate; }; //increment/decrement curarg++; argc--; argv++; }; dkmakesintab(); x->x_sin = dksintab; x->x_nummod = nummod; x->x_freq = freq; x->x_carharm = carharm; x->x_conv = ((double)TABLEN)/(double)sys_getsr(); x->x_carhlet = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("carharm")); x->x_modhlet = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_list, gensym("modharm")); x->x_modilet = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_list, gensym("modidx")); x->x_phaselet = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); x->x_outlet = outlet_new(&x->x_obj, gensym("signal")); return (x); errstate: pd_error(x, "dkfm~: improper args"); return NULL; }
void ep_ambipan::getInfo() { int hp; object_post(ep_MSP::getObjectPointer(), "Info Ambipan~ : "); if(this->base) post(" coordonnees cartesiennes,"); else post(" coordonnees polaires,"); post(" offset = %f,", this->offset); post(" temps d'interpolation (pour le controle) = %d ms,", (int)(this->dtime*1000/sys_getsr())); post(" nombre de haut-parleurs = %d," , this->N); post(" position des haut-parleurs:"); for( hp=0; hp<this->N-1; hp++) post(" hp n°%d: %f.x + %f.y,", hp+1, this->dist[hp]*cos(this->teta[hp]), this->dist[hp]*sin(this->teta[hp])); post(" hp n°%d: %f.x + %f.y.", hp+1, this->dist[hp]*cos(this->teta[hp]), this->dist[hp]*sin(this->teta[hp])); post(" ***"); }
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); } }
static void *oggamp_new(t_floatarg fdographics, t_floatarg fnchannels, t_floatarg fbufsize) { t_oggamp *x; int nchannels = fnchannels, bufsize = fbufsize * 1024, i; float *buf; if (nchannels < 1) nchannels = 2; /* two channels as default */ else if (nchannels > MAXSTREAMCHANS) nchannels = MAXSTREAMCHANS; /* check / set buffer size */ if (!bufsize) bufsize = DEFBUFPERCHAN * nchannels; else if (bufsize < MINBUFSIZE) bufsize = MINBUFSIZE; else if (bufsize > MAXBUFSIZE) bufsize = MAXBUFSIZE; buf = getbytes(bufsize*sizeof(t_float)); if (!buf) return (0); x = (t_oggamp *)pd_new(oggamp_class); for (i = 0; i < nchannels; i++) outlet_new(&x->x_obj, gensym("signal")); x->x_noutlets = nchannels; x->x_connection = outlet_new(&x->x_obj, gensym("float")); x->x_clock = clock_new(x, (t_method)oggamp_tick); x->x_outvec = (t_sample **)getbytes(nchannels * sizeof(t_sample *)); pthread_mutex_init(&x->x_mutex, 0); pthread_cond_init(&x->x_requestcondition, 0); pthread_cond_init(&x->x_answercondition, 0); x->x_vecsize = 2; x->x_disconnect = 0; x->x_state = STATE_IDLE; x->x_canvas = canvas_getcurrent(); x->x_streamchannels = 2; x->x_fd = -1; x->x_buf = buf; x->x_bufsize = bufsize; x->x_siginterval = 16; /* signal 16 times per buffer */ x->x_fifosize = x->x_fifohead = x->x_fifotail = x->x_fifobytes = x->x_requestcode = 0; x->x_connectstate = 0; /* indicating state of connection */ x->x_samplerate = x->x_streamrate = sys_getsr(); x->x_resample = 0; x->x_vorbis = 0; x->x_sync = 0; x->x_recover = -1; /* just ignore buffer underruns */ /* graphical buffer status display */ x->x_graphic = (int)fdographics; x->x_canvas = canvas_getcurrent(); logpost(NULL, 4, oggamp_version); post("oggamp~: set buffer to %dk bytes", bufsize/1024); /* start child thread */ pthread_create(&x->x_childthread, 0, oggamp_child_main, x); return (x); }
void *gendy_new(t_symbol *s, long ac, t_atom *av){ t_gendy *x = NULL; long init_cps; x = (t_gendy *)object_alloc(gendy_class); if (x) { dsp_setup((t_pxobject *)x, 0); x->mFreqMul = (float) 1.f/sys_getsr(); x->mPhase = 1.f; //should immediately decide on new target x->mAmp = 0.0; x->mNextAmp = 0.0; x->mSpeed = 100; x->mIndex = 0; // if the first value is a long use it as our number of cps // non incremented av always points to the first value in the atom array if (attr_args_offset(ac, av) > 0 && atom_gettype(av) == A_LONG) { init_cps = atom_getlong(av); if(init_cps>0){ x->g_cps = (int) init_cps; object_post((t_object*) x, "number of cps: %d", x->g_cps); } else { x->g_cps = CONTROL_POINTS; object_error((t_object*) x, "number of cps too small, setting to default (12)"); } } else { x->g_cps = CONTROL_POINTS; object_post((t_object*)x, "no number of cps supplied, using the default (12)"); } x->mMemoryAmp = (float*)sysmem_newptr(x->g_cps * sizeof(float)); x->mMemoryDur = (float*)sysmem_newptr(x->g_cps * sizeof(float)); // defaults x->g_ampdist = 0; x->g_durdist = 0; x->g_adparam = 1.f; x->g_ddparam = 1.f; x->g_minfreq = 440.f; x->g_maxfreq = 660.f; x->g_ampscale = 0.5f; x->g_durscale = 0.5f; // process the attributes after the defaults have been set attr_args_process(x, ac, av); // set up the random generator x->rgen.init(rand()); //initialise to zeroes and separations int i=0; for(i=0; i < x->g_cps; ++i) { x->mMemoryAmp[i] = 2 * x->rgen.frand() - 1.0; x->mMemoryDur[i] = x->rgen.frand(); } outlet_new((t_object *)x, "signal"); } return (x); }
void *grans_new(t_symbol *s, long argc, t_atom *argv) { int n; t_grans *x = (t_grans *)object_alloc(grans_class); if (x) { dsp_setup((t_pxobject *)x, 6); //object_post((t_object *)x, "%d agrc", argc); x->maxoscillators = DEFAULTMAXOSCILLATORS; if( argc > 0) { int i; t_atom *ap; for (i = 0, ap = argv; i < argc; i++, ap++) { if(atom_gettype(ap) == A_LONG) { switch(i){ case 0: n = atom_getlong(ap); x->maxoscillators = n; // object_post((t_object *)x, "%d oscillators initialized", n); break; case 1: n = atom_getlong(ap); x->numoutlets = n; // object_post((t_object *)x, "%d outlets?", n); while(n--){ outlet_new(x, "signal"); } default: break; } } } } else { x->numoutlets = 1; outlet_new(x, "signal"); // outlet_new(x, "signal"); } x->ob.z_misc |= Z_NO_INPLACE; x->base = (t_osc *)calloc(x->maxoscillators, sizeof(t_osc)); x->sinetab = (double *)calloc(STABSZ, sizeof(double)); x->wind_costab = (double *)calloc(STABSZ, sizeof(double)); x->expdecaytab = (double *)calloc(STABSZ, sizeof(double)); x->dampedsinetab = (double *)calloc(STABSZ, sizeof(double)); x->sincwindow = (double *)calloc(STABSZ, sizeof(double)); double coefshape[NSHAPINGTABS]; PowTableFunction(NSHAPINGTABS, coefshape, 1, 0.0001, 1.0, 2.0); x->exptab = (double **)calloc(NSHAPINGTABS, sizeof(double *)); long i; for(i = 0; i < NSHAPINGTABS; i++){ x->exptab[i] = (double *)calloc(STABSZ, sizeof(double)); if(x->exptab[i]) { PowTableFunction(STABSZ, x->exptab[i], 1, 0.0001, 1.0, coefshape[i] * 10.0); } else { object_error((t_object *)x, "could not allocate memory for lookup table"); } } //put some allocation checking in here probably x->samplerate = sys_getsr(); if(x->samplerate<=0) x->samplerate = 44100; x->sampleinterval = 1.0 / x->samplerate; x->pk = ( STABSZ * x->sampleinterval ) * ( 1l << ( 32 - TPOW )) ; x->pkw = ( STABSZ * x->sampleinterval ) ; x->maxhz = (x->samplerate / 2) * x->pkw; x->nosc = x->next_nosc = 0; x->prev_in1 = 0.0; x->sincripples = 5; //could make this an attribute, or maybe compute sinc in realtime... Makeoscsinetable(x); MakeCosWindow(x); MakeExpDecaytable(x); MakeDampedSineWindow(x); MakeSincWindow(x); grans_clear(x); x->always_on = 0; t_dictionary *d = NULL; d = dictionary_new(); if (d) { attr_args_dictionary(d, argc, argv); attr_dictionary_process(x, d); object_free(d); } } else { object_post((t_object *)x, "this is potentially bad!"); } return (x); }
t_eobj* wrappedClass_new(t_symbol* name, long argc, t_atom* argv) { WrappedClass* wrappedPdClass = NULL; WrappedInstancePtr x = NULL; TTValue sr(sys_getsr()); TTValue v, none; long attrstart = attr_args_offset(argc, argv); // support normal arguments TTErr err = kTTErrNone; // Find the WrappedClass //hashtab_lookup(wrappedPdClasses, name, (t_object**)&wrappedPdClass); wrappedPdClass = (WrappedClass*)wrappedPdClasses[name->s_name]; // If the WrappedClass has a validity check defined, then call the validity check function. // If it returns an error, then we won't instantiate the object. if (wrappedPdClass) { if (wrappedPdClass->validityCheck) err = wrappedPdClass->validityCheck(wrappedPdClass->validityCheckArgument); else err = kTTErrNone; } else err = kTTErrGeneric; if (!err) x = (WrappedInstancePtr)eobj_new(wrappedPdClass->pdClass); if (x) { x->wrappedClassDefinition = wrappedPdClass; x->maxNumChannels = 2; // An initial argument to this object will set the maximum number of channels if (attrstart && argv) x->maxNumChannels = atom_getlong(argv); ttEnvironment->setAttributeValue(kTTSym_sampleRate, sr); if (wrappedPdClass->options && !wrappedPdClass->options->lookup(TT("numChannelsUseFixedRatioInputsToOutputs"), v)) { TTUInt16 inputs; TTUInt16 outputs; inputs = v[0]; outputs = v[1]; x->numInputs = x->maxNumChannels * inputs; x->numOutputs = x->maxNumChannels * outputs; } else if (wrappedPdClass->options && !wrappedPdClass->options->lookup(TT("fixedNumChannels"), v)) { TTUInt16 numChannels; numChannels = v[0]; x->numInputs = numChannels; x->numOutputs = numChannels; } else if (wrappedPdClass->options && !wrappedPdClass->options->lookup(TT("fixedNumOutputChannels"), v)) { TTUInt16 numChannels; numChannels = v[0]; x->numInputs = x->maxNumChannels; x->numOutputs = numChannels; } else { x->numInputs = x->maxNumChannels; x->numOutputs = x->maxNumChannels; } if (wrappedPdClass->options && !wrappedPdClass->options->lookup(TT("additionalSignalInputSetsAttribute"), v)) { x->numControlSignals = v.size(); x->controlSignalNames = new TTSymbol[x->numControlSignals]; for (TTUInt16 i=0; i<x->numControlSignals; i++) { x->numInputs++; x->controlSignalNames[i] = v[i]; } } x->wrappedObject = new TTAudioObject(wrappedPdClass->ttblueClassName, x->maxNumChannels); x->audioIn = new TTAudio(x->numInputs); x->audioOut = new TTAudio(x->numOutputs); attr_args_process(x,argc,argv); // handle attribute args /* x->dumpOut = outlet_new((t_object*)x,NULL); for (short i=1; i < x->numInputs; i++) inlet_new(&x->obj.o_obj, &x->obj.o_obj.ob_pd, &s_signal, &s_signal); */ // eobj_dspsetup(x,x->numInputs,0); // dsp_setup(x, x->numInputs); // inlets //if (wrappedPdClass->options && !wrappedPdClass->options->lookup(TT("numControlOutlets"), v)) // v.get(0, numControlOutlets); if (wrappedPdClass->options && !wrappedPdClass->options->lookup(TT("controlOutletFromNotification"), v)) { TTUInt16 outletIndex = 0; TTSymbol notificationName; outletIndex = v[0]; notificationName = v[1]; // TODO: to support more than one notification->outlet we need see how many args are actually passed-in // and then we need to track them in a hashtab or something... x->controlOutlet = outlet_new((t_object*)x, NULL); x->controlCallback = new TTObject("callback"); x->controlCallback->set("function", TTPtr(&wrappedClass_receiveNotificationForOutlet)); x->controlCallback->set("baton", TTPtr(x)); // dynamically add a message to the callback object so that it can handle the 'objectFreeing' notification x->controlCallback->instance()->registerMessage(notificationName, (TTMethod)&TTCallback::notify, kTTMessagePassValue); // tell the source that is passed in that we want to watch it x->wrappedObject->registerObserverForNotifications(*x->controlCallback); } x->outlets = new t_outlet*[x->numOutputs]; for (short i=0; i < x->numOutputs; i++) x->outlets[i] = outlet_new(&x->obj.o_obj, &s_signal); // x->obj.z_misc = Z_NO_INPLACE; } return (t_eobj*)x; }
static void *pluck_new(t_symbol *s, int argc, t_atom *argv){ t_pluck *x = (t_pluck *)pd_new(pluck_class); s = NULL; ///////////////////////////////////////////////////////////////////////////////////// static int seed = 1; random_init(&x->x_rstate, seed++); float freq = 0; float decay = 0; float cut_freq = 15000; x->x_noise_input = 0; ///// int argnum = 0; int flag = 0; while(argc > 0){ if(argv->a_type == A_FLOAT && !flag){ //if current argument is a float t_float argval = atom_getfloatarg(0, argc, argv); switch(argnum){ case 0: freq = argval; break; case 1: decay = argval; break; case 2: cut_freq = argval; break; default: break; }; argnum++; argc--; argv++; } else if(argv->a_type == A_SYMBOL){ flag = 1; t_symbol *curarg = atom_getsymbolarg(0, argc, argv); if(!strcmp(curarg->s_name, "-in")){ x->x_noise_input = 1; argc--; argv++; } else{ goto errstate; }; } else{ goto errstate; } }; ///////////////////////////////////////////////////////////////////////////////////// x->x_sr = sys_getsr(); x->x_alloc = x->x_last_trig = 0; x->x_xnm1 = x->x_xnm2 = x->x_ynm1 = x->x_ynm2 = 0.; x->x_sum = PLUCK_MAXD; x->x_sz = PLUCK_STACK; // clear out stack buf, set pointer to stack x->x_ybuf = x->x_fbstack; pluck_clear(x); x->x_freq = freq; x->x_maxdel = 1000; // ship off to the helper method to deal with allocation if necessary pluck_sz(x); // inlets / outlet x->x_trig_let = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); x->x_alet = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); pd_float((t_pd *)x->x_alet, decay); x->x_inlet_cutoff = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); pd_float((t_pd *)x->x_inlet_cutoff, cut_freq); if(x->x_noise_input) inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); x->x_outlet = outlet_new((t_object *)x, &s_signal); return (x); errstate: pd_error(x, "[pluck~]: improper args"); return NULL; }
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); }
/* initialize the lame library */ static int mp3write_tilde_lame_init(t_mp3write *x) { time_t now; int ret; x->lgfp = lame_init(); /* set default parameters for now */ #ifndef UNIX /* load lame_enc.dll library */ HINSTANCE dll; dll=LoadLibrary("lame_enc.dll"); if(dll==NULL) { error("mp3write~: error loading lame_enc.dll"); closesocket(x->x_fd); x->x_fd = -1; post("mp3write~: connection closed"); return -1; } #endif { const char *lameVersion = get_lame_version(); post( "mp3write~ : using lame version : %s", lameVersion ); } /* setting lame parameters */ lame_set_num_channels( x->lgfp, 2); lame_set_in_samplerate( x->lgfp, sys_getsr() ); lame_set_out_samplerate( x->lgfp, x->x_samplerate ); lame_set_brate( x->lgfp, x->x_bitrate ); lame_set_mode( x->lgfp, x->x_mp3mode ); lame_set_quality( x->lgfp, x->x_mp3quality ); lame_set_emphasis( x->lgfp, 1 ); lame_set_original( x->lgfp, 1 ); lame_set_copyright( x->lgfp, 1 ); /* viva free music societies !!! */ lame_set_disable_reservoir( x->lgfp, 0 ); lame_set_padding_type( x->lgfp, PAD_NO ); ret = lame_init_params( x->lgfp ); if ( ret<0 ) { post( "mp3write~ : error : lame params initialization returned : %d", ret ); return -1; } else { x->x_lame=1; /* magic formula copied from windows dll for MPEG-I */ x->x_lamechunk = 2*1152; post( "mp3write~ : lame initialization done. (%d)", x->x_lame ); } lame_init_bitstream( x->lgfp ); /* setting tag information */ id3tag_init(x->lgfp); id3tag_v1_only(x->lgfp); id3tag_space_v1(x->lgfp); id3tag_set_artist(x->lgfp, "Pd Session"); now=time(NULL); sprintf( x->x_title, "Started at %s", ctime(&now) ); id3tag_set_title(x->lgfp, x->x_title ); return 0; }
void *HoaRecomposer_new(t_symbol *s, long argc, t_atom *argv) { t_HoaRecomposer *x = NULL; t_dictionary *d; int order = 4, inputs = 10; x = (t_HoaRecomposer *)object_alloc((t_class*)HoaRecomposer_class); if (x) { if(atom_gettype(argv) == A_LONG) order = atom_getlong(argv); if(atom_gettype(argv+1) == A_LONG) inputs = atom_getlong(argv+1); /* Base Attributes */ x->f_ambiRecomposer = new AmbisonicRecomposer(order, inputs, Hoa_Fixe, sys_getblksize(), sys_getsr()); x->f_ambiRecomposer->setRampInMs(20.); x->f_ramp_time = x->f_ambiRecomposer->getRampInMs(); x->f_mode = gensym("fixe"); dsp_setup((t_pxobject *)x, x->f_ambiRecomposer->getNumberOfInputs()); for (int i = 0; i < x->f_ambiRecomposer->getNumberOfOutputs(); i++) outlet_new(x, "signal"); x->f_ob.z_misc = Z_NO_INPLACE; attr_args_process(x, argc, argv); d = (t_dictionary *)gensym("#D")->s_thing; if (d) attr_dictionary_process(x, d); object_attr_setdisabled((t_object *)x, gensym("ramp"), (x->f_mode == gensym("fixe")) ? 1 : 0); } return (x); }
void *centroid_new(t_symbol *s, short argc, t_atom *argv) { t_int i; t_int vs = sys_getblksize(); t_centroid *x = (t_centroid *)newobject(centroid_class); t_float ms2samp; dsp_setup((t_pxobject *)x,2); x->c_clock = clock_new(x,(method)centroid_tick); x->c_outcent = floatout((t_centroid *)x); x->c_Fs = sys_getsr(); x->c_centroid = 0.0f; x->BufWritePos = 0; ms2samp = x->c_Fs * 0.001f; if (argv[0].a_type == A_LONG) x->BufSize = argv[0].a_w.w_long; // Samples else if (argv[0].a_type == A_FLOAT) x->BufSize = (int)(argv[0].a_w.w_float * ms2samp); // Time in ms else x->BufSize = DEFBUFSIZE; if (argv[1].a_type == A_LONG) x->c_overlap = argv[1].a_w.w_long; // Samples else if (argv[1].a_type == A_FLOAT) x->c_overlap = (int)(argv[1].a_w.w_float * ms2samp); // Time in ms else x->c_overlap = x->BufSize/2; if (argv[2].a_w.w_sym == ps_rectangular) x->c_window = Recta; else if (argv[2].a_w.w_sym == ps_hanning) x->c_window = Hann; else if (argv[2].a_w.w_sym == ps_hamming) x->c_window = Hamm; else if (argv[2].a_w.w_sym == ps_blackman) x->c_window = Black; else x->c_window = Black; x->FFTSize = x->BufSize; if (x->BufSize < vs) { x->FFTSize = vs; x->BufSize = vs; } else if ((x->BufSize > vs) && (x->BufSize < 128)) x->FFTSize = 128; else if ((x->BufSize > 128) && (x->BufSize < 256)) x->FFTSize = 256; else if ((x->BufSize > 256) && (x->BufSize < 512)) x->FFTSize = 512; else if ((x->BufSize > 512) && (x->BufSize < 1024)) x->FFTSize = 1024; else if ((x->BufSize > 1024) && (x->BufSize < 2048)) x->FFTSize = 2048; else if ((x->BufSize > 2048) && (x->BufSize < 4096)) x->FFTSize = 4096; else if ((x->BufSize > 8192) && (x->BufSize < 16384)) x->FFTSize = 16384; else if ((x->BufSize > 16384) && (x->BufSize < 32768)) x->FFTSize = 32768; else if (x->BufSize > 32768) { post(" Maximum FFT Size is 65536",0); x->FFTSize = 65536; x->BufSize = 65536; } // Overlap case if (x->c_overlap > x->BufSize-vs) { post(" You can't overlap so much...",0); x->c_overlap = x->BufSize-vs; } else if (x->c_overlap < 1) x->c_overlap = 0; // Allocate memory x->Buf1 = t_getbytes(x->BufSize * sizeof(float)); x->Buf2 = t_getbytes(x->BufSize * sizeof(float)); x->BufFFT = t_getbytes(x->FFTSize * sizeof(float)); x->WindFFT = t_getbytes(x->FFTSize * sizeof(float)); x->memFFT = t_getbytes(CMAX * x->FFTSize * sizeof(float)); // memory allocated for fft twiddle // Compute and store Windows if ((x->c_window > Recta) && (x->c_window <= Black)) { switch (x->c_window) { case Hann: for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = HANNING_W(i, x->FFTSize); break; case Hamm: for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = HAMMING_W(i, x->FFTSize); break; case Black: for (i=0; i<x->FFTSize; ++i) x->WindFFT[i] = BLACKMAN_W(i, x->FFTSize); break; } } return (x); }
static void *dkgoertzel_new(t_symbol *s, int argc, t_atom * argv){ t_dkgoertzel_tilde *x = (t_dkgoertzel_tilde *)pd_new(dkgoertzel_tilde_class); //defaults t_float maxdel = DKGOERTZEL_DELAY; t_float initdel = DKGOERTZEL_MINMS; t_float gain = DKGOERTZEL_DEFGAIN; x->x_sr = sys_getsr(); x->x_alloc = 0; x->x_sz = DKGOERTZ_STACK; //clear out stack bufs, set pointer to stack x->x_ybuf = x->x_fbstack; x->x_xbuf = x->x_ffstack; dkgoertzel_clear(x); int argnum = 0; //current argument while(argc){ if(argv -> a_type == A_FLOAT){ t_float curf = atom_getfloatarg(0, argc, argv); switch(argnum){ case 0: initdel = curf; break; case 1: gain = curf; break; default: break; }; argnum++; argc--; argv++; } else if(argv -> a_type == A_SYMBOL){ t_symbol * cursym = atom_getsymbolarg(0, argc, argv); if(argc>= 2){ if(strcmp(cursym->s_name, "-maxdelay") == 0){ t_float curf = atom_getfloatarg(1, argc, argv); maxdel = curf; } else{ goto errstate; }; argc -=2; argv += 2; } else{ goto errstate; }; }; }; x->x_maxdel = maxdel > 0 ? maxdel : DKGOERTZEL_DELAY; //ship off to the helper method to deal with allocation if necessary dkgoertzel_sz(x); //boundschecking //this is 1/44.1 (1/(sr*0.001) rounded up, good enough? if(initdel < DKGOERTZEL_MINMS){ initdel = DKGOERTZEL_MINMS; } else if(initdel > x->x_maxdel){ initdel = x->x_maxdel; }; //inlets outlets x->x_dellet = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); pd_float((t_pd *)x->x_dellet, initdel); x->x_gainlet = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal); pd_float((t_pd *)x->x_gainlet, gain); x->x_outlet = outlet_new((t_object *)x, &s_signal); return (x); errstate: pd_error(x, "dkgoertzel~: improper args!"); return NULL; }
/************new***********/ void *phasevoc_tilde_new(t_symbol *s, int argc, t_atom *argv) { t_phasevoc_tilde *x = (t_phasevoc_tilde *)pd_new(phasevoc_tilde_class); inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("timestretch")); inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("pitchshift")); outlet_new(&x->x_obj, &s_signal); x->buffPos = outlet_new(&x->x_obj, &s_float); x->sampleRate = sys_getsr(); x->circBuffSeconds = 5; x->circBuffLength = x->sampleRate * x->circBuffSeconds; x->circBuffIndex = 0; x->circBuffWindowBackIndex = x->circBuffWindowStart = 0; x->sampHoldBuffIndex = x->sampHoldBuffWindowIndex = x->sampHoldBuffWindowStart = x->circBuffToSampHoldCopyIndex = 0; x->sampHoldBuffLength = 0; x->timestretch = 1.0; x->pitchshift = 0.0; x->fftSize = 1024; x->fftHalfSize = x->fftSize >> 1; x->hopSize = 64; x->overlapChunk = x->fftSize>>2; x->overlap = x->fftSize/x->hopSize; x->twoPi = 8.0f * atanf(1.0f); x->bufferPosition = 0; x->n = 64; x->inputTime = x->outputTime = x->dsp_tick = 0; x->buffer_limit = x->fftSize/x->n/x->overlap; x->fft_tick = 0; x->outputTime = 0; x->phaselock = 0; x->pause = 0; x->waszeroflag = 0; while (argc > 0) { t_symbol *firstarg = atom_getsymbolarg(0, argc, argv); if (!strcmp(firstarg->s_name, "-buffsize")) { phasevoc_tilde_buffsize(x, atom_getfloatarg(1, argc, argv)); argc-=2, argv+=2; } else if (!strcmp(firstarg->s_name, "-windowsize")) { phasevoc_tilde_windowsize(x, atom_getfloatarg(1, argc, argv)); argc-=2, argv+=2; } else if (!strcmp(firstarg->s_name, "-hopsize")) { phasevoc_tilde_hopsize(x, atom_getfloatarg(1, argc, argv)); argc-=2, argv+=2; } else { pd_error(x, "phasevoc: %s: unknown flag or argument missing", firstarg->s_name); argc--, argv++; } } // x->circBuff = (t_float *)t_getbytes(0); x->circBuff = (t_float *)t_resizebytes(x->circBuff, 0, sizeof(float) * x->circBuffLength); // x->sampHoldBuff = (t_float *)t_getbytes(0); x->sampHoldBuff = (t_float *)t_resizebytes(x->sampHoldBuff, 0, sizeof(float) * x->circBuffLength); // x->inFrontBuff = (t_float *)t_getbytes(0); x->inFrontBuff = (t_float *)t_resizebytes(x->inFrontBuff, 0, sizeof(float) * x->fftSize); // x->inBackBuff = (t_float *)t_getbytes(0); x->inBackBuff = (t_float *)t_resizebytes(x->inBackBuff, 0, sizeof(float) * x->fftSize); // x->outBuff = (t_float *)t_getbytes(0); x->outBuff = (t_float *)t_resizebytes(x->outBuff, 0, sizeof(float) * (x->hopSize + x->n)); // x->inFrontShift = (t_float *)t_getbytes(0); x->inFrontShift = (t_float *)t_resizebytes(x->inFrontShift, 0, sizeof(float) * x->fftSize); // x->inBackShift = (t_float *)t_getbytes(0); x->inBackShift = (t_float *)t_resizebytes(x->inBackShift, 0, sizeof(float) * x->fftSize); // x->frontReal = (t_float *)t_getbytes(0); x->frontReal = (t_float *)t_resizebytes(x->frontReal, 0, sizeof(float) * (x->fftHalfSize+1)); // x->frontImag = (t_float *)t_getbytes(0); x->frontImag = (t_float *)t_resizebytes(x->frontImag, 0, sizeof(float) * (x->fftHalfSize+1)); // x->backReal = (t_float *)t_getbytes(0); x->backReal = (t_float *)t_resizebytes(x->backReal, 0, sizeof(float) * (x->fftHalfSize+1)); // x->backImag = (t_float *)t_getbytes(0); x->backImag = (t_float *)t_resizebytes(x->backImag, 0, sizeof(float) * (x->fftHalfSize+1)); // x->prevReal = (t_float *)t_getbytes(0); x->prevReal = (t_float *)t_resizebytes(x->prevReal, 0, sizeof(float) * (x->fftHalfSize+1)); // x->prevImag = (t_float *)t_getbytes(0); x->prevImag = (t_float *)t_resizebytes(x->prevImag, 0, sizeof(float) * (x->fftHalfSize+1)); // x->conjReal = (t_float *)t_getbytes(0); x->conjReal = (t_float *)t_resizebytes(x->conjReal, 0, sizeof(float) * (x->fftHalfSize+1)); // x->conjImag = (t_float *)t_getbytes(0); x->conjImag = (t_float *)t_resizebytes(x->conjImag, 0, sizeof(float) * (x->fftHalfSize+1)); // x->outReal = (t_float *)t_getbytes(0); x->outReal = (t_float *)t_resizebytes(x->outReal, 0, sizeof(float) * (x->fftHalfSize+1)); // x->outImag = (t_float *)t_getbytes(0); x->outImag = (t_float *)t_resizebytes(x->outImag, 0, sizeof(float) * (x->fftHalfSize+1)); // x->rsqrt = (t_float *)t_getbytes(0); x->rsqrt = (t_float *)t_resizebytes(x->rsqrt, 0, sizeof(float) * (x->fftHalfSize+1)); // x->outSpectra = (t_float *)t_getbytes(0); x->outSpectra = (t_float *)t_resizebytes(x->outSpectra, 0, sizeof(float) * x->fftSize); // x->analWindow = (t_float *)t_getbytes(0); x->analWindow = (t_float *)t_resizebytes(x->analWindow, 0, sizeof(float) * x->fftSize); // x->synthWindow = (t_float *)t_getbytes(0); x->synthWindow = (t_float *)t_resizebytes(x->synthWindow, 0, sizeof(float) * x->fftSize); // x->nonoverlappedOutBuff = (t_float *)t_getbytes(0); x->nonoverlappedOutBuff = (t_float *)t_resizebytes(x->nonoverlappedOutBuff, 0, sizeof(float) * x->fftSize * x->overlap); init_window(x); return (void *)x; }
static void plugin_tilde_plug (Pd_Plugin_Tilde* x, t_symbol* plug_name) { plugin_tilde_ladspa_close_plugin(x); x->plugin_library_filename = NULL; x->plugin_library_filename = plugin_tilde_search_plugin (x, plug_name->s_name); if (x->plugin_library_filename == NULL) error("plugin~: plugin not found in any library"); if (plugin_tilde_open_plugin (x, plug_name->s_name, x->plugin_library_filename,(unsigned long)sys_getsr ())) error("plugin~: Unable to open plugin"); else { post("plugin~: \"%s\"", x->plugin.ladspa.type->Name); } }
void *munger_new(double maxdelay, long channels) { int i, j; t_munger *x = (t_munger *)object_alloc(munger_class); //zero out the struct, to be careful (takk to jkclayton) if (x) { for(i=sizeof(t_pxobject);i<sizeof(t_munger);i++) ((char *)x)[i]=0; } if (maxdelay < 100.) maxdelay = 3000.; //set maxdelay to 3000ms by default post("munger: maxdelay = %f milliseconds", maxdelay); if (channels < 2) x->num_channels = 2; else x->num_channels = channels; if (x->num_channels > MAXCHANNELS) x->num_channels = MAXCHANNELS; post ("munger: number channels = %d", x->num_channels); dsp_setup((t_pxobject *)x,8); for (i=0;i<x->num_channels;i++) { outlet_new((t_object *)x, "signal"); } x->srate = sys_getsr(); x->one_over_srate = 1./x->srate; x->srate_ms = x->srate/1000.; x->one_over_srate_ms = 1./x->srate_ms; //x->buflen = (float)BUFLENGTH; if (x->recordBuf) sysmem_freeptr(x->recordBuf); x->initbuflen = (float)(maxdelay + 50.) * 44.1; //adding a little extra to avoid boundary bugs. x->buflen = x->initbuflen; x->maxsize = x->buflen / 3.; x->twothirdBufsize = x->maxsize * 2.; x->onethirdBufsize = x->maxsize; x->minsize = MINSIZE; x->voices = 10; x->gain = 1.; x->randgain = 0.; munger_alloc(x); x->twelfth = 1./12.; x->semitone = pow(2., 1./12.); x->smoothPitch = 1; x->scale_len = PITCHTABLESIZE; x->grate = 1.; x->grate_var = 0.; x->glen = 1.; x->glen_var = 0.; x->gpitch = 1.; x->gpitch_var = 0.; x->gpan_spread = 0.; x->time = 0; x->position = -1.; //-1 default == random positioning x->gimme = 0.; x->power = 1; x->ambi = 0; x->maxvoices = 20; x->oneshot = 0; x->newnote = 0; for(i=0; i<NUMVOICES; i++) { x->gvoiceSize[i] = 1000; x->gvoiceSpeed[i] = 1.; x->gvoiceCurrent[i] = 0.; x->gvoiceDirection[i] = 1; x->gvoiceOn[i] = 0; x->gvoiceDone[i] = 0; x->gvoiceRPan[i] = .5; x->gvoiceLPan[i] = .5; x->gvoiceGain[i] = 1.; ADSR_init(&x->gvoiceADSR[i]); x->gvoiceADSRon[i] = 0; for(j=0;j<MAXCHANNELS;j++) { x->gvoiceSpat[i][j] = 0.; } //note and oneshot inits x->noteTransp[i] = 0.; x->noteSize[i] = 100.; x->notePan[i] = 0.5; x->noteGain[i] = 1.; x->noteAttack[i] = 20.; x->noteDecay[i] = 50.; x->noteSustain[i] = 0.3; x->noteRelease[i] = 200.; } for(i=0;i<MAXCHANNELS;i++) { x->channelGain[i] = 0.; x->channelGainSpread[i] = 0.; } //init hanning window x->doHanning = 0; for(i=0; i<WINLENGTH; i++) x->winTable[i] = 0.5 + 0.5*cos(TWOPI * i/WINLENGTH + .5*TWOPI); for(i=0; i<PITCHTABLESIZE; i++) { x->pitchTable[i] = 0.; } x->rampLength = 256.; //sample buffer //for(i=0; i<BUFLENGTH; i++) x->recordBuf[i] = 0.; for(i=0; i<x->initbuflen; i++) x->recordBuf[i] = 0.; x->recordOn = 1; //boolean x->recordCurrent = 0; x->recordRampVal = 0; x->rec_ramping = 0; x->externalBuffer = 0; //use internal buffer by default srand(0.54); //post("mungery away"); return (x); }