Noob question: filter on an envelope

Hi everyone! I’m trying to do the simplest thing ever: apply an envelope to a filter

(
	SynthDef.new(\sine2, {
	|freq=40, atk=0.03, sus=0.03, rel=9, pan=0, gain=1, trig=0, amp=0.08, out=0|
	var sig, env, filter;
	sig = VarSaw.ar(freq, width: 0.85);
	sig = tanh(Line.ar(0.001, gain) * sig);
	sig = sig.softclip;
	env = Env(
		[0,1,1,0],
		[atk, sus, rel],
		\sine
	).ar(2);
	sig = sig * env;
	sig = Pan2.ar(sig, pan, amp);
	filter = BLowPass.ar(sig, EnvGen.kr(Env([20, 10000, 20], [4,4]), trig));
	Out.ar(out, sig);
}).add;
)

Could someone point me to a simple example with an envelope applied to a filter? I can’t find one in the tutorials.

1 Like

Also, the forum tries to auto render your text, and often posting code without special formatting will mean that parts of it disappear/render out…meaning that if someone were to copy and paste your code there would be parts missing.

You can avoid this by using back ticks, the little tick mark that on US keyboards is with the tilde key.

Writing text, `single backticks` become in-line code.

→ Writing text, single backticks become in-line code.

```
// a multi-line block should have
// three backticks at the beginning
// and another three at the end
```

// a multi-line block should have
// three backticks at the beginning
// and another three at the end
1 Like

Thank you, but what about having a different envelope for the filter? What’s wrong with my code?

See below. The only issue with your code was that the envelope was being triggered by trig, and that was set to 0, so it was never triggered. You also were assigning the output of the filter to a new variable, but outputting “sig”, so you would have never hear the filter even if it were working:

(
SynthDef.new(\sine2, {
	|freq=40, atk=0.03, sus=0.03, rel=9, pan=0, gain=1, trig=1, amp=0.08, out=0|
	var sig, env, filter;
	sig = VarSaw.ar(freq, width: 0.85);
	sig = tanh(Line.ar(0.001, gain) * sig);
	sig = sig.softclip;
	env = Env(
		[0,1,1,0],
		[atk, sus, rel],
		\sine
	).ar(2);
	sig = sig * env;
	sig = Pan2.ar(sig, pan, amp);
	//sig = BLowPass.ar(sig, env.linexp(0,1,20,10000).poll, 1, 1);
	sig = BLowPass.ar(sig, EnvGen.kr(Env([20, 10000, 20], [4,4]), trig).poll);
	Out.ar(out, sig);
}).play;
)

If you used my commented version of the BLowPass instead of yours, it uses the same env as your volume env, but controlling the filter.

Sam

2 Likes

You aren’t actually outputting the filtered signal.
Swap Out.ar(out, sig) to be Out.ar(out, filter)

1 Like

Thank you so much to @Sam_Pluta and @thresholdpeople for such a quick reply!
I had a trig=1 in my Synth.new, so the issue was the Out.ar(out, sig). :blush: