2 summary:: Envelope generator
3 related:: Classes/Linen, Classes/Env
4 categories:: UGens>Envelopes
9 Plays back break point envelopes. The envelopes are instances of the
10 link::Classes/Env:: class. The envelope and the arguments for code::levelScale:: ,
11 code::levelBias:: , and code::timeScale::
12 are polled when the EnvGen is triggered and remain constant for the
13 duration of the envelope.
22 An link::Classes/Env:: instance, or an Array of Controls.
23 (See link::Classes/Control:: and the example below for how to use
26 The envelope is polled when the EnvGen is triggered. The Env inputs can be other UGens.
31 This triggers the envelope and holds it open while > 0. If the
32 Env is fixed-length (e.g. Env.linen, Env.perc), the gate argument
33 is used as a simple trigger. If it is an sustaining envelope
34 (e.g. Env.adsr, Env.asr), the envelope is held open until the
35 gate becomes 0, at which point is released.
37 If strong::gate:: < 0, force release with time code:: -1.0 - gate ::, see link::#forced_release:: below.
41 Scales the levels of the breakpoints.
46 Offsets the levels of the breakpoints.
51 Scales the durations of the segments.
56 An integer representing an action to be executed when the env is
57 finished playing. This can be used to free the enclosing synth,
58 etc. See link::Reference/UGen-doneActions:: for more detail.
62 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.
69 SynthDef(\env_help, { | out, gate = 0 |
71 z = EnvGen.kr(Env.adsr, gate) * SinOsc.ar(440, 0, 0.1);
85 // it does not matter to what value the gate is set, as long as it is > 0
91 subsection:: Changing an Env while playing
94 SynthDef(\env, { arg i_outbus=0;
97 // make a dummy 8 segment envelope
98 env = Env.newClear(8);
100 // create a control argument array
101 envctl = \env.kr( env.asArray );
103 ReplaceOut.kr(i_outbus, EnvGen.kr(envctl, doneAction: 2));
109 Out.ar(0, SinOsc.ar(In.kr(0), 0, 0.2));
113 s.sendMsg(\c_set, 0, 800);
115 s.sendMsg(\s_new, \sine, 1001, 1, 0);
117 e = Env([700, 900, 900, 800], [1, 1, 1]*0.4, \exp).asArray;
118 s.sendBundle(nil, [\s_new, \env, 1002, 2, 1001], [\n_setn, 1002, \env, e.size] ++ e);
120 f = Env([1000, 1000, 800, 1000, 900, 1000], [1, 1, 1, 1, 1]*0.3, \step).asArray;
121 s.sendBundle(nil, [\s_new, \env, 1003, 2, 1001], [\n_setn, 1003, \env, f.size] ++ f);
123 s.sendMsg(\n_free, 1001);
126 subsection:: Forced release
127 If the gate of an EnvGen is set to -1 or below, then the envelope will cutoff immediately.
128 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.
129 The cutoff shape is linear.
132 SynthDef(\stealMe, { arg gate = 1;
133 Out.ar(0, {BrownNoise.ar}.dup * EnvGen.kr(Env.asr, gate, doneAction:2))
137 s.sendMsg(\s_new, \stealMe, 1001, 1, 0);
139 s.sendMsg(\n_set, 1001, \gate, -1.1); // cutoff in 0.1 seconds
141 If the synthDef has an arg named "gate", the convenience method of Node can be used: code::node.release(releaseTime)::
143 d = { arg gate=1; {BrownNoise.ar}.dup * EnvGen.kr(Env.asr, gate, doneAction:2) }.play;
147 subsection:: Fast triggering tests
152 Env.new([ 0.001, 1, 0.5, 0 ], [ 0.01, 0.3, 1 ], -4, 2, nil),
154 ) * SinOsc.ar(440, 0, 0.1)
161 Env.perc( 0.1, 0.0, 0.5, 1, \welch ),
164 ) * SinOsc.ar(440, 0, 0.3)
169 subsection:: Modulating the levelScale
171 // no, it doesn't take a ugen in
175 Env.asr( 0.1, 1.0, 0.5, \welch ),
177 FSinOsc.ar(1.0).range(0.0, 1.0),
179 ) * SinOsc.ar(440, 0, 0.3)
183 // an .ir rate input, a float or an ir rate ugen like Rand would work
187 Env.asr( 0.1, 1.0, 0.5, \welch ),
191 ) * SinOsc.ar(440, 0, 0.3)