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