public class Oscil extends UGen
An Oscil is a UGen that generates audio by oscillating over a Waveform at a particular frequency. For instance, if you were to create this Oscil:
Oscil testTone = new Oscil( 440, 1, Waves.SINE );
When patched to an AudioOuput, it would generate a continuous sine wave tone at 440 Hz and would sound like a test tone. This frequency also happens to be the same as the pitch played by the lead oboist in a orchestra when they tune up at the beginning of a concert.
However, rather than give Oscil a fixed, or limited, set of sounds it can generate, instead it simply oscillates over a generic Waveform object. Waveform is simply an interface that declares a value method, which is used by Oscil to determine what value it should output at any given moment in time. Generally, you will use predefined Waveforms from the Waves class, or generated Waveforms using the WavetableGenerator class. However, there's no particular reason you couldn't define your own classes that implement the Waveform interface.
Another abstraction the Oscil UGen makes use of is the Frequency class. This class allows you to define a frequency in terms of pitch, midi note, or hertz. This is often quite useful when writing musical scores with code. For instance, we could use the Frequency class when creating an Oscil that will sound the same as the example above:
Oscil testTone = new Oscil( Frequency.ofPitch("A4"), 1, Waves.SINE );
UGen.InputType, UGen.UGenInput
Modifier and Type | Field and Description |
---|---|
UGen.UGenInput |
amplitude
Patch to this to control the amplitude of the oscillator with another
UGen.
|
UGen.UGenInput |
frequency
Patch to this to control the frequency of the oscillator with another
UGen.
|
UGen.UGenInput |
offset
Patch to this to control the DC offset of the Oscil with another UGen.
|
UGen.UGenInput |
phase
Patch to this to control the phase of the oscillator with another UGen.
|
Constructor and Description |
---|
Oscil(float frequencyInHertz,
float amplitude)
Constructs an Oscil UGen given frequency in Hz and amplitude.
|
Oscil(float frequencyInHertz,
float amplitude,
Waveform waveform)
Constructs an Oscil UGen, given frequency in Hz, amplitude, and a waveform
|
Oscil(Frequency frequency,
float amplitude)
Constructs an Oscil UGen given a Frequency and amplitude.
|
Oscil(Frequency frequency,
float amplitude,
Waveform waveform)
Constructs an Oscil UGen given a Frequency, amplitude, and a waveform
|
Modifier and Type | Method and Description |
---|---|
Waveform |
getWaveform()
Returns the Waveform currently being used by this Oscil.
|
void |
reset()
Resets the time-step used by the Oscil to be equal to the current
phase input value.
|
protected void |
sampleRateChanged()
This routine will be called any time the sample rate changes.
|
void |
setAmplitude(float newAmp)
Sets the amplitude of this Oscil.
|
void |
setFrequency(float hz)
Sets the frequency of this Oscil.
|
void |
setFrequency(Frequency newFreq)
Sets the frequency of this Oscil.
|
void |
setPhase(float newPhase)
Set the amount that the phase will be offset by.
|
void |
setWaveform(Waveform theWaveform)
Changes the Waveform used by this Oscil.
|
protected void |
uGenerate(float[] channels)
Implement this method when you extend UGen.
|
addAudio, addControl, addControl, addInput, channelCount, channelCountChanged, getLastValues, patch, patch, patch, printInputs, removeInput, sampleRate, setChannelCount, setSampleRate, tick, unpatch, unpatch
public UGen.UGenInput amplitude
public UGen.UGenInput frequency
public UGen.UGenInput phase
public UGen.UGenInput offset
public Oscil(float frequencyInHertz, float amplitude, Waveform waveform)
frequencyInHertz
- float: the frequency this Oscil should oscillate atamplitude
- float: the amplitude of this Oscil.waveform
- Waveform: the waveform this Oscil will oscillate overpublic Oscil(float frequencyInHertz, float amplitude)
frequencyInHertz
- float: the frequency this Oscil should oscillate atamplitude
- float: the amplitude of this Oscil.public Oscil(Frequency frequency, float amplitude)
frequency
- Frequency: the frequency this Oscil should oscillate at.amplitude
- float: the amplitude of this Oscil.public Oscil(Frequency frequency, float amplitude, Waveform waveform)
frequency
- Frequency: the frequency this Oscil should oscillate at.amplitude
- float: the amplitude of this Oscil.waveform
- Waveform: the waveform this Oscil will oscillate overprotected void sampleRateChanged()
sampleRateChanged
in class UGen
public void setFrequency(float hz)
hz
- the frequency, in Hertz, to set this Oscil topublic void setFrequency(Frequency newFreq)
newFreq
- the Frequency to set this Oscil topublic void setAmplitude(float newAmp)
newAmp
- amplitude to set this Oscil topublic void setPhase(float newPhase)
newPhase
- float: the phase offset valuepublic void setWaveform(Waveform theWaveform)
theWaveform
- the new Waveform to usepublic Waveform getWaveform()
public void reset()
protected void uGenerate(float[] channels)
UGen
getLastValues
method of your audio UGenInput to
retrieve the audio you want to modify, which you will then modify however
you need to, assigning the result to the values in channels
.