EnvGen:
Filter:
Classes | UGens > Envelopes

EnvGen : UGen : AbstractFunction : Object

Envelope generator
Source: EnvGen.sc

Description

Plays back break point envelopes. The envelopes are instances of the Env class. The envelope and the arguments for levelScale, levelBias, and timeScale are polled when the EnvGen is triggered, and at the start of a new envelope segment. All values remain constant for the duration of each segment.

Class Methods

EnvGen.ar(envelope, gate: 1.0, levelScale: 1.0, levelBias: 0.0, timeScale: 1.0, doneAction: 0)

EnvGen.kr(envelope, gate: 1.0, levelScale: 1.0, levelBias: 0.0, timeScale: 1.0, doneAction: 0)

Arguments:

envelope

An Env instance, or an Array of Controls. (See Control and the example below for how to use this.)

The envelope is polled when the EnvGen is triggered, and at the start of a new envelope segment. The Env inputs can be other UGens.

gate

This triggers the envelope and holds it open while > 0. If the Env is fixed-length (e.g. Env.linen, Env.perc), the gate argument is used as a simple trigger. If it is an sustaining envelope (e.g. Env.adsr, Env.asr), the envelope is held open until the gate becomes 0, at which point is released.

If gate < 0, force release with time -1.0 - gate. See Forced release below.

levelScale

The levels of the breakpoints are multiplied by this value. This value can be modulated, but is only sampled at the start of a new envelope segment.

levelBias

This value is added as an offset to the levels of the breakpoints. This value can be modulated, but is only sampled at the start of a new envelope segment.

timeScale

The durations of the segments are multiplied by this value. This value can be modulated, but is only sampled at the start of a new envelope segment.

doneAction

An integer representing an action to be executed when the env is finished playing. This can be used to free the enclosing synth, etc. See Done for more detail.

Discussion:

NOTE: The actual minimum duration of a segment is not zero, but one sample step for audio rate and one block for control rate. This may result in asynchronicity when in two envelopes of different number of levels, the envelope times add up to the same total duration. Similarly, when modulating times, the new time is only updated at the end of the current segment - this may lead to asynchronicity of two envelopes with modulated times.

Inherited class methods

Instance Methods

Inherited instance methods

Undocumented instance methods

.canFreeSynth

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Audio/canFreeSynth.sc

Examples

Specifying an envelope for each new synth

Forced release

If the gate of an EnvGen is set to -1 or below, then the envelope will cutoff immediately. The time for it to cutoff is the amount less than -1, with -1 being as fast as possible, -1.5 being a cutoff in 0.5 seconds, etc. The cutoff shape and final value are read from the Env's last node.

If the synthDef has an arg named "gate", the convenience method of Node can be used: node.release(releaseTime)

Forced release ignores multi-node release stages, always performing a one-node release, reading curve and end value from the Env's last node, and overwriting its duration.

Fast triggering tests

Modulating the levelScale

Filter cutoff modulation and initial envelope level

When using an envelope to modulate a filter's cutoff/center frequency, at higher resonance settings, a short attack time can produce a spike in volume. If this effect is not desired, and the filter's attack is always at the beginning of the synth (as is usually the case when playing a pattern), the artifact can be avoided by setting the envelope's initial level closer to target level for shorter attack times (below about 0.05 sec).

The following example shows how to do this in a SynthDef: Attack times between 0 and 0.05 seconds will produce initial envelope values between 1.0 (attack time = 0 means no attack) and 0.0. If the attack time is greater than 0.05 seconds, the envelope will start at 0.0. (The envelope is between 0.0 and 1.0 and mapped onto a valid frequency range.)

To hear the (potentially loud) short-attack artifacts, edit the var envInit line to read var envInit = 0;.

The above works only for initial values. If a short attack is retriggered in the middle of a synth, then the envelope cannot adjust the low value for reattack (because the envelope's initial value is used only once, at the beginning of the synth, and never touched again). In that case, open the amplitude envelope slightly later to avoid the artifact.

NOTE: These artifacts are more prominent in SuperCollider versions after fall 2024 (3.14.x). In earlier versions, EnvGen's initial value was in the middle of the first segment, reducing the slope of the initial attack. Code migrated to newer SC versions may require one of the above adjustments.

More examples

For more information about the control bus mapping used in the line a = Synth(\sine, [freq: f.asMap]);, see Node: -map and Bus: -asMap.