// Tube amp simulation // Copyright 2008 Les Hall // This software is protected by the GNU General Public License // variables 0 => int model; // 0 = no distortion, 1 = tube distortion 0 => float last; // last sample of ramped sinusoid // the patch SinOsc sinosc => Gain ramp_mult => blackhole; Phasor phasor => ramp_mult; Step output => dac; // the patch parameters 220 => sinosc.freq; 3 => ramp_mult.op; // multiplier 0.333 => phasor.freq; 2 => phasor.gain; // instantiate classes Keyboard_Interface Kbd_Intf; // time warp while (true) { ramp_mult.last () => last; if (model == 0) { last => output.next; } if (model == 1) { Math.sgn (last) * Math.pow (Std.fabs (last), 1.5) => output.next; } samp => now; } // Interface to the keyboard class Keyboard_Interface { // parameters 0 => int keyboard_device; // we want the 0th keyboard 10::ms => dur kbd_env_dur; // keyboard envelope duration // variables int kbd_value; // value of key pressed // hid initialization Hid hid; HidMsg hidmsg; if (!hid.openKeyboard (keyboard_device)) { me.exit(); } // launch the time loop spork ~ time_loop (); // time loop fun void time_loop () { while (true) { hid => now; // wait for a key press while (hid.recv (hidmsg)) { // while new keys are in queue if (hidmsg.isButtonDown ()) { // check for button down message hidmsg.which => kbd_value; // save button value if (kbd_value == 4) { // if "a" key is pressed 0 => model; <<<"no distortion">>>; } if (kbd_value == 5) { // if "b" key is pressed 1 => model; <<<"x squared distortion">>>; } } } } } }