Env superclass: Object An Env is a specification for a segmented envelope used by EnvGen. An Env can have any number of segments. They can stop at a particular value or loop several segments when sustaining. An Env can have several shapes for its segments. Creation *new(levels, times, curves, releaseNode, loopNode) Create a new envelope specification. levels - an array of levels. The first level is the initial value of the envelope. times - an array of durations of segments in seconds. There should be one fewer duration than there are levels. curves - this parameter determines the shape of the envelope segments. The possible values are: 'step' - flat segments 'linear' - linear segments 'exponential' - natural exponential growth and decay. In this case, the levels must all be nonzero and the have the same sign. 'sine' - sinusoidal S shaped segments. 'welch' - sinusoidal segments shaped like the sides of a Welch window. a Float - a curvature value for all segments. An Array of Floats - curvature values for each segments. releaseNode - an Integer or nil. The envelope will sustain at the release node until released. loopNode - an Integer or nil. If not nil the sustain portion will loop from the releaseNode to the loop node. Env.new([0,1,0.7,0],[2,3,2],'linear').plot; // different shaped segments: Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4],'linear').plot; Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4],'exponential').plot; Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4],'sine').plot; Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4],'welch').plot; Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4],'step').plot; Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4], -2).plot; Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4], 2).plot; Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4],[0,3,-3,-1]).plot; Fixed Duration Envelope Creation Methods The following class methods create some frequently used envelope shapes which have a fixed duration. *linen(attackTime, sustainTime, releaseTime, sustainLevel) Creates a new envelope specification which has a trapezoidal shape. attackTime - the duration of the attack portion. sustainTime - the duration of the sustain portion. releaseTime - the duration of the release portion. sustainLevel - the level of the sustain portion. Env.linen(1, 2, 3, 0.6).plot; Env.linen(1, 2, 3, 0.6).test; Env.linen(1, 2, 3, 0.6, 'sine').plot; Env.linen(1, 2, 3, 0.6, 'welch').plot; Env.linen(1, 2, 3, 0.6, -3).plot; *triangle(duration, level) Creates a new envelope specification which has a triangle shape. duration - the duration of the envelope. level - the peak level of the envelope. Env.triangle(1, 1).plot; Env.triangle(1, 1).test; *sine(duration, level) Creates a new envelope specification which has a hanning window shape. duration - the duration of the envelope. level - the peak level of the envelope. Env.sine(1, 1).plot; Env.sine(1, 1).test; *perc(attackTime, releaseTime, peakLevel, curve) Creates a new envelope specification which (usually) has a percussive shape. attackTime - the duration of the attack portion. releaseTime - the duration of the release portion. peakLevel - the peak level of the envelope. curve - the curvature of the envelope. Env.perc(0.01, 1, 1, -4).plot; Env.perc(0.01, 1, 1, -4).test; Env.perc(0.001, 1, 1, -4).test; // sharper attack Env.perc(0.001, 1, 1, -8).test; // change curvature Env.perc(1, 0.01, 1, 4).test; // reverse envelope Sustained Envelope Creation Methods The following methods create some frequently used envelope shapes which have a sustain segment. *adsr(attackTime, decayTime, sustainLevel, releaseTime, peakLevel, curve) Creates a new envelope specification which is shaped like traditional analog attack-decay-sustain-release (adsr) envelopes. attackTime - the duration of the attack portion. decayTime - the duration of the decay portion. sustainLevel - the level of the sustain portion as a ratio of the peak level. releaseTime - the duration of the release portion. peakLevel - the peak level of the envelope. curve - the curvature of the envelope. Env.adsr().plot; Env.adsr(0.02, 0.2, 0.25, 1, 1, -4).plot; Env.adsr(0.02, 0.2, 0.25, 1, 1, -4).test(2); Env.adsr(0.001, 0.2, 0.25, 1, 1, -4).test(2); // sharper attack *asr(attackTime, sustainLevel, releaseTime, peakLevel, curve) Creates a new envelope specification which is shaped like traditional analog attack-sustain-release (asr) envelopes. attackTime - the duration of the attack portion. sustainLevel - the level of the sustain portion as a ratio of the peak level. releaseTime - the duration of the release portion. peakLevel - the peak level of the envelope. curve - the curvature of the envelope. Env.asr(0.02, 0.5, 1, 1, -4).plot; Env.asr(0.02, 0.5, 1, 1, -4).test(2); Env.asr(0.001, 0.5, 1, 1, -4).test(2); // sharper attack Env.asr(0.02, 0.5, 1, 1, 'linear').test(2); // linear segments Utilities plot Plot the Envelope in a window. For examples look at those given above. blend(anotherEnv, blendFraction) Blend two envelopes. anotherEnv - an Env. blendFraction - a number from zero to one. ( // a demonstration of envelope blending var a, b, sa, sb, v1, v2, v3, s1, w, z; // make some envelopes a = Env.new([0, 1, 0.3, 0.8, 0], [2, 3, 1, 4], [3, 2, -2, -4]); b = Env.new([0, 0.2, 1, 0.4, 0], [1, 1, 1, 2], [-2, -2, 1, 0]); // generate signals to plot sa = Synth.collect({ EnvGen.ar(a, 1, 0, 1, 0, 0.01 / a.times.sum) }, 0.01); sb = Synth.collect({ EnvGen.ar(b, 1, 0, 1, 0, 0.01 / a.times.sum) }, 0.01); // create a window w = GUIWindow.new("Env blending", Rect.new( 128, 64, 528, 400 )); v1 = SignalView.new( w, Rect.new( 21, 23, 177, 123 ), sa, -1, 1); v2 = SignalView.new( w, Rect.new( 183, 23, 339, 123 ), sb, -1, 1); v3 = SignalView.new( w, Rect.new( 21, 186, 177, 286 ), nil,-1, 1); s1 = SliderView.new( w, Rect.new( 184, 138, 339, 158 ), " ", 0.5, 0, 1, 0.01, 'linear'); StringView.new( w, Rect.new( 48, 136, 176, 156 ), "Blend Fraction :"); // calculate an appropriate zoom z = ceil(sa.size / v1.bounds.width); v1.zoom = z; v2.zoom = z; v3.zoom = z; // make a slider action proc that blends the envelopes and plots the result s1.action = { v3.signal = Synth.collect({ var c, ec; c = blend(a, b, s1.value); ec = EnvGen.ar(c, 1, 0, 1, 0, 0.01 / a.times.sum); }, 0.01); v3.refresh; }; s1.action.value; ) ////////////////////////////////////////// EnvGen Envelope Generator EnvGen.ar(envelope, mul, add, levelScale, levelBias, timeScale, gate) Plays back break point envelopes. The envelopes are instances of the Env class. See the Env help file for more info. If the gate input is not supplied then the envelope begins at time zero of the event in which it is spawned and is released when the event is released. And envelope only has a physical end time (used to cut off events in a Spawn) if the gate input is not supplied. envelope - an instance of Env. mul - a signal to be multiplied by the envelope. add - a signal to be added to the envelope. levelScale - scales the levels of the breakpoints. levelBias - offsets the levels of the breakpoints. timeScale - scales the breakpoint durations. gate - The gate input will trigger an attack and hold a sustain of the envelope. If not supplied, gate defaults to -99, which means that the envelope triggers immediately and sustains until released by its enclosing Synth. ( // no gate, envelope plays once, sustaining until released by the Synth. var env; e = Env.adsr(0.001, 0.2, 0.25, 0.3, 1, -4); { arg synth; synth.releaseTime = 2; EnvGen.ar(e, LFSaw.ar(300, 0.2), 0, 1, 0, 1) }.scope(0.3); ) ( // trigger EnvGen with a pulse wave. // MouseX controls trigger frequency. // MouseY controls sustain time. var env; e = Env.adsr(0.001, 0.2, 0.25, 0.3, 1, -4); { var gate; gate = LFPulse.kr(MouseX.kr(0.2, 20, 'exponential'), MouseY.kr(0.01,0.99)); EnvGen.ar(e, LFSaw.ar(300, 0.2), 0, 1, 0, 1, gate) }.scope(0.3); )