{
   "labels" : [
      "effect",
      "drone",
      "granular"
   ],
   "is_private" : null,
   "id" : "1-4ZT",
   "code" : "/*\r\nGrainFreeze.scd\r\nprm\r\nSynthDef for capturing and holding incoming audio as a drone\r\npatrickryanmcminn@gmail.com\r\nhttp://www.patrickmcminn.com/\r\n*/\r\n\r\n// execute within the parentheses:\r\n(\r\nSynthDef(\\prm_GrainFreeze, {\r\n  |\r\n  inBus = 0, outBus = 0, amp = 1,\r\n  trigRate = 60, grainDur = 0.35, pos = 0.3, rate = 1,\r\n  attackTime = 0.5, decayTime = 0, sustainLevel = 1, releaseTime = 2, gate = 1,\r\n  lowPassCutoff = 7000, highPassCutoff = 100, postDistCutoff = 18000, distAmt = 1\r\n  |\r\n\r\n  var input, record, localBuf;\r\n  var grainTrig, granulation, env, lpf, hpf, dist, sig;\r\n\r\n  // Record (into a 1 second, mono buffer)\r\n  input = In.ar(inBus, 1);\r\n  localBuf = LocalBuf.new(SampleRate.ir * 1, 1).clear;\r\n  record = RecordBuf.ar(input, localBuf, loop: 0);\r\n\r\n  //// Granulate:\r\n  // Random distribution of triggers prevents amplitude modulation artifacts\r\n  grainTrig = Dust.ar(trigRate);\r\n  granulation = GrainBuf.ar(1, grainTrig, grainDur, localBuf, rate, pos);\r\n\r\n  // Filter and distort\r\n  lpf = LPF.ar(granulation, lowPassCutoff);\r\n  hpf = HPF.ar(lpf, highPassCutoff);\r\n  dist = (hpf * distAmt).distort;\r\n  dist = LPF.ar(dist, postDistCutoff);\r\n\r\n  // Envelope -- delays start until recording has finished\r\n  env = EnvGen.kr(Env.dadsr(1, attackTime, decayTime, sustainLevel, releaseTime), gate, amp, doneAction: 2);\r\n  sig = dist * env;\r\n\r\n  // Output\r\n  sig = Out.ar(outBus, sig);\r\n}).add;\r\n)\r\n\r\n\r\n\r\n//// examples:\r\n\r\n// execute this:\r\na = Bus.audio;\r\n// then this:\r\nb = { Out.ar(a, SoundIn.ar(0)) }.play;\r\n\r\n// sing, whistle, or play a steady held note, then execute this line of code:\r\nc = Synth(\\prm_GrainFreeze, [\\inBus, a, \\outBus, 0, \\attackTime, 4], addAction: \\addToTail);\r\n\r\n\r\n// play at half the speed, (one octave down):\r\nc.set(\\rate, 0.5);\r\n\r\n// set lowpass cutoff:\r\nc.set(\\lowPassCutoff, 2500);\r\n\r\n// set high pass cutoff:\r\nc.set(\\highPassCutoff, 1000);\r\n\r\n// reset it:\r\nc.set(\\highPassCutoff, 20);\r\n\r\n// set distortion (CAREFUL!! Gets loud):\r\n(\r\nc.set(\\postDistCutoff, 1500);\r\nc.set(\\distAmt, 60.dbamp);\r\n)\r\n\r\n// increase release time and free:\r\n(\r\nc.set(\\releaseTime, 10);\r\nc.set(\\gate, 0);\r\n)",
   "name" : "Grain Freeze",
   "author" : "patrickryanmcminn",
   "ancestor_list" : [],
   "description" : "SynthDef for capturing and holding incoming audio as a drone"
}
