Shuffling an Array of Audio on Demand

Hello

I keep trying to do on the server stuff that is trivial in the language… this one keeps tripping me, so any wisdom is welcome.

Let’s say I have an array of audio (12 sines for instance) that I want, on a trigger, to clump randomly by 4 groups of 3.

In the language, it would look like this

(1..12).scramble.clump(3)

where [1 to 12] are my sources.

How can I do that on the server in a sane way? I am struggling here.

any pointers welcome

What do you mean by clump them? Do you want to sum them? Like have 4 summed sets?

Sam

eventually I’ll sum them but I’d like (on a trigger) to be able to rearange them

so

→ [ [ 8, 9, 5 ], [ 1, 4, 3 ], [ 2, 11, 6 ], [ 10, 7, 12 ] ]
then
→ [ [ 2, 5, 8 ], [ 12, 1, 4 ], [ 11, 10, 6 ], [ 3, 7, 9 ] ]
then
→ [ [ 9, 12, 4 ], [ 6, 11, 2 ], [ 7, 5, 3 ], [ 10, 1, 8 ] ]
etc

each of the nested array would be summed to generate a single array of 4 items indeed

the same problem I had earlier this week when I tried to (on trigger again) reorder 10 channels of audio

from

→ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
to
→ [ 3, 11, 10, 5, 7, 4, 12, 9, 2, 8, 6, 1 ]
to
→ [ 8, 1, 3, 2, 7, 12, 9, 6, 10, 11, 5, 4 ]

(on Demand rate)

The reordering part is like this:

	var sig = /* ... 12 channels of something... */;
	var trig = /* ... something to trigger a reshuffle */;
	var shuffler = Dseq([Dshuf((0..11), 1)], inf);
	var order = Array.fill(12, {
		Demand.kr(trig, 0, shuffler)
	});
	oscs = Select.ar(order, oscs);

Demo with panning the clumps across the field (use the mouse to isolate the clumps, and click to reorder):

(
a = {
	var oscs = SinOsc.ar(220 * (1..12));
	var trig = MouseButton.kr(lag: 0) + Impulse.kr(0);
	var shuffler = Dseq([Dshuf((0..11), 1)], inf);
	var order = Array.fill(12, {
		Demand.kr(trig, 0, shuffler)
	});
	var x = MouseX.kr(0, 3);
	var mask = Array.fill(4, { |i|
		var theta = (x - i).clip(-1, 1) * 0.5pi;
		cos(theta)
	});
	oscs = Select.ar(order, oscs).clump(3)
	.collect(_.sum);  // collapse 12 --> 4
	oscs = Pan2.ar(oscs * mask, Array.series(4, -1, 2/3));
	oscs.sum * 0.1
}.play;
)

hjh

2 Likes

wow thanks this is exactly what i was looking for and couldn’t get my head around!