Multiple and independent pitchEvent keys inside a SynthDef

Hello Synths!

I am pretty sure that this begginer’s question have been asked in the list, but I couldn’t find it there.

How can I make multiple and independent pitchEvent keys inside a SynthDef ? I would like to have multiple freq arguments that would support freq/midinote/note/degree and would be independently controllable from patterns. Is it described on the doc? Something like this:

(
SynthDef(\SimpleSine, {
arg freq = 440, freq1 = 2, freq2 = 0.1, out;
var sig;
sig = PMOsc.ar(freq, freq1, freq2);

 Out.ar(out, sig) }).add;
)

(
f = Pbind(
\instrument, \SimpleSine,
\degree, Pseq([0, 1, 2, 4, 6, 3, 4, 8], inf),
\degree1, Pwhite(-7, 7) ,
\degree2, Pbrown(0, 7, 1) ,
\dur, 0.5, \octave, 3,
).play;
)

All the best,
Zé Craum

Check out array arguments (SynthDef help file). Whenever you write something like xy1, xy2 etc. consider writing arrays.

For some reason especially array args seem to fbe unpopular, or they are poorly documented, or both. Array args are a bit tricky with patterns though - but not really, just note that you have to wrap into an extra array to avoid expanding into multiple synths per event (which normally happens if you use arrays within event patterns).

(
SynthDef(\SimpleSine_arrayArg, {
    arg freq = #[440, 2, 0.1], out;
    var sig;
    freq.poll;
    sig = PMOsc.ar(freq[0], freq[1], freq[2]);
    Out.ar(out, sig * EnvGen.ar(Env.perc, doneAction: 2)) 
}).add;
)

(
f = Pbind(
    \instrument, \SimpleSine_arrayArg,
    \degree, Ptuple([
        Pseq([0, 1, 2, 4, 6, 3, 4, 8], inf),
        Pwhite(-7, 7) ,
        Pbrown(0, 7, 1)
    ]).collect([_]), // wrap into extra array
    \dur, 0.5, 
    \octave, [[5, 3, 2]] // wrap into extra array here too
).trace.play;
)

The miSCellaneous_lib quark contains a tutorial “Event patterns and array args”.
Also see Nathan’s note on NamedControl, esp. the chapter “Advantage: Better multichannel controls”:

1 Like

My answer was a quite formal one, another point is if it makes sense to pass the index as degree. Also if you are fine with inharmonic spectra, you could e.g. think about passing the modulation frequency by an integer factor or a simple fraction of the carrier etc.

1 Like

For sure! This was just an hipotetical example, I will use other frequencies as integer multiples of the fundamental or as control frequencies for vibrato, tremolo, etc.

Thanks a lot!