Copying a channel of a buffer to another channel of the same buffer?


Is there a way to copy one channel of a buffer to another channel of the same buffer?

It would be handy to use a synth including because users could make a 2-channel buffer from a mono sound file.

When you have one channel from PlayBuf, you can .dup it for stereo, so there is no need to copy the data in memory for this use case.


1 Like

@jamshark makes a good point. Also if your situation does require copying a channel, check out FluidBufCompose in the FluCoMa toolkit.

1 Like

I would say that the following will result in different levels and the use of panning is different:

  • case 1: playing a one-channel buffer and using .dup.
  • case 2: playing Pan2 with a one-channel buffer (or playing Balance2 with a two-channel buffer)
~b1 = Buffer.readChannel(s, Platform.resourceDir +/+ "sounds/SinedPink.aiff", channels: [0]);
~b2 = Buffer.readChannel(s, Platform.resourceDir +/+ "sounds/SinedPink.aiff", channels: [0, 0]);

case 1:

{, ~b1, loop: 1) ! 2}.play

{, ~b2, loop: 1) }.play

Screenshot 2024-03-28 at 0.00.16

case 2

{, ~b1, loop: 1)) }.play

{ var src =, ~b2, loop: 1);[0], src[1]) }.play

Screenshot 2024-03-28 at 0.00.02

I think the following way is the simplest way to control mono and stereo files in a unified way using PlayBuf and pan control:

~buf_2ch = { |server, path|
	var numChsOfBuf = SoundFile.use(path, { |f| f.numChannels });
	if(numChsOfBuf == 1) {
		Buffer.readChannel(server, path, channels: [0, 0])
	} {, path)

~b3 = ~buf_2ch.(s, Platform.resourceDir +/+ "sounds/SinedPink.aiff")
~b4 = ~buf_2ch.(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav")

~play_schBuf = { |buf, rate, loop, pan=0, level=0.1|
	var signal =, buf, rate *, loop:loop);[0], signal[1], pan, level)

{ ~play_schBuf.(~b3, 1, 1, 0, 0.1) }.play
{ ~play_schBuf.(~b4, 1, 1, 0, 0.1) }.play

For me, it was a pain to separate mono and stereo files to play buffers, and this simplifies a lot of things. Wouldn’t it be useful for many users to implement ~buf_2ch as Buffer.read2ch? I am thinking of making it as a PR.