// chaotic sound synthesis with cross-modulated fm synthesis // h => increase modulation frequency // g => decrease modulation frequency // 9 => decrease modulation gain by a lot // 8 => increase modulation gain by a lot // i => increase modulation gain by a little // k => decrease modulation gain by a little // l => increase modulation gain by a little // j => decrease modulation gain by a little // ===== the keyboard input ===== Hid hi; HidMsg msg; // which keyboard 0 => int device; // open keyboard (get device number from command line) if( !hi.openKeyboard( device ) ) me.exit(); <<< "keyboard '" + hi.name() + "' ready", "" >>>; spork ~ key( ); // ===== the patch: modulator to carrier ===== SinOsc m => SinOsc c => dac; // carrier frequency 220 => c.freq; // modulator frequency 20 => m.freq; // index of modulation 100000 => m.gain; // cross modulation c => m; // phase modulation is FM synthesis (sync is 2) 2 => c.sync; 2 => m.sync; // time-loop while( true ) 1::second => now; // function to read from keys fun void key( ) { while( true ) { // wait on event hi => now; // get one or more messages while( hi.recv( msg ) ) { // check for action type if( msg.isButtonDown() ) { if( msg.ascii == 76 ) { m.gain( ) + 10.0 => m.gain; <<< "m gain: ", m.gain( ) >>>; } if( msg.ascii == 74 ) { m.gain( ) - 10.0 => m.gain; <<< "m gain: ", m.gain( ) >>>; } if( msg.ascii == 73 ) { m.gain( ) + 1000 => m.gain; <<< "m gain: ", m.gain( ) >>>; } if( msg.ascii == 75 ) { m.gain( ) - 1000 => m.gain; <<< "m gain: ", m.gain( ) >>>; } if( msg.ascii == 56) { m.gain( ) + 10000 => m.gain; <<< "m gain: ", m.gain( ) >>>; } if( msg.ascii == 57) { m.gain( ) - 10000 => m.gain; <<< "m gain: ", m.gain( ) >>>; } if( msg.ascii == 72) { // increase m.freq m.freq( ) + 10 => m.freq; <<< "m freq: ", m.freq( ) >>>; } if( msg.ascii == 71) { // decrease m.freq m.freq( ) - 10 => m.freq; <<< "m freq: ", m.freq( ) >>>; } } } } }