1 title:: 13_BinaryOp_synthesis
2 summary:: Mark Polishook tutorial
3 categories:: Tutorials>Mark_Polishook_tutorial
4 related:: Tutorials/Mark_Polishook_tutorial/00_Introductory_tutorial
6 section::Binary messages
8 The pattern for a binary message is
11 ## RECEIVER || OPERATOR || OPERAND
20 is a receiver (the object to which a message is sent), a binary operator, and an operand.
22 section::Mixing = addition
24 Use addition (a binary operation) to mix two or more ugens.
28 // mix 2 sawtooth waves
30 Saw.ar(500, 0.05) // receiver
32 Saw.ar(600, 0.06) // operand
38 // mix 3 unit generators.
40 Saw.ar(500, 0.05) // receiver
42 Saw.ar(600, 0.06) // operand
43 // when evaluated produce
45 // this BinaryOpUGen is then a receiver for an
46 + // addition operator followed by
47 Saw.ar(700, 0.07) // an operand
52 ////////////////////////////////////////////////////////////////////////////////////////////////////
54 Rewrite the previous example with the Mix ugen.
60 // the ugens that will be mixed go into an array
71 Or use Mix.arFill to create the same result.
74 { Mix.arFill(3, { arg i; Saw.ar(500 + (i * 100), 0.05) }) }.scope;
77 Every time the function is evaluated, the argument i is incremented. So i equals 0 the first time the function is evaluated, i equals 1 the second time, i equals 2, the third time, and so on.
79 section::Scaling = multiplication
81 Apply an envelope, in the form of a low-frequency sine wave, to a WhiteNoise generator.
84 { WhiteNoise.ar(0.1) * SinOsc.kr(1, 1) }.scope;
88 // ... imitates a train?
90 (WhiteNoise.ar(0.1) * SinOsc.kr(1, 1))
92 (BrownNoise.ar(0.1) * SinOsc.kr(2, 1))
100 Dynamically modulate any parameter in a ugen (such as frequency, phase, or amplitude) with an envelope.
103 // modulate amplitude
104 { SinOsc.ar(440, 0, 0.1) * EnvGen.kr(Env.sine(1), doneAction: 2) }.scope;
107 Setting the doneAction argument (control) to 2 insures that after the envelope reaches its endpoint, SuperCollider will release the memory it used for the instances of the SinOsc and the EnvGen.
109 section::Keyword arguments
111 Keywords make code easier to read and they allow arguments to be presented in any order. Here, the doneAction and the timeScale arguments are expressed in keyword style.
115 SynthDef("timeScale", { arg ts = 1;
118 SinOsc.ar(440, 0, 0.4)
123 timeScale: ts // scale the duration of an envelope
129 Synth("timeScale", [\ts, 0.1]); // timeScale controls the duration of the envelope
132 ////////////////////////////////////////////////////////////////////////////////////////////////////
135 // scale the duration of the envelope for every new synth
139 Synth("timeScale", [\ts, 0.01.rrand(0.3)]);
147 section::Additive Synthesis
149 Additive synthesis is as its name says. Components are added (mixed) together.
153 { // evaluate the function 12 times
159 [67.0.rrand(2000), 67.0.rrand(2000)],
166 EnvGen.kr(Env.perc(11, 6), doneAction: 2)
173 The promise of additive synthesis is that one can add sine waves to create any sound that can be imagined.
175 The problem of additive synthesis is that each and every sine wave and their envelopes have to be specified explicitly.
177 Create nuanced textures by scaling sine waves with envelopes and then mixing the result.
184 n, // generate n sine waves
186 SinOsc.ar( // each with a possible frequency between
187 [67.0.rrand(2000), 67.0.rrand(2000)], // low.rrand(high) ... floating point values
189 n.reciprocal // scale the amplitude of each sine wave
190 // according to the value of n
193 EnvGen.kr( // put an envelope on each of the sine waves
194 Env.sine(2.0.rrand(17)),
195 doneAction: 0 // deallocate envelopes only when the
196 // entire sound is complete (why?)
200 * // put an envelope over the whole patch
211 (Or use the link::Classes/Klang:: ugen to produce a similar effect).
213 section::Ring modulation
218 { SinOsc.ar(440, 0, 0.571) * SinOsc.kr(880) }.scope
220 // use an lfo to modulate the amplitude of the modulator
223 SinOsc.ar(440, 0, 0.571)
225 (SinOsc.kr(880) // wrap the modulator and the lfo in parenthese
227 SinOsc.kr([6.99, 8.01].reciprocal)
233 section::Amplitude modulation
235 Multiply two UGens and restrict the value of the modulator to positive values (use the .abs message to calculate 'absolute' value) to create what Charles Dodge calls "classic" amplitude modulation.
238 // use an lfo to modulate the amplitude of the modulator
241 SinOsc.ar(440, 0, 0.571)
243 (SinOsc.kr(880).abs // wrap the modulator and the lfo in parenthese
245 SinOsc.kr([6.99, 8.01].reciprocal)
251 ////////////////////////////////////////////////////////////////////////////////////////////////////
253 Compare "classic" amplitude modulation and ring modulation
257 { SinOsc.ar(440, 0, 0.571) * SinOsc.kr(880).abs }.scope
260 // ... what's the difference?
261 { SinOsc.ar(440, 0, 0.571) * SinOsc.kr(880) }.scope
264 ////////////////////////////////////////////////////////////////////////////////////////////////////
266 go to link::Tutorials/Mark_Polishook_tutorial/14_Subtractive_synthesis::