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/ var t_c = TempoClock.new; // 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 secondPart_clock = TempoClock.new( 1 ); // 1 beat per second // holds the SinOsc's var sounds = Array.new( number_of_SinOscs ); // We'll need 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; secondPart_clock.sched( (1+(time*5)), { sounds = sounds.add( func.play ); } ); }); // stop secondPart_clock.sched( when_to_stop, { number_of_SinOscs.do( { arg index; sounds[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 { // holds currently-running "FirstPart" var sound = 0; // will know when secondPart stops var when_secondPart_stops = 0; t_c.tempo = 1; // Scheduling: (obviously not ideal for a program any larger) // first part t_c.sched( 1, { sound = Synth.new( "FirstPart" ); } ); t_c.sched( 60, { sound.free; } ); // second and third parts t_c.sched( 60, { when_secondPart_stops = secondPart.value; t_c.sched( when_secondPart_stops, { sound = Synth.new( "FirstPart" ); } ); t_c.sched( ( when_secondPart_stops + 30 ), { sound.free; } ); } ); }.value;