// ambiophonic processor // // Improved phase cancelation using subtraction // of the channels first tried by Howard Moscovitz, // No filters, no feedback. I have found it sounds // better this way // July 8, 2008 // Howard Moscovitz // // July 13, 2008 // Les Hall // modified to be a class, to work with adc input, // and added keyboard volume control // parameters 0 => int keyboard_device; // keyboard device number // variables Event volume_change; // instantiate the classes ambio A; Keyboard_Interface K; // the patch adc.left => A.L_in; adc.right => A.R_in; A.L_out => dac.left; A.R_out => dac.right; SinOsc boop => dac; // the patch parameters 200 => boop.freq; 0 => boop.gain; K.get_volume () => dac.gain; // spork the volume adjust shred spork ~ volume_adjust (); // time after time... while (true) { second => now; } // define the class class ambio { Gain L_in => Gain L_minus; Gain R_in => Gain R_minus; -1 => L_minus.gain => R_minus.gain; L_in => Gain L_prime; R_minus => L_prime; R_in => Gain R_prime; L_minus => R_prime; L_prime => DelayA L_delay; R_prime => DelayA R_delay; 0.080::ms => dur delay; L_delay.max (10*delay); L_delay.delay (delay); R_delay.max (10*delay); R_delay.delay (delay); -1.0 => L_delay.gain => R_delay.gain; R_delay => Gain L_out; L_in => L_out; L_delay => Gain R_out; R_in => R_out; 0.5 => L_out.gain => R_out.gain; } // volume adjust shred function void volume_adjust () { while (true) { volume_change => now; K.get_volume () => dac.gain; } } // Interface to the keyboard class Keyboard_Interface { // variables int kbd_value; // value of key pressed 0.2 => float volume; // the volume, from 0 to 1 // 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 == 47) { // if "[" for "lower volume" is pressed 0.05 -=> volume; // lower volume if (volume < 0) { // if volume is below zero now 0 => volume; // then set it to zero } volume_change.broadcast (); make_boop (); } if (kbd_value == 48) { // if "]" for "raise volume" is pressed 0.05 +=> volume; // raise volume if (volume > 1) { // if volume is above one now 1 => volume; // then set it to one } volume_change.broadcast (); make_boop (); } if (kbd_value == 49) { // if "\" for "mute volume" is pressed 0.0 => volume; // mute volume volume_change.broadcast (); } } } } } fun float get_volume () { return volume; } fun void make_boop () { 1 => boop.gain; 100::ms => now; 0 => boop.gain; } }