Setting up Audio Channels using Routines?

Hello all,

I am recently trying to switch over from using Patterns to using Routines to generate music with a PlayBuf SynthDef. While I was using Patterns, I created a Channel mixer that fed audio to a Master output.

Please see below:

Setting up audio buses and grouping:

	~sources = Group.head;
	~mixer = Group.tail;

	//CHANNELS 1-3
	~patch1 = Bus.audio(s, 2);
	~patch2 = Bus.audio(s, 2);
	~patch3 = Bus.audio(s, 2);
	~channel1 = Group.tail(~mixer);
	~channel2 = Group.tail(~mixer);
	~channel3 = Group.tail(~mixer);

	//MASTER
	~patch5 = Bus.audio(s, 2);
	~master1 = Group.tail(~mixer);

SynthDefs for my buffer sampler and Channels. I am using the patch argument to route the audio to different channels and then all of the channels get outputted through the Master channel.

	//MAINBUF
	SynthDef.new(\mainbuf, {
		arg amp=1, pan=0, rate=1, pos=0, bank, atk=0.01, rel=1, loop=1, gate=1, fader=1, patch=22, bufrate=44100, smoothing=0.5;
		var sig, env, z;
		env = EnvGen.kr(Env.perc(atk, rel), gate, doneAction: 2);
		sig = PlayBuf.ar(1, bank, BufRateScale.kr(bank) * rate, 1, pos, loop) * env;
		sig = Pan2.ar(sig, pan);
		sig = Out.ar(patch, sig * amp * fader);
	}).add;

	//CHANNELS/ FX
	~channel1 = (
		SynthDef(\ch1mix, {
			arg moogcut=21000, gain=0, highcut=22, lowcut=22, fader=1, crossfader=1, maxdelaytime=0.2, delaytime=0.2, decaytime=1.0, mul=1, pitchRatio=1, pitchDispersion=0, timeDispersion=0;
			var sig;
			sig = In.ar(~patch1, 2);
			sig = MoogFF.ar(sig, moogcut, gain);
			sig = AllpassC.ar(sig, maxdelaytime, delaytime, decaytime, mul);
			sig = HPF.ar(sig, highcut);
			sig = PitchShift.ar(sig, delaytime, pitchRatio, pitchDispersion, timeDispersion);
			sig = Out.ar(~patch5, sig * fader * crossfader);
		}).play(~channel1);
	);
	~master1 = (
		SynthDef(\mastermix, {
			arg moogcut=29000, gain=0, highcut=22, masterfader=1, mix=0.33, room=0.5, damp=0.5, delaytime=0, pitchRatio=1, pitchDispersion=0, fader=1;
			var sig;
			sig = In.ar(~patch5, 2);
			sig = FreeVerb.ar(sig,mix,room,damp);
			sig = PitchShift.ar(sig, delaytime, pitchRatio, pitchDispersion);
			sig = Compander.ar(sig);
			sig = Limiter.ar(sig);
			sig = Out.ar(0, sig * masterfader * fader);
		}).play(~master1);
	);

This is working as expected with Patterns. If I run a pdef like this, I can route the audio based on the patch to specific channels and then the target would be ~sources.

		Pdef(\a10, Pbind(
			\instrument, \mainbuf, \group, ~sources,
			\patch, ~patch1,
			\amp, 1,
			\dur, 1/4,
			\atk, 0.1,
			\rel, 0.1,
			\rate, 1,
			\pos, 1,
			\bank, 1,
		)).quant_(4);
	);
	Pdef(\a10).play(t, quant:4);

Here is the node tree:

My question is, how can I get this set up using Routines?

I am using the same audio buses / grouping and SynthDefs, however, when I try to apply the arguments / target using a Synth, I am not hearing any audio:

The Synth that is being created within the Routine.

							// Create the synth and wait for the tatum duration
							s.makeBundle(s.latency, {
								synth = Synth(\mainbuf, [
									patch: ~patch1,
									buffer: currentBuffer,
									rate: currentRate,
									rel: rel,
									mainbuf: mainbuf,
									amp: 0.6,
								], ~sources);
							});
							s.makeBundle (s.latency, {
								synth.set(\gate, 0);
							});

Am I missing something here? Does this look set up correctly?

Thank you for your time!

Apologies, I got this working after writing everything out. Typo on my end. The code is working as expected.

2 Likes