/  Basic Unit Generators

UGen

Gain

Impulse

Step

SndBuf

SndBuf2

ADSR

Envelope

Delay

DelayL

DelayA

Echo

Noise

CNoise

Osc

SinOsc

TriOsc

SawOsc

PulseOsc

SqrOsc

Phasor

HalfRect

FullRect

Chugraph

Chugen

UGen_Multi

UGen_Stereo

Mix2

Pan2

Basic unit generator (UGen) base classes, simple signal generators, envelopes, and more.

UGen

inherits : Object

Base class for all unit generator (UGen) types.

constructors

UGen()

Default constructor for UGen.

member functions

int buffered(int val)

Set the unit generator's buffered operation mode, typically used externally from hosts that embed ChucK as a component. If true, the UGen stores a buffer of its most recent samples, which can be fetched using global variables in the host language.

int buffered()

Get the ugen's buffered operation mode.

UGen chan(int num)

Get channel (as a UGen) at specified index.

int channels(int num)

Set number of channels. (currently NOT supported)

int channels()

Get number of channels.

float gain(float val)

Set the gain of the unit generator.

float gain()

Get the gain of the unit generator.

int isConnectedTo(UGen rhs)

Return true if this UGen's output is connected to the input of rhs; if either this UGen or rhs has more than one channel, this function returns true if any connections exist between the channels; return false if there are no connections.

float last()

Get the last sample value of the unit generator.

int op(int val)

Set the unit generator's operation mode. Accepted values are: 1 (sum inputs), 2 (take difference between first input and subsequent inputs), 3 (multiply inputs), 4 (divide first input by subsequent inputs), 0 (do not synthesize audio, output 0) or -1 (passthrough inputs to output).

int op()

Get the unit generator's operation mode.


Gain

inherits : UGen : Object

A gain control unit generator. (All unit generators can already change their own gain; this is an explicit way to add multiple outputs together and scale them.)

examples

constructors

Gain()

Default constructor for Gain.

Gain(float gain)

Construct a Gain with default value.


Impulse

inherits : UGen : Object

An impulse generator. Can be used to set the value of the next sample; default for each sample is 0 if not set. Additionally, this can be used to generate a digital signal, one sample at a time.

examples

constructors

Impulse()

Default constructor for Impulse.

member functions

float next(float next)

Set the value of next sample. (Note: if you are using the UGen.last() method to read the output of the impulse, the value set by Impulse.next() does not appear as the output until after the next sample boundary. In this case, there is a consistent 1::samp offset between setting .next(...) and reading that value using .last().)

float next()

Get value of next sample to be generated.


Step

inherits : UGen : Object

A step generator. Step behaves like Impulse, except that once a next value is set, that value is held for all following samples, until a different value is set.

examples

constructors

Step()

Default constructor for Step.

Step(float value)

Construct a Step with default value.

member functions

float next(float next)

Set the next step value.

float next()

Get the next step value.


SndBuf

inherits : UGen : Object

An interpolating sound buffer/player with single-channel output; can read audio data from a variety of uncompressed formats.

examples

constructors

SndBuf()

Default constructor for SndBuf.

SndBuf(string path)

Construct a SndBuf with the 'path' to a sound file to read.

SndBuf(string path, float rate)

Construct a SndBuf with the 'path' to a sound file to read, and a default playback 'rate' (1.0 is normal rate)

SndBuf(string path, float rate, int pos)

Construct a SndBuf with the 'path' to a sound file to read, a default playback 'rate' (1.0 is normal rate), and starting at sample position 'pos'

member functions

int channel(int channel)

For sound file containing more than one channel of audio, select the channel to play.

int channel()

Get the selected chanel of audio this buffer is playing.

int channels()

Get number of channels available in the sound file.

int chunks(int frames)

Set chunk size, in frames, for loading the file from disk. Set to 0 to disable chunking.

int chunks()

Get chunk size, in frames, for loading the file from disk. 0 indicates that chunking is disabled.

int frames()

Get total number of sample frames in the file; same as .samples().

float freq(float freq)

Set loop rate (in file loops per second).

float freq()

Get loop rate (in file loops per second).

int interp(int interp)

Set interpolation mode: (0) drop sample; (1) linear interpolation; (2) sinc interpolation.

int interp()

Get interpolation mode: (0) drop sample; (1) linear interpolation; (2) sinc interpolation.

dur length()

Get total length of the file as a duration.

int loop(int loop)

Toggle looping file playback.

int loop()

Get whether file playback is set to loop.

float phase(float phase)

Set phase position, normalized to [0,1).

float phase()

Get phase position, normalized to [0,1).

float phaseOffset(float value)

Advance the playhead by the specified phase offset in [0,1), where 0 is no advance and 1 advance the entire length of the file.

float play(float play)

(same as .rate)

float play()

(same as .rate)

int pos(int pos)

Set play position (between 0 and number of samples).

int pos()

Get play position (between 0 and number of samples).

float rate(float rate)

Set playback rate (relative to file's natural speed). For example, 1.0 is 'normal', 0.5 is half speed, and 2 is twice as fast.

float rate()

Get playback rate (relative to file's natural speed). For example, 1.0 is 'normal', 0.5 is half speed, and 2 is twice as fast.

string read(string read)

Read file for reading.

int ready()

Query whether the SndBuf is ready for use (e.g., sound file successfully loaded).

int samples()

Get total number of sample frames in the file; same as .frames().

float valueAt(int pos)

Get sample value at given position (in samples).

string write(string read)

Set file for writing (currently unsupported).


SndBuf2

inherits : SndBuf : UGen : Object

An interpolating sound buffer with two-channel output. Reads from a variety of uncompressed formats.

constructors

SndBuf2()

Default constructor for SndBuf2.


ADSR

inherits : Envelope : UGen : Object

This Envelope subclass implements a traditional ADSR (Attack, Decay, Sustain, Release) envelope. It responds to simple `keyOn` and `keyOff` messages, keeping track of its state. by Perry R. Cook and Gary P. Scavone, 1995 - 2002.

examples

constructors

ADSR()

Default constructor for ADSR.

member functions

float attackRate(float value)

Set attack rate.

float attackRate()

Get attack rate.

dur attackTime(dur value)

Set attack time.

dur attackTime()

Get attack time.

float decayRate(float value)

Set decay rate.

float decayRate()

Get decay rate.

dur decayTime(dur value)

Set decay time.

dur decayTime()

Get decay time.

float releaseRate(float value)

Set release rate.

float releaseRate()

Get release rate.

dur releaseTime(dur value)

Set release time.

dur releaseTime()

Get release time.

void set(float attackTime, float decayTime, float sustainLevel, float releaseTime)

Set attack, decay, sustain, and release all at once (in seconds).

void set(dur attackDuration, dur decayDuration, float sustainLevel, dur releaseDuration)

Set attack, decay, sustain, and release all at once.

int state()

Get state; attack=0, decay=1, sustain=2, release=3, done=4.

float sustainLevel(float value)

Set sustain level.

float sustainLevel()

Get sustain level.

static member variables

int ATTACK

See state() function. Denotes that the envelope is in the attack stage.

int DECAY

See state() function. Denotes that the envelope is in the decay stage.

int DONE

See state() function. Denotes that the envelope has completed all stages.

int RELEASE

See state() function. Denotes that the envelope is in the release stage.

int SUSTAIN

See state() function. Denotes that the envelope is in the sustain stage.


Envelope

inherits : UGen : Object

This class implements a simple envelope generator which is capable of ramping to a target value by a specified rate. It also responds to simple `keyOn` and `keyOff` messages, ramping to 1.0 on `keyOn` and to 0.0 on `keyOff`. by Perry R. Cook and Gary P. Scavone, 1995 - 2002.

examples

constructors

Envelope()

Default constructor for Envelope.

member functions

dur duration(dur value)

Set duration to reach target.

dur duration()

Get duration to reach target.

int keyOff()

Get keyOff state.

int keyOff(int value)

Ramp to 0.0.

int keyOn()

Get keyOn state.

int keyOn(int value)

Ramp to 1.0.

float rate(float value)

Set rate of change.

float rate()

Get rate of change.

float target(float value)

Set value to ramp to.

float target()

Get value to ramp to.

float time(float value)

Set time to reach target (in seconds).

float time()

Get time to reach target (in seconds).

float value(float value)

Set immediate value.

float value()

Get immediate value.


Delay

inherits : UGen : Object

A non-interpolating digital delay-line. A fixed maximum length of 4095 and a delay of zero is set using the default constructor. Alternatively, the delay and maximum length can be set during instantiation with an overloaded constructor. A non-interpolating delay line is typically used in fixed delay-length applications, such as for reverberation. by Perry R. Cook and Gary P. Scavone, 1995 - 2002.

examples

constructors

Delay()

Default constructor for Delay.

member functions

void clear()

Clear delay line.

dur delay(dur value)

Set length of delay.

dur delay()

Get length of delay.

dur max(dur value)

Set max delay (buffer size).

dur max()

Get max delay (buffer size).


DelayL

inherits : UGen : Object

A fractional-length digital delay-line using first-order linear interpolation. A fixed maximum length of 4095 and a delay of zero is set using the default constructor. Alternatively, the delay and maximum length can be set during instantiation with an overloaded constructor. Linear interpolation is an efficient technique for achieving fractional delay lengths, though it does introduce high-frequency signal attenuation to varying degrees depending on the fractional delay setting. The use of higher order Lagrange interpolators can typically improve (minimize) this attenuation characteristic. by Perry R. Cook and Gary P. Scavone, 1995 - 2002.

examples

constructors

DelayL()

Default constructor for DelayL.

member functions

void clear()

Clear delay line.

dur delay(dur value)

Set length of delay.

dur delay()

Get length of delay.

dur max(dur value)

Set max delay (buffer size).

dur max()

Get max delay (buffer size).


DelayA

inherits : UGen : Object

A fractional-length digital delay-line using a first-order allpass filter. A fixed maximum length of 4095 and a delay of 0.5 is set using the default constructor. Alternatively, the delay and maximum length can be set during instantiation with an overloaded constructor. An allpass filter has unity magnitude gain but variable phase delay properties, making it useful in achieving fractional delays without affecting a signal's frequency magnitude response. In order to achieve a maximally flat phase delay response, the minimum delay possible in this implementation is limited to a value of 0.5. by Perry R. Cook and Gary P. Scavone, 1995 - 2002.

examples

constructors

DelayA()

Default constructor for DelayA.

member functions

void clear()

Clear delay line.

dur delay(dur value)

Set length of delay.

dur delay()

Get length of delay.

dur max(dur value)

Set max delay (buffer size).

dur max()

Get max delay (buffer size).


Echo

inherits : UGen : Object

An echo effect. by Perry R. Cook and Gary P. Scavone, 1995 - 2002.

examples

constructors

Echo()

Default constructor for Echo.

member functions

dur delay(dur value)

Set length of echo.

dur delay()

Get length of echo.

dur max(dur value)

Set max delay (buffer size).

dur max()

Get max delay (buffer size).

float mix(float value)

Set mix level (wet/dry).

float mix()

Get mix level (wet/dry).


Noise

inherits : UGen : Object

A white noise generator.

examples


CNoise

inherits : UGen : Object

A noise generator with multiple noise synthesis modes.

constructors

CNoise()

Default constructor for CNoise.

member functions

float fprob(float fprob)

Probability [0-1] used for calculating XOR noise.

string mode(string mode)

Noise synthesis mode. Supported modes are "white", "pink", "flip", and "xor".


Osc

inherits : UGen : Object

Base class for simple oscillator unit generators.

constructors

Osc()

Default constructor for Osc.

Osc(float freq)

Construct Osc at specified frequency.

Osc(float freq, float phase)

Construct Osc at specified frequency and phase.

member functions

float freq(float hz)

Set frequency of oscillator in Hertz; maintains phase.

float freq()

Get frequency of oscillator in Hertz.

dur period(dur value)

Set period of oscillator (inverse of frequency).

dur period()

Get period of oscillator (inverse of frequency).

float phase(float phase)

Set oscillator phase, in range [0,1).

float phase()

Get oscillator phase, in range [0,1).

float sfreq(float hz)

Set frequency of oscillator in Hertz; resets phase to 0.

int sync(int type)

Choose how to interpret input: (0) sync frequency to input; (1) sync phase to input; (2) frequency modulation (add input to internal frequency).

int sync()

Get current interpretation of input: (0) sync frequency to input; (1) sync phase to input; (2) frequency modulation (add input to internal frequency).


SinOsc

inherits : Osc : UGen : Object

A sine wave oscillator.

examples

constructors

SinOsc()

Default constructor for SinOsc.

SinOsc(float freq)

Construct SinOsc at specified frequency.

SinOsc(float freq, float phase)

Construct SinOsc at specified frequency and phase.


TriOsc

inherits : Osc : UGen : Object

A triangle wave oscillator.

examples

constructors

TriOsc()

Default constructor for TriOsc.

TriOsc(float freq)

Construct TriOsc at specified frequency.

TriOsc(float freq, float phase)

Construct TriOsc at specified frequency and phase.

member functions

float width(float width)

Set width of triangle wave (ratio of rise time to fall time).

float width()

Get width of triangle wave (ratio of rise time to fall time).


SawOsc

inherits : TriOsc : Osc : UGen : Object

Sawtooth wave oscillator.

examples

constructors

SawOsc()

Default constructor for SawOsc.

SawOsc(float freq)

Construct SawOsc at specified frequency.

SawOsc(float freq, float phase)

Construct SawOsc at specified frequency and phase.

member functions

float width(float width)

Whether sawtooth wave is to fall (0) or rise (1).

float width()

Whether sawtooth wave is to fall (0) or rise (1).


PulseOsc

inherits : Osc : UGen : Object

A pulse width oscillator.

examples

constructors

PulseOsc()

Default constructor for PulseOsc.

PulseOsc(float freq)

Construct PulseOsc at specified frequency.

PulseOsc(float freq, float phase)

Construct PulseOsc at specified frequency and phase.

member functions

float width(float width)

Set width of duty cycle [0,1).

float width()

Get width of duty cycle [0,1)/.


SqrOsc

inherits : PulseOsc : Osc : UGen : Object

A square wave oscillator (same as PulseOsc with 0.5 duty cycle).

examples

constructors

SqrOsc()

Default constructor for SqrOsc.

SqrOsc(float freq)

Construct SqrOsc at specified frequency.

SqrOsc(float freq, float phase)

Construct SqrOsc at specified frequency and phase.

member functions

float width()

Set width of duty cycle (always 0.5).


Phasor

inherits : Osc : UGen : Object

A phasor oscillator; linearly rises from 0 to 1; can be used as a phase control.

examples

constructors

Phasor()

Default constructor for Phasor.

Phasor(float freq)

Construct Phasor at specified frequency.

Phasor(float freq, float phase)

Construct Phasor at specified frequency and phase.


HalfRect

inherits : UGen : Object

A half wave rectifier.


FullRect

inherits : UGen : Object

A full wave rectifier.


Chugraph

inherits : UGen : Object

Base class for subgraph-based user-created in-language unit generators.

examples

constructors

Chugraph()

Default constructor for Chugraph.

member variables

UGen inlet

Terminal for sources chucked into this ugen.

UGen outlet

Terminal for the output of this ugen.


Chugen

inherits : UGen : Object

Base class for user-created in-language unit generators.

examples

constructors

Chugen()

Default constructor for Chugen.


UGen_Multi

inherits : UGen : Object

Base class for multi-channel unit generators.

constructors

UGen_Multi()

Default constructor for UGen_Multi.

member functions

UGen chan(int which)

Get UGen representing a specific channel of this UGen, or null if no such channel is available.


UGen_Stereo

inherits : UGen_Multi : UGen : Object

Base class for stereo unit generators.

constructors

UGen_Stereo()

Default constructor for UGen_Stereo.

member functions

float pan(float val)

Pan between left and right channels, in range [-1,1], with -1 being far-left, 1 far-right, and 0 centered.

float pan()

Pan between left and right channels, in range [-1,1], with -1 being far-left, 1 far-right, and 0 centered.

int panType(int val)

Set the panning type: (1) constant power panning, (0) unity gain anti-panning.

int panType()

Get the panning type: (1) constant power panning, (0) unity gain anti-panning.

member variables

UGen left

Left channel (same as .chan(0)).

UGen right

Right channel (same as .chan(1)).


Mix2

inherits : UGen_Stereo : UGen_Multi : UGen : Object

A stereo-to-mono unit generator for mixing stereo signal to mono.

constructors

Mix2()

Default constructor for Mix2.