// Guitar Motion Sensor Software - Wah only // 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 2000.0 => float freq_gain; // gain of frequency 50.0 => float acc_gain; // gain of acceleration 0.9 => float k_tau; // smoothing constant 0.95 => float k_lpf; // averaging constant // variables float input[3]; // the input values from the accelerometer float g; // the current g force, total float g_tau; // smoothed g force float g_lpf; // low-pass-filtered g force float frequency; // the frequency setting float phi; // vertical angle for off switch time start; // start time int exit; // true to exit program // Print Heading <<<"", "">>>; <<<"", "">>>; <<<"", "">>>; <<<" ______ _______ _______", "">>>; <<<"| ____ | | | |______", "">>>; <<<"|_____| | | | ______|", "">>>; <<<" Guitar Motion Sensor", "">>>; <<<"", "">>>; <<<" Wah Effect", "">>>; <<<"", "">>>; // the patch adc => LPF wah_lpf => dac; adc => BPF wah_bpf => dac; dac => Gain atten => WvOut wvout => blackhole; // the patch parameters freq_gain => wah_lpf.freq; freq_gain => wah_bpf.freq; 1.0 => wah_lpf.Q; 1.0 => wah_bpf.Q; 2.0 => wah_bpf.gain; 5.0 => adc.gain; 0.1 => atten.gain; filename => wvout.wavFilename; // initialize hid Hid hid; HidMsg hidmsg; if (!hid.openJoystick (joystick_device)) { <<<"JoyStick not found at device", joystick_device>>>; } else { <<< "Joystick '" + hid.name () + "' ready.", "" >>>; } // time loop 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 3.0 * Math.sqrt (input[0]*input[0] + input[1]*input[1] + input[2]*input[2]) => g; k_tau * g_tau + (1.0 - k_tau) * g => g_tau; k_lpf * g_lpf + (1.0 - k_lpf) * g_tau => g_lpf; // 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 wah frequency freq_gain * (1.0 / (1.0 + Math.exp (-acc_gain * (g_tau - g_lpf) ) ) ) => frequency; frequency => wah_lpf.freq; frequency => wah_bpf.freq; } } } // end of program filename => wvout.closeFile; <<<"", "">>>; <<<"End of Program: Exit", "">>>;