(
Server.default.waitForBoot {

	// audio is in the smp/ subfolder from the location of this file
	var path = PathName.new(thisProcess.nowExecutingPath).pathOnly +/+ "smp/contrapoints_gender_critical.wav";
	~contra = Buffer.read(s, path);

	// a mono channel feeding reverb fx
	~revBus = Bus.audio(s, 1);

	// stereo channel feeding granular reverb/delay
	~granBus = Bus.audio(s, 2);

	// two buffers for granluar rev/delay
	~granbufL = Buffer.alloc(s, 6 * s.sampleRate);
	~granbufR = Buffer.alloc(s, 6 * s.sampleRate);


	// SynthDefs

	SynthDef(\bufPlayer, {
		arg out=0, sndbuf, gate = 1, amp = 0.1, pos = 0, rate = 1;
		var snd, com, env;

		env = EnvGen.ar(Env.asr(0.01, 1, 0.01), gate, doneAction:Done.freeSelf);
		snd = PlayBuf.ar(1, sndbuf, rate: rate, startPos: pos);
		com = CombN.ar(snd, 0.5, Rand(0.01, 0.05), mul:0.6);
		snd = snd + (com * Rand(0, 1));
		snd = RLPF.ar(snd, Rand(1000, 5000), 0.2);
		snd = HPF.ar(snd, Rand(200,1000));
		snd = Decimator.ar(snd/2, ExpRand(5000,44100), add:snd/2);
		com = CombN.ar(snd, 0.5, Rand(0.1, 0.5));
		snd = snd + (com * Rand(0,0.5));
		snd = Limiter.ar(snd,0.1) * 4;
		snd = snd * env * amp;

		Out.ar(out, snd);
	}).add;

	
	SynthDef(\revfx, {
		arg inBus, outBus=0, revtime = 5, dry=1, wet=0.2, roomsize=100;
		var snd;

		snd = In.ar(inBus);
		snd = GVerb.ar(snd, roomsize, revtime, drylevel: dry, earlyreflevel: 0, taillevel: wet) ;

		Out.ar(outBus, snd);
	}).add;

	
	SynthDef(\grainIn, { 
		arg inBus, outBus=0, bufL, bufR, amp=0.5, freq=220, fvar=1, 
		dur = 0.5, durvar = 0.05, pos = 0, posvar = 0.05, pitch = 1, pitchvar = 0.01,
		width = 0.8, gain = 0.4, wet = 1, dry = 3 ;
		var inSnd, snd;

		// audio from a bus
		inSnd = In.ar(inBus, 2);

		// continously record into two buffers
		RecordBuf.ar(inSnd[0], bufL);
		RecordBuf.ar(inSnd[1], bufR);

		// granulate the audio in buffers
		snd = GrainBuf.ar(
			numChannels: 1,
			trigger: Impulse.kr(freq + (freq * (fvar * LFNoise2.kr(freq)))), 
			dur: dur + (durvar * LFNoise2.kr(freq)), // in seconds
			sndbuf: [bufL, bufR], // not sure if this works correctly
			rate: pitch + (pitchvar * LFNoise2.kr(5)), 
			pos: SinOsc.ar(0.03, phase:[0,0.1]).range(0,1) + (posvar * LFNoise2.kr(freq)), // 0-1
			interp: 2, 
			//pan: LFNoise1.kr(10).range(width.neg, width), 
			maxGrains: 512,	mul: gain, add: inSnd*2
		);

		// mix granulated and original sound
		snd = (snd * wet) + (inSnd * dry);
		
		snd = snd * amp;
		snd = Limiter.ar(snd, 0.7);
		Out.ar(outBus,snd);
	}).add;
	
}
)

// create fx
~reverb = Synth(\revfx, [\inBus, ~revBus, \outBus, ~granBus]);
~granulator = Synth(\grainIn, [\inBus, ~granBus, \bufL, ~granbufL, \bufR, ~granbufR], addAction:\addToTail)



// play it with a patterns
(
Pbindef(\bufPlat,
	\instrument, \bufPlayer,
	\sndbuf, ~contra,
	\amp, 0.3,
	
	\dur, Prand([1, 2, 3, Pn(1/4,4), 1/2, Pseq([Pn(1/8,6), Pn(1/4,3)]), Pn(1/3,3)], inf),
	
	//\pos, Prand(list: (0..~contra.numFrames), repeats: inf),
	\pos, Pseq([
		Pxrand([1, 3, 5, 7, 9], 200),
		Pxrand([11, 13, 15, 17, 20], 200),
		Pxrand([22, 24, 26, 28], 200),
		Prand((0..~contra.numFrames), 30)
	] * ~contra.sampleRate, inf),
	
	\legato, Prand((3..6) * 0.1, inf),
	\out, ~revBus
).play
)


	      
yes, the audio comes from ContraPoint's 'Gender Critical' video.