Hi,
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 PlayBuf.ar
because users could make a 2-channel buffer from a mono sound file.
Hi,
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 PlayBuf.ar
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.
hjh
@jamshark makes a good point. Also if your situation does require copying a channel, check out FluidBufCompose in the FluCoMa toolkit. flucoma.org
I would say that the following will result in different levels and the use of panning is different:
.dup
.~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:
{ PlayBuf.ar(1, ~b1, loop: 1) ! 2}.play
{ PlayBuf.ar(2, ~b2, loop: 1) }.play
case 2
{ Pan2.ar(PlayBuf.ar(1, ~b1, loop: 1)) }.play
{ var src = PlayBuf.ar(2, ~b2, loop: 1); Balance2.ar(src[0], src[1]) }.play
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])
} {
Buffer.read(server, 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 = PlayBuf.ar(2, buf, rate * BufRateScale.kr(buf), loop:loop);
Balance2.ar(signal[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.