From 670ec549f6f855361dee5c6cdf270bffff12d331 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 1 Oct 2017 19:50:24 -0400 Subject: [PATCH] More bits in ch 2.4 --- sclang-play/tut/ch02.sc | 106 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/sclang-play/tut/ch02.sc b/sclang-play/tut/ch02.sc index 475175f..bc52379 100644 --- a/sclang-play/tut/ch02.sc +++ b/sclang-play/tut/ch02.sc @@ -318,3 +318,109 @@ ) }.scope ) + +( + a = { + SinOsc.ar(440) * 0.1 + }.play; +) + +( + a.run(false); +) + +( + a.run; +) + +( + a.free; +) + +( + a = { + arg freq=440; + SinOsc.ar(freq) * 0.1 + }.play +) + +( + a = { + arg freq=440, amp=0.1; + SinOsc.ar(freq) * amp; + }.play +) + +( + a.set(\freq, rrand(220, 440), \amp, rrand(0.05, 0.2)); +) + +( + { + var carrier, modulator, carrfreq, modfreq; + + carrfreq = MouseX.kr(440, 5000, 'exponential'); + modfreq = MouseY.kr(1, 5000, 'exponential'); + + carrier = SinOsc.ar(carrfreq, 0, 0.5); + modulator = SinOsc.ar(modfreq, 0, 0.5); + + carrier * modulator; + }.scope +) + +( + { SinOsc.ar(440, 0, 0.5) }.scope +) + +( + { SinOsc.ar(440, 0, 0.5, 0.5) }.scope +) + +( + { + var carrier, modulator, carrfreq, modfreq; + + carrfreq = MouseX.kr(440, 5000, 'exponential'); + modfreq = MouseY.kr(1, 5000, 'exponential'); + + carrier = SinOsc.ar(carrfreq, 0, 0.5); + modulator = SinOsc.ar(modfreq, 0, 0.25, 0.25); + + carrier * modulator; + }.scope +) + +( + var w, carrfreqslider, modfreqslider, moddepthslider, synth; + + w = Window("frequency modulation", Rect(100, 400, 400, 300)); + w.view.decorator = FlowLayout(w.view.bounds); + + synth = { + arg carrfreq=440, modfreq=1, moddepth=0.1; + SinOsc.ar(carrfreq + (moddepth * SinOsc.ar(modfreq)), 0, 0.25) + }.scope; + + carrfreqslider = EZSlider( + w, 300@50, "carrfreq", + ControlSpec(20, 5000, 'exponential', 10, 440), + { |ez| synth.set(\carrfreq, ez.value) } + ); + w.view.decorator.nextLine; + + modfreqslider = EZSlider( + w, 300@50, "modfreq", + ControlSpec(1, 5000, 'exponential', 1, 1), + { |ez| synth.set(\modfreq, ez.value) } + ); + w.view.decorator.nextLine; + + moddepthslider = EZSlider( + w, 300@50, "moddepth", + ControlSpec(0.01, 5000, 'exponential', 0.01, 0.01), + { |ez| synth.set(\moddepth, ez.value) } + ); + + w.front; +)