{
   "labels" : [
      "115granular"
   ],
   "code" : "// =================================\r\n// A4 - musc-115-granular\r\n// GRANULAR SAMPLING\r\n// =================================\r\n\r\n/*\r\nThe code below is exactly what we built in class.\r\nYou will need a MONO sample.\r\n\r\n*/\r\n\r\n// make sure to boot server first\r\n\r\n// load a sound file (or two...)\r\nb = Buffer.read(s, \"/Users/Mason/Desktop/Nena ‎- 99 Luftballons mono.wav\");\r\nc = Buffer.read(s, \"/Users/Mason/Desktop/Sweet Dreams Eurythmics mono.wav\");\r\n\r\n// buffer handy tools:\r\nb.play;\r\n// check number of channels\r\nb.numChannels;\r\n// check duration\r\nb.duration;\r\n// check how many samples are in the sample\r\nb.numFrames;\r\n\r\nc.play;\r\n\r\n// SynthDefs\r\n(\r\n// simple synthdef, no filters or effects, just env and panning control\r\nSynthDef(\"granny1\", {arg rate = 1, amp = 1, buffer, startPos = 0, attack = 0.02, release = 0.5, panning = 0;\r\n    var snd, env;\r\n    env = Env.perc(attackTime: attack, releaseTime: release, level: amp).kr(doneAction: 2);\r\n    snd = PlayBuf.ar(\r\n        numChannels: 1,\r\n        bufnum: buffer,\r\n        rate: rate,\r\n        startPos: startPos.linlin(0, 1, 0, BufFrames.kr(buffer))\r\n    );\r\n    snd = snd * env;\r\n\tsnd = Pan2.ar(snd, panning);\r\n    Out.ar(0, snd);\r\n}).add;\r\n\r\n// Same as above, but adding a filter just for fun\r\nSynthDef(\"granny2\", {arg rate = 1, amp = 1, buffer, startPos = 0, attack = 0.02, release = 0.5, ffreq = 1000, rq = 0.1, panning = 0;\r\n    var snd, env;\r\n    env = Env.perc(attackTime: attack, releaseTime: release, level: amp).kr(doneAction: 2);\r\n    snd = PlayBuf.ar(\r\n        numChannels: 1,\r\n        bufnum: buffer,\r\n        rate: rate,\r\n        startPos: startPos.linlin(0, 1, 0, BufFrames.kr(buffer))\r\n    );\r\n    snd = snd * env;\r\n    snd = BPF.ar(snd, ffreq, rq);\r\n    snd = Pan2.ar(snd, panning);\r\n    Out.ar(0, snd);\r\n}).add;\r\n\r\n// Same as above, but adding an echo effect (CombC)\r\nSynthDef(\"granny3\", {arg rate = 1, amp = 1, buffer, startPos = 0, attack = 0.02, release = 0.5, ffreq = 1000, rq = 0.1, panning = 0, delay = 0.3, decay = 1;\r\n    var snd, env;\r\n    env = Env.perc(attackTime: attack, releaseTime: release, level: amp).kr(doneAction: 2);\r\n    snd = PlayBuf.ar(\r\n        numChannels: 1,\r\n        bufnum: buffer,\r\n        rate: rate,\r\n        startPos: startPos.linlin(0, 1, 0, BufFrames.kr(buffer))\r\n    );\r\n    snd = snd * env;\r\n    snd = BPF.ar(snd, ffreq, rq);\r\n\tsnd = CombC.ar(snd, maxdelaytime: 2, delaytime: delay, decaytime: decay);\r\n    snd = Pan2.ar(snd, panning);\r\n    Out.ar(0, snd);\r\n}).add;\r\n\r\n\r\n\r\n)\r\n\r\n// Some testing Pbinds\r\n\r\n// One\r\n(\r\n~one = Pbind(\r\n    \\instrument, \"granny1\",\r\n\t\\rate, 100, // notice this one ENDS after 4 cycles\r\n    \\amp, 1,\r\n    \\startPos, 0.1,\r\n    \\attack, 0.5,\r\n    \\release, 2,\r\n    \\buffer, b, // which buffer to play from\r\n    \\dur, 2,\r\n);\r\n)\r\n\r\n\r\n// Two\r\n(\r\n~two = Pbind(\r\n    \\instrument, \"granny1\",\r\n\t\\rate, 10,\r\n\t\\amp, Pwhite(0.1, 0.9),\r\n\t\\startPos, Prand([0.24, 0.33, 0.66, 0.89], 32), // this one ENDS after 32 notes\r\n    \\attack, 0.01,\r\n    \\release, 0.1,\r\n    \\buffer, b, // which buffer to play from\r\n    \\dur, 0.15,\r\n\t\\panning, Pwhite(-1, 1.0); // control L/R here\r\n);\r\n)\r\n\r\n\r\n// Three (this one uses granny2, with the filter)\r\n(\r\n~three = Pbind(\r\n    \\instrument, \"granny2\", // notice I'm using granny2 synthdef here\r\n\t\\rate, Prand([5, 5, 7, 0.92, 1.01, 2, 2, 12], inf),\r\n\t\\amp, 5, // boosted to 5 because filtering attenuates a lot of the sound\r\n\t\\startPos, Pseq([0.24, 0.33, 0.66, 0.89], inf),\r\n    \\attack, 0.02,\r\n    \\release, 0.4,\r\n\t\\ffreq, Pseq([100, 200, 400, 500, 600, 900, 1000, 2000], inf),\r\n\t\\rq, 0.01,\r\n    \\buffer, c, // which buffer to play from\r\n    \\dur, 0.25,\r\n\t\\panning, Pwhite(-0.5, 0.5)\r\n);\r\n)\r\n\r\n\r\n\r\n\r\n// Four (this one uses granny3, with a filter AND a CombC (the delay/echo))\r\n(\r\n~four = Pbind(\r\n    \\instrument, \"granny3\", // notice I'm using granny2 synthdef here\r\n\t\\rate, Pseq([5, 7, 3, 13], inf),\r\n\t\\amp, 1, // boosted to 5 because filtering attenuates a lot of the sound\r\n\t\\startPos, Pseq([0.14, 0.13, 0.7, 0.9], inf),\r\n    \\attack, 0.5,\r\n    \\release, 2,\r\n\t\\ffreq, Pseq([100, 200, 400, 550, 9000, 50, 100, 2000], inf),\r\n\t\\rq, 0.1,\r\n\t\\delay, 0.2,\r\n\t\\decay, 2,\r\n    \\buffer, c, // which buffer to play from\r\n    \\dur, 0.5,\r\n\t\\panning, Pwhite(-0.5, 0.5)\r\n);\r\n\r\n(\r\n~five = Pbind(\r\n    \\instrument, \"granny2\", // notice I'm using granny2 synthdef here\r\n\t\\rate, Pseq([5, 20, 40, 100, 200], inf),\r\n\t\\amp, 5, // boosted to 5 because filtering attenuates a lot of the sound\r\n\t\\startPos, Pseq([0.24, 0.33, 0.66, 0.89], inf),\r\n    \\attack, 0.02,\r\n    \\release, 0.4,\r\n\t\\ffreq, Pseq([2000], inf),\r\n\t\\rq, 0.01,\r\n    \\buffer, c, // which buffer to play from\r\n    \\dur, 0.25,\r\n\t\\panning, Pwhite(-0.5, 0.5)\r\n);\r\n)\r\n\r\n\r\n\r\n\r\n\r\n\r\n)\r\n\r\n~one.play;\r\n~two.play;\r\n~three.play;\r\n~four.play;\r\n~five.play;\r\n(\r\n{\r\n\t\r\n~threeplay1=~three.play;\r\n7.wait;\r\n~fourplay=~four.play;\r\n2.wait;\r\n~fourplay.stop;\t\r\n~threeplay2=~three.play;\r\n3.wait;\r\n~threeplay2.stop;\r\n~threeplay1.stop;\r\n~fiveplay=~five.play;\r\n4.wait;\r\n~fiveplay.stop;\t\r\n~threeplay1=~three.play;\r\n~fourplay=~four.play;\t\r\n4.wait;\r\n~threeplay1.stop;\t\r\n~fourplay.stop;\r\n~threeplay1=~three.play;\r\n1.wait;\r\n~threeplay1.stop;\t\r\n~threeplay1=~three.play;\r\n1.wait;\r\n~threeplay1.stop;\r\n~threeplay1=~three.play;\r\n1.wait;\r\n~threeplay1.stop;\t\r\n~threeplay1=~three.play;\r\n1.wait;\r\n~threeplay1.stop;\t\r\n~fiveplay=~five.play;\t\r\n4.wait;\r\n~fiveplay.stop;\r\n~threeplay1=~three.play;\t\r\n\t\r\n\r\n\t\t\r\n\t\r\n}.fork;\r\n)",
   "is_private" : null,
   "id" : "1-55E",
   "name" : "115granular",
   "author" : "Mason McCormack",
   "description" : "115granular\r\n\r\nhttps://soundcloud.com/macdaddymase/115granular",
   "ancestor_list" : []
}
