I don't understand t_xxx parameters in a SynthDef

Hey there

I’m running SC 3.9.3.

I’m having difficulties understanding t_ arguments to Synthdef.

In the Synthdef help file there’s the following code snippet :

// the following two defs are equivalent. The first uses a 't_' arg:
(
SynthDef(\trigTest, { |out, t_trig=0, freq=440| // t_trig creates a TrigControl
    Out.ar(out, SinOsc.ar(freq+[0,1], 0, Decay2.kr(t_trig, 0.005, 1.0)));
}, [0, 4]        // lag the freq by 4 seconds (the second arg), but not t_trig (won't work anyway)
).add;
)

// This second version makes trig a \tr arg by specifying it in the rates array.
(
SynthDef(\trigTest2, { |out, trig=0, freq=440|
    Out.ar(out, SinOsc.ar(freq+[0,1], 0, Decay2.kr(trig, 0.005, 1.0)));
    }, [\tr, 4]        // lag the freq (lagtime: 4s), \tr creates a TrigControl for trig
).add;
)

// Using the second version create a synth
z = Synth.head(s, \trigTest2);

// now trigger the decay envelope
z.set(\trig, 1);                 // you can do this multiple times
z.set(\trig, 1, \freq, 220);     // hear how the freq lags
z.set(\trig, 1, \freq, 880);

z.free; //free the synth

but

z = Synth(\trigTest);
z.set(\trig, 1);

does not trigger any sound.

Could someone explain why I should name a Synthdef parameter t_trig instead of trig and the magic involved ?

Thanks in advance !

geoffroy

1 Like

In your code:

z = Synth(\trigTest);
z.set(\trig, 1);

\trig must be \t_trig as follows:

z = Synth(\trigTest);
z.set(\t_trig, 1);

In your SynthDef(\trigTest, …), there is no argument \trig, but \t_trig.

Have a look at the post on named controls in Learning Resources. You might find that an easier approach.

Thanks for your answers.

I was being confused by the fact that the parameter must be named “trig” in a Pbind/Pmono.
So “trig” in Pbind, “t_trig” if sent directly to Synth.

cf. http://doc.sccode.org/Tutorials/A-Practical-Guide/PG_03_What_Is_Pbind.html

(
SynthDef(\trig_demo, { |out, freq = 440, gate = 1, t_trig = 1|    // t_trig here
    var    env = Decay2.kr(t_trig, 0.01, 0.1),
        sig = SinOsc.ar(freq, 0, env)
            * Linen.kr(gate, 0.01, 0.1, 0.1, doneAction: Done.freeSelf);
    Out.ar(out, sig ! 2)
}).add;
)

(
p = Pmono(\trig_demo,
    \freq, Pexprand(200, 800, inf),
    \trig, 1,    // note that this is NOT t_trig -- just \trig
    \delta, 0.125
).play;
)

Well, this is a pretty confusing and erraneous help example …
maybe it uncovers a bug too …

First:
It seems the out parameter was added later, so there should be three items in the ‘rates’ array –
look into the post window with the original example, it gives a warning.

The first version of trigTest2 should look like this:

(
SynthDef(\trigTest2, { |out, trig=0, freq=440|
    Out.ar(out, SinOsc.ar(freq+[0,1], 0, Decay2.kr(trig, 0.005, 1.0)));
    }, [0, \tr, 4]        // lag the freq (lagtime: 4s), \tr creates a TrigControl for trig
).add;
)

Otherwise you wouldn’t get the lag !

Analogously the first SynthDef should be

(
SynthDef(\trigTest, { |out, freq=440, t_trig=0| // t_trig creates a TrigControl
    Out.ar(out, SinOsc.ar(freq+[0,1], 0, Decay2.kr(t_trig, 0.005, 1.0)));
}, [0, 0, 4]        // lag the freq by 4 seconds (the second arg), but not t_trig (won't work anyway)
);
)

That way you get the trigger with

z.set(\t_trig etc.

BUT: not the freq lag – I have no idea why, anyone ?

Greetings

Daniel

If you follow the NameControl style recommendation in Learning Resources mentioned above you can write your synth like this:

(SynthDef(\trig_demo, {
var out = \out.kr(0);
var freq = \freq.kr(440);
var gate = \gate.kr(1);
var trig = \trig.tr(1);
var env = Decay2.kr(trig, 0.01, 0.1),
sig = SinOsc.ar(freq, 0, env)
* Linen.kr(gate, 0.01, 0.1, 0.1, doneAction: Done.freeSelf);
Out.ar(out, sig ! 2)
}).add;)

Confusion around the the magic format of t_* args and the rates array hopefully kinda goes away.

1 Like

I’m aware of that. The point is that there’s a misleading helpfile and maybe a bug and that should be corrected.
I’ll post on Github.

2 Likes

Ah, … there’s no bug but another mistake in the helpfile,
the first SynthDef \trigTest isn’t added – so a combo of 3 mistakes in these few lines …

2 Likes

Thanks everyone, I think I got it now !