Mutlichannel output with PlayBuf

Greetings.
I am trying to get this bit of code to output 4 channels, but it seems PlayBuf won’t allow it (at least that’s how I understand it). Any ideas on how to do this?

(
SynthDef(\try3, {
	arg out=0, buf=0, rate=1, speed=0.01, pan=0, amp=0.5;
	var sig, env, panPos;

	env = EnvGen.kr(Env([0, 1, 1, 0], [0.01, BufDur.ir(buf) - 0.02, 0.01]), doneAction:2);

	sig = PlayBuf.ar(2, buf, rate: BufRateScale.kr(buf) * rate, trigger: 0, loop:0, doneAction:2);

	panPos = LFNoise1.kr(speed).range(-1, 1);

	sig = PanAz.ar(4, sig, panPos);
	Out.ar(out, sig * amp);
}).add;
)

(
~fieldrecs = Synth(\try3, [
	\buf, [~pani1, ~sho1].choose,  
	\amp, 0.4,     
	\out, 0,       
]);
)

I can’t test this, but looking at the code, maybe you should be using SplayAz instead of PanAz, since the PlayBuf outputs 2 channels.
Hope that helps.
Paul

1 Like

PanAz pans a single channel to a position in a speaker ring.

If you give it more than one channel, then it will multichannel-expand to n number of PanAz units. PanAz.ar(4, oneChannel) means one channel in, four out. PanAz.ar(4, twoChannelArray) means two channels in, 8 out, and those eight will be clumped into 4:

[
	// the whole PanAz result for the first input channel
	[ leftCh0, leftCh1, leftCh2, leftCh3 ],

	// the whole PanAz result for the second input channel
	[ rightCh0, rightCh1, rightCh2, rightCh3 ]
]

If you then .sum those, you would get a single four-channel result.

So perhaps: PanAz.ar(4, sig, panPos + [width.neg, width]) where width is how far apart you want the input channels to be, in the quad result.

hjh

1 Like

thank you for the reply.
It is not exactly clear to me as to how I am supposed to sum each channel :sweat_smile: (quite new to SC)

I tried different things and got a working solution here:

(
SynthDef(\try3, {
	arg out=0, buf=0, rate=1, speed=0.1, width=2, amp=0.5;
	var sig, env, panPos, leftPan, rightPan, sum;
	
	env = EnvGen.kr(Env([0, 1, 1, 0], [0.01, BufDur.ir(buf) - 0.02, 0.01]), doneAction:2);

	sig = PlayBuf.ar(2, buf, rate: BufRateScale.kr(buf) * rate, trigger: 0, loop:0, doneAction:2);

	panPos = LFNoise1.kr(speed).range(-2, 2);

	leftPan = PanAz.ar(4, sig[0], panPos - (width * 0.25)); 
	rightPan = PanAz.ar(4, sig[1], panPos + (width * 0.25)); 

	sum = leftPan + rightPan;

	Out.ar(out, sum * amp * env);
}).add;
)

(
~fieldrecs = Synth(\try3, [
	\buf, [~pani1, ~sho1].choose,
	\width, 2,   
	\amp, 0.4,     
	\out, 0,      
]);
)

but I had to adjust the width and also the panPos = LFNoise1.kr(speed).range(-2, 2); , otherwise I was still getting only two channels out.
It feels it’s not exactly “correct” as to how the signal and L-R is treated.
thoughts?

It’s much simpler than you think:

sig = PanAz.ar(4, sig, panPos + (0.25 * width * [-1, 1]));

If you start here, then sig.sum is the mixdown of the 4-channel signals, to 4 channels.

hjh

1 Like

was indeed quite simpler.
much appreciated!