core | ugens | analysis




A UGen for panning a mono signal in a stereo field. Because of the generally accepted meaning of pan, this UGen strictly enforces the channel count of its input and output. Anything patched to the audio input of Pan will be configured to generate mono audio, and when Pan is patched to any other UGen, it will throw an exception if that UGen tries to set Pan's channel count to anything other than 2.


Construct a Pan UGen with a specific starting pan value.
Pan(float panValue)


panValue — float: a value of 0 means to pan dead center, -1 hard left, and 1 hard right.




/* panExample<br/>
   is an example of using the Pan UGen inside an Instrument.
   The Instrument is designed to play a single tone that is panned 
   back and forth across the stereo field based on the value of a 
   low frequency oscillator (LFO). An LFO is simply an Oscil that 
   has a frequency that is usually well below audible range.
   This sketch uses the Instrument to play two notes, one which 
   slowly pans back and forth across the entire stereo field (-1, 1)
   and one which more quickly pans back and forth between a 
   smaller range.
   For more information about Minim and additional features, 
   author: Damien Di Fede

// import everything necessary to make sound.
import ddf.minim.*;
import ddf.minim.ugens.*;

// create all of the variables that will need to be accessed in
// more than one methods (setup(), draw(), stop()).
Minim minim;
AudioOutput out;

// define a PanInstrument that implements the Instrument interface
// so that we can use instances of it with playNote
class PanInstrument implements Instrument
  // create all variables that must be used throughout the class
  Oscil sineOsc, LFO;
  Pan pan;
  // constructors for this intsrument
  PanInstrument( float oscFrequency, float oscAmplitude, float lfoFrequency, float lfoAmplitude )
    // create new instances of any UGen objects as necessary
    sineOsc = new Oscil( oscFrequency, oscAmplitude, Waves.SINE );
    // the arguments to the Pan UGen are for the balance and width.
    // balance ranges from -1 to 1, which basically are hard-left and 
    // hard-right, respectively.
    // we create our pan with 0 because we will drive the value of 
    // the balance using Pan's balance UGenInput.
    pan = new Pan(0);
    // LFO stands for low frequency oscillator. we will use this to control
    // the balance input of the Pan Ugen.
    LFO = new Oscil( lfoFrequency, lfoAmplitude, Waves.SINE );
    // patch everything together up to the final output
    sineOsc.patch( pan );
    LFO.patch( pan.pan );
  // every instrument must have a noteOn( float ) method
  void noteOn( float dur )
    // and patch to the output
    pan.patch( out );
  // every instrument must have a noteOff() method
  void noteOff()
    // and unpatch the output 
    // this causes the entire instrument to stop calculating sampleframes
    // which is good when the instrument is no longer generating sound.
    pan.unpatch( out );

// setup is run once at the beginning
void setup()
  // initialize the drawing window
  size( 512, 200, P2D );
  // initialize the minim and out objects
  minim = new Minim( this );
  // because we are using a Pan UGen, we need a stereo output.
  out = minim.getLineOut( Minim.STEREO, 1024 );
  // initialize the myNote object as a PanInstrument
  PanInstrument myNote = new PanInstrument( 587.3f, 0.5, 0.5, 1.0 );
  // play a note with the myNote object
  out.playNote( 0.5, 2.6, myNote );
  // give a new note value to myNote
  myNote = new PanInstrument( 415.3f, 0.5, 3.0, 0.5 );
  // play another note with the myNote object
  out.playNote(3.5, 2.6, myNote );

// draw is run many times
void draw()
  // erase the window to black
  background( 0 );
  // draw using a white stroke
  stroke( 255 );
  // draw the waveforms
  for( int i = 0; i < out.bufferSize() - 1; i++ )
    // find the x position of each buffer value
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);


Web & Application