{
   "is_private" : null,
   "id" : "1-4RG",
   "code" : "//Fig 44.5: Motor\r\n//Contains the subpatches shown in fig 44.2, 44.3, 44.4 and 44.6.\r\n\r\n(\r\n{ \r\n \r\n  |     // arguments range: 0.0 - 1.0\r\n        runtime         = 0.2, \r\n        statorLevel     = 0.7,  \r\n        brushLevel      = 0.9,  \r\n        rotorLevel      = 0.6,  \r\n        maxSpeed        = 0.3,  \r\n        volume          = 0.5,\r\n        tubeRes         = 0.2\r\n  |\r\n \r\n        var motorEnv, motorEnv1, motorEnv2, motor, rotor, drive, stator, resonance;\r\n \r\n        // fig 44.2: Speed Control Envelope\r\n        motorEnv = (Line.ar(0,1,runtime * 20, doneAction:2)) * 2;\r\n        motorEnv1 = (1 - motorEnv.min(1)).pow(6); // fast growing curve\r\n        motorEnv2 = motorEnv.max(1) - 1; // linear decay\r\n        motorEnv = (motorEnv1 + motorEnv2) * (-1) + 1;\r\n \r\n        drive = motorEnv * (maxSpeed * (-2000));\r\n        drive = LFSaw.ar(drive, 1, 0.5, 0.5);\r\n \r\n        // fig 44.3: Rotor\r\n        rotor = WhiteNoise.ar;\r\n        rotor = BPF.ar(rotor, 4000, 1.reciprocal) * brushLevel;\r\n        rotor = (rotor + (rotorLevel * 0.2)) * drive.pow(4);\r\n \r\n        // fig 44.4: Stator\r\n        stator = (Wrap.ar(drive * 2) * 2pi).cos;\r\n        // notice the difference in SC between (stator * stator) and stator.pow(2)\r\n        // to achieve the desired sound result from the book, use (stator * stator)\r\n        // stator = stator.pow(2) + 1; // equals stator ** 2 + 1; \r\n        stator = (stator * stator) + 1; \r\n        stator = (1 / stator - 0.5) * statorLevel;\r\n \r\n        // fig 44.6: FM body resonance\r\n        resonance = SinOsc.ar(178) * drive + motorEnv;\r\n        resonance = (resonance * 2pi).cos;\r\n        resonance = (resonance - OnePole.ar(resonance, exp(-2pi * (180 * SampleDur.ir))));\r\n        resonance = (resonance - OnePole.ar(resonance, exp(-2pi * (180 * SampleDur.ir))));\r\n        resonance = resonance * tubeRes;\r\n \r\n        motor = motorEnv * (rotor + stator + resonance);\r\n        motor = (motor * volume).dup;\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/Motors",
   "labels" : [
      "motor",
      "machine"
   ],
   "description" : "based on pure data code from the book \"Designing Sound\" by Andy Farnell. (Chapter 44, Practical 21, Motors)",
   "ancestor_list" : [],
   "author" : "DSastre",
   "name" : "Motors"
}
