Using BufChannels throws ERROR

I thought I can retrieve the number of channels with the UGen BufChannels like this:

(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
{
	PlayBuf.ar(BufChannels.kr(b), b)
}.play
)

But this throws this error:

ERROR: Non Boolean in test.
RECEIVER:
Instance of BinaryOpUGen

Can any one spot the problem in my code?

Some arguments to Ugens will accept other Ugens, some only accept static data - that is, data known when the synthdef is compiled. The channel count of everything must be static - in other words, it must a language side, not server side.

BufChannels.kr is a dynamic (Ugen/server-side) way of getting the number of channels, what you want to the language side (static) way - b.numChannels.

However you will get sync problems here. Do this instead:

(
s.waitFotBoot {
   var buffer = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
   s.sync;
   { PlayBuf.ar(buffer.numChannels, buffer) }.play
}
)
1 Like

So if I understood you correctly BufChannels is not supposed to be used as an argument to PlayBuf. How can I know (for any ugen) which arguments are supposed to be static, which not? Is this documented any where?

Check out the help doc on PlayBuf.

numChannels
Number of channels that the buffer will be. This must be a fixed integer. The architecture of the SynthDef cannot change after it is compiled.

Meaning the value should be static with respect to the synth def.

1 Like