SynthDef and RecordBuf

Hi everyone,
i need to create a single SynthDef starting from these elements (del_2, del_3 and x). I would create a tool to use in live electronics that is able to loop, use grain and delay starting from the attached script - combining del_2, del_3 and x in a single SynthDef, and adding elements (for example freeze, or other effects) on it.

My question is not so much in the form as in a good ‘aesthetic’ outcome. In fact, I tried to merge the two SynthDef myself but, even if the form may be correct, the result always goes into feedback and I don’t understand the reason. Likewise, the loop formally works but on a practical level it doesn’t define the duration, or if I want to overwrite the loop.

Rhe result will then be managed via OSC or GUI.

Thanks so much!


b = Buffer.alloc(s, s.sampleRate * 2);

// Synth input\mic, {arg inBus=0,outBus=0,amp=0;
	                var sig;
	                    sig = * amp.lag(0.02);
	                    sig =;

// Synth router

SynthDef(\router, {arg inBus=0, outBus=0, fadeT = 1;
		           var sig, init, gate;
		               sig    =,1);
		               init   =;
		               outBus =;
			           gate   = > 0;

			              sig *[0,0,1], [0,fadeT],\cub),gate+init));
, fadeT, fadeT),
			              sig *[0,1,0], [0,fadeT],\cub),gate));


~micBus =,1); 
~delBus =,1); 

~micGrp =;
~fxGrp  = Group.after(~micGrp); 

a = Synth(\mic,    [\inBus,0,       \outBus,~micBus,\amp,1],       ~micGrp); 
b = Synth(\router, [\inBus,~micBus, \outBus,~delBus, \fadeT, 0.5], ~micGrp, \addToTail);

// First Synthdef

SynthDef(\del_2, {arg inBus=0, outBus=0, maxdel=2, del=0.5, fbk=0.0,
	                  amp=0, gate=0, fade=0.2, done=2;
	              var in, local, sig, dly, env;
	                  in    =;
	                  local = + [in, 0];  // Dual mono
	                  dly   =, maxdel, del,1 );
		              dly   =;
	                  env   =,fade,1,fade,done);
		 * fbk); // reverse = ping pong effect
	    , local * env * amp);

c = Synth(\del_2,[\inBus,~delBus,\outBus,0, \amp,1,\fade,0.5, \del, 0.8, \fbk,0.2, \gate,1],~fxGrp);    // Delay


// Second Synthdef

SynthDef(\del_3, {arg inBus=0, outBus=0, maxdel=10, del=0.5, decayT=1, mix=0,
	                  amp=0, gate=0, fade=0.2, pan=0, done=2;
	              var in, sig, dly, pann, env;
	                  in    =;
	                  dly   =, maxdel, del, decayT);
	                  env   =,fade,1,fade,done);
	                  sig   =; 
		              sig   =, in, mix) * env * amp;
	                  pann  =, pan);
	   , pann);

c = Synth(\del_3,[\inBus,~delBus,\outBus,0,\amp,1,\fade,0.5, \decayT,2, \gate,1],~fxGrp);    // Delay

c.set(\del,0.5,\mix, -1);
c.set(\del,0.5,\mix, 0.5);

// Loop

x = {
	var sig;
    sig =;,b,\,\,\,\,\;!2,b,loop:1);

May I ask… does it need to be a single SynthDef?

I’d suggest modularizing, for a couple of reasons:

  • Simpler SynthDefs are easier to develop and troubleshoot. (Instead of trying to get 20 features to work all at once, work on one of them first, then another.)
  • If each effect is its own SynthDef (and Synth), you can reorder effects easily just by reordering Synth nodes. If it’s one big SynthDef, the order of operations is fixed, and you can’t change it without replacing the entire big node.

By “looping,” I presume that you want to record a bar or two and play it back repeatedly. The end of the sample looping back to the beginning is very likely to be discontinuous, producing a click. So you don’t want to do this using PlayBuf or BufRd’s loop input. You will need a crossfade. Perhaps try XPlayBuf: Release v0.1.2-xfade · elgiano/XPlayBuf · GitHub – alternately, you could implement a cross fade using built-in SC UGens.

XPlayBuf has a ‘loopDur’ input.

The built-in buffer players don’t have a loop duration input, but they can be reset on demand. You can implement loop duration, and overwrite, in terms of reset.