// Guitar Motion Sensor Software - Thunderstorm Effect // Copyright 2008 Les Hall // with thunder by kijjaz and rain by wppk // 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", "">>>; <<<"", "">>>; <<<" Thunderstorm Effect", "">>>; <<<"", "">>>; // the patch // with kijjaz's thunder (I changed it a little) Noise noise => LPF f1 => Gain mult => SinOsc overdrive => NRev nrev => dac; adc => Gain squared; adc => Gain buffer => squared; squared => DelayA delay1 => Gain feedback1 => delay1; feedback1 => DelayA delay2 => Gain feedback2 => delay2; feedback2 => LPF f2 => HPF f3 => mult; adc => Gain guitar => dac; dac => Gain atten => WvOut wvout => blackhole; // the patch parameters 200 => f1.freq; 3 => mult.op; 2 => mult.gain; 1 => overdrive.sync; 2 => overdrive.gain; 0.1 => nrev.mix; 0.5 => nrev.gain; 3 => squared.op; 100::ms => delay1.max; 9::ms => delay1.delay; 0.9 => feedback1.gain; 100::ms => delay2.max; 11::ms => delay2.delay; 0.9 => feedback2.gain; 500 => f2.freq; 50 => f3.freq; 1.0 => guitar.gain; 5.0 => adc.gain; 1.0 => dac.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.", "" >>>; } // wppk's rain spork ~ rainforground(); spork ~ raindistance(.3,5); spork ~ beatgen(80, .9, 0.1, 1); spork ~ raindrops(5, 1.0 ); // 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 0.1 + 0.1 * (1.0 - 1.0 / (1.0 + Math.exp (-acc_gain * Math.fabs (g - g_avg) + 5.0 ) ) ) => nrev.mix; } } } // end of program filename => wvout.closeFile; <<<"", "">>>; <<<"End of Program: Exit", "">>>; fun void beatgen( float base, float beat, float gain, int minutes){ beat/2 => float half; base + half => float freq1; base - half => float freq2; SinOsc s1 => dac.left; gain => s1.gain; SinOsc s2 => dac.right; gain => s2.gain; freq1 => s1.freq; freq2 => s2.freq; minutes::minute => now; } fun void raindistance( float gain, int minutes){ while(true){ Noise n => BPF b => LPF l => JCRev r => dac; n.gain(gain); l.freq(10000.0); b.Q(8); b.freq( 880.0);r.mix(.1); minutes::minute=> now; } } fun void raindrops(int rainfreq, float dropvolume){ Impulse i => BPF bpf => LPF lpf => JCRev r => dac; SinOsc n => bpf; 20.0 => n.freq; n.gain(dropvolume); bpf.Q (10); r.mix(.1); while (true) { lpf.freq (100 * (5 +maybe+maybe+maybe+maybe+maybe)); bpf.freq (500*(5+maybe+maybe+maybe+maybe+maybe+maybe+maybe+maybe)); i.next (10*(maybe+maybe+maybe+maybe)); (rainfreq+maybe+maybe+maybe+maybe+maybe+maybe+maybe+maybe) *5::ms => now; } } fun void rainforground() { Impulse i => BPF bpf => LPF lpf => dac; SqrOsc n => bpf; 3000.0 => n.freq; n.width(1.5); n.gain(.3); bpf.Q (15); while (true) { lpf.freq (50 * (5 +maybe+maybe+maybe+maybe+maybe)); bpf.freq (80*(5+maybe+maybe+maybe+maybe+maybe+maybe+maybe+maybe)); i.next (10*(maybe+maybe+maybe+maybe)); (1+maybe+maybe+maybe+maybe+maybe+maybe+maybe+maybe)*100::ms => now; } }