2 //this Synth uses the AudioIn as a trigger to step through and granulate the loaded buffer
5 b = Buffer.read(s, "sounds/a11wlk01.wav"); //use your own buffer here - mine is probably not on your computer
8 SynthDef("TriggerBufferGranular", {arg out=0, bufnum=0, in=1, thresh = 0.004, ampScaler = 1, duration =
9 0.2, pan=0,centerPosition=0.1, interp=1, incrementBy = 200;
11 var trig, amp, gatedAmp, triggerBool, outamp, bufferFrames, bufRateScale;
12 var bufPointer, trigs, env, envGens, outArray, grNum;
14 grNum = 4; // the number of granulators in the synthdef
15 bufferFrames = BufFrames.kr(bufnum);
16 bufRateScale = BufRateScale.kr(bufnum);
17 amp = Amplitude.kr (AudioIn.ar(in));
18 triggerBool = (AudioIn.ar(in) >= thresh);
19 gatedAmp = Latch.kr(amp, triggerBool);
20 outamp = (gatedAmp * ampScaler);
22 trig = Trig.kr(triggerBool, duration/4); //makes a trigger if triggerBool goes over the threshold
23 env = Env([0,1,0],[duration/2,duration/2],'sine');
25 bufPointer = PulseCount.kr(trig); //a counter that counts the number of triggers triggered
27 //each trigger below triggers once for every four times trig (above) triggers (if a trig trig could trig trig)
29 trigs = Array.fill(grNum, {|i| PulseDivider.kr(trig, 4, i )});
30 envGens = Array.fill(grNum, {|i| EnvGen.kr(env, trigs[i] ) });
32 //trigs correspond to and trigger a PlayBuf below - the pointer slowly moves through the file
33 outArray = Array.fill(grNum, {|i| PlayBuf.ar(1, bufnum, bufRateScale, trigs[i], (bufPointer*incrementBy)%bufferFrames)*envGens[i]});
35 Out.ar(out, Pan2.ar(Mix(outArray)));
37 }).play(s,[\out, 0, \bufnum, b.bufnum]);