// Guitar Motion Sensor Software - Dirty Effect // Copyright 2008 Les Hall // This software is protected by the GNU General Public License // parameters 0 => int joystick_device; // joystick device number "GMS.wav" => string filename; // output filename 100.0 => float acc_gain; // acceleration gain 0.99 => float tau; // lpf constant // variables float input[3]; // the input values from the accelerometer float g; // the current g force, total float g_prev; // previous g force float g_avg; // averaged g force float phi; // vertical angle for off switch time start; // start time int exit; // true to exit program // Print Heading <<<"", "">>>; <<<"", "">>>; <<<"", "">>>; <<<" ______ _______ _______", "">>>; <<<"| ____ | | | |______", "">>>; <<<"|_____| | | | ______|", "">>>; <<<" Guitar Motion Sensor", "">>>; <<<"", "">>>; <<<" Dirty Effect", "">>>; <<<"", "">>>; // the patch adc => Gain boost => Gain accel => SinOsc sinosc => Gain mult => dac; adc => mult; Step step => accel; dac => Gain atten => WvOut wvout => blackhole; // the patch parameters 1000.0 => boost.gain; 3 => accel.op; 1 => mult.op; 5.0 => adc.gain; 0.1 => atten.gain; filename => wvout.wavFilename; // initialize hid Hid hid; HidMsg hidmsg; if (!hid.openJoystick (joystick_device)) { <<<"Accelerometer not found at device", joystick_device>>>; me.exit(); } else { <<< "Accelerometer '" + hid.name () + "' ready.", "" >>>; } // time loop 1::second => now; now => start; while (exit == 0) { hid => now; while (hid.recv (hidmsg)) { if (hidmsg.isAxisMotion ()) { // record the input value for debug purposes hidmsg.axisPosition => input[hidmsg.which]; // calculate g force g => g_prev; 3.0 * Math.sqrt (input[0]*input[0] + input[1]*input[1] + input[2]*input[2]) => g; tau * g_avg + (1.0 - tau) * g => g_avg; // calculate phi Math.atan2 (input[1], input[0]) => phi; // quit when guitar points down if (phi > pi * 3.0 / 4.0) { if (now - start > 1::second) { 1 => exit; } } // set effect 1.0 - 1.0 / (1.0 + Math.exp (-acc_gain * Math.fabs (g - g_avg) + 5.0 ) ) => step.next; } } } // end of program filename => wvout.closeFile; <<<"", "">>>; <<<"End of Program: Exit", "">>>;