//Cross synthesize mic & guitar // by Rebecca Fiebrink, 2009 //FFT for mic input adc => Gain g => FFT fftx => blackhole; // pump up gain for headset mic 50 => g.gain; //FFT for sound buffer FFT ffty => blackhole; // ifft transforms back into audio IFFT ifft => JCRev j => dac; .00 => j.mix; // set FFT size 2048 => fftx.size => ffty.size => int FFT_SIZE; // desired hop size FFT_SIZE / 16 => int HOP_SIZE; // set window and window size Windowing.hann(512) => fftx.window; Windowing.hann(512) => ffty.window; // Load guitar sound into buffer SndBuf buffy => ffty; "shuffle.wav" => buffy.read; // loop it 1 => buffy.loop; // use this to hold contents of spectral computation complex Z[FFT_SIZE/2]; // control loop while( true ) { // take fft fftx.upchuck() @=> UAnaBlob X; //spectrum from adc ffty.upchuck() @=> UAnaBlob Y; //spectrum from buffer // bin by bin: for( int i; i < FFT_SIZE/2; i++ ) { (X.cval(i)$polar).mag => float m; //threshold to get rid of fan noise etc. if (m > .0004) { Math.pow((X.cval(i)$polar).mag, .3) * Y.cval(i) => Z[i]; } else { 0 * Y.cval(i) => Z[i]; } } // take ifft ifft.transform( Z ); // advance time HOP_SIZE::samp => now; }