ddf.minim.signals
Class Oscillator

java.lang.Object
  extended by ddf.minim.signals.Oscillator
All Implemented Interfaces:
AudioSignal
Direct Known Subclasses:
PulseWave, SawWave, SineWave, SquareWave, TriangleWave

public abstract class Oscillator
extends java.lang.Object
implements AudioSignal

Oscillator is an implementation of an AudioSignal that handles most of the work associated with an oscillatory signal like a sine wave. To create your own oscillator you must extend Oscillator and implement the value method. Oscillator will call this method every time it needs to sample your waveform. The number passed to the method is an offset from the beginning of the waveform's period and should be used to sample your waveform at that point.

Author:
Damien Di Fede

Field Summary
protected static float TWO_PI
          The float value of 2*PI.
 
Constructor Summary
Oscillator(float frequency, float amplitude, float sampleRate)
          Constructs an Oscillator with the requested frequency, amplitude and sample rate.
 
Method Summary
 float amplitude()
          Returns the current amplitude.
 float frequency()
          Returns the current frequency.
 void generate(float[] signal)
          Fills signal with values in the range of [-1, 1].
 void generate(float[] left, float[] right)
          Fills left and right with values in the range of [-1, 1].
 void noPortamento()
          Turns off portamento.
 float pan()
          Returns the current pan value.
 float period()
          Returns the period of the waveform (the inverse of the frequency).
 void portamento(int millis)
          Sets how many milliseconds it should take to transition from one frequency to another when setting a new frequency.
 float sampleRate()
           
 void setAmp(float a)
          Set the amplitude of the Oscillator, range is [0, 1].
 void setAudioListener(AudioListener al)
           
 void setFreq(float f)
          Sets the frequency of the Oscillator in Hz.
 void setPan(float p)
          Set the pan of the Oscillator, range is [-1, 1].
 void setPanNoGlide(float p)
          Set the pan of the Oscillator, but don't smoothly transition from whatever the current pan value is to this new one.
protected abstract  float value(float step)
          Returns the value of the waveform at step.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TWO_PI

protected static final float TWO_PI
The float value of 2*PI. Provided as a convenience for subclasses.

See Also:
Constant Field Values
Constructor Detail

Oscillator

public Oscillator(float frequency,
                  float amplitude,
                  float sampleRate)
Constructs an Oscillator with the requested frequency, amplitude and sample rate.

Parameters:
frequency - the frequency of the Oscillator
amplitude - the amplitude of the Oscillator
sampleRate - the sample rate of the Oscillator
Method Detail

sampleRate

public final float sampleRate()

setFreq

public final void setFreq(float f)
Sets the frequency of the Oscillator in Hz. If portamento is on, the frequency of the Oscillator will transition from the current frequency to f.

Parameters:
f - the new frequency of the Oscillator

frequency

public final float frequency()
Returns the current frequency.

Returns:
the current frequency

setAmp

public final void setAmp(float a)
Set the amplitude of the Oscillator, range is [0, 1].

Parameters:
a - the new amplitude, it will be constrained to [0, 1]

amplitude

public final float amplitude()
Returns the current amplitude.

Returns:
the current amplitude

setPan

public final void setPan(float p)
Set the pan of the Oscillator, range is [-1, 1].

Parameters:
p - - the new pan value, it will be constrained to [-1, 1]

setPanNoGlide

public final void setPanNoGlide(float p)
Set the pan of the Oscillator, but don't smoothly transition from whatever the current pan value is to this new one.

Parameters:
p - - the new pan value, it will be constrained to [-1,1]

pan

public final float pan()
Returns the current pan value.

Returns:
the current pan value

portamento

public final void portamento(int millis)
Sets how many milliseconds it should take to transition from one frequency to another when setting a new frequency.

Parameters:
millis - the length of the portamento

noPortamento

public final void noPortamento()
Turns off portamento.


generate

public final void generate(float[] signal)
Description copied from interface: AudioSignal
Fills signal with values in the range of [-1, 1]. signal represents a mono audio signal.

Specified by:
generate in interface AudioSignal
Parameters:
signal - the float array to fill

generate

public final void generate(float[] left,
                           float[] right)
Description copied from interface: AudioSignal
Fills left and right with values in the range of [-1, 1]. left represents the left channel of a stereo signal, right represents the right channel of that same stereo signal.

Specified by:
generate in interface AudioSignal
Parameters:
left - the left channel
right - the right channel

setAudioListener

public final void setAudioListener(AudioListener al)

period

public final float period()
Returns the period of the waveform (the inverse of the frequency).

Returns:
the period of the waveform

value

protected abstract float value(float step)
Returns the value of the waveform at step. To take advantage of all of the work that Oscillator does, you can create your own periodic waveforms by extending Oscillator and implementing this function. All of the oscillators included with Minim were created in this way.

Parameters:
step - an offset from the beginning of the waveform's period
Returns:
the value of the waveform at step