{
   "name" : "Getting Freq-y With It",
   "author" : "ianmcdougall60",
   "ancestor_list" : [],
   "description" : "Assignment 2 for MUSC 115\r\n\r\nhttps://soundcloud.com/user-68447368/getting-freq-y-with-it-115modulations",
   "labels" : [
      "115modulations"
   ],
   "is_private" : null,
   "id" : "1-55a",
   "code" : "// =======================\r\n// MUSC 115 Assigment 2\r\n// =======================\r\n// SynthDefs (AM and FM)\r\n// =======================\r\n\r\n// Your name:  Ian McDougall\r\n\r\n(\r\n\r\nSynthDef(\"hihat\", {arg out = 0, amp = 0.5, att = 0.01, rel = 0.2, ffreq = 6000, pan = 0;\r\n\tvar env, snd;\r\n\tenv = Env.perc(att, rel, amp).kr(doneAction: 2);\r\n\tsnd = WhiteNoise.ar;\r\n\tsnd = HPF.ar(in: snd, freq: ffreq, mul: env);\r\n\tOut.ar(out, Pan2.ar(snd, pan));\r\n}).add;\r\n\r\nSynthDef(\"snare\", {arg out = 0, amp = 0.1, sinfreq = 180, att = 0.01, rel = 0.2, ffreq = 2000, pan = 0;\r\n\tvar env, snd1, snd2, sum;\r\n\tenv = Env.perc(att, rel, amp).kr(doneAction: 2);\r\n\tsnd1 = HPF.ar(\r\n\t\tin: WhiteNoise.ar,\r\n\t\tfreq: ffreq,\r\n\t\tmul: env\r\n\t);\r\n\tsnd2 = SinOsc.ar(freq: sinfreq, mul: env);\r\n\tsum = snd1 + snd2;\r\n\tOut.ar(out, Pan2.ar(sum, pan));\r\n}).add;\r\n\r\n\r\n\r\nSynthDef(\"kick\", {arg out = 0, amp = 0.3, sinfreq = 60, glissf = 0.9, att = 0.01, rel = 0.45, pan = 0;\r\n\tvar env, snd, ramp;\r\n\tenv = Env.perc(att, rel, amp).kr(doneAction: 2);\r\n\tramp = XLine.kr(\r\n\t\tstart: sinfreq,\r\n\t\tend: sinfreq * glissf,\r\n\t\tdur: rel\r\n\t);\r\n\tsnd = SinOsc.ar(freq: ramp, mul: env);\r\n\tsnd = Pan2.ar(snd, pan);\r\n\tOut.ar(out, snd);\r\n}).add;\r\n\r\nSynthDef(\"sawSynth\", { arg freq = 440, amp = 0.1, att = 0.1, rel = 2, lofreq = 1000, hifreq = 3000;\r\n    var env, snd;\r\n    env = Env.perc(\r\n\t\tattackTime: att,\r\n\t\treleaseTime: rel,\r\n\t\tlevel: amp\r\n\t).kr(doneAction: 2);\r\n    snd = Saw.ar(freq: freq * [0.99, 1, 1.001, 1.008], mul: env);\r\n\tsnd = LPF.ar(\r\n\t\tin: snd,\r\n\t\tfreq: LFNoise2.kr(1).range(lofreq, hifreq)\r\n\t);\r\n    snd = Splay.ar(snd);\r\n    Out.ar(0, snd);\r\n}).add;\r\n\r\n\r\nSynthDef(\"am1\", {arg freq = 440, modfreq = 2, amp = 0.2, att = 0.01, rel = 3;\r\n    var carrier, modulator, env;\r\n    env = Env.perc(\r\n        attackTime: att,\r\n        releaseTime: rel,\r\n        level: amp\r\n    ).kr(2);\r\n    modulator = SinOsc.ar(modfreq).range(0, 1);\r\n    carrier = SinOsc.ar(freq: freq, mul: env * modulator);\r\n    Out.ar(0, carrier ! 2);\r\n}).add;\r\n\r\nSynthDef(\"am2\", {arg freq = 440, modfreq = 2, amp = 0.2, att = 0.01, sus = 0.2, rel = 3, gate = 1, pos = 0;\r\n    var carrier, modulator, env;\r\n    env = Env.asr(\r\n        attackTime: att,\r\n\t\tsustainLevel: sus,\r\n        releaseTime: rel\r\n\t).kr(doneAction: 2, gate: gate, mul: amp);\r\n    modulator = SinOsc.ar(modfreq).range(0, 1);\r\n    carrier = SinOsc.ar(freq: freq, mul: env * modulator);\r\n\tOut.ar(0, Pan2.ar(carrier, pos));\r\n}).add;\r\n\r\nSynthDef(\"am3\", {arg freq = 440, modfreq = 2, amp = 0.2, att = 0.01, sus = 0.2, rel = 3, gate = 1, pos = 0;\r\n    var carrier, modulator, env;\r\n    env = Env.asr(\r\n        attackTime: att,\r\n\t\tsustainLevel: sus,\r\n        releaseTime: rel\r\n\t).kr(doneAction: 2, gate: gate, mul: amp);\r\n    modulator = SinOsc.ar(modfreq).range(0, 1);\r\n\tfreq = freq * LFNoise2.kr([2, 1/2, 1/3, 1/4, 1]).range(0.98, 1.01);\r\n    carrier = Pulse.ar(freq: freq, mul: env * modulator);\r\n\tcarrier = Mix.ar(carrier);\r\n\tcarrier = LPF.ar(carrier, Line.kr(10000, 1000, att));\r\n\tOut.ar(0, Pan2.ar(carrier, pos));\r\n}).add;\r\n\r\nSynthDef(\"fm1\", {arg freq = 440, modfreq = 5, modindex = 10, amp = 0.1, pos = 0, gate = 1, att = 0.01, rel = 0.3;\r\n\tvar carrier, modulator, freqdev, env;\r\n\t// i = d/m, so d = m*i\r\n\tfreqdev = modfreq * modindex;\r\n\tmodulator = SinOsc.ar(freq: modfreq, mul: freqdev);\r\n\tcarrier = SinOsc.ar(freq: freq + modulator);\r\n\tenv = Env.asr(\r\n\t\tattackTime: att,\r\n\t\tsustainLevel: amp,\r\n\t\treleaseTime: rel\r\n\t).kr(doneAction: 2, gate: gate);\r\n\tcarrier = Pan2.ar(in: carrier, pos: pos, level: env);\r\n\tOut.ar(0, carrier * 0.5);\r\n}).add;\r\n\r\nSynthDef(\"fm2\", {arg freq = 440, modindex = 10, amp = 0.1, pos = 0, gate = 1, att = 0.01, rel = 0.3;\r\n\tvar carrier, modulator, freqdev, env, modfreq;\r\n\t// i = d/m, so d = m*i\r\n\tmodindex = Line.kr(modindex, 1, att);\r\n\tmodfreq = freq / 2;\r\n\tfreqdev = modfreq * modindex;\r\n\tmodulator = SinOsc.ar(freq: modfreq, mul: freqdev);\r\n\tcarrier = SinOsc.ar(freq: freq + modulator);\r\n\tenv = Env.asr(\r\n\t\tattackTime: att,\r\n\t\tsustainLevel: amp,\r\n\t\treleaseTime: rel\r\n\t).kr(doneAction: 2, gate: gate);\r\n\tcarrier = Pan2.ar(in: carrier, pos: pos, level: env);\r\n\tOut.ar(0, carrier * 0.5);\r\n}).add;\r\n\r\n) // end of SynthDef code\r\n\r\n\r\n\r\n// ========================\r\n// Pbind collection\r\n//\r\n// tip: to work on a Pbind separately, copy and paste it\r\n// into a new window, add .play at end for convenience\r\n// (change/listen/change again/listen again),\r\n// and when you are done, copy it back here, don't\r\n// forget to REMOVE the .play from it.\r\n// Also create your own variable names that make sense to you.\r\n// ========================\r\n\r\n(\r\n~amx = Pbind(\r\n    \\instrument, \"am1\",\r\n    \\midinote, Pseq([80, 79, 78, 77, 76, 75, 74, 73, 72, 71,70, 69, 68, 67, 66, 65, 64, 63, 62, 61,60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50], 4),\r\n    \\dur, 0.2,\r\n    \\amp, 0.2,\r\n    \\att, 0.1,\r\n    \\rel, 4,\r\n    \\modfreq, Pseq([12, 9, 7, 5, 3], inf),\r\n\t\\pos, Prand([-100, 100], inf)\r\n);\r\n\r\n~amy = Pbind(\r\n    \\instrument, \"am1\",\r\n    \\midinote, Prand([72, 79, 77, 79, 82, 79, 87, 86, 84, 82, 84, 79], 12),\r\n\t\\ctranspose, [-24, -19],\r\n    \\dur, Pseq([Pn(0.1, 5), 0.2], inf),\r\n    \\amp, Pwhite(0.15, 0.2),\r\n    \\att, 0.01,\r\n    \\rel, 0.1,\r\n\t\\modfreq, Pwhite(10, 30),\r\n\t\\pos, 0\r\n);\r\n\r\n~amz = Pbind(\r\n    \\instrument, \"am1\",\r\n    \\freq, Pseq([200, 180, 160, 140, 120, 100, 90, 80, 40], 3),\r\n    \\dur, Pseq([1, 1, 1, 0.5, 0.5, 0.25, 0.25, 0.15, 0.15], inf),\r\n\t\\amp, Pseq([1, 4], inf),\r\n\t\\att, 0.05,\r\n    \\rel, Pwhite(0.3, 3)\r\n);\r\n\r\n~amshort = Pbind(\r\n\t\\instrument, \"am1\",\r\n\t\\degree, Pseq([0, 1, 2, 3, 4], inf),\r\n\t\\modfreq, Prand([130, 145, 200, 500, 300], inf),\r\n\t\\amp, Pwhite(0.1, 0.4),\r\n\t\\dur, Prand([0.2, 0.1, 0.1, 1], inf),\r\n\t\\att, 0.01,\r\n\t\\rel, Pkey(\\dur),\r\n\t\\pos, Pseq([-0.5, 0.5], inf)\r\n);\r\n\r\n~jumpy = Pbind(\r\n\t\\instrument, \"am1\",\r\n\t\\degree, Pseq([0, 2], inf),\r\n\t\\modfreq, Pseq([1, 5, 10, 50, 100], inf),\r\n\t\\amp, 0.4,\r\n\t\\dur, 0.2,\r\n\t\\att, 0.01,\r\n\t\\rel, Pwhite(0.3, 0.5),\r\n\t\\pos, Pwhite(-1, 1.0)\r\n);\r\n\r\n~burger = Pbind(\r\n\t\\instrument, \"am2\",\r\n\t\\freq, Pseq([1000, 820, 900, 1000], 8),\r\n\t\\modfreq, Pseq([10000], inf),\r\n\t\\amp, Pseq([0.5, 0.5, 0.5, 0.5, 0.7, 0.7, 0.7, 0.9, 0.9, 0.9, 1, 1, 1, 1],inf),\r\n\t\\dur, 0.2,\r\n\t\\att, 0,\r\n\t\\rel, Pseq([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,3,3, 3, 3, 3,3],inf),\r\n\t\\pos, Pseq([-50, -25, -20, 20, 25, 50], inf)\r\n);\r\n\r\n\r\n~harmonics = Pbind(\r\n\t\\instrument, \"am2\",\r\n\t\\freq, Pseries(100, 50, 20),\r\n\t\\modfreq, Pseq([1, 500, 10, 50, 100], inf),\r\n\t\\amp, 0.2,\r\n\t\\att, 0.02,\r\n\t\\rel, 4,\r\n\t\\pos, Pwhite(-1, 1),\r\n\t\\dur, 0.1\r\n);\r\n\r\n~amak = Pbind(\r\n    \\instrument, \"am3\",\r\n    \\midinote, Prand([72, 79, 77, 79, 82, 79, 87, 86, 84, 82, 84, 79], inf),\r\n\t\\ctranspose, -12,\r\n\t\\dur, Pseq([Pn(0.5, 5), Prand([1.5, 3])], inf),\r\n    \\amp, Pwhite(0.15, 0.5),\r\n\t\\att, Pwhite(0.5, 1),\r\n\t\\rel, Pwhite(1, 3.0),\r\n    \\modfreq, Pseq([7, 9, 10, 11], inf)\r\n);\r\n\r\n~amik = Pbind(\r\n    \\instrument, \"am3\",\r\n    \\freq, Prand([\r\n\t\t[100, 105, 108],\r\n\t\t[220, 225, 230],\r\n\t\t[100, 110, 115],\r\n\t\t[200, 220, 225],\r\n\t\t],\r\n\t\t8),\r\n    \\dur, Pseq([1, 2, 2, 1], inf),\r\n    \\amp, 0.5,\r\n\t\\att, 0,\r\n\t\\rel, 0.8,\r\n\t\\modfreq, Pseq([100], inf),\r\n\t\\pos, Pseq([-0.5, 0, 0.5], inf)\r\n);\r\n\r\n~fmuh = Pbind(\r\n    \\instrument, \"fm2\",\r\n\t\\dur, 1,\r\n\t\\degree, Pseq([0, 4, 5, 6], 8),\r\n\t\\modindex, Pseq([5, 6, 7, 10], inf),\r\n\t\\amp, 0.1,\r\n\t\\att, Pwhite(0.1, 0.3),\r\n\t\\rel, Pwhite(1, 3.0),\r\n\t\\pos, Pwhite(-1, 1.0)\r\n);\r\n\r\n\r\n~fmwow = Pbind(\r\n    \\instrument, \"fm1\",\r\n    \\dur, 0.2,\r\n\t\\freq, Pseq([120, 240, 360, 480], 12),\r\n\t\\modfreq, Pseq([1, 2, 4, 8], 8),\r\n    \\modindex, 1, //\r\n\t\\amp, Pseq([0.3, 0.4, 0.6, 0.8], inf),\r\n\t\\att, 0.5,\r\n\t\\rel, 3,\r\n);\r\n\r\n\r\n~fmclouds = Pbind(\r\n    \\instrument, \"fm2\",\r\n\t\\dur, Prand([1, 2, 0.5], inf),\r\n\t\\freq, Pseq([120, 240, 80], 8),\r\n\t\\modindex, Prand([900, 1000],inf),\r\n\t\\amp, 0.01,\r\n\t\\att, Pwhite(1, 4),\r\n\t\\rel, Pseq([100, 20, 40,60,100],inf),\r\n\t\\pos, 0\r\n);\r\n\r\n~fmbass = Pbind(\r\n    \\instrument, \"fm2\",\r\n\t\\dur, Pwhite(0.27, 0.275),\r\n\t\\note, Pseq([\r\n\t\tPseq([0, 4, 7, 9, Prand([10, 12]), 9, 7, 4], 2), // I\r\n\t\tPseq([0, 4, 7, 9, 10, 9, 7, 4], 1) + 5, // IV\r\n\t\tPseq([0, 4, 7, 9, 10, 9, 7, 4], 1), // I\r\n\t\t7, 11, 14, 11, 7, 5, 4, 2 // V\r\n\t], inf),\r\n\t\\ctranspose, -12,\r\n\t\\modindex, Pseq([ 6, 7, 8, 9, 20, 9, 8, 4, 1 ], inf),\r\n\t\\amp, Pseq([0.3, 0.35, 0.4, 0.45, 0.5, 0.45, 0.4, 0.3, 0.2], inf),\r\n\t\\att, 0.01,\r\n\t\\rel, 0.2,\r\n\t\\pos, 0\r\n);\r\n\r\n~fmletsdothis = Pbind(\r\n    \\instrument, \"fm2\",\r\n\t\\dur, Pseq([1],inf),\r\n\t\t\\freq, Pseq([80, 140, 100], 4),\r\n\t\\ctranspose, 12,\r\n\t\\modindex, Pseq([1, 5, 6, 7, 10], inf),\r\n\t\\amp, 0.8,\r\n\t\\att, 0.01,\r\n\t\\rel, Pwhite(1, 2.0),\r\n\t\\pos, 0\r\n);\r\n\r\n\r\n~kick =\r\nPbind(\r\n\t\\instrument, \"kick\",\r\n\t\\dur, Pseq([1/2, Rest(1/2), 1/2, Rest(1/2), 1/3, 1/3, 1/3, 1/2, Rest(1/2), 1/2, Rest(1/2)], inf),\r\n\t\\att, 0.01,\r\n\t\\rel, 0.22,\r\n\t\\sinfreq, 60,\r\n\t\\glissf, 0.9,\r\n\t\\amp, 2,\r\n);\r\n\r\n~snare =\r\nPbind(\r\n\t\\instrument, \"snare\",\r\n\t\\dur, Pseq([1/3, Rest(1/3), 1/3, 1, 1, 1], 4),\r\n\t\\att, 0.01,\r\n\t\\rel, Pseq([0.1,0.1, 0.1, 0.75, 0.75, 0.75], 4),\r\n\t\\sinfreq, 180,\r\n\t\\ffreq, 200,\r\n\t\\amp, 0.1\r\n);\r\n~hihat=\r\nPbind(\r\n\t\\instrument, \"hihat\",\r\n\t\\dur, Pseq([Rest(2.5), 1/2, 1/8, 1/8, Rest(1/2)], inf),\r\n\t\\att, Pseq([0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.04], inf),\r\n\t\\rel, 0.1,\r\n\t\\ffreq, 11000,\r\n\t\\pan, 0,\r\n\t\\amp, 0.3\r\n);\r\n\r\n~buildup =\r\nPbind(\r\n\t//BUILD UP\r\n\t\\instrument, \"kick\",\r\n\t\\dur, Pseq([1/4, 1/4, 1/8, 1/8, 1/8, 1/8, 1/16, 1/16, 1/16, 1/16, 1/16, 1/16, 1/16, 1/16, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32, 1/32], 1),\r\n\t\\att, 0.01,\r\n\t\\rel, 0.025,\r\n\t\\sinfreq, 60,\r\n\t\\glissf, 0.9,\r\n\t\\amp, 1.8,\r\n);\r\n\r\n\r\n\r\n\r\n\r\n) // end of Pbind collection\r\n\r\n\r\n// =============\r\n// Double check your the Pbinds (listen)\r\n// Remember: some of them are inf, others are finite\r\n// you can adjust that by changing the Pbinds\r\n// =============\r\n\r\n~amx.play;    //exfiles - good for melody\r\n~amy.play;    //good for background\r\n~amz.play;   //good for beginning\r\n~amshort.play;  //weird jittering stuff\r\n~jumpy.play;    //melodic stuff\r\n~burger.play;   //also melodic\r\n~harmonics.play;  //harmonics\r\n~amak.play;      //melodic maybe could be cool bass\r\n~amik.play;     //chordy stuff, midlevel\r\n\r\n~fmbass.play;   //pretty basic bass\r\n~fmclouds.play;  //cloudy chordy\r\n~fmuh.play;   //pretty basic notes\r\n~fmwow.play;  //weird glisandoing stuff\r\n~fmletsdothis.play;   //cool melody with bass accompaniement\r\n~snare.play;\r\n~kick.play;\r\n~hihat.play;\r\n\r\n// =============\r\n// COMPOSITION\r\n// =============\r\n// Build your sequence here\r\n// you can use either {}.fork or Pspawner\r\n// see Pspawner help file.\r\n\r\n(\r\nPspawner({arg maestro;\r\n\t~kickplayer = maestro.par(~kick);\r\n\tmaestro.seq(Ppar([~amz]));\r\n\tmaestro.par(Ppar([~snare, ~hihat]));\r\n\tmaestro.wait(1);\r\n\tmaestro.seq(~buildup);\r\n\tmaestro.seq(~fmletsdothis);\r\n\tmaestro.seq(Ppar([~fmwow, ~amik]));\r\n\tmaestro.wait(1);\r\n\tmaestro.seq(~buildup);\r\n\tmaestro.seq(Ppar([~fmletsdothis, ~burger]));\r\n\tmaestro.seq(Ppar([~fmclouds, ~amx]));\r\n\tmaestro.suspendAll;\r\n\r\n\r\n\r\n}).play;\r\n)"
}
