// used to analyze the data adc => FFT fft => blackhole; Machine.add(me.dir() + "/BPM_Class.ck") => int bpmID; int marimbaID; int keysID; int harmony1ID; int harmony2ID; 0 => int count; SndBuf waves => dac; me.dir()+"/waves.wav" => waves.read; waves.samples() => waves.pos; waves.gain(0.7); 0 => waves.pos; // set parameters 800 => fft.size; // set hann window Windowing.hann(400) => fft.window; // compute srate second / samp => float srate; // control loop while( true ) { // upchuck: take fft fft.upchuck(); // if the fval is strong enough, like a clap, then a piece of // music will be added if((fft.fval(0) * srate / 2) > 100) { if(count == 0) { Machine.add(me.dir() + "/MarimbaPlayer.ck") => marimbaID; waves.gain(0.4); count ++; } else if(count == 1) { Machine.add(me.dir() + "/KeyboardPlayer.ck") => keysID; count ++; } else if(count == 2) { Machine.add(me.dir() + "/HarmonyPlayer.ck") => harmony1ID; Machine.add(me.dir() + "/Harmony2Player.ck") => harmony2ID; count ++; } else if(count == 3) { Machine.remove(harmony1ID); Machine.remove(harmony2ID); count ++; } else if(count == 4) { Machine.remove(keysID); count ++; } else if(count == 5) { Machine.remove(marimbaID); count ++; break; } } // print out centroid <<< fft.fval(0) * srate / 2 >>>; // advance time fft.size()::samp => now; } //continues the waves for another 4 seconds 4::second => now; waves.gain(0.7);