{
   "labels" : [
      "nature",
      "electricity"
   ],
   "code" : "//Fig 39.3: Hum source\r\n//Contains the subpatch shown in fig 39.2.\r\n\r\n(\r\n{\r\n\tvar humSource, noise, comb;\r\n \r\n\thumSource = Clip.ar(LFSaw.ar([99.8, 100.2], 1, 0.5, 0.5).sum - 1, -0.5, 0.5);\r\n \r\n\tnoise = LPF.ar(LPF.ar(WhiteNoise.ar,2),2);\r\n\tnoise = noise * noise * 500;\r\n \r\n\thumSource = humSource * noise;\r\n \r\n\t// fig 39.2: Comb unit\r\n\tcomb = DelayC.ar(InFeedback.ar(10), delaytime: (noise+20)/1000);\r\n\tOffsetOut.ar(10, (humSource + OnePole.ar(comb * 0.2, exp(-2pi * (3000 * SampleDur.ir)))));\r\n \r\n\tcomb!2 ;\r\n \r\n}.play;\r\n)\r\n\r\n\r\n//Fig 39.8: Hum and sparks\r\n\r\n//Contains the subpatches shown in fig 39.2, 39.4, 39.5, 39.6 & 39.7. \r\n//The scope windows show the same information as in the diagnostic graphs of fig 39.4.\r\n\r\n(\r\n{\r\n\tvar noise, phasor, chirpPulse, randGate, chirpAmp, clip, snap, trig, formant, comb;\r\n \r\n\tphasor = LFSaw.ar([-99.8, 100.2], 1, 0.5, 0.5);\r\n\t \r\n\tnoise = WhiteNoise.ar!2;\r\n\tnoise[0] = OnePole.ar(noise[0], exp(-2pi * (0.1 * SampleDur.ir)));\r\n\tnoise[0] = OnePole.ar(noise[0], exp(-2pi * (0.1 * SampleDur.ir)));\r\n\tnoise[0] = noise[0].max(0) * 700 + 3;\r\n \r\n \r\n\t// fig 39.4: Chirp pulse\r\n\tchirpPulse = phasor[0].scope * noise[0];\r\n\tchirpPulse = chirpPulse.min(1) - (chirpPulse.max(1) - 1 * 1e+09).min(1);\r\n\tchirpPulse.scope;\r\n\tchirpPulse = ((chirpPulse + 0.1)**2 * 12 * 2pi).cos * chirpPulse;\r\n\tchirpPulse.scope;\r\n\tchirpPulse = (chirpPulse - OnePole.ar(chirpPulse, exp(-2pi * (300 * SampleDur.ir))));\r\n \r\n \r\n\t// fig 39.5: Random Gate\r\n\trandGate = WhiteNoise.ar;\r\n\trandGate = OnePole.ar(randGate, exp(-2pi * (3 * SampleDur.ir)));\r\n\trandGate = OnePole.ar(randGate, exp(-2pi * (3 * SampleDur.ir)));\r\n\trandGate = Clip.ar(noise.max(2) - 0.0008 * 1e+09, 0, 1);\r\n\trandGate = OnePole.ar(randGate, exp(-2pi * (30 * SampleDur.ir)));\r\n\trandGate = chirpPulse * randGate;\r\n \r\n \r\n\tnoise[1] = LPF.ar(LPF.ar(WhiteNoise.ar,2),2);\r\n\tnoise[1] = noise[1] * noise[1] * 500;\r\n \r\n \r\n\tclip = Clip.ar((phasor.sum - 1) * noise[1], -0.9, 0.1);\r\n \r\n \r\n\tchirpAmp = OnePole.ar(clip, exp(-2pi * (15 * SampleDur.ir)));\r\n\tchirpAmp = OnePole.ar(chirpAmp, exp(-2pi * (15 * SampleDur.ir)));\r\n\tchirpAmp = Clip.ar((chirpAmp * 500).max(0.1) - 0.1 * 1e+09, 0, 1);\r\n\tchirpAmp = OnePole.ar(chirpAmp, exp(-2pi * (30 * SampleDur.ir)));\r\n \r\n \r\n\tchirpPulse = chirpPulse * chirpAmp * 0.6;\r\n\ttrig = (Amplitude.kr(clip)>0.03);\r\n \r\n \r\n\t// fig 39.7: Spark snap\r\n\tsnap = 0!2;\r\n\tsnap[0] = EnvGen.ar(Env.new([0,1,0], [0, 0.5]), trig);\r\n\tsnap[0] = snap[0] * snap[0] * snap[0] * WhiteNoise.ar * 0.5;\r\n\tsnap[1] = EnvGen.ar(Env.new([0,1,0], [0, 10/1000]), trig);\r\n\tsnap[1] = SinOsc.ar(snap[1] * 7000 + 20);\r\n\tsnap = snap.sum * 0.05;\r\n \r\n \r\n\t// fig 39.6: Spark formant\r\n\tformant = BPF.ar(snap, 1.8 * [4600, 7200, 480, 720], [5,5,7,8].reciprocal);\r\n\tformant = formant[0..1].sum * 2 + formant[2] * 1.2 + formant[3] * 2.5;\r\n\tformant = BPF.ar(formant, 2500, 0.5.reciprocal);\r\n \r\n \r\n\t// fig 39.2 Comb unit\r\n\tcomb = DelayC.ar(InFeedback.ar(10), delaytime: (noise[1] + 20)/1000);\r\n\tOffsetOut.ar(10, (chirpPulse + clip + snap + OnePole.ar(comb * 0.2, exp(-2pi * (3000 * SampleDur.ir)))));\r\n \r\n\tcomb!2;\r\n \r\n}.play;\r\n)\r\n\r\n\r\n// code also available here:\r\n// http://en.wikibooks.org/wiki/Designing_Sound_in_SuperCollider/Electricity",
   "is_private" : null,
   "id" : "1-4RF",
   "author" : "DSastre",
   "name" : "Electricity",
   "ancestor_list" : [],
   "description" : "Hum and spark sounds. Based on pure data code from the book \"Designing Sound\" by Andy Farnell. (Chapter 39, Practical 16, Electricity)"
}
