{
   "code" : "/*\r\nBased on a model by David Ronan (http://issta.ie/wp-content/uploads/The-Physical-Modelling-of-a-Sitar.pdf).\r\nRequires sc3-plugins.\r\n\r\nLacks shimmer. Sounds more like a banjo than a sitar. I don't know whether\r\nthis is just a matter of tuning parameters or whether the model itself needs\r\nfixing.\r\n*/\r\n\r\n(\r\n// Single string of a sitar.\r\nSynthDef(\\tar, {\r\n\t|\r\n\tout = 0, in = 0, inscale = 1.0, freq = 440, bw = 1.03, amp = 0.5\r\n\tpos = 0.1,\r\n\thc1 = 1, hc3 = 30, hfreq = 3000,\r\n\tvc1 = 1, vc3 = 30, vfreq = 3000\r\n\t|\r\n\tvar inp, jawari, snd;\r\n\t// Input audio -- may be a pluck impulse (chikari) or audio (tarafdar)\r\n\tinp = In.ar(in, 1) * inscale;\r\n\t// Jawari (bridge) simulation. This is the heart of Ronan's model.\r\n\t// Violins and guitars have vertical bridges. The jawari is flat, and this causes the tar to buzz against the jawari.\r\n\t// Physically, end of the string coming in contact the bridge causes the string to shorten.\r\n\t// We assume that the audio output is a reasonable approximation of how much contact the string has with the bridge.\r\n\t// So we shorten the DWG (by adjusting its frequency) according to its own audio output.\r\n\tjawari = LocalIn.ar(1);\r\n\t// Make the jawari control rate\r\n\tjawari = A2K.kr(jawari);\r\n\t// Make the jawari affect the freq exponentially\r\n\tjawari = jawari.linexp(-1, 1, bw.reciprocal, bw);\r\n\t// The string itself has horizontal and vertical planes, which we simulate with two different DWGPlucked instances\r\n\tsnd = [\r\n\t\tDWGPlucked.ar(freq * jawari, pos: pos, c1: hc1, c3: hc3, inp: LPF.ar(inp, hfreq)),\r\n\t\tDWGPlucked.ar(freq * jawari, pos: pos, c1: vc1, c3: vc3, inp: LPF.ar(inp, vfreq))\r\n\t].sum;\r\n\tLocalOut.ar(snd);\r\n\tOut.ar(out, snd * amp);\r\n}).add;\r\n\r\nSynthDef(\\pluckImpulse, {\r\n\t|out = 0, t_trig = 0, amp = 0.3|\r\n\tOut.ar(out, PinkNoise.ar * EnvGen.kr(Env.perc(0.01, 0.02), t_trig) * amp);\r\n}).add;\r\n\r\n// Useful for testing. For programmatic usage use \\pluckImpulse\r\nSynthDef(\\mousePluck, {\r\n\t|out = 0, num = 0, amp = 0.3|\r\n\tvar m = MouseY.kr(0, 8);\r\n\tvar trig = (num <= m) & (m < (num + 1)) * MouseButton.kr(0, 1, 0);\r\n\tOut.ar(out, PinkNoise.ar * EnvGen.kr(Env.perc(0.01, 0.02), trig) * amp);\r\n}).add;\r\n\r\nSynthDef(\\sitar, {\r\n\t|out = 0, chikari = 0, tarafdar = 0, dry = 0.5, wet = 0.5, amp = 0.5|\r\n\tvar snd = In.ar(chikari, 1) * dry;\r\n\tsnd = snd + (In.ar(tarafdar, 1) * wet);\r\n\t// Dumb gourd model. I randomly picked freqs/bws/amps.\r\n\t// Please let me know if you have some estimates of the resonances of a real sitar gourd.\r\n\tsnd = snd + BPF.ar(snd, [90, 132, 280], [1.3, 0.9, 1.4], [0.9, 0.6, 0.7]).sum;\r\n\tsnd = Pan2.ar(snd, 0, amp);\r\n\tOut.ar(out, snd);\r\n}).add;\r\n)\r\n\r\n(\r\n// Don't take this example tuning seriously.\r\n// I know next to nothing about ragas and sitar tuning.\r\n~chikariFreqs = 48.midicps * [1, 16/15, 5/4, 4/3, 3/2, 8/5, 15/8, 2];\r\n~numChikari = ~chikariFreqs.size;\r\n~tarafdarFreqs = 48.midicps * [1, 16/15, 5/4, 4/3, 3/2, 8/5, 15/8, 2, 2*16/15, 2*5/4, 2*4/3, 2*3/2];\r\n~numTarafdar = ~tarafdarFreqs.size;\r\n)\r\n\r\n(\r\n// Pluck impulse busses, one per chikari\r\n~pluckBus = Bus.audio(s, ~numChikari);\r\n// Summed output of all chikari (plucked strings)\r\n~chikariBus = Bus.audio(s, 1);\r\n// Summed output of all tarafdar (sympathetic strings)\r\n~tarafdarBus = Bus.audio(s, 1);\r\n)\r\n\r\n// Use the mouse button to strum.\r\n\r\n(\r\n~pluckGroup = Group();\r\n~chikariGroup = Group.after(~pluckGroup);\r\n~tarafdarGroup = Group.after(~chikariGroup);\r\n\r\n~pluck = ~numChikari.collect { |i|\r\n\tSynth(\\mousePluck, [\r\n\t\t\\out, ~pluckBus.index + i,\r\n\t\t\\num, i,\r\n\t], ~pluckGroup);\r\n};\r\n~chikari = ~numChikari.collect { |i|\r\n\tSynth(\\tar, [\r\n\t\t\\in, ~pluckBus.index + i,\r\n\t\t\\out, ~chikariBus,\r\n\t\t\\freq, ~chikariFreqs[i],\r\n\t\t\\bw, 1.08,\r\n\t\t\\hc1, 4, \\hc2, 50,\r\n\t\t\\vc1, 3, \\vc3, 30,\r\n\t\t\\amp, 0.1\r\n\t], ~chikariGroup);\r\n};\r\n~tarafdar = ~numTarafdar.collect { |i|\r\n\tSynth(\\tar, [\r\n\t\t\\in, ~chikariBus,\r\n\t\t\\inscale, 0.1,\r\n\t\t\\out, ~tarafdarBus,\r\n\t\t\\freq, ~tarafdarFreqs[i] * 1.0.rand.linexp(0, 1, 0.99, 1.01),\r\n\t\t\\pos, 0.4,\r\n\t\t\\bw, 1.08,\r\n\t\t\\hc1, 4, \\hc2, 50,\r\n\t\t\\vc1, 3, \\vc3, 30,\r\n\t\t\\amp, 0.1\r\n\t], ~tarafdarGroup);\r\n};\r\n~sitar = Synth.after(~tarafdarGroup, \\sitar, [\r\n\t\\chikari, ~chikariBus,\r\n\t\\tarafdar, ~tarafdarBus,\r\n\t\\dry, 1,\r\n\t\\wet, 0.5,\r\n\t\\amp, 0.8\r\n]);\r\n)",
   "is_private" : null,
   "id" : "1-50b",
   "labels" : [
      "guitar",
      "instrument",
      "physical model",
      "plucked strings",
      "pluck",
      "sitar"
   ],
   "ancestor_list" : [],
   "description" : "guhhh, lots of complication for not that much payoff. please fork if you have some ideas for how to improve this",
   "author" : "snappizz",
   "name" : "DWG sitar model"
}
