SynthDef bad implementation in Pbind

Hello to all;
the SynthDef I attached in the code works great and as expected when I play it with Synth(\d) . Now, if I do it with a Pbind it turns into a cricket cage. I used an envelope on another version I made to see if I could get good results but it didn’t work.
I like the sweep of the lfo and the sound I get and I would like to use it in a composition doing live coding and be able to manipulate some parameters to make it more dynamic live.
Does anyone have any ideas to improve it ?
Thanks

(
SynthDef(\d, {
	var freq, sig, trig, deg, cutoffFreq, lfo;


	trig = Impulse.ar(\impf.ir(4)); // Genera un pulso a 4Hz
	deg = Demand.ar(
		trig,
		0,
		Dseq([0, 2, -1, -3], inf) // Secuencia de grados
	);

	freq = (DegreeToKey.ar(b, deg) + 50).midicps; // Convierte grados a frecuencia MIDI
	freq = freq * {Rand(-0.1, 0.1).midiratio}.dup(4); // Aplica aleatoriedad a la frecuencia
	sig = Saw.ar(freq); // Genera la señal con oscilador en forma de sierra
	sig = Splay.ar(sig); // Espacializa la señal

	// Aquí está el LFO para barrido del filtro
	lfo = SinOsc.kr(0.1,0,\amp.ir(1)).range(80, 5000); // Oscilador sinusoidal lento que oscila entre 500Hz y 5000Hz

	// Aplicar el MoogFF con frecuencia de corte controlada por el LFO
	sig = MoogFF.ar(sig, lfo);

	Out.ar(0, sig); // Envía la señal a la salida
}).add;


)

Synth(\d)

What is ‘b’ in Freq = DegreeToKey.ar(b, deg)? It must be defined outside the synthdef or…?

You are right to note that b is not defined within SynthDef. In the context of DegreeToKey.ar(b, deg), b would represent a scale or buffer containing musical scale information that will be used to map degrees to MIDI frequencies.

I have no problems getting the same type sound by evaluating:

(
Pdef(\test, Pbind(
	\instrument, \d,
)).play
)

Only issue is that I can’t stop the sound without command + period because you did not include a gated envelope in the synthdef as you mentioned.