~delay1 = Bus.audio(s, 2);

(
SynthDef(\dlywrangler, {
	arg out=0, in, wet=0.1;
	var snd, dly2;
	snd = In.ar(in,2);
	dly2 = CombN.ar(HPF.ar(snd,300), 1, [0.5,0.77], 5, mul:LFNoise1.kr(0.1).range(0.8,0.3));
	snd = CombN.ar(snd, 1, Lag.ar(LFNoise0.ar(1).range(0.01,0.1),0.1), 3, mul:wet) + snd;
	snd = Limiter.ar(snd, 0.8);
	snd = snd + dly2;
	Out.ar(out, snd);
}).add;


SynthDef(\bap, {
	arg freq=440, gate=1, out=0, amp=0.1;
	var snd = Saw.ar([freq, freq*1.01]);
	var env = Linen.kr(gate, releaseTime: 0.1, doneAction:2);
	snd = snd + SinOsc.ar([freq*0.99, freq]);
	snd = snd + Pulse.ar([freq*0.99, freq]);
	
	snd = snd.clip2(LFNoise1.ar(0.3).range(0.3,0.8)) * 5;
	snd = snd.wrap2(LFNoise1.ar(0.3).range(0.3,0.8)) * 2;
	snd = snd.fold2(LFNoise1.ar(0.3).range(0.3,0.8)) * 5;
	snd = Limiter.ar(snd);
	snd = Splay.ar(snd);
	Out.ar(out, snd*env*amp);
}).add;
)

~dlywrang1 = Synth(\dlywrangler, [\out, 0, \in, ~delay1]);

Pdef(\s2).play
(
Pbindef(\s2,
	\instrument, \bap,
	\degree, 0,
	\dur, 2,
	\octave, [2,3],
	\amp, 0.5,
	\legato, 1,
	\out, ~delay1,
	\dlywet, Pstutter(8, Pfunc({~dlywrang1.set(\wet, rrand(0, ((3..6) * 0.1).choose ) ) }))
)
)


~dlywrang1.free
