(
SynthDef(\verbDelayFX, {
	arg inBus, outBus, revWet=0.8, dlyWet=0.8, feedback = 0.5 ;
	
	var snd = In.ar(inBus, 2);
	var verb = JPverb.ar(snd);
	var delay = Greyhole.ar(snd, feedback: feedback);
	snd = snd + (verb * revWet) + (delay * dlyWet) * 0.5;
	
	Out.ar(outBus, snd);
}).add;

SynthDef(\bgrain, { |out = 0, gate = 1, amp = 0.1, bufnum = \b, gfreq=150, rate=0.5|
    var snd, pan, env, freqdev;

    pan = LFNoise1.kr(0.1).range(-1, 1) * LFNoise0.kr(gfreq).range(0.2,1);
    env = EnvGen.kr(
        Env([0, 1, 0], [20, 20], \sin, 1),
        gate,
        doneAction: Done.freeSelf);
	rate = [0.5, 1];
	snd = GrainBuf.ar(
		numChannels:2,
		trigger:Impulse.kr(LFNoise1.kr(gfreq).range(0.8,1) * gfreq),
		dur: 0.7  * LFNoise0.kr(gfreq).range(1,1.1),
		sndbuf: bufnum,
		rate: [rate * LFNoise1.kr.range(0.99, 1), rate * LFNoise1.kr.range(0.99, 1) * 2],
		pos: LFNoise2.kr(0.01).range(0, 1) * LFNoise0.kr(gfreq).range(1,1.02),
		//pos: LFTri.kr(0.25),
		interp: 2,
		pan: pan);
	snd = RLPF.ar(snd, freq: LFNoise2.kr(0.1).exprange(400,15000));
	snd = snd * LFNoise2.ar(0.01).range(0.6,1);
	snd = snd * env * amp;
	snd = Limiter.ar(snd, 0.7);
	
	Out.ar(out, snd);
}).add;
);

// load sound file
//b = Buffer.read(s, thisProcess.nowExecutingPath.dirname +/+ "smp/calling.wav");
b = Buffer.readChannel(s, thisProcess.nowExecutingPath.dirname +/+ "smp/Famonics - Gliding - Calling.flac", channels: [0]);

// create a bus for reverb
~reverBus = Bus.audio(s,2);

(
// create reverb with input from reverb bus
~reverbDelay = Synth(\verbDelayFX, [\inBus, ~reverBus, \outBus, 0, \revWet, 0.5, \dlyWet, 0.5], addAction: \addAfter);

// start granulator
~grain1 = Synth(\bgrain, [\out, ~reverBus, \bufnum, b], addAction: \addToHead);
)

// fadeout
~grain1.set(\gate, 0);








