Reference p5.Envelope

p5.Envelope

Generate an amplitude envelope.

Examples

Syntax

p5.Envelope([attack], [decay], [sustain], [release])

Parameters

attack
Number: how quickly the envelope reaches the maximum level
decay
Number: how quickly the envelope reaches the sustain level
sustain
Number: how long the envelope stays at the decay level
release
Number: how quickly the envelope fades out after the sustain level

Fields

attackTime

Time until envelope reaches attackLevel

attackLevel

Level once attack is complete.

decayTime

Time until envelope reaches decayLevel.

decayLevel

Level after decay. The envelope will sustain here until it is released.

releaseTime

Duration of the release portion of the envelope.

releaseLevel

Level at the end of the release.

Methods

set

Reset the envelope with a series of time/value pairs.

setADSR
Sets the attack, decay, sustain, and release times of the envelope.
setRange

Set max (attackLevel) and min (releaseLevel) of envelope.

setExp

Set whether the envelope ramp is linear (default) or exponential. Exponential ramps can be useful because we perceive amplitude and frequency logarithmically.

play
Trigger the envelope and release it after the sustain time.
triggerAttack
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.
triggerRelease
Trigger the Release of the envelope. Similar to releasing the key on a piano and letting the sound fade according to the release level and release time.
ramp

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

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.

mult

Multiply the p5.Envelope's output amplitude by a fixed value. Calling this method again will override the initial mult() with new values.

scale

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.

releaseTime
Sets the release time of the envelope.
attackTime
Sets the attack time of the envelope.
Notice any errors or typos? Please let us know. Please feel free to edit src/Envelope.js and open a pull request!

Related References