The [vline~] Pd object is well suited to use as an ADSR envelope generator. This patch uses the ADSR to modulate the amplitude of a [phasor~] object signal generator, but can be used to affect other attributes of a sound source as well. The first four sliders in the patch control the attack, decay, sustain, and release times. These sliders use a percentage of the segment length, thus the segment length slider must be in a non zero position in order for the ADSR sliders to register any amount of time. The attack level slider controls the maximum level at which the attack rises. The sustain level slider is pretty self explanatory. And the note volume acts as a master volume affecting all segments. The basic operation inside [pd adsr] is divided into three parts: calculate the ADSR times, load these times into [pack] objects, and feed these lists to the [vline~] object. The volume control in this case is controlled by the [*~] signal multiply object which multiplies the sound signal by the envelope signal.
useful patch, thanks!
Hi! This is a really great patch. I’m trying to use this in combination with my midi keyboard. The only thing I’m struggling with is that I don’t want to trigger the release until I actually let go of the key on the keyboard… I think I have to change segment_length into something else, but I don’t know what to replace it with. Help please?
Thanks. You can hold your release data any number of ways and then send it to vline~ when your note off data is encountered i.e. (vel=0).
I think the problem is that the provided Pd patch has the Sustain implemented as a timed stage, but it should be implemented as a level to be held until the MIDI note off command is received and starts the Release stage. I posted a patch on my blog where the Sustain is implemented as a level.
http://havencking.blogspot.com/2016/01/dadsr-envelope-generator-in-pure-data.html