// chaotic sound synthesis with cross-modulated fm synthesis // ===== PREPARE MIDI ===== // device to open 0 => int device; MidiIn min; MidiMsg msg; // try to open MIDI port, exit if we cannot if( !min.open( device ) ) me.exit( ); // print out the device that we opened <<< "MIDI device:", min.num( ), " -> ", min.name( ) >>>; spork ~ getMIDI( ); // ===== the patch: modulator to carrier ===== SawOsc m => SawOsc c => Gain g => dac; 0.004 => g.gain; // 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 MIDI controller fun void getMIDI( ) { while( true ) { // wait on event min => now; // get one or more messages while( min.recv( msg ) ) { // check for action type if( msg.data1 == 176 ) { // m.gain( ) with knob (direct) if( msg.data2 == 11 ) { 20000.0*(msg.data3 / 127.0) => m.gain; <<< "m.gain: ", m.gain( ) >>>; } // m.gain( ) with knob (MORE) if( msg.data2 == 12 ) { 30000.0*(msg.data3 / 127.0) => m.gain; <<< "m.gain: ", m.gain( ) >>>; } // m.freq( ) with knob (direct) if( msg.data2 == 13 ) { 20000.0*(msg.data3 / 127.0) => m.freq; <<< "m.freq: ", m.freq( ) >>>; } // m.freq( ) with knob (direct) if( msg.data2 == 14 ) { 200.0*(msg.data3 / 127.0) => m.freq; <<< "m.freq: ", m.freq( ) >>>; } // c.freq( ) with knob (direct) if( msg.data2 == 15 ) { 20000.0*(msg.data3 / 127.0) => c.freq; <<< "c.freq: ", c.freq( ) >>>; } // c.freq( ) with knob (direct) if( msg.data2 == 16 ) { 10*(msg.data3 / 127.0) => c.gain; <<< "c.gain: ", c.gain( ) >>>; } if( g.gain( ) >= 1.0 ) { <<< g.gain( ) >>>; 0.9 => g.gain; } } } } }