From Fedora Project Wiki
(page creation)
 
m (revised minor programming errors, spacing, inefficiencies)
 
Line 1: Line 1:
<pre>
<pre>
// "Method One"
// "Method One"
//  
//  
Line 9: Line 8:
// http://creativecommons.org/licenses/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
// second part of the form -- I've substantially re-written this, so
// that it can be easily used in other programs.
// that it can be easily used in other programs.
//  
//  
// Because of my defaults argument values, when called with  
// Because of my defaults argument values, when called with  
var secondPart =  
var secondPart =
{
{
   arg number_of_SinOscs = 10,
   arg number_of_SinOscs = 10,
Line 23: Line 21:
    
    
   // new, personal clock, so we don't interfere with the global one
   // new, personal clock, so we don't interfere with the global one
   var secondPart_clock = TempoClock.new( 1 ); // 1 beat per second
   var t_c = TempoClock.new( 1 ); // 1 beat per second
 
   var so = Array.new( number_of_SinOscs ); // holds the SinOsc's
  // holds the SinOsc's
   var sounds = Array.new( number_of_SinOscs );
    
    
   // We'll need this later.
   // We'll need to know this, later.
   var when_to_stop = ( 1 + ( pause_length * number_of_SinOscs ) );
   var when_to_stop = ( 1 + ( pause_length * number_of_SinOscs ) );
    
    
Line 44: Line 40:
   {
   {
       arg time;
       arg time;
       secondPart_clock.sched( (1+(time*5)), { sounds = sounds.add( func.play ); } );
       t_c.sched( (1+(time*5)), { so = so.add( func.play ); } );
   });
   });
 
 
   // stop
   // stop
   secondPart_clock.sched( when_to_stop,
   t_c.sched( when_to_stop,
                          {
              {
                              number_of_SinOscs.do( { arg index; sounds[index].free; } );
                number_of_SinOscs.do( { arg index; so[index].free; } );
                              nil;
                nil;
                          });
              });
    
    
   // I want to return this, so that a function calling me knows when
   // I want to return this, so that a function calling me knows when
Line 58: Line 54:
   when_to_stop;
   when_to_stop;
};
};


// first part of the form
// first part of the form
SynthDef.new( "FirstPart",
SynthDef.new( \FirstPart,
{
{
   // sets up the frequencies of both channels
   // sets up the frequencies of both channels
Line 88: Line 89:
// "Main" function
// "Main" function
{
{
   // holds currently-running "FirstPart"
   var t_c = TempoClock.default;
  var sound = 0;
  var sound = nil; // holds currently-running "FirstPart"
 
  // will know when secondPart stops
  var when_secondPart_stops = 0;
    
    
   t_c.tempo = 1;
   t_c.tempo_( 1 ); // set the tempo to one beat per second
    
    
   // Scheduling: (obviously not ideal for a program any larger)
   // Scheduling:
  // first part
   t_c.sched( 1, { sound = Synth.new( \FirstPart ); } );
   t_c.sched( 1, { sound = Synth.new( "FirstPart" ); } );
   t_c.sched( 61, { sound.free; } );
   t_c.sched( 60, { sound.free; } );
   t_c.sched( 61, { secondPart.value; nil; } ); // this takes 51 beats to complete
  // second and third parts
  t_c.sched( 113, { sound = Synth.new( \FirstPart ); } );
   t_c.sched( 60, { when_secondPart_stops = secondPart.value;  
  t_c.sched( 143, { sound.free; } );
                    t_c.sched( when_secondPart_stops, { sound = Synth.new( "FirstPart" ); } );
                    t_c.sched( ( when_secondPart_stops + 30 ), { sound.free; } );
                  } );
    
    
}.value;
}.value;


)
</pre>
</pre>

Latest revision as of 20:32, 25 July 2010

// "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;

)