Tone repeats when code lies within Synth def but not when written as a simple function

I am trying to understand why when the following code occurs within a synthdef and is played through Pbind the tone repeats endlessly:

SynthDef(\synthA, {|dur = 0 out = 0, freq = 400|
	var sig, numHarm = 15;
	sig  = Mix.fill(numHarm,
		{arg count;
			Pan2.ar(
				SinOsc.ar(freq *  count + 1, mul: max(0, LFNoise1.kr(3) + Line.kr(1, -1, 20)))* 0.2
    )
		}
	);
	Out.ar(0, sig!2);
}).store;

y = Pbind(
	\instrument, \synthA,
	\freq, 80,
	\dur,20
).play;
)

Whilst when situated within a simple function only single tone is generated.

  play({
var numHarm = 15, freq = 80;
	Mix.fill(numHarm,
		{arg count;
			Pan2.ar(
				SinOsc.ar(freq *  count + 1, mul: max(0, LFNoise1.kr(3) + Line.kr(1, -1, 20)))* 0.2
    )
		}
	);
})

Clearly there is something fundamental I haven’t grasped. I would be grateful if someone opuld explain. Thx in advance.

You need an envelope with a gate argument in the synth def. dur is calculated by Pbind, no need to declare it explicitly in the synth def. Pbind generates a new synth on every event. Without the envelope it’ll keep generating new synths without ever freeing them. In a simple function you just create one synth. If you evaluate the function several times you get the same result.

SynthDef(\synthA, {|gate = 1, out = 0, freq = 400|
	var sig, numHarm = 15, env;
	sig  = Mix.fill(numHarm,
		{arg count;
			Pan2.ar(
				SinOsc.ar(freq *  count + 1, mul: max(0, LFNoise1.kr(3) + Line.kr(1, -1, 20)))* 0.2
    )
		}
	);
	env = EnvGen.kr(Env.adsr, gate, doneAction:2);
	Out.ar(0, sig!2 * env);
}).add;

y = Pbind(
	\instrument, \synthA,
	\freq, 80,
	\dur,1
).play;

Thx for your reply. Unfortunately this does not solve the problem. Running the code results the tone being ceaselessly repeated as before :frowning:

hmm… well, yes, of course. That’s what Pbind is for, it repeats patterns over and over again. If you just want a drone, that is just one note, you need to creat a Synth, not a Pbind.

a = Synth(\synthA, [freq:80])

But that is what the function does as well. I think I don’t quite get what you are trying to achieve.

I set \dur to 1 second. Did you change it to 20?:

y = Pbind(
	\instrument, \synthA,
	\freq, 80,
	\dur,20
).play;

Yh. I get it. I thought the Pbind binding happened only once; conceptual confusion on my part. As usual you think you’re getting the hang of the language and some simple fact slips past you. Thx for your time.

1 Like