{
   "ancestor_list" : [],
   "description" : "Ten layers of sound, all constantly running,\r\nyet only one is in \"sharp focus\" at any time.\r\nMove the mouse up and down to control the focal depth.\r\nby Dan Stowell 2012-05-14, after a chat w Simon Katan.\r\n\r\nYou'll need the PV_MagSmooth ugen which is in sc3-plugins.",
   "author" : "danstowell",
   "name" : "sonic focal depth",
   "code" : "/*\r\nsonic focal depth\r\nTen layers of sound, all constantly running,\r\nyet only one is in \"sharp focus\" at any time.\r\nMove the mouse up and down to control the focal depth.\r\nby Dan Stowell 2012-05-14, after a chat w Simon Katan.\r\n\r\nYou'll need the PV_MagSmooth ugen which is in sc3-plugins.\r\n*/\r\n\r\ns.boot\r\n\r\n~nlayers = 10;\r\n~basefreqs = ~nlayers.collect{|x|  (x * 7 + 60).midicps};\r\n~fftbufs = ~nlayers.collect{ Buffer.alloc(s, 2048) };\r\n\r\n(\r\nx = {\r\n\tvar layers, position, trig, ampenv, freqenv, layerpos, smoothfactor, ampfactor;\r\n\tposition = MouseY.kr(0, 1);\r\n\t/* Create sounds - each layer must have spectral variation in it */\r\n\tlayers = ~basefreqs.collect{ |basefreq|\r\n\t\ttrig = Dust.ar(10);\r\n\t\tampenv = Decay2.ar(trig, 0.0001, 0.2);\r\n\t\tfreqenv = Decay.ar(trig, 0.1).linexp(0,1,1,1.5);\r\n\t\tSinOsc.ar(freqenv * basefreq, 0, ampenv);\r\n\t};\r\n\t/* Now apply focal effect - least smoothing (0) when the \r\n\t\tmouse is at the same \"position\" as a layer */\r\n\tlayers = layers.collect{|son, i|\r\n\t\tlayerpos = i / (~nlayers - 1); // 0 to 1\r\n\t\tsmoothfactor = 1 - (layerpos - position).abs.linexp(0,1, 1, 0.0005);\r\n\t\tampfactor    =     (layerpos - position).abs.linlin(0,1, 1, 0.9);\r\n\t\tIFFT(PV_MagSmooth(FFT(~fftbufs[i], son), smoothfactor))\r\n\t\t * ampfactor * AmpCompA.ir(~basefreqs[i], ~basefreqs[3])\r\n\t};\r\n\tlayers.mean.dup\r\n}.play;\r\n)\r\n\r\nx.free",
   "id" : "1-4Q5",
   "is_private" : null,
   "labels" : []
}
