Issue in trying to understand bus routing

Hey everyone, I’m in the process of figuring out busses, and this simple code doesn’t seem to work. I’m be grateful for any help anyone can offer. As far as I understand it, sending audio to an audio bus from one SynthDef should allow me to receive audio from another SynthDef; however, when I try to execute the code below (line 30) I don’t receive any output from the Synth, which I’ve specified to receive audio from the g.busses.a bus:

Server.default.options.inDevice_("MacBook Air Microphone")
s.reboot
(
g = ();
g.busses = ();
s.newBusAllocators;
g.busses.a = Bus.audio(s, 2);
~bus = Bus.audio(s, 2);
)

(
SynthDef(\bustest, { arg out = 0;
	Out.ar(out, SinOsc.ar(220));
}).add
)

x = Synth(\bustest, [ \out, 0 ] );
x.set(\out, g.busses.a.index);
x.set(\out, 0);

(
SynthDef(\testbus, { arg inBus = 0, out = 0;
	var sig;
	sig = In.ar(inBus, 2);
	Out.ar(0, sig);
}).add;
)

z = Synth(\testbus)
z.set(\inBus, g.busses.a.index); // bus doesn't work
z.set(\inBus, 1); // microphone works
z.free

Thank you

Hi – I ran your example, and added one statement at the end. I also renamed \bustest to \source and \testbus to \fx because descriptive names are easier to understand when debugging.

s.queryAllNodes(true);

NODE TREE Group 0
   1 group
      1001 fx
        inBus: 4 out: 0
      1000 source
        out: 4

So you’ve ended up with the effect synth preceding the source – so that it’s reading a signal that hasn’t been produced yet. This is why you get silence.

A very common use case is to create a long-running effect synth first. This is part of the signal-routing architecture; it’s typical to set up the architecture before playing notes. Then, you want the notes to come before the effect. So SC’s default way to position synth nodes is at the head of the target group.

If you flip your script and create \testbus (the effect) first, then it will work as you expect. Alternately, when creating \bustest (source), you can specify the target and addAction.

hjh

Just to add something to James explanation.

I like using Synth.after for this.

z = Synth.after(x, \testbus)

Thank you for the help, that makes more sense to me now.