home/ atoms/ sc-bus-allocation-private

Use Bus.audio to allocate private buses safely, avoiding conflicts with hardware I/O buses

SuperCollider’s audio buses are numbered: 0 to numOutputBusChannels-1 are hardware outputs, next block are hardware inputs, the rest are private internal buses. Hard-coding an integer bus index (e.g., Out.ar(6, sig)) risks conflicts if hardware I/O counts change. Instead, use Bus.audio(s, numChannels) to allocate: SuperCollider automatically picks the lowest available private bus. A ‘multichannel bus’ in SuperCollider is just a block of adjacent single-channel buses; allocating a 2-channel bus reserves two consecutive indices. When you pass a Bus object as a Synth argument, it’s automatically converted to its integer index.

Examples

~reverbBus = Bus.audio(s, 2); // allocates 2 adjacent private buses y = Synth.new(\reverb, [\in, ~reverbBus]); x = Synth.new(\blip, [\out, ~reverbBus]);

Assessment

What is the difference between hard-coding bus index 16 and using Bus.audio(s, 1)? When would bus 16 be an unsafe choice?

“you should use the Bus object, in order to let SuperCollider handle the allocation of busses for you.”
corpus · supercollider-tutorials-full-transcripts-and-code-eli-fields · chunk 16