{
   "is_private" : null,
   "id" : "1-57B",
   "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\ns.waitForBoot({\r\n\t// Single string of a sitar.\r\n\tSynthDef(\\tar, {\r\n\t\t|\r\n\t\tout = 0, in = 0, inscale = 1.0, freq = 440, bw = 1.03, amp = 0.5\r\n\t\tpos = 0.1,\r\n\t\thc1 = 1, hc3 = 30, hfreq = 3000,\r\n\t\tvc1 = 1, vc3 = 30, vfreq = 3000\r\n\t\t|\r\n\t\tvar inp, jawari, snd;\r\n\t\t// Input audio -- may be a pluck impulse (chikari) or audio (tarafdar)\r\n\t\tinp = In.ar(in, 1) * inscale;\r\n\t\t// Jawari (bridge) simulation. This is the heart of Ronan's model.\r\n\t\t// Violins and guitars have vertical bridges. The jawari is flat, and this causes the tar to buzz against the jawari.\r\n\t\t// Physically, end of the string coming in contact the bridge causes the string to shorten.\r\n\t\t// We assume that the audio output is a reasonable approximation of how much contact the string has with the bridge.\r\n\t\t// So we shorten the DWG (by adjusting its frequency) according to its own audio output.\r\n\t\tjawari = LocalIn.ar(1);\r\n\t\t// Make the jawari control rate\r\n\t\tjawari = A2K.kr(jawari);\r\n\t\t// Make the jawari affect the freq exponentially\r\n\t\tjawari = jawari.linexp(-1, 1, bw.reciprocal, bw);\r\n\t\t// The string itself has horizontal and vertical planes, which we simulate with two different DWGPlucked instances\r\n\t\tsnd = [\r\n\t\t\tDWGPlucked.ar(freq * jawari, pos: pos, c1: hc1, c3: hc3, inp: LPF.ar(inp, hfreq)),\r\n\t\t\tDWGPlucked.ar(freq * jawari, pos: pos, c1: vc1, c3: vc3, inp: LPF.ar(inp, vfreq))\r\n\t\t].sum;\r\n\t\tLocalOut.ar(snd);\r\n\t\tOut.ar(out, snd * amp);\r\n\t}).add;\r\n\r\n\tSynthDef(\\pluckImpulse, {\r\n\t\t|out = 0, t_trig = 0, amp = 0.3|\r\n\t\tOut.ar(out, PinkNoise.ar * EnvGen.kr(Env.perc(0.01, 0.02), t_trig) * amp);\r\n\t}).add;\r\n\r\n\t// Useful for testing. For programmatic usage use \\pluckImpulse\r\n\tSynthDef(\\mousePluck, {\r\n\t\t|out = 0, num = 0, amp = 0.3|\r\n\t\tvar m = MouseY.kr(0, 8);\r\n\t\tvar trig = (num <= m) & (m < (num + 1)) * MouseButton.kr(0, 1, 0);\r\n\t\tOut.ar(out, HPF.ar(WhiteNoise.ar, 400) * EnvGen.kr(Env.perc(0.001, 0.03, 0.5), trig) * amp);\r\n\t}).add;\r\n\r\n\tSynthDef(\\sitar, {\r\n\t\t|out = 0, chikari = 0, tarafdar = 0, dry = 0.5, wet = 0.5, amp = 0.5|\r\n\t\tvar snd = In.ar(chikari, 1) * dry;\r\n\t\tvar lfo;\r\n\t\tsnd = snd + (In.ar(tarafdar, 1) * wet);\r\n\t\t// Dumb gourd model. I randomly picked lope only transitions to the release node when released. Examples are below. Tfreqs/bws/amps.\r\n\t\t// Please let me know if you have some estimates of the resonances of a real sitar gourd.\r\n\t\tsnd = snd + BPF.ar(snd, [90, 132, 280], [1.3, 0.9, 1.4], [0.9, 0.6, 0.7]).sum;\r\n\t\tsnd = Pan2.ar(GVerb.ar(0.3*snd, roomsize:1, damping:0.7), 0, amp);\r\n\t\tOut.ar(out, snd);\r\n\t}).add;\r\n\r\n\ts.sync;\r\n\r\n\t// Don't take this example tuning seriously.\r\n\t// I know next to nothing about ragas and sitar tuning.\r\n\t~chikariFreqs = 48.midicps * [1, 16/15, 5/4, 4/3, 3/2, 8/5, 15/8, 2];\r\n\t~numChikari = ~chikariFreqs.size;\r\n\t~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\t~numTarafdar = ~tarafdarFreqs.size;\r\n\r\n\t// Pluck impulse busses, one per chikari\r\n\t~pluckBus = Bus.audio(s, ~numChikari);\r\n\t// Summed output of all chikari (plucked strings)\r\n\t~chikariBus = Bus.audio(s, 1);\r\n\t// Summed output of all tarafdar (sympathetic strings)\r\n\t~tarafdarBus = Bus.audio(s, 1);\r\n\r\n\t~pluckGroup = Group();\r\n\t~chikariGroup = Group.after(~pluckGroup);\r\n\t~tarafdarGroup = Group.after(~chikariGroup);\r\n\r\n\t~pluck = ~numChikari.collect { |i|\r\n\t\tSynth(\\mousePluck, [\r\n\t\t\t\\out, ~pluckBus.index + i,\r\n\t\t\t\\num, i,\r\n\t\t], ~pluckGroup);\r\n\t};\r\n\t~chikari = ~numChikari.collect { |i|\r\n\t\tSynth(\\tar, [\r\n\t\t\t\\in, ~pluckBus.index + i,\r\n\t\t\t\\out, ~chikariBus,\r\n\t\t\t\\freq, ~chikariFreqs[i],\r\n\t\t\t\\bw, 1.08,\r\n\t\t\t\\hc1, 4, \\hc2, 50,\r\n\t\t\t\\vc1, 3, \\vc3, 30,\r\n\t\t\t\\amp, 0.1\r\n\t\t], ~chikariGroup);\r\n\t};\r\n\t~tarafdar = ~numTarafdar.collect { |i|\r\n\t\tSynth(\\tar, [\r\n\t\t\t\\in, ~chikariBus,\r\n\t\t\t\\inscale, 0.1,\r\n\t\t\t\\out, ~tarafdarBus,\r\n\t\t\t\\freq, ~tarafdarFreqs[i] * 1.0.rand.linexp(0, 1, 0.99, 1.01),\r\n\t\t\t\\pos, 0.4,\r\n\t\t\t\\bw, 1.08,\r\n\t\t\t\\hc1, 4, \\hc2, 50,\r\n\t\t\t\\vc1, 3, \\vc3, 30,\r\n\t\t\t\\amp, 0.1\r\n\t\t], ~tarafdarGroup);\r\n\t};\r\n\t~sitar = Synth.after(~tarafdarGroup, \\sitar, [\r\n\t\t\\chikari, ~chikariBus,\r\n\t\t\\tarafdar, ~tarafdarBus,\r\n\t\t\\dry, 1,\r\n\t\t\\wet, 0.5,\r\n\t\t\\amp, 0.8\r\n\t]);\r\n});\r\n)",
   "labels" : [
      "guitar",
      "code fork",
      "instrument",
      "physical model",
      "plucked strings",
      "pluck",
      "sitar"
   ],
   "ancestor_list" : [
      "1-50b"
   ],
   "description" : "fork of a sitar model by @snappizz... it sounds better to me although I have no idea how it's supposed to sound.\r\nModifications are in the plucking (while playing with the example I found that the envelope and spectrum of the plucking has a significant influence on the resulting sound - I went for a sharper sound) and I added a GVerb for additional metallic resonance.\r\n\r\nFeel free to further improve :)",
   "author" : "56228375",
   "name" : "Re: DWG sitar model"
}
