File: 13_BinaryOp_synthesis.schelp

package info (click to toggle)
supercollider 1%3A3.10.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,496 kB
  • sloc: cpp: 283,513; lisp: 74,040; ansic: 72,252; sh: 23,016; python: 7,175; makefile: 1,087; perl: 766; java: 677; yacc: 314; lex: 175; ruby: 136; objc: 65; xml: 15
file content (266 lines) | stat: -rw-r--r-- 5,938 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
title:: 13_BinaryOp_synthesis
summary:: Mark Polishook tutorial
categories:: Tutorials>Mark_Polishook_tutorial
related:: Tutorials/Mark_Polishook_tutorial/00_Introductory_tutorial

section::Binary messages

The pattern for a binary message is

table::
## RECEIVER || OPERATOR || OPERAND
::

For example

code::
2 * 3
::

is a receiver (the object to which a message is sent), a binary operator, and an operand.

section::Mixing = addition

Use addition (a binary operation) to mix two or more ugens.

code::
(
	// mix 2 sawtooth waves
	{
		Saw.ar(500, 0.05)	// receiver
		+			// operator
		Saw.ar(600, 0.06)	// operand
	}.scope;
)


(
// mix 3 unit generators.
	{
		Saw.ar(500, 0.05)	// receiver
		+			// operator
		Saw.ar(600, 0.06)	// operand
						// when evaluated produce
						// a BinaryOpUGen
						// this BinaryOpUGen is then a receiver for an
		+				// addition operator followed by
		Saw.ar(700, 0.07)		// an operand
	}.scope;
)
::

////////////////////////////////////////////////////////////////////////////////////////////////////

Rewrite the previous example with the Mix ugen.

code::
(
{
	Mix.ar(
		// the ugens that will be mixed go into an array
		[
			Saw.ar(500, 0.05),
			Saw.ar(600, 0.06),
			Saw.ar(700, 0.06)
		]
	)
}.scope
)
::

Or use Mix.arFill to create the same result.

code::
{ Mix.arFill(3, { arg i; Saw.ar(500 + (i * 100), 0.05) }) }.scope;
::

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.

section::Scaling = multiplication

Apply an envelope, in the form of a low-frequency sine wave, to a WhiteNoise generator.

code::
{ WhiteNoise.ar(0.1) * SinOsc.kr(1, 1) }.scope;

(
	// scaling and mixing
	// ... imitates a train?
	{
		(WhiteNoise.ar(0.1) * SinOsc.kr(1, 1))
		+
		(BrownNoise.ar(0.1) * SinOsc.kr(2, 1))

	}.scope;
)
::

section::Envelopes

Dynamically modulate any parameter in a ugen (such as frequency, phase, or amplitude) with an envelope.

code::
// modulate amplitude
{ SinOsc.ar(440, 0, 0.1) * EnvGen.kr(Env.sine(1), doneAction: Done.freeSelf) }.scope;
::

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.

section::Keyword arguments

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.

code::
(
SynthDef("timeScale", { arg ts = 1;
	Out.ar(
		0,
		SinOsc.ar(440, 0, 0.4)
		*
		EnvGen.kr(
			Env.sine(1),
			doneAction: Done.freeSelf,
			timeScale: ts	// scale the duration of an envelope
		)
	)
}).add;
)

Synth("timeScale", [\ts, 0.1]); // timeScale controls the duration of the envelope
::

////////////////////////////////////////////////////////////////////////////////////////////////////

code::
// scale the duration of the envelope for every new synth
(
r = Routine({
	loop({
		Synth("timeScale", [\ts, 0.01.rrand(0.3)]);
		0.5.wait;
	})
});
)
r.play
::

section::Additive Synthesis

Additive synthesis is as its name says. Components are added (mixed) together.

code::
(
{	// evaluate the function 12 times
	var n = 12;
	Mix.arFill(
		n,
		{
			SinOsc.ar(
				[67.0.rrand(2000), 67.0.rrand(2000)],
				0,
				n.reciprocal * 0.75
			)
		}
	)
	*
	EnvGen.kr(Env.perc(11, 6), doneAction: Done.freeSelf)
}.scope
)
::

section::Envelopes

The promise of additive synthesis is that one can add sine waves to create any sound that can be imagined.

The problem of additive synthesis is that each and every sine wave and their envelopes have to be specified explicitly.

Create nuanced textures by scaling sine waves with envelopes and then mixing the result.

code::
(
{	var n = 12;

	Mix.arFill(
			n,						// generate n sine waves
			{
			SinOsc.ar(					// each with a possible frequency between
				[67.0.rrand(2000), 67.0.rrand(2000)],	// low.rrand(high) ... floating point values
				0,
				n.reciprocal				// scale the amplitude of each sine wave
									// according to the value of n
			)
			*
			EnvGen.kr(					// put an envelope on each of the sine waves
				Env.sine(2.0.rrand(17)),
				doneAction: Done.none 				// deallocate envelopes only when the
									// entire sound is complete (why?)
			)
		}
	)
	*								// put an envelope over the whole patch
	EnvGen.kr(
		Env.perc(11, 6),
		doneAction: Done.freeSelf,
		levelScale: 0.75
	)

}.scope
)
::

(Or use the link::Classes/Klang:: ugen to produce a similar effect).

section::Ring modulation

Multiply two UGens.

code::
{ SinOsc.ar(440, 0, 0.571) * SinOsc.kr(880) }.scope

// use an lfo to modulate the amplitude of the modulator
(
	{
		SinOsc.ar(440, 0, 0.571)
		*
		(SinOsc.kr(880)				// wrap the modulator and the lfo in parenthese
		* 					// why ... ?
		SinOsc.kr([6.99, 8.01].reciprocal)
		)
	}.scope
)
::

section::Amplitude modulation

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.

code::
// use an lfo to modulate the amplitude of the modulator
(
	{
		SinOsc.ar(440, 0, 0.571)
		*
		(SinOsc.kr(880).abs			// wrap the modulator and the lfo in parenthese
		* 					// why ... ?
		SinOsc.kr([6.99, 8.01].reciprocal)
		)
	}.scope
)
::

////////////////////////////////////////////////////////////////////////////////////////////////////

Compare "classic" amplitude modulation and ring modulation

code::
// "classic"
{ SinOsc.ar(440, 0, 0.571) * SinOsc.kr(880).abs }.scope

// "ring"
// ... what's the difference?
{ SinOsc.ar(440, 0, 0.571) * SinOsc.kr(880) }.scope
::

////////////////////////////////////////////////////////////////////////////////////////////////////

go to link::Tutorials/Mark_Polishook_tutorial/14_Subtractive_synthesis::