signal triggered attack-decay envelope generator

    Oct 17 2012 | 3:30 pm
    I would like to program an attack-decay envelope that is triggered by a single-sample impulse signal (the default [click~] for example).
    For example, if the attack time is 100 ms and the decay time is 2000 ms, when the envelope receives an impulse, the envelope goes from 0 to 1 in 100 ms, then goes back to 0 in 2000 ms (let's assume the envelope is linear for this thread). Total envelope time should not exceed 2100 ms.
    For any attack and decay times, the envelope must always reach 1 (or very very close to). Also, it should be possible to retrigger this envelope during the decay stage.
    Is there a solution using regular MSP processing?

    • Oct 17 2012 | 7:42 pm
      adsr~ can be triggered by a signal, as can zigzag~. And although click~ will not work on it's own to trigger adsr~, for some reason it will if you do it as below - feel free to explain, someone! Cheers Roger
    • Oct 17 2012 | 10:09 pm
      the original question is not mine but....can you please explain the [-~ 1.]? Or is that restating your own question?
      I spent a good 30 mins on this challenge, using similar but unsuccessful methods - [adsr~] and various filters and delays - and could NOT get a result (frown-y face).
      postscript this question got me thinking that, wouldn't it be fun to have a sort of "so you think you can Max?" tab on the forum, or a group of that ilk.......
    • Oct 17 2012 | 11:15 pm
      @roger Many thanks for your patch and for telling me about [zigzag~]. I have no idea why it works either. Moreover, I could not find a way to retrigger the envelope so that it does not go to zero before restarting. On analogue modular synthesizers, the retrigger input is always a separated input, making things way more simple.
      To complicate things, though I talked about linear envelopes, I use shaped envelopes in practice. I would use [pow~] for this, but with envelopes you want different shaping on each stage (attack, decay, release), without any "jump" when changing the exponent. It's not that easy to implement with either [adsr~], [line~] or [zigzag~]. But I know how to do it in source code so I guess I should learn Gen.
      My current envelope is based on [curve~] because this one can have a "logarithmic" rise and an "exponential" fall. This envelope works well but cannot be signal-triggered unfortunately.
    • Oct 18 2012 | 8:56 am
      @Brendan Yes, I'm afraid that would be restating my question! How I got there was through the assumption that click~ was not going below zero to make a zero/non-zero transition. I tried subtracting a small number e.g. .01, but nothing happened until I tried -1. Interestingly, this inverts the envelope, but that's easily fixed with a *~ -1.
      I was looking for an audio triggered ramp the other day, to do audio-rate sequencing, which was how I found out about adsr~ and zigzag~. Shot~ was no good, because I wanted it to be interruptable, but as Julien says, even this method doesn't re-trigger without dipping to zero, creating annoying clicks when you use it to trigger samples. Cheers Roger
    • Oct 18 2012 | 9:53 am
      It occurred to me that it should be possible to do something about the re-triggering using Puckette's 'switch-and-ramp' method (p.97 of 'Techniques..'). It's by no means perfect, but the patch below seems to work OK with a phasor~ - I haven't tried with click~ yet. Obviously you do get some discontinuities, but it might be good enough for control envelopes, depending on your application, Cheers Roger
    • Oct 20 2012 | 5:32 pm
      @Julien: it definitely is possible. There's different ways of doing it, but some are easier than others. I've found that RC-style envelopes sound a lot better for amplitude envelopes. The key thing for getting the reattack is that you need the envelope to be shaped by an RC filtering circuit (slide~), rather than explicitly generated.
      Check out the AHD envelope in my AnalogKick project. Word of warning: the timing is off, because slide~ moves exponentially. It's not terrible for short values, but for long decays, it is fairly inaccurate. There is a means of correcting it, and it's in the next version of AnalogKick, but I haven't had time to get the other components of it working. (preset interpolation + storing presets in M4L)
    • Oct 30 2012 | 1:07 pm
      Thanks for this patch Peter
      Actually I use slide~ a lot, and also +=~ sometimes (this one rather as a workaround for MSP limits), but did not think about using both at the same time for making envelopes.
      Depending on the attack time, the envelope does not always have the same maximum amplitude, so further shaping with pow~ could potentially be a problem (or maybe I could use several cascaded slide~ objects instead of pow~).
      About inaccurate timing, it's ok for me, and actually it's the same on most analogue modular synth envelopes (if you can change the curves, which is usually done using feedback techniques)
      All this [I mean, this thread, not your envelope] looks quite complicated (not complex) for a basic envelope. Maybe I am completely wrong, but the more I use MSP and the more I feel like it's so much easier to use C / C++ (apart from audio driver management). I could find the time to learn Gen maybe, because I would not have to care about audio driver management then.