Signal controlled ADSR~

Johnnyc777's icon

I need to control an ADSR~ with a signal.
Basically I have a Groove~ playing a short sample of a Buffer~ inside a Poly~, I would like the ADSR~ to turn the Poly~ off when the sample has finished playing, the tricky thing is that I wish to implement a tape delay style repeat for the sample and want the ADSR~ to turn off when the whole sound (sample + tape delay decay) has completed. I've tried using a

Any ideas good people?

Roman Thilenius's icon

do you need to modulate the envelope while playing? if not, i would use a buffer~ as envelope.

Johnnyc777's icon

Hey Roman, Thanks for your reply. The envelope does not need to modulate while playing but does need to be defined before the sound is played, each envelope would be a different size too so I'm not sure this would work, I'm using the Groove~ to play a snippet of sound (say 200ms) with a decaying tape delay to it, so if the tape delay repeats 5 times then the envelope would need to be 1000ms, I suppose I could do some maths to work out the length it would need to be but I'd just like to control the ADSR~ with the signal of the decaying sound somehow if this makes sense

Peter McCulloch's icon

It sounds like your sample is a one-shot (plus effects). Assuming this is so, I would recommend messing with the maxsustain parameter for ADSR~. Normally, ADSR has an attack (triggered by non-zero) and a release (triggered by 0). If you set the max sustain time, you can treat the envelope as a oneshot and set the max sustain time accordingly.

If you convert your decay delay into decibels, you can measure the RT60. (how long it takes for the sound to decay 60 decibels) Since you know the delay loop time and how much it drops, you can figure out how long it will take for the tail to decay by 60 dB (or any other arbitrary amount). That gets added onto your envelope's sustain or release time.

target_decay_in_db / loop_decay_in_db = number_of_repeats
number_of_repeats * loop_time = sustain_time (RT60)

Johnnyc777's icon

Hey Peter, thanks for taking the time to reply, My sound is a one-shot thing but will be repeated a lot inside a Poly~. I think I've realised that I'm gonna have to do the maths on this one to make it viable, could you embellish a little on your equation to get the RT-60 value as this is exactly what I need; what do you mean exactly by the target decay and the loop decay? Could you provide a simple patch?
Thanks again dude, really appreciate the help.
:)

Johnnyc777's icon

...by the way I'm using Tapin~ and Tapout~ for my tape delay so the values I use for the calculation will be the Tapout~ argument and the value of *~ which comes out of Tapout~ and back into Tapin~. Hope this helps?! :)

...also I believe this is the equation I need to solve: y(t) = a × ekt

Where y(t) = value at time "t"
a = value at the start
k = rate of growth (when >0) or decay (when
t = time

I'm not entirely sure how to implement this into Max though?

TapeDelay.maxpat
Max Patch
Peter McCulloch's icon

It's essentially an exponential decay but when you express it in terms of logarithms (e.g. decibels), then it really just becomes a multiplication. Here's an example of how to calculate it. Note that the time estimate is approximate because there are opportunities for constructive and destructive interference in the feedback loop.

The usefulness of the RT measure depends on the context. RT60 is a reasonable measurement on its own, but in a more busy mix, you might be interested in how long it takes a sound to decay by some other amount, say 30 dB.

If I want it to decay by 30 dB and it gets softer by -3 dB each time through the loop, it's going to take 10 loops to decay 30 dB. If my delay time is 75 ms, then it's going to take 750 ms for the sound to decay by 30 dB. (75 ms * 10 loops)

Max Patch
Copy patch and select New From Clipboard in Max.

HTH,
PM

Johnnyc777's icon

That's exactly what I need thanks Peter, I had pseudo-fixed it by having a *~ object send its sum back into itself and getting an if/then object to bang when the number was lower than 0.01 but it was always a quick fix, this is precise and will give me exactly what I need to finish off my Poly~
Thanks for taking the time mate. :)