How to change parameters over time in SynthDef

Hello everyone,

I’m new to this, please excuse if this has been answered before.

How can the durations of the envelope segments be changed over time? I tried to multiply the values using an LFDNoise1.ar for example, but it does not seem to work. I guess I’m missing a basic point here, but I can’t figure it out.

Any help would be greatly appreciated.

(SynthDef.new(\norg,{
	var snd,env;
	env=Env.new([0,1,0],[1, 1]);
	env=EnvGen.ar(env,\gate.kr(1), doneAction: 2);
	snd=SinOsc.ar(\freq.kr(100),0,0.1);
	snd=snd*env;
	Out.ar([-1,1], snd);
}).add)


(Pbind(\instrument,\norg,
	\freq, Pseq((100..200),inf),
	\dur,  Pseq([1,Rest(2)],inf),
).play;
)

Hello and welcome!

It’s generally not a good idea to use modulation (like LFDNoise1) on envelope durations. Instead, I would suggest using controls for \atk and \rel in the SynthDef, and then use Pwhite or Pexprand to set them randomly in the Pbind.

(SynthDef.new(\norg,{
	var snd,env;
    env=Env.new([0,1,0],[\atk.kr(1), \rel.kr(1)]);
	env=EnvGen.ar(env,\gate.kr(1), doneAction: 2);
	snd=SinOsc.ar(\freq.kr(100),0,0.1);
	snd=snd*env;
	Out.ar([-1,1], snd);
}).add)


(Pbind(\instrument,\norg,
	\freq, Pseq((100..200),inf),
	\dur,  Pseq([1,Rest(2)],inf),
    \atk, Pwhite(0.1, 1),
    \rel, Pwhite(0.1, 1)
).play;
)

Also check out DemandEnvGen if you want a way to do this entirely in one SynthDef

https://doc.sccode.org/Classes/DemandEnvGen.html

Thank you so much PitchTrebler and semiquaver. I will try both suggestions and will find out about how they work.

Thanks!

1 Like

I know this thread is a bit old, but you can also use Pseg, which works like an envelope but from a Pbind

Amazing, thank you so much, I will take a look into this. This seems very handy!