\ir in the synthdef

Hi everyone, do you know what ‘\ir!5’ stands for? I’ve searched for help but didn’t understand it well. Thank you all for your help.

			// a simple percussive envelope
SynthDef(\percSin, { |out, amp=0.1, freq=440, sustain=0.01, pan|
	var snd = FSinOsc.ar(freq);
	var env = EnvGen.ar(
		Env.perc(0.1, 0.9, amp), timeScale: sustain, doneAction: 2);
	OffsetOut.ar(out, Pan2.ar(snd * env, pan));
}, \ir ! 5).add;
	\instrument, \percSin, \sustain, 0.05,
	\freq, 250, \amp, 0.2, \dur, 0.5, \lag, 0
	\instrument, \percSin, \sustain, 0.05,
	\freq, 875, \amp, 0.1, \dur, 0.5, \lag, 0

The third argument for SynthDef is rates. Quote from the help file:

An optional Array of specifications for the ugenGraphFunc’s arguments. The order corresponds to the order of arguments. See the examples below to see how these are used.

\ir ! 5 is shorthand for \ir.dup(5) and returns [ \ir, \ir, \ir, \ir, \ir ]. It makes sure that the first 5 SynthDef arguments (here: all arguments) are initial rate, i.e. they are only evaluated once when the Synth is created, otherwise they would be control rate. This just makes the computation of certain UGens slightly more efficient. Typically you wouldn’t have to bother with these kinds of micro optimizations.


To specify the rates inplace, you can use NamedControl or its shorthand, it has many improvements (and a few draw backs) over using function args.

Here is an example.

FSinOsc.ar(\freq.ir(440)) * \amp.kr(0.2) * \otherSound.ar(0!2);
1 Like