Passing variable-sized array argument to a Synth

What is the correct way of defining a Synth which takes in it’s argument a variable sized array of inputs? For instance how could I define a Synth for additive synthesis, in which the frequencies are defined as an input array, so that it’s possible to pass different sized arrays of frequencies to the Synth?

There is no direct way to do that.

You can define multiple SynthDefs for different sizes, and select them by name.

Or you can define a SynthDef with a bigger array, and set the amp of the unused partials to 0.

Or a hybrid approach would be to define a separate SynthDef for, say, 10 partials, and 20, and 30, and so on, and choose by name the smallest SynthDef that would handle the number of partials for this note, and switch off the amp for the excess partials – this way would balance the desire not to create too many SynthDefs vs the desire not to waste too many oscillators.

hjh

you can make a function that plays a function - like so:

a = {|array| { SinOsc.ar(array, 0, array.size.reciprocal / 10)}.play };
a.([300, 400, 444, 475])
a.([666, 655, 654])

See miSCellaneous_lib’s tutorial “Event patterns and array args” which contains examples of that kind.

2 Likes