// Slork 2013 // Week 2 ChucK Tutorial // Mouse control + FM // Spencer Salazar - spencer@ccrma.stanford.edu // setup our audios - frequency modulation (FM) SinOsc mod => SinOsc car => Envelope env => NRev reverb => dac; 0.05 => reverb.mix; // this is the magic that tells chuck to do FM 2 => car.sync; // set carrier frequency 200 => car.freq; // open mouse Hid mouse; mouse.openMouse(0); HidMsg msg; float sumX; float sumY; // loop forever while(true) { // wait for new input mouse => now; // receive input while(mouse.recv(msg)) { // button down - activate envelope if(msg.type == Hid.BUTTON_DOWN) 1 => env.keyOn; // button up - deactivate envelope else if(msg.type == Hid.BUTTON_UP) 1 => env.keyOff; // mouse motion - modulate FM parameters else if(msg.type == Hid.MOUSE_MOTION) { msg.deltaX +=> sumX; msg.deltaY +=> sumY; // cumulative X position controls modulator frequency sumX => mod.freq; // cumulative Y position controls modulator gain ("index of modulation") sumY => mod.gain; } } }