{
   "code" : "// ************************************\r\n// Ring Modulation (GUI)\r\n// Patch 1 - Basic Demo\r\n// Bruno Ruviaro, 2013-08-02\r\n// ************************************\r\n\r\n/*\r\n\r\nSimple interface to experiment with with Ring Modulation.\r\nRing Modulation is the multiplication of two bipolar signals (Carrier and Modulator) by one another. It is a type of Amplitude Modulation.\r\nA bipolar signal outputs values between -1 and +1. The resulting spectrum contains the sum and the difference of C and M frequencies.\r\nWatch the spectrum on the Frequency Analyzer window.\r\n\r\nHow to start:\r\nSelect all (ctrl + A), then evaluate (ctrl + period).\r\n\r\n\r\n*/\r\n\r\ns.waitForBoot({\r\n\r\n\tvar win, carrFreqKnob, carrFreqNumber, carrFreqLabel, modFreqKnob, modFreqNumber, modFreqLabel, volumeSlider, defaultFont, carrSpec, modSpec, synth, carrMenu;\r\n\r\n\tdefaultFont = Font(\"Verdana\", 16, bold: true);\r\n\r\n\t// Main window\r\n\tWindow.closeAll;\r\n\r\n\twin = Window.new(\"Ring Modulation\", Rect(20, 400, 610, 280));\r\n\twin.onClose = {s.freeAll; Window.closeAll; \"Ring Modulation window closed.\".postln; \"\".postln};\r\n\twin.background = Color.yellow(0.8);\r\n\twin.alpha = 0.9;\r\n\tFreqScope.new;\r\n\twin.front;\r\n\r\n\t// Carrier Frequency Knob\r\n\tcarrSpec = ControlSpec(20, 20000, 'exp', 0, 440, \" Hz\");\r\n\tcarrFreqKnob = Knob.new(win, Rect(20, 20, 200, 200))\r\n\t.action = {arg v;\r\n\t\tvar freq = carrSpec.map(v.value);\r\n\t\tcarrFreqNumber.string = freq.round;\r\n\t\tsynth.set(\\carrFreq, freq)};\r\n\tcarrFreqKnob.value = carrSpec.unmap(carrSpec.default);\r\n\r\n\t// Carrier Frequency Number\r\n\tcarrFreqNumber = StaticText.new(win, Rect(80, 210, 80, 25));\r\n\tcarrFreqNumber.background = Color.yellow(0.8);\r\n\tcarrFreqNumber.alpha = 0.9;\r\n\tcarrFreqNumber.align = \\center;\r\n\tcarrFreqNumber.string = 440;\r\n\tcarrFreqNumber.font = defaultFont;\r\n\r\n\t// Carrier Frequency Label\r\n\tcarrFreqLabel = StaticText.new(win, Rect(20, 240, 200, 25));\r\n\tcarrFreqLabel.string = \"Carrier Frequency\";\r\n\tcarrFreqLabel.align = \\center;\r\n\tcarrFreqLabel.font = defaultFont;\r\n\r\n\t// Modulator Frequency Knob\r\n\tmodSpec = ControlSpec(0.5, 5000, 'exp', 0, 2, \" Hz\");\r\n\tmodFreqKnob = Knob.new(win, Rect(260, 20, 200, 200))\r\n\t.action = {arg v;\r\n\t\tvar freq = modSpec.map(v.value);\r\n\t\tmodFreqNumber.string = freq.round(0.1);\r\n\t\tsynth.set(\\modFreq, freq)};\r\n\tmodFreqKnob.value = modSpec.unmap(modSpec.default);\r\n\r\n\t// Modulator Frequency Number\r\n\tmodFreqNumber = StaticText.new(win, Rect(320, 210, 80, 25));\r\n\tmodFreqNumber.background = Color.yellow(0.8);\r\n\tmodFreqNumber.alpha = 0.9;\r\n\tmodFreqNumber.align = \\center;\r\n\tmodFreqNumber.string = 2;\r\n\tmodFreqNumber.font = defaultFont;\r\n\r\n\t// Modulator Frequency Label\r\n\tmodFreqLabel = StaticText.new(win, Rect(260, 240, 200, 25));\r\n\tmodFreqLabel.string = \"Modulator Frequency\";\r\n\tmodFreqLabel.align = \\center;\r\n\tmodFreqLabel.font = defaultFont;\r\n\r\n\t// Volume Slider\r\n\tvolumeSlider = EZSlider(\r\n\t\tparent: win,\r\n\t\tbounds: Rect(510, 20, 70, 200),\r\n\t\tlabel: \"VOLUME\",\r\n\t\tcontrolSpec: ControlSpec(-40, 0, \\lin, 0.1, -24, \"dB\"),\r\n\t\taction: {|ez| synth.set(\\amp, ez.value.dbamp)},\r\n\t\tlabelWidth: 80,\r\n\t\tunitWidth: 30,\r\n\t\tlayout: 'vert')\r\n\t.setColors(\r\n\t\tstringColor: Color.black,\r\n\t\tsliderBackground: Color.grey(0.9),\r\n\t\tnumNormalColor: Color.black)\r\n\t.font = Font(\"Verdana\", 14, bold: true);\r\n\r\n\tvolumeSlider.numberView.align = \\center;\r\n\tvolumeSlider.unitView.align = \\center;\r\n\r\n\t// Menu\r\n\tcarrMenu = PopUpMenu(win, Rect(510, 230, 70, 30));\r\n\tcarrMenu.items = [\"Sine\", \"Blip\", \"Saw\"];\r\n\tcarrMenu.background = Color.white;\r\n\tcarrMenu.font = Font(\"Verdana\", 13, bold: true);\r\n\tcarrMenu.action = {arg menu; synth.set(\\which, menu.value)};\r\n\r\n\t{\r\n\t\tSynthDef(\"ring-mod\", {arg carrFreq = 440, modFreq = 2, amp = 0.06, which = 0;\r\n\t\t\tvar carrier, modulator;\r\n\t\t\tcarrier = Select.ar(which,\r\n\t\t\t\t[\r\n\t\t\t\t\tSinOsc.ar(Lag.kr(carrFreq)),\r\n\t\t\t\t\tBlip.ar(Lag.kr(carrFreq), 5),\r\n\t\t\t\t\tSaw.ar(Lag.kr(carrFreq))\r\n\t\t\t]);\r\n\t\t\tmodulator = SinOsc.ar(Lag.kr(modFreq));\r\n\t\t\tOut.ar(0, carrier * modulator * amp);\r\n\t\t}).add;\r\n\r\n\t\ts.sync;\r\n\r\n\t\tsynth = Synth(\"ring-mod\");\r\n\r\n\t}.fork;\r\n\r\n\tCmdPeriod.doOnce({win.close});\r\n\r\n}); // end of waitForBoot",
   "is_private" : null,
   "id" : "1-4UE",
   "labels" : [
      "gui",
      "synthesis techniques",
      "amplitude modulation",
      "ring modulation"
   ],
   "description" : "Simple interface to experiment with with Ring Modulation (a type of Amplitude Modulation).",
   "ancestor_list" : [],
   "author" : "Bruno Ruviaro",
   "name" : "Ring Modulation GUI Demo"
}
