-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path03-make-a-sound.html
147 lines (127 loc) · 9.94 KB
/
03-make-a-sound.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- 2025-02-07 Fri 19:32 -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Make a Sound</title>
<meta name="author" content="modula t. worm" />
<meta name="generator" content="Org Mode" />
<link type='text/css' rel='stylesheet' href='css.css' />
</head>
<body>
<div id="preamble" class="status">
<nav>
<ol class="bar">
<li value="0"><a href="index.html">Contents</a></li>
<li><a href="01-introduction.html">Introduction</a></li>
<li><a href="02-getting-started.html">Getting Started</a></li>
<li><a href="03-make-a-sound.html">Make a Sound</a></li>
<li><a href="04-further-soundmaking.html">Further Soundmaking</a></li>
<li><a href="05-sampling.html">Sampling</a></li>
<li><a href="06-sequencing.html">Sequencing</a></li>
<li><a href="07-effects.html">Effects</a></li>
<li><a href="08-architecture.html">Architecture</a></li>
<li><a href="09-other-libraries.html">Other Libraries</a></li>
</ol>
</nav>
</div>
<div id="content" class="content">
<header>
<h1 class="title">Make a Sound</h1>
</header><div id="outline-container-orgbbeb400" class="outline-2">
<h2 id="orgbbeb400">First Sound</h2>
<div class="outline-text-2" id="text-orgbbeb400">
<p>
Once your Lisp and cl-collider environment is set up and loaded and the server booted, you can create sound! Here is the fastest way to make a sound with cl-collider:
</p>
<div class="org-src-container">
<pre class="src src-lisp"><span class="org-rainbow-delimiters-depth-1">(</span>proxy<span class="org-whitespace-space"> </span><span class="org-builtin">:foo</span><span class="org-whitespace-space"> </span><span class="org-rainbow-delimiters-depth-2">(</span>sin-osc.ar<span class="org-whitespace-space"> </span>440<span class="org-whitespace-space"> </span>0<span class="org-whitespace-space"> </span>0.2<span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<p>
When you evaluate this line, you should hear a sine wave from your left speaker.
</p>
<p>
The <code>proxy</code> function basically starts a synthesis process on the server for you. In order to refer back to the synth process, we give it a name: <code>:foo</code>. The next argument is the "body" of the proxy. This defines the sound that the proxy generates.
</p>
<p>
In order to define a sound we use unit generators, or "UGens" for short. A unit generator is the most basic building block of sound available to us in cl-collider. Each UGen is specialized to generate or affect sound in a particular way. In this case, <code>sin-osc.ar</code> means a sine wave oscillator (<code>sin-osc</code>) at audio rate (<code>.ar</code>). The arguments to the sin-osc are, in order: frequency (in cycles per second), phase, and an amount to multiply the sin-osc's output by (commonly referred to as "mul"). In this case, we provide <code>0.2</code> to reduce the volume of the sin-osc from its default of <code>1</code>. In addition, <code>sin-osc.ar</code> accepts another argument after mul, which is "add"–a number to add to the sin-osc's output. It defaults to <code>0</code>.
</p>
</div>
</div>
<div id="outline-container-org441d2c7" class="outline-2">
<h2 id="org441d2c7">Change the Sound</h2>
<div class="outline-text-2" id="text-org441d2c7">
<p>
If we want to change the sound being generated, we can simply edit the body of the <code>proxy</code>. For example, if we want to lower the frequency of the sin-osc, we can change the proxy to the following:
</p>
<div class="org-src-container">
<pre class="src src-lisp"><span class="org-rainbow-delimiters-depth-1">(</span>proxy<span class="org-whitespace-space"> </span><span class="org-builtin">:foo</span><span class="org-whitespace-space"> </span><span class="org-rainbow-delimiters-depth-2">(</span>sin-osc.ar<span class="org-whitespace-space"> </span>300<span class="org-whitespace-space"> </span>0<span class="org-whitespace-space"> </span>0.2<span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<p>
Evaluating the new snippet should result in the sound output being replaced with another sine wave of a lower pitch.
</p>
<p>
If you want to stop the sound, use <code>nil</code> for the body parameter:
</p>
<div class="org-src-container">
<pre class="src src-lisp"><span class="org-rainbow-delimiters-depth-1">(</span>proxy<span class="org-whitespace-space"> </span><span class="org-builtin">:foo</span><span class="org-whitespace-space"> </span>nil<span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<p>
To restart the sound, just add the body back into the proxy and re-evaluate.
</p>
<p>
Aside from <code>sin-osc</code>, SuperCollider provides many other kinds of unit generators. For example, here's a saw wave:
</p>
<div class="org-src-container">
<pre class="src src-lisp"><span class="org-rainbow-delimiters-depth-1">(</span>proxy<span class="org-whitespace-space"> </span><span class="org-builtin">:foo</span><span class="org-whitespace-space"> </span><span class="org-rainbow-delimiters-depth-2">(</span>saw.ar<span class="org-whitespace-space"> </span>300<span class="org-whitespace-space"> </span>0.2<span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<p>
The <code>saw</code> UGen doesn't have a phase argument, so this time we only have to provide two: <code>300</code> for the frequency, and <code>0.2</code> for mul.
</p>
</div>
</div>
<div id="outline-container-orga156bbb" class="outline-2">
<h2 id="orga156bbb">UGens Controlling UGens</h2>
<div class="outline-text-2" id="text-orga156bbb">
<p>
It's also possible to control the parameters of one UGen with another:
</p>
<div class="org-src-container">
<pre class="src src-lisp"><span class="org-rainbow-delimiters-depth-1">(</span>proxy<span class="org-whitespace-space"> </span><span class="org-builtin">:foo</span><span class="org-whitespace-space"> </span><span class="org-rainbow-delimiters-depth-2">(</span>saw.ar<span class="org-whitespace-space"> </span><span class="org-rainbow-delimiters-depth-3">(</span>sin-osc.kr<span class="org-whitespace-space"> </span>0.5<span class="org-whitespace-space"> </span>0<span class="org-whitespace-space"> </span>150<span class="org-whitespace-space"> </span>300<span class="org-rainbow-delimiters-depth-3">)</span><span class="org-whitespace-space"> </span>0.2<span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<p>
In this case, instead of providing a number for the saw's frequency, we supply a <code>sin-osc</code>. The <code>sin-osc</code> is set to have a frequency of <code>0.5</code>. The mul is set to 150, which multiplies the sine wave's output by 150. Then, since the add argument is 300, 300 is added. Since the default range of <code>sin-osc</code> is from <code>-1</code> to <code>1</code>, multiplying it by 150 changes its range to <code>-150</code> to <code>150</code>. Then adding 300 produces the final range of <code>150</code> to <code>450</code>; thus the <code>saw</code>'s frequency is being modulated from 150 to 450.
</p>
<p>
If we want to actually start having fun, we can give ourselves more immediate control over the UGen by using the <code>mouse-y</code> UGen for one of its parameters:
</p>
<div class="org-src-container">
<pre class="src src-lisp"><span class="org-rainbow-delimiters-depth-1">(</span>proxy<span class="org-whitespace-space"> </span><span class="org-builtin">:foo</span><span class="org-whitespace-space"> </span><span class="org-rainbow-delimiters-depth-2">(</span>saw.ar<span class="org-whitespace-space"> </span><span class="org-rainbow-delimiters-depth-3">(</span>mouse-y.kr<span class="org-whitespace-space"> </span>20<span class="org-whitespace-space"> </span>10000<span class="org-whitespace-space"> </span><span class="org-builtin">:exponential</span><span class="org-rainbow-delimiters-depth-3">)</span><span class="org-whitespace-space"> </span>0.2<span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<p>
After evaluating this code, try moving your mouse up and down. You should hear that the pitch of the saw wave increases as you go up, and decreases as you go down. The parameters of <code>mouse-y</code> are the bottom of the range (<code>20</code>), the top of the range (<code>10000</code>), and the "warp" (<code>:exponential</code>). The first two should be self-explanatory: when the mouse is at the bottom of the screen, the <code>mouse-y</code> UGen outputs 20. When the mouse is at the top, <code>mouse-y</code> outputs 10000. The warp parameter specifies the slope of the range from the bottom to the top. Here we use <code>:exponential</code> because the human brain perceives pitch exponentially. If you want, you can change the warp to <code>:linear</code> instead, which is the default.
</p>
<p>
By now you may have noticed that some of the UGens we've been using have had <code>.kr</code> instead of <code>.ar</code>. As mentioned before, <code>ar</code> specifies to run the UGen at audio rate. <code>kr</code>, on the other hand, is for control rate, which means that the server processes that UGen less often, and thus uses less CPU power on them. Generally you would want to use <code>.kr</code> when the signal that the UGen is processing or generating isn't going to be heard directly, and doesn't exceed frequencies around 30Hz.
</p>
<p>
Note that not all UGens are available in both control- and audio-rate versions. <code>mouse-x</code> and <code>mouse-y</code>, for example, only provide control rate output. So <code>mouse-x.ar</code> is invalid and would give you an error.
</p>
<p>
<a href="02-getting-started.html">Previous: Getting Started</a> / <a href="04-further-soundmaking.html">Next: Further Soundmaking</a>
</p>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="date">Created: 2017-06-13 Tue 02:48. Updated: 2025-02-07 Fri 19:32.</p>
</div>
</body>
</html>