Envelopes are pre-defined amplitude distribution over time. Typically, envelopes are used to control the output volume of an object, a series of fades referred to as Attack, Decay, Sustain and Release ( ADSR ). Envelopes can also control other Web Audio Parameters—for example, a p5.Envelope can control an Oscillator's frequency like this: osc.freq(env)
.
Use <a href="/reference/p5.Envelope/setRange/">setRange</a>
to change the attack/release level. Use <a href="/reference/p5.Envelope/setADSR/">setADSR</a>
to change attackTime, decayTime, sustainPercent and releaseTime.
Use the <a href="/reference/p5.Envelope/play/">play</a>
method to play the entire envelope, the <a href="/reference/p5.Envelope/ramp/">ramp</a>
method for a pingable trigger, or <a href="/reference/p5.Envelope/triggerAttack/">triggerAttack</a>
/ <a href="/reference/p5.Envelope/triggerRelease/">triggerRelease</a>
to trigger noteOn/noteOff.
Examples
Fields
Time until envelope reaches attackLevel
Level once attack is complete.
Time until envelope reaches decayLevel.
Level after decay. The envelope will sustain here until it is released.
Duration of the release portion of the envelope.
Level at the end of the release.
Methods
Reset the envelope with a series of time/value pairs.
Set values like a traditional ADSR envelope .
Set max (attackLevel) and min (releaseLevel) of envelope.
Assign a parameter to be controlled by this envelope. If a p5.Sound object is given, then the p5.Envelope will control its output gain. If multiple inputs are provided, the env will control all of them.
Set whether the envelope ramp is linear (default) or exponential. Exponential ramps can be useful because we perceive amplitude and frequency logarithmically.
Play tells the envelope to start acting on a given input. If the input is a p5.sound object (i.e. AudioIn, Oscillator, SoundFile), then Envelope will control its output volume. Envelopes can also be used to control any Web Audio Audio Param.
Trigger the Attack, and Decay portion of the Envelope. Similar to holding down a key on a piano, but it will hold the sustain level until you let go. Input can be any p5.sound object, or a Web Audio Param.
Trigger the Release of the Envelope. This is similar to releasing the key on a piano and letting the sound fade according to the release level and release time.
Exponentially ramp to a value using the first two values from setADSR(attackTime, decayTime)
as time constants for simple exponential ramps. If the value is higher than current value, it uses attackTime, while a decrease uses decayTime.
Add a value to the p5.Oscillator's output amplitude, and return the oscillator. Calling this method again will override the initial add() with new values.
Multiply the p5.Envelope's output amplitude by a fixed value. Calling this method again will override the initial mult() with new values.
Scale this envelope's amplitude values to a given range, and return the envelope. Calling this method again will override the initial scale() with new values.