//-- // name: autotune.ck // desc: Final project for Music 220A Autumn 2014-2015 // Developed from pitch tracker by Rebecca Fiebrink + Ge Wang 2007 // // author: Mark Kwon // date: 2014 //-- // analysis adc => PoleZero dcblock => FFT fft => blackhole; adc => PitShift shifter => dac; // set to block DC .99 => dcblock.blockZero; // set FFT params 4096 => fft.size; // window Windowing.hamming( fft.size() ) => fft.window; // to hold result UAnaBlob blob; // find sample rate second / samp => float srate; // interpolate float input_freq, curr_freq, target_freq, target_gain, curr_gain; spork ~ ramp_stuff(); //[65.41, 73.42, 82.41, 87.31, 98.00, 110.00, 123.47] @=> float notes[]; [65.41, 73.42, 82.42, 98.00, 110.00] @=> float notes[]; 4 => int num_octaves; // go for it while( true ) { // take fft fft.upchuck() @=> blob; // find peak 0 => float max; int where; for( int i; i < blob.fvals().cap(); i++ ) { // compare if( (i $ float) / fft.size() * srate < 500 && blob.fvals()[i] > max ) { // save blob.fvals()[i] => max; i => where; } } 9999.0 => float min_diff; // set freq (where $ float) / fft.size() * srate => input_freq; if (input_freq != curr_freq) { 9999.0 => min_diff; } for ( 0 => int i; i < notes.cap(); i++){ for ( 1=> int oct; oct < num_octaves ; oct ++) { if ( Std.fabs(input_freq - notes[i]*(2^oct) ) < min_diff) { input_freq => curr_freq; Std.fabs(input_freq - notes[i]*(2^oct)) => min_diff; notes[i]*(2^oct) => target_freq; } } } // set gain (max / .8) => target_gain; // hop (fft.size()/2)::samp => now; } // interpolation fun void ramp_stuff() { // infinite time loop while ( true ) { float new_freq; curr_freq => new_freq; //target_freq - curr_freq => float diff; <<< "Target: " + target_freq + "curr: " + curr_freq >>>; //5 => int steps; 2*target_freq / curr_freq => shifter.shift; 1.0 => shifter.mix; 0.025::second => now; // had to get rid of slowly shifting for recording since the pitch was oscillating //for ( 0 => int i; i < steps; i++) { // float changed; // diff * (1/(steps $ float)) + new_freq => changed; // changed / new_freq => shifter.shift; // <<< changed/new_freq >>>; // // // //0.0025::second => now; // 0.1::second => now; // changed => new_freq; //} } }