Designing a simple ADSR(-ish) envelope generator from scratch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Always excited for these

👍︎︎ 10 👤︎︎ u/mobilityMovement 📅︎︎ Jun 14 2021 🗫︎ replies

Love your videos!

👍︎︎ 4 👤︎︎ u/diglitch 📅︎︎ Jun 14 2021 🗫︎ replies

Your videos and the way you are presenting things are beautiful. Thank you!

👍︎︎ 4 👤︎︎ u/[deleted] 📅︎︎ Jun 14 2021 🗫︎ replies

Love ur videos man

👍︎︎ 3 👤︎︎ u/romanowy_ 📅︎︎ Jun 14 2021 🗫︎ replies

You’ve got a terrific Reddit handle, Moritz!

👍︎︎ 4 👤︎︎ u/EightBitEstep 📅︎︎ Jun 14 2021 🗫︎ replies

These videos are fantastic. Always excited to watch them. Thank you.

👍︎︎ 2 👤︎︎ u/Stranger-Sun 📅︎︎ Jun 15 2021 🗫︎ replies

These videos are really great! Super clear and helpful. I’m going to try this out and put it in my eurorack.

Btw, are the pots linear type A or log type B? Thanks!

👍︎︎ 2 👤︎︎ u/HexagonalBokeh 📅︎︎ Jun 15 2021 🗫︎ replies

this is on my list now! WOW °.°

👍︎︎ 2 👤︎︎ u/knopsl 📅︎︎ Jun 15 2021 🗫︎ replies
Captions
if you've been following this channel for a while and built along with my videos chances are you've now got a vco a filter and maybe a vca in your diy modular rack and while these are essential modules they're not all that usable without another important addition an envelope generator why is that what do we need an envelope generator for simple we've only got two hands best case so there's a hard limit to how many knobs we can turn and parameters we can tweak at the same time also those hands are generally sluggish sloppy and imprecise wouldn't it be much better if we had some virtual programmable robot hand to help us out that would do what we tell it to do reliably and precisely whenever we wanted to if your answer is yes then you might be a control freak also you'd probably want an envelope generator like this one [Music] [Applause] [Music] [Music] [Music] so what exactly is happening here simple this envelope generator is acting as a virtual hand tweaking a cutoff frequency and amplitude a pitch how does that work well in both my oscillator and filter series we went to great lengths to make them voltage controllable this pays off now because both for the oscillator's pitch and for the filter's cutoff frequency we now have two interchangeable options if we want to manipulate them by turning a knob or by sending a voltage into these inputs so if we want the filter to open up for example we can either turn this guy to the right or we send in a high-level voltage here now of course if we only wanted to open the filter and keep it open we could send in a fixed 12-volt signal and be done with it that's not all that useful though normally you'd want the filter to close at some point too so why not simply use a square wave oscillator since a square wave is really just an oscillation between a high and a low level voltage this would indeed cause our filter to open up and close down even better it would do so rhythmically as the oscillator cycles through its phases and while this does work it has two severe limitations first the opening and closing movements are always instant with no way of making them any more gradual this might be what you want in some contexts but often you'd need something less abrupt and second we can't change the rhythmic pattern all we get is a constant staccato here's what that would sound like i'm using a very slow square wave to control the filter's cutoff frequency now i don't know about you but to me that sounds very static and lifeless so what can we do about that well the most obvious thing is to try and make the rising and falling edges here less steep in envelope terms we'd say that we want to slow down the attack and extend the release and while this may sound complicated it's actually anything but all we need are two components a resistor and a capacitor set up like this now if you've seen my videos on analog filters this setup should look strikingly familiar that's because this is really just a box standard low pass filter and what it does to our square wave is exactly what we said we're after it takes the rising and falling edges and makes them less steep here's how it works once the voltage over here switches from low to high a current will be forced through the resistor and into the capacitor slowly filling it up as the capacitor is being charged the voltage at this point slowly rises until the cap is completely filled up and the voltage is here and here align then when the input signal swings low the whole process reverses now the capacitor will push its contents through the resistor and into the input so to speak this happens because the voltage on this side is much higher than the voltage over here then as the capacitor empties out slowly the two voltages align again as you can see this will turn our square wave input into something like a very basic attack release envelope but before we try this we'll have to think about the appropriate values for the capacitor and resistor now since we're dealing with a very very slow square wave oscillation at the input they'll need to be pretty big otherwise the effect will be so minimal that we won't be able to tell the difference in my experiments a 100k resistor coupled with a one microfarad capacitor gave me some decent results so i'll set this up on my breadboard sending the input square in here and then connecting this side to my filter cv input let's see how it sounds and yeah the filter movement is much less abrupt we've got a slower attack and an extended release as planned but what if we want to adjust the effect well we've essentially got two options here we could change either the capacitor or resistor value but because switching components is not the most user-friendly strategy i am going to replace the fixed resistor with a potentiometer this way we can adjust the resistance and thereby the speed of the charging and discharging process on the fly a one mega ohm pod should give us a decent enough range here let's hear how that sounds wow wow wow wow and yeah we can now dial in a more or less intense effect the only problem with this is that the attack and release phases are not adjustable independently changing one will always also change the other so how can we separate the two it's actually really easy all we need are two diodes and another one mega ohm potentiometer here's how this works diodes as you probably know are basically one-way streets for electricity so by putting two of them in parallel like this facing in opposite directions we are taking a two-way street and we're splitting it into two one-way streets where before our capacitor was charged and discharged through the same resistor now each phase gets their own so when the input signal swings high a current will flow through this diode and only this diode through this resistor and into the capacitor and during the low phase the current will take this other path this means that this potentiometer now controls the attack and this one controls the release cool so let's give this a try i'll set up the second part over here bring in our two diodes and connect everything to the capacitor [Music] as you can hear i'm not able to sculpt the filter movement much more freely great so what we have here is an ultra simple passive attack release envelope generator why passive because it does not include any form of amplification it's getting all of its power from the square wave oscillator is this a problem that very much depends on what your goals and context are in this current form the envelope can only properly function if two external conditions are met the circuit triggering it in our case the oscillator needs to be able to provide enough current and the circuit we're controlling in our case the filter needs to draw as little current as possible from our envelope why simple let's imagine we put a 100k resistor between our square wave oscillator and the envelope this way we are severely limiting the amount of current flowing into our circuit and that means that even if we dial our attack and release pots all the way down charging and discharging our capacitor here will not be instant as we'd expect but instead would take a while on the other side imagine our filter was also using the envelope to drive an led since leds are pretty power hungry this would basically suck our capacitor dry and then eat up all the current coming through the attack pot turning our envelope curve into a pretty flat line now granted this is a worst case scenario well-designed modules should always have high current outputs and low to no current inputs which ironically is a standard our envelope here does not live up to at all it eats up our oscillator signal while providing nothing for the filter thankfully fixing that is really straightforward we'll simply buffer both the in and output with op amps now if you don't know how these work i've put a link to a thorough explanation in the description but the basic gist is that if you set op-amps up like this they act as what we call voltage buffers these things take in a voltage and provide an identical copy at their output while being able to supply a decent amount of current because of that it no longer really matters how much current the input can provide and how much the next circuit eats up cool but why the 1k resistor at the output here then and what's all this additional stuff at the input well unfortunately there's other worst case scenarios we need to consider the first one of which being a classic user error imagine that user plugs our envelope's output into some other module's output by accident if that other module also uses a voltage buffer there we'll basically create a short circuit since buffers can not only source but also sync plenty of current so by placing a 1k resistor here we make sure that in this scenario the maximum amount of current that can flow is limited saving our op amps from a potential early grave okay easy so now let's tackle this additional op-amp over here what kind of problem does it fix well while we did make sure that our circuit gets enough current we haven't thought about the voltage we're feeding it yet we should though because that voltage will determine the voltage range across which our envelope is operating think of it this way if all our envelope does is take the input signal and make the rising and falling edges less steep then the maximum height of the resulting curve is completely determined by that input signal why is that a problem because if the input signal would for example just swing between 0 and 1 volts that curve would be really flat and a flatter curve means a reduced range of effect when controlling our filter for example this flat curve would barely be able to move the cutoff point so basically our envelope would behave very differently depending on what kind of circuit we use to drive or trigger it and for me that would get very annoying very fast but since it's very easy to eliminate this kind of external dependency let's get rid of it to do that we use this op-amp which i've set up in the comparator configuration a comparator if you don't know basically just looks at an input voltage compares that input voltage to a reference voltage and then tells us which one is higher how does it tell us by either pushing its output voltage up to the positive or pulling it down to the negative supply rail so in my case that would be either plus or minus 12 volts here's how this particular setup works in detail i've set up a voltage divider to get our reference voltage a 100k 47k combination gives us approximately 3.8 volts to work with so whenever our input voltage here is higher than that the comparator's output will jump to plus 12 volts and if it's lower it drops down to -12. why did i choose that exact threshold to be honest mostly just because i had packs of 100ks and 47ks lying on my table when i was testing this but i still feel that 3.8 volts is a decent value here it's low enough that any sequencer should be able to trigger the envelope but definitely high enough to prevent it from firing randomly because of electromagnetic interference okay so now our envelope will always get the same 12 volts to work with as long as our input signal passes the threshold but what about the comparator's low state we said that once the input drops below the threshold we get -12 volts at this point this is not ideal because traditionally the baseline for an envelope's output is supposed to be 0 volts which is why i've decided to put a diode followed by a 100k resistor to ground between our comparator's output and the buffer's input here's what that does whenever the comparator is pushing out 12 volts the diode conducts and we also get about 12 volts at the buffer's input but once the voltage here turns negative the diode will block normally the buffer's input would now be undefined or floating but since we have this 100k resistor to ground right here that input gets pulled down to zero volts instead which is why we call this a pull down resistor by the way and with this we've now forced the envelope's operating voltage range to always be between 0 and 12 volts but enough theory let's build this and see if it actually works first i'll set up a tl074 which is four op-amps in one chip this op-amp will be our comparator so i'll connect this socket to its non-inverting input next i'll set the threshold at the inverting input with a 100k 47k voltage divider using a diode i'll then route the comparator's output to this op-amp's non-inverting input by connecting the inverting input and the output with a small jumper i configure it as a voltage buffer that buffer's output then links up to our existing capacitor charging and discharging paths finally i'll connect that capacitor to the op-amp over here also setting it up as a buffer add in the 1k output protection resistor between buffer and output socket and we're done to test this let's first send in our square wave oscillation as you can hear everything's working pretty much like before though the range of the filter movement is significantly increased where it gets interesting though is when we use a sequencer to trigger the envelope instead to do that we connect our envelope to the sequence's gate output the gate output will basically just send out a high voltage whenever a node is supposed to play so when i push one of these pads our envelope gets triggered and runs through its attack phase if i hold it long enough we reach the envelope's peak and will stay there until i let go then the release phase starts and eventually we return to the initial state so now we've got a proper active attack release envelope and while we could leave it there i'd rather put a bit more effort in to give us finer control over the envelope curves shape on the left side here i've drawn up what our current circuit is capable of producing a simple attack release curve on the other side we have a more complex attack decay sustain release curve what's the difference well while both curves have an attack and a release phase the one on the right adds a decay phase and the ability to set a specific sustain level the idea here is this if the sustain is set to a lower value than the envelope's peak we get this drop after the attack this is the decay phase once that's through the curve settles on the set sustain level while the input signal stays high from here we enter the release once the input swings low what's the benefit of this added complexity simple we can produce a wider variety of sounds me personally i really like short plucky percussive hits and also glidy acid bass lines and both of those are not really doable with a simple attack release envelope now turning the circuit we have into a proper adsr envelope is sadly somewhat out of scope for this video still with very little extra effort we can build something that approximates it here's how that would work as you can see i've basically just copied our comparator and pasted it down here both the new and the original one get the input signal and they share the reference voltage but i've placed a high pass filter before this one now if you don't know a basic high pass will turn a square wave cycle into two short voltage spikes first a positive one when the input transitions from low to high and then a negative one when it drops from high to low now since we're not interested in the negative spike and it could cause our comparator to glitch out under certain circumstances i've decided to block it with another diode 100k resistor combination okay but what do we need the positive one for simple by feeding this positive spike into our comparator we get a quick 12 volts burst right when the envelope is triggered so with a fast attack the envelope's curve will always start at the peak level why is that important to answer that we'll first have to talk about the other comparator down here since it doesn't have a high pass at its input it will simply behave like the comparator in our previous iteration whenever the input voltage is above 3.8 volts we'll get a constant 12 volts at the output the diode here serves the same purpose as the one up there it blocks the comparator's low state after this i've set up another potentiometer as a variable voltage divider this allows us to take the 12 volts during the comparative high phase and freely scale them to any value between those 12 and 0 volts and whatever voltage we dial in here will be our sustain level why because this 100k resistor doesn't connect straight to ground like before but rather to our sustain level voltage if that sounds confusing let's break it down step by step so our input starts out low this means that both our comparator's outputs sit at -12 volts but because of our two diodes this doesn't propagate and so our buffer's input gets pulled down to zero volts through the 100k resistor and potentiometer giving us zero volts at the envelopes output as well next let's assume that the input signal goes high this will do two things we'll get a voltage spike after our high pass which gets converted into a short 12 volts burst by this comparator simultaneously the other comparator pushes out a constant 12 volts that gets scaled down by our sustained potentiometer let's assume we've set it to about 50 and this means that at the buffer's input we've got our 12 volts burst coming from here and a constant 6 volts coming from down here now since there's no resistor in this path but a 100k in this one the burst will win and push the overall voltage here up to about 12 volts our buffer being a buffer will copy those 12 volts and push them out over here again assuming that we've dealt in a fast attack there will be a pretty low resistance on this path allowing the capacitor to be charged up to about 12 volts before the burst here is over so at this point our envelopes output sits somewhere around 12 volts its peak value but because the burst here is a burst it'll quickly die down and the comparator's output will drop to -12 volts so suddenly with this diode blocking the only voltage applied to the buffer's input is our sustain level 6 volts this means that our buffer's output will drop from around 12 to those 6 volts allowing our capacitor to partially discharge through this path because remember the burst charged it up to around 12 volts once the voltage here has dropped to the sustain level it will stabilize giving us a constant 6 volts at the envelope's output until the input signal swings low our buff's output drops to zero volts and the capacitor is allowed to complete its discharging process the result is an output curve with four distinct phases attack decay sustain and release now as you might have noticed there are two rather big caveats here first both in the decay and the release phase the capacitor discharges through the same potentiometer this means that you can't control those two phases individually changing one will also change the other so we can never have a curve with a long decay and a super short release second the decay phase is directly dependent on the set attack why is that simple if we dial in a slow attack the capacitor will not be charged up to the peak level during the short initial burst maybe it won't even reach the set sustain level let alone surpass it so in effect we basically skip the decay phase as we are never dropping down to the sustain level now granted a proper adsr envelope shouldn't have these two problems but for how simple our circuit is and how few components it uses i think we can book this as a worthwhile trade-off if you're on board with this let's take to the breadboard and see if it all works as expected first let's put the high pass between our input socket and the comparator for that i'll simply route the signal through a 1 microfarad capacitor followed by a diode connected to the comparator's input add in the 10k and 100k resistors to ground and then we'll set this op-amp up as a comparator as well so i'll connect these two inverting inputs while slightly reworking our 100k 47k voltage divider for the non-inverting input we'll just grab the signal directly from the input socket next i'll add in our sustain potentiometer the left side connects straight to ground while the right side gets the comparator's output through a diode finally this 100k resistor shouldn't link to ground but to the sustain pods middle connector instead all done for demonstration purposes i'll also connect an led to the envelope's output so we can see what's going on if you try this make sure to put a big enough resistor before that led a 2k should do the trick so let's give this a try to start out i'll trigger the envelope manually again by pushing one of these pads i've dealt in a very fast attack a short to medium decay and release and a 50 sustain level here's what that sounds like [Music] i think you can clearly hear and see the initial burst followed by the slow drop to the sustain level followed by the trail off once i let go of the pad here's what happens if i play with the sustain and decay release parts a bit [Music] okay but what about the attack well let's first try to slow it down just a touch [Music] as you can hear we still get somewhat of a decay phase after the attack but watch what happens as i slow that attack way down [Music] as expected we basically skip the decay phase to wrap things up let's try it with a proper sequence i'm sending the filter's output into a vca which is also controlled by our envelope giving us a proper traditional monosynth voice in total here's what that sounds like [Music] sheep [Music] [Music] sweeps [Music] uh [Music] [Music] so even though this circuit isn't perfect we can still get a bunch of different sounds from it even some percussive hits and acid baselines which i am quite happy with still it bugs me a bit that we can't control decay and release independently as that will be necessary to get an even better acid sound so in a future video we'll try to beef our circuit up and turn it into a proper adsr envelope in the meantime be sure to check out my patreon where you can get access to a bunch of bonus content like pcb layouts a live stream replay archive and a private discord community anyways thanks for watching and until next time see ya you
Info
Channel: Moritz Klein
Views: 19,900
Rating: undefined out of 5
Keywords: DIY, Synth, Mortiz, Modular, Envelope, ADSR
Id: aGFb7JbTdNU
Channel Id: undefined
Length: 30min 59sec (1859 seconds)
Published: Mon Jun 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.