Correct way to handle ADSR with multiple voices

Hi everyone!

I’m trying to figure out the best way to go about giving each of my voices their own ADSR. The idea is to have a basic keyboard instrument where each note is its own voice, and each voice is a sine wave with an ADSR applied to it.

So far I have figured (and also seen while viewing other peoples work) that there seem to be two methods.

Method 1: Create a loop that sample by sample calculates the sound, envelope etc, combines everything and writes the result to the output buffer.

Method 2: Create a seperate buffer (I’ve seen this created both as a member variable and as a local function variable), and operate on that buffer with functions like ‘applyEnvelopeToBuffer’, the write the contents of that local buffer to the output buffer.

Which of these methods is the preferred/better method? I’ve gone with method 1, as I imagine it would be the more memory efficient one. However I’ve seen plenty of people use the second. I’m wondering what the advantages of each are, and specifically why anyone would use the second?

I imagine the second method would be useful if you want to perform the work in parallel on different threads? I can also see some sense in it potentially being more readable or easy to understand. I think ultimately go with what feels right to you. In my experience I’ve normally seen method 1, but I’ve not done much in the way of synths.

1 Like