// SMACK DETECTION PART // smack detection threshold 50 => int threshold; // poll rate .01::second => dur poll_rate; // recovery time (after smack detection) .1::second => dur recover_time; // instantiate a Hid object Hid hi; HidMsg msg; // open tilt sensor if( !hi.openTiltSensor() ) { <<< "tilt sensor unavailable", "" >>>; me.exit(); } // "go" <<< "ready to smack", "" >>>; // remember HidMsg last; // initialize hi.read( 9, 0, last ); // SOUND SYNTHESIS PART // Load sample over the first half-second adc => LiSa yell => JCRev rev => Gain g => dac; g.gain(0.2); // declare sample attributes 1::second => yell.duration; 1 => yell.record; 1::second => now; 0 => yell.record; 15 => yell.maxVoices; fun void smack() { yell.getVoice() => int voice1; Math.abs(msg.x - last.x) => float rev_mix; (rev_mix * .005) => rev_mix; rev_mix => rev.mix; <<< "Reverb mix:", rev_mix >>>; Math.abs(msg.y - last.y) => float g_gain; (g_gain * .005) => g_gain; g_gain => g.gain; <<< "Gain:", g_gain >>>; yell.play(voice1, 1); yell.duration() => now; yell.play(voice1, 0); } // infinite event loop while( true ) { hi.read( 9, 0, msg ); (Math.abs(msg.x - last.x) + Math.abs(msg.y - last.y) + Math.abs(msg.z - last.z)) => int diff; if (diff > threshold) { spork ~ smack(); recover_time => now; } else { poll_rate => now; } }