// Tube amp simulation // Copyright 2008 Les Hall // This software is protected by the GNU General Public License // parameters // variables 0 => int model; // 0 = no distortion, 1 = tube distortion 0 => float last; // last sample of ramped sinusoid // the patch SinOsc osc => Gain ramp_mult => HPF hpf => LPF lpf => blackhole; lpf => HalfRect hr_pos => Gen7 gen7_pos => Gain summer => blackhole; lpf => Gain inv1 => HalfRect hr_neg => Gen7 gen7_neg => Gain inv2 => summer; Phasor phasor => ramp_mult; Step output => dac; // the patch parameters 220 => osc.freq; 7 => hpf.freq; 3000 => lpf.freq; [0., 0.1, 0.275404, 0.1, 0.378580, 0.1, 0.452500, 0.1, 0.525216, 0.1, 0.597520, 0.1, 0.668775, 0.1, 0.738244, 0.1, 0.805170, 0.1, 0.801702, 0.1, 0.904239] => gen7_pos.coefs => gen7_neg.coefs; -1 => inv1.gain => inv2.gain; 3 => ramp_mult.op; // multiplier 0.333 => phasor.freq; 1 => phasor.gain; // instantiate classes Keyboard_Interface Kbd_Intf; // time warp while (true) { if (model == 0) { ramp_mult.last () => last; last => output.next; } if (model == 1) { summer.last () => last; last => output.next; } 1::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; <<<"tube distortion">>>; } } } } } }