Voices are counting up

I never used the EnvGen adsr. , so I tried it
The env is set to doneaction :2 , yet the voices keep on stacking up when sequenced from a Pbind

   {| ampatt =0.001,ampdec=1,ampsus=0.2,amprel=0.3filtatt=0.001,filtdecay=0.500,filtsus=0.2,filtrel=0.2,osc1amp=0.3,osc2amp=0.3,osc3amp=0.3,offset1=0,offset2=0.2,offset3=(-0.2),filterfreq=600,res=1,freq=30,
   	var sig,sig1,sig2,sig3,ampenvelope,filterenvelope;






ADSR needs a gate.


Hmmm you mean it needs a gate off , that is part of the Env. class ?
I always use EnvGen.ar(Env( [levels ],[times ], [ curves ]),doneAction:2) , and there the gate is ( I supppose ) always 1 by default

I has the same arguments as the Env.adsr , gate ,levelscale, levelbias , timescale ,doneAction .
Is it becasue the Env.adsr gate it tied to the sustain level ?
So why and more importantly how do I give a gate 0 from Pbind, pseq ?

I am probably doing something horribly wrong , I declared argument gate , sequenced it in a pbind (0,1,0,1,00and it makes no difference

See the Examples section of EnvGen help, specifically “// using a gated envelope to gate a sound” (this example uses an arg for doneAction, but usually we just hardcode doneAction: 2 – the gate handling is canonical in this example though).


OK, now I have a bit more time to add some detail.

You’re right that EnvGen’s default gate is a constant 1.

BUT the definition of an ADSR envelope is that it should proceed through the attack and decay phases, and hold at the sustain level until the gate closes.

How does the gate close?

SuperCollider defines “open” as gate > 0 (any positive value, even only slightly larger than 0), and “closed” as gate <= 0.

So the gate must be positive for some time, and then change to 0 to close it.

Closing the gate means that the value must change – hence, you can’t close an open gate with a constant signal – i.e. “always 1 by default” is not valid for ADSR. (Note that this is true in other synth software as well. If, in VCV Rack, you put a constant positive voltage into the gate input of an ADSR module, then likewise, you will find that the envelope will not close.)

That leads to the canonical way to do a gated envelope in SC.

  • SynthDef has a control input called ‘gate’ with default 1.
  • Use this in EnvGen’s gate input, with doneAction: 2.

I don’t think there’s a better way to do this – so my recommendation is to get comfortable with the canonical way and just repeat this pattern whenever you need it.

The default \note event type does it automatically, so you don’t have to.


// default synthdef is gated!
// you've used it before
// so you've been playing gated events
// many many times already, and it just worked
-> true

// this will hold for 2 beats, then release
(instrument: \default, sustain: 2).play;

There is one bit of fine print with gate in patterns: by default, events do not send a gate value at the beginning of a note, instead assuming that the SynthDef has specified a positive default. This is to save a little bit of CPU time.

This means that if you try to sequence gate, the synths won’t get the values from the pattern (at least not by default).

But normally, sequencing gate values is not necessary, because the main thing is just that the note begins to play.

The automatic release message from the \note event type is separate from this.