// code from ChucK examples larry++ and curly++ + OSC receiver // which keyboard to open (chuck --probe to available) 0 => int KB_DEVICE; // create our OSC receiver OscIn oin; // create our OSC message OscMsg msg; //------------ tick --------------// // impulse to filter to dac SndBuf i => BiQuad f => Gain g => JCRev r => dac; // second formant i => BiQuad f2 => g; // third formant i => BiQuad f3 => g; // set the filter's pole radius 0.800 => f.prad; .995 => f2.prad; .995 => f3.prad; // set equal gain zeroes 1 => f.eqzs; 1 => f2.eqzs; 1 => f3.eqzs; // initialize float variable 0.0 => float v => float v2; // set filter gain .1 => f.gain; .1 => f2.gain; .01 => f3.gain; 0.05 => r.mix; // load glottal pop "special:glot_pop" => i.read; // play 1.0 => i.rate; //------------ growl --------------// // impulse to filter to dac SndBuf i2 => NRev r2 => dac; // load glottal ooo "special:glot_ooo" => i2.read; // play 1.0 => i2.rate; .1 => r2.mix; 0.3 => i2.gain; 0.0 => float v3; //------------ chaos --------------// SndBuf i3 => Noise n => dac; 0.0 => n.gain; //------------ sporks --------------// spork ~ OSCreceiver(); spork ~ tick(); spork ~ growl(); spork ~ chaos(); //------------ main --------------// while (true) { 100::ms => now; } fun void tick() { // infinite time-loop while( true ) { // set the current sample/impulse 0 => i.pos; // sweep the filter resonant frequency 250.0 + Math.sin(v*100.0)*20.0 => v2 => f.pfreq; 2290.0 + Math.sin(v*200.0)*50.0 => f2.pfreq; 3010.0 + Math.sin(v*300.0)*80.0 => f3.pfreq; // increment v v + .05 => v; // gain 0.2 + Math.sin(v)*.1 => g.gain; // advance time (1000.0 + Math.random2f(-100.0, 100.0))::ms => now; } } // variable growls fun void growl() { // infinite time-loop while( true ) { // set the current sample/impulse 0 => i2.pos; // control gain //Math.random2f(0,0.5) + Math.cos(v3) => i2.gain; // increment v 0.1 +=> v3; // advance time Math.random2f(81, 120)::ms => now; } } // start to play noise fun void chaos() { // infinite time-loop while( true ) { Math.random2f(0.2,0.4) => i3.gain; 100::ms => now; } } // handler for incoming OSC notes messages fun void OSCreceiver() { // use port 6449 (or whatever) 6449 => oin.port; // create an address in the receiver, expect an int and a float oin.addAddress( "/chuck, fff" ); // infinite event loop while( true ) { // wait for event to arrive oin => now; // grab the next message from the queue while( oin.recv(msg) ) { // expected datatype float f; float f1; float f2; msg.getFloat(0)*10 => f => i2.rate; msg.getFloat(0)/10 => r2.mix; msg.getFloat(1)/100 => f1 => n.gain; msg.getFloat(2) => f2 => i2.gain; // print <<< "param (via OSC):", f >>>; <<< "param 1 (via OSC):", f1 >>>; <<< "param 2 (via OSC):", f2 >>>; } } } //------------------------------------------------------------------------------ // Keyboard Input //------------------------------------------------------------------------------ Hid hid; HidMsg msgH; // open keyboard (get device number from command line) if( !hid.openKeyboard( KB_DEVICE ) ) me.exit(); <<< "keyboard '" + hid.name() + "' ready", "" >>>; spork ~ kb(); fun void kb() { // infinite event loop while( true ) { // wait on event hid => now; // get one or more messages while( hid.recv( msgH ) ) { // check for action type if( msgH.isButtonDown() ) // button down { <<< "down:", msgH.which, "(code)", msgH.key, "(usb key)", msgH.ascii, "(ascii)" >>>; if( msgH.ascii == 87 ) // w // chaos { 0.2 => i3.gain; 0.2 => n.gain; <<< "W key pressed" >>>; } else if( msgH.ascii == 83 ) // s // 0s 1s { 0.0 => i2.gain; <<< "s key pressed" >>>; } } } } }