Argument for multichannel expansion in a SynthDef

hey, im aware of this thread: Problems with variable literal array and NamedControl - #3 by jamshark70

whats a good way to use an argument / variable for multichannel expansion in a SynthDef.
for example: { something } ! variable;

when i for example know the range could be between 1 and 20.
I thought of having an Array with 20 items \[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
and then should i use Demand Ugens for picking the right amount of numbers, or whats the right way to go about that?


This one definitely belongs in the top 10 commonly-asked SC questions.

… and the key part of the answer is that SynthDefs cannot create or destroy elements dynamically. So a SynthDef has to be more like Max/MSP or Pd, in that all of the elements must exist upfront. (In Pd, you would [clone] an abstraction a given number of times, and [switch~] individual instances on and off as needed.)

Instead of creating and destroying them, you can dynamically suppress some of the elements’ output.

Exactly how you do that depends on the context.

Usually, the context for multichannel expansion is a parallel signal chain, in which a structure (e.g. oscillator → filter) is duplicated and mixed down, for a richer sound. In this case, “suppressing” an output happens in the mixdown stage – multiplying by 0. Here, there’s one “gate” per channel, which is 1 if the channel should sound and 0 if not.

var maxHarmonics = 30;

a = { |n = 1, freq = 220|
	var harmonics =\harmonics,
		Array.fill(maxHarmonics, { |i| i + 1 })
	var gates = n >= (1 .. maxHarmonics);
	(( * harmonics) *, 0.1))
	.sum * 0.1

c = Bus.control(s, 1);
b = {, 30) }.play(outbus: c);\n, c);

The thread that you referenced was about demand-rate sequencing. This is a completely different context, so you should not expect a sequencing solution to apply to parallel-chain mixdown. (Just because “there’s a thread about dynamic arrays and it uses Demand units” does not mean that Demand is applicable to every case involving dynamic sizing.)


yes, ive seen the difference to my question of multichannel expansion with dynamic arrays.
I just wanted to point out that i was trying to come up with a solutuon on my own.

thanks for the clarification :slight_smile:
i will try to implement your example.