{
   "labels" : [
      "live",
      "loop",
      "grains",
      "granular"
   ],
   "is_private" : null,
   "id" : "1-59n",
   "code" : "// allocate a Buffer\r\ns = Server.local;\r\nb = Buffer.alloc(s, 44100 * 1.0, 1); // a 1 second 1 channel Buffer\r\n\r\nSynthDef(\"granular_sampling\", \r\n        {arg trigger = 0, graindur = 0.2, sndbuf, transp = 1, \r\n         pos = 0, pan = 0, envbuf = -1, amp = 1, gate = 1;\r\n\tvar env, snd;\r\n\tRecordBuf.ar(SoundIn.ar(0), sndbuf, loop: 1);\r\n\tenv = EnvGen.kr(Env.asr, gate, levelScale: amp, doneAction: 2);\r\n\tsnd = GrainBuf.ar(\r\n\t\tnumChannels: 1,\r\n\t\ttrigger: Impulse.kr(trigger),\r\n\t\tdur: graindur,\r\n\t\tsndbuf: sndbuf,\r\n\t\trate: transp,\r\n\t\tpos: pos,\r\n\t\tpan: pan,\r\n\t\tenvbufnum: envbuf);\r\n        snd = DelayC.ar(snd, 0.1, 0.1); // add delay OR add some reverg :)\r\n        // snd = GVerb.ar(BPF.ar(snd, 90.midicps), roomsize:30, revtime:8, drylevel:0.5);\r\n        snd = snd!2 * 0.8 + (SoundIn.ar([0,1]) * 0.3); // many ways to add the src :)\r\n\tOut.ar(0, snd * env ); // use the envelope, and out\r\n\r\n\t// this is a freak :) but get's env and stereo ; with out arts)\r\n\t//Out.ar(0, (snd!2 * 0.7) * env + (SoundIn.ar(0,1)*0.1));\r\n        // Plain and mono out\r\n\t//Out.ar(0, (snd * env) + SoundIn.ar(0,1));\r\n}).add;\r\n\r\n// Play it with Pbind ... \r\n// with 'just 8' grains it bounces around nicely ;)\r\na = Pbind(\r\n\t\\instrument, \"granular_sampling\",\r\n\t\\trigger, 8,\r\n\t\\graindur, Pexprand(0.01, 0.9, inf),\r\n\t\\sndbuf, b,\r\n\t\\transp, Prand([1/4,1/3,1/2,2/3,3/4,1], inf),\r\n\t\\pos, 0,\r\n\t//\\pos, Pseq([1/4,1/2,3/4], inf),\r\n\t\\pan, 0,\r\n\t\\amp, Prand([0.5, 0.9], inf),\r\n\t\\envbuf, -1,\r\n\t\\dur, Prand([1+1/3,1/2,2/3,3/4,1], inf),\r\n);\r\n\r\na.play;",
   "name" : "looping buffer granuals",
   "author" : "blueprint",
   "ancestor_list" : [],
   "description" : "This is a granular synth, much inspired by http://sccode.org/1-4WM\r\n\r\nIt's distinct in that the SynthDef loops in a live recording buffer with a slight delay and is added back to the input (on the bus) ....\r\n\r\nWhen I was starting I was looking for something like this ...."
}
