{
   "author" : "Callum Goddard",
   "name" : "Mono2eN - SynthDef",
   "description" : "The synthdef version of the mono2eN system - a multichannel autospatilisation musical performance tool.",
   "ancestor_list" : [],
   "labels" : [
      "spatial",
      "performance tool"
   ],
   "id" : "1-4T6",
   "is_private" : null,
   "code" : "s = Server.internal;\r\ns.boot;\r\n\r\n(\r\nSynthDef(\"4for8\", {\r\n\targ width=2, level=0.5;\r\n\r\n        // change to match number of output audio channels\r\n\tvar numChans = 6;\r\n\r\n\tvar in, amp, pos=0, sig, sig2, sig2pan, out, chain, chainSpec, centroid, freq, hasFreq, freq2, hasFreq2;\r\n\r\n\tin = SoundIn.ar(0);  // input\r\n\r\n\t# freq, hasFreq = Pitch.kr(\r\n\t\t\t\t\tin,\r\n\t\t\t\t\tampThreshold: 0.09,\r\n\t\t\t\t\tmedian: 7);\r\n\tfreq = freq * hasFreq* 0.01;\r\n\tfreq.poll;\r\n\r\n\tchainSpec = FFT(LocalBuf(2048, 1), in);\r\n\r\n\tcentroid = SpecCentroid.kr(chainSpec);\r\n\r\n\tcentroid = ((centroid * 0.0005)-0.3)*10;\r\n\r\n\t// new possition determined by centroid\r\n\tpos = VarLag.kr(\r\n\t\t\tcentroid,\r\n\t\t\t0.9,\r\n\t\t\t);  // smooths the position\r\n\r\n\r\n\t// PanAz position of the sound\r\n\tsig = PanAz.ar(\r\n\t\t     numChans,\r\n\t\t     in,\r\n\t\t     pos,\r\n\t\t     level,\r\n\t\t     width,\r\n\t\t).scramble;\r\n\r\n\tchain = FFT({LocalBuf(2048, 1)}.dup(numChans), sig);\r\n\r\n\tchain = PV_MagFreeze(chain, SinOsc.kr(freq*100));\r\n\r\n\tsig2 = IFFT(chain);\r\n\r\n\tsig2pan = SplayAz.ar(\r\n\t\tnumChans,\r\n\t\tsig2\r\n\t);\r\n\r\n\t// Mixing wet and dry signal.\r\n\tout = sig + sig2pan;\r\n\tout = out*0.7;\r\n\tOut.ar(0, out);\r\n}).add;\r\n\r\n)\r\n\r\n(\r\nx = Synth(\"4for8\")\r\n\r\nx.set(\\width, 5, \\level, 0.2)\r\n)"
}
