Getting clicks when using adsr~ with buffer~ and play~

jorgen's icon

I'm making a simple drum machine that stores audio samples in a buffer~ and plays them using play~ after a line~. When a sample is triggered two messages go to line~, one int with the start time and a list with the end time and duration. The play~ sends the signal out to a live.gain.

I would like to have an envelope on the sample. I've tried using adsr~ which works except that I get ugly clicks on the sound, especially after altering the attack. How to avoid this?

The way I've done it is to make a *~ and plug the the signal from play~ into the left input and the signal from adsr~ into the right input. The A, D, S and R are controlled using live.dials. When the sample is triggered a message with the float 0.9 goes into the left input of the adsr~.

What I've tried so far:

- Sending different numbers into the left input of adsr~
- Changing the order of a) 0.9 left input into adsr~ and b) control messages to the line~ (start, end
and duration times)
- Since I don't really need it: Removing the release. After this I've tried changing the default
release time (from 0 to 1000) and sending a message maxsustain 0 into the left input of the adsr~
at the beginnning

Any ideas?

Mike S's icon

If you select your objects and then click copy compressed you can post parts of your patch to the forum.

Sounds like you could use a rampsmooth~ object below your adsr~

jorgen's icon

Thanks for input! The rampsmooth~ didn't quite fix it, although it made it a bit better. I played around with the arguments but couldn't remove the clicks.

In detail the issue is that I get clicks on certain samples (which aren't there without the adsr~), especially when the attack is nonzero and I trigger the sample while it's still playing, or if the decay ends before the sample so that it is cutoff.

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

I'll give the copy compressed thing a go, here it is:

As you can see you can drop a sample where it says "sample" and then trigger it using the button. I apologize for messy code..

Mike S's icon

try it directly after the adsr~

jorgen's icon

It still clicks, with no arguments and with 10 10, 50 50, 500 500 and 2000, 2000 in the rampsmooth~. Did that fix it for you?

Mike S's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Sorry if I've borked your presentation mode, you need to take in to the jump both in the sample position and adsr. I've just used a delay object which triggers things once they're ready - think you might need to work on the messages to line as the pitch is changing when I select. Try adding the line messages in to one message, will make things easier and you can see exactly what is being sent

jorgen's icon

It works beautifully, thank you so much!

I'm trying to understand what you did, this is what it looks like to me: When you trigger the sample you quickly (5ms) fade out the signal from play~, then "set up" the adsr~ (send its signal to the final *~1), then wait 20ms before fading in again the signal from play~.

Is that correct? And would it be enough to make sure the adsr~ gets triggered before play~ is faded in again or is the delay~ essential? I can try this out myself of course but if it is essential then I'm curious as to why. Something to do with the rampsmooth~?

jorgen's icon

I'm also wondering if it's possible to let previously triggered samples "finish" when I trigger new ones i.e. so that you can have the same sample playing "several times" on top of itself. Or would this require use of polyphony objects etc?

Mike S's icon

I've tried to simplify it a bit. You're right in thinking that it's just a fade out/in. Basically when you're changing the amplitude of a signal, and also changing the sample value (or sample position in the audio file) you will create a jump in both signals, this is what causes the click. So you are probably getting clicks from two sources, the sample, and the amplitude envelope. Try playing with the number boxes connected to the delay and pack objects and see when you hear the clicks. And this is [delay], not [delay~], very important difference. One delays a bang, the other a signal.

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

And yes you're right about the polyphony, you would normally use a poly~ object for this.

jorgen's icon

Thanks, that looks much cleaner! But I'm a but uncertain how to trigger samples in your newest version? I thought it might be the button or toggle connected to the metro but it doesn't seem so. And what is the metro doing?

Mike S's icon

just triggers at a rate, the button below it will trigger the sample once loaded and a selection made on the waveform~