From Fedora Project Wiki
// "Method One" // // Composed for the Fedora Project's "Musicians' Guide." // Christopher Antila. // // Creative Commons CC-BY-SA 3.0 // http://creativecommons.org/licenses/by-sa/3.0/ ( // second part of the form -- I've substantially re-written this, so // that it can be easily used in other programs. // // Because of my defaults argument values, when called with var secondPart = { arg number_of_SinOscs = 10, pitch_low = 200, pitch_high = 800, pause_length = 5; // new, personal clock, so we don't interfere with the global one var t_c = TempoClock.new( 1 ); // 1 beat per second var so = Array.new( number_of_SinOscs ); // holds the SinOsc's // We'll need to know this, later. var when_to_stop = ( 1 + ( pause_length * number_of_SinOscs ) ); // makes a stereo SinOsc with pseudo-random pitch between // pitch_low and pitch_high var func = { var freq = pitch_low + (pitch_high - pitch_low).rand; [ SinOsc.ar( freq:freq, mul:0.01), SinOsc.ar( freq:freq, mul:0.01) ]; }; // play them starting on beat 1, then every pause_length beats thereafter number_of_SinOscs.do( { arg time; t_c.sched( (1+(time*5)), { so = so.add( func.play ); } ); }); // stop t_c.sched( when_to_stop, { number_of_SinOscs.do( { arg index; so[index].free; } ); nil; }); // I want to return this, so that a function calling me knows when // I'm going to stop. when_to_stop; }; // first part of the form SynthDef.new( \FirstPart, { // sets up the frequencies of both channels var frequencyL = SinOsc.kr( freq:10, mul:200, add:400 ); // oscillating var frequencyR = SinOsc.kr( freq:1, mul:50, add:150 ); // oscillating var frequencyL_drone = SinOsc.kr( freq:0.03, mul:20, add:100 ); // drone var frequencyR_drone = SinOsc.kr( freq:0.01, mul:20, add:210 ); // drone // changes the volume of the oscillating part in the left channel var volumeL = SinOsc.kr( freq:0.5, mul:0.02, add:0.03 ); // left channel var left = [ SinOsc.ar( freq:frequencyL, mul:volumeL ), // this is the oscillating part SinOsc.ar( freq:[frequencyL_drone,2*frequencyL_drone], mul:0.02 ), // the rest make up the drone SinOsc.ar( freq:[5*frequencyL_drone,7*frequencyL_drone], mul:0.005 ), SinOsc.ar( freq:[13*frequencyL_drone,28*frequencyL_drone], mul:0.001 ) ]; // right channel var right = [ SinOsc.ar( freq:frequencyR, mul:0.1 ), // this is the oscillating part SinOsc.ar( freq:[frequencyR_drone,2*frequencyR_drone], mul:0.02 ), // the rest make up the drone SinOsc.ar( freq:4*frequencyR_drone, mul:0.005 ), SinOsc.ar( freq:[64*frequencyR_drone,128*frequencyR_drone], mul:0.01 ) ]; // high frequencies! Out.ar( 0, [left,right] ); } ).send( s ); // "Main" function { var t_c = TempoClock.default; var sound = nil; // holds currently-running "FirstPart" t_c.tempo_( 1 ); // set the tempo to one beat per second // Scheduling: t_c.sched( 1, { sound = Synth.new( \FirstPart ); } ); t_c.sched( 61, { sound.free; } ); t_c.sched( 61, { secondPart.value; nil; } ); // this takes 51 beats to complete t_c.sched( 113, { sound = Synth.new( \FirstPart ); } ); t_c.sched( 143, { sound.free; } ); }.value; )