{"id":177,"date":"2013-06-01T11:00:45","date_gmt":"2013-06-01T19:00:45","guid":{"rendered":"http:\/\/www.earlevel.com\/main\/?p=177"},"modified":"2019-02-24T15:05:27","modified_gmt":"2019-02-24T23:05:27","slug":"envelope-generators","status":"publish","type":"post","link":"https:\/\/www.earlevel.com\/main\/2013\/06\/01\/envelope-generators\/","title":{"rendered":"Envelope generators\u2014ADSR Part 1"},"content":{"rendered":"<p>After discussing the exponential decay of the one-pole filter in a recent article, I couldn&#8217;t help but think about envelope generators. Besides, it would be handy to have one to test out some of these other components I&#8217;ve been writing about.<\/p>\n<p>The staple of analog synthesizers is the ADSR envelope generator. Sure, when creating an envelope computationally, we don&#8217;t have the limitations of hardware, so we could make envelopes of unlimited complexity. But the abundance of &#8220;virtual analog&#8221; plug-ins attest to the fact that the simple ADSR is a very effective design\u2014and mandatory if we&#8217;re simulating most vintage gear. And it&#8217;s more manageable to explain how to make an ADSR, and let you take it from there if you wish.<\/p>\n<h3>States and gates<\/h3>\n<p>Envelope generators are defined by their <em>states<\/em>. Typically, an envelope generator of a synthesizer at rest is in an <em>idle<\/em> state, outputting zero level. When you press a key, it raises a gate to the &#8220;on&#8221; state, triggering the envelope generator into its initial <em>attack<\/em> state. The output of the envelope generator begins to rise at an attack rate determined by a user control. As long as the key remains down, keeping the gate &#8220;on&#8221;, the envelope rises until it reaches its maximum output. At that time, it switches to the <em>decay<\/em> state, and moves towards the user-defined sustain level (set anywhere from zero to maximum output) at the rate set by another user control. Upon reaching the sustain level, the envelope generator switches to the <em>sustain<\/em> state, and remains there as long as the key is held. Once the key is released and the gate changes to &#8220;off&#8221;, the envelope generator switches to the <em>release<\/em> state, and begins moving towards zero at the rate set by a fourth user control.<\/p>\n<table>\n<table border=\"1\">\n<tr>\n<th>State<\/td>\n<th>Action<\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>do nothing (output remains at zero)<\/td>\n<\/tr>\n<tr>\n<td>Attack<\/td>\n<td>continue increasing output at attack rate; if max is reached, change <em>state<\/em> to Decay<\/td>\n<\/tr>\n<tr>\n<td>Decay<\/td>\n<td>continue reducing output at decay rate; if sustain level reached, change <em>state<\/em> to Sustain<\/td>\n<\/tr>\n<tr>\n<td>Sustain<\/td>\n<td>do nothing (output remains at the sustain level)<\/td>\n<\/tr>\n<tr>\n<td>Release<\/td>\n<td>continue reducing output at release rate; if zero is reached, change <em>state<\/em> to Idle<\/td>\n<\/tr>\n<\/table>\n<p>Note that the Idle and Sustain states have no exit rules. Moves out of these states are driven by a <em>gate<\/em> signal\u2014driven by a synthesizer key press and release, typically, though the gate can be from a low frequency oscillator or step sequencer, for instance. Here are the additional state rules, driven by the gate transitions:<\/p>\n<table>\n<table border=\"1\">\n<tr>\n<th>Gate transition<\/td>\n<th>Action<\/td>\n<\/tr>\n<tr>\n<td>from &#8220;off&#8221; to &#8220;on&#8221;<\/td>\n<td>set <em>state<\/em> to Attack<\/td>\n<\/tr>\n<tr>\n<td>from &#8220;on&#8221; to &#8220;off&#8221;<\/td>\n<td>if <em>state<\/em> is not Idle, then set <em>state<\/em> to Release<\/td>\n<\/tr>\n<\/table>\n<h3>Curves<\/h3>\n<p>Some envelope generators\u2014more often of the software variety than hardware\u2014have attack, decay, and release segments that rise or fall in a straight line. But hardware envelope generators use exponential segments, typically. The exponential moves come from the charging and discharging of capacitors with current limited by resistors\u2014one-pole filters, basically. Besides being easy to design with simple transistors, resistors, and capacitors, the exponential segments work especially well for amplitude envelopes, since we hear on a log scale (the exponential control against the log response makes the volume changes sound linear with respect to loudness).<\/p>\n<p>Let&#8217;s take a look at how this works in our one-pole filter. You can view a one-pole filter as simply feeding back a percentage of the previous output, with the percentage value controlling the rate of the resulting exponential curve.<\/p>\n<h3>A simple AR envelope generator<\/h3>\n<p>To get the leanest view of how an envelope generator works, let&#8217;s start with the simplest. Synthesizers generate gate signals, typically, when a key is pressed\u2014the gate starts at 0v with no keys down, jumps to 1v when a key is pressed, and back to 0v when the key is released. If we use that as the control signal to our VCA, we&#8217;d have an organ-like instant on and off\u2014not very flexible.<\/p>\n<p>But if we route that into a one-pole filter\u2014a resistor feeding a capacitor to ground\u2014the processed gate would ramp up and down with an exponentially-shaped curve, at a rate depending on the resistor and capacity values multiplied together. (Since it&#8217;s more difficult and costly to make variable capacitors, we use a fixed capacitor and a variable resistor.) Here&#8217;s a circuit simulation of this basic AR (Attack-Release) envelope generator:<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2013\/06\/one-pole-ckt.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/main\/wp-content\/uploads\/2013\/06\/one-pole-ckt.png\" alt=\"one-pole ckt\" width=\"291\" height=\"167\" class=\"alignnone size-full wp-image-189\" \/><\/a><br \/>\n<a href=\"\/main\/wp-content\/uploads\/2013\/06\/one-pole-ckt-step.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/main\/wp-content\/uploads\/2013\/06\/one-pole-ckt-step.png\" alt=\"one-pole ckt step\" width=\"432\" height=\"216\" class=\"alignnone size-full wp-image-188\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2013\/06\/one-pole-ckt-step.png 432w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2013\/06\/one-pole-ckt-step-300x150.png 300w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><\/a><\/p>\n<p>This generator is just as simple in software\u2014a gate that toggles from 0 to 1, fed into a one-pole filter, which is a delay and a multiplier taking the place of a capacitor and resistor. Here&#8217;s an iterative simulation done in a spreadsheet, using a feedback value calculated to be equivalent to the capacitor and resistor values shown in the circuit:<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2013\/06\/AR-calc.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/main\/wp-content\/uploads\/2013\/06\/AR-calc.png\" alt=\"AR calc\" width=\"449\" height=\"130\" class=\"alignnone size-full wp-image-187\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2013\/06\/AR-calc.png 449w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2013\/06\/AR-calc-300x86.png 300w\" sizes=\"(max-width: 449px) 100vw, 449px\" \/><\/a><\/p>\n<h3>Next: ADSR<\/h3>\n<p>But the AR isn&#8217;t a very flexible envelope generator\u2014it&#8217;s a simple shape, and a single control value sets both attack and decay times. It would be useful for flute-type sounds, but not for guitar, for instance. For guitar, we&#8217;d like a fast attack, a slow decay, and a quick release. For that kind of complexity, we need a more elaborate circuit, with transistors to switch in difference resistances and target levels for capacitor charging.<\/p>\n<p>Next up, we&#8217;ll delve into the specifics of an ADSR envelope generator in software.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After discussing the exponential decay of the one-pole filter in a recent article, I couldn&#8217;t help but think about envelope generators. Besides, it would be handy to have one to test out some of these other components I&#8217;ve been writing &hellip; <a href=\"https:\/\/www.earlevel.com\/main\/2013\/06\/01\/envelope-generators\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,9,23],"tags":[],"_links":{"self":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/177"}],"collection":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/comments?post=177"}],"version-history":[{"count":3,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":825,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/177\/revisions\/825"}],"wp:attachment":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}