supernova: fixes for boost-1.49 and gcc-4.7
[supercollider.git] / Help / Collections / Signal.html
blobcd8e52a8e5b269fd843199ec862a654ba793a42f
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.48">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0021e7}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #9d1c12}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; min-height: 17.0px}
20 span.s1 {font: 18.0px Helvetica}
21 span.s2 {color: #000000}
22 span.s3 {color: #0026b4}
23 span.s4 {color: #002fe0}
24 span.s5 {color: #0021e7}
25 span.s6 {color: #606060}
26 span.s7 {color: #9d1c12}
27 span.Apple-tab-span {white-space:pre}
28 </style>
29 </head>
30 <body>
31 <p class="p1"><span class="s1"><b>Signal<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>sampled audio buffer</b></p>
32 <p class="p2"><br></p>
33 <p class="p3"><span class="s2"><b>Inherits from: </b><a href="../Core/Object.html"><b>Object</b></a><b> : </b><a href="Collection.html"><b>Collection</b></a></span><span class="s3"><b> :</b></span><span class="s2"><b> </b><a href="SequenceableCollection.html"><b>SequenceableCollection</b></a></span><span class="s3"><b> : </b><a href="ArrayedCollection.html"><span class="s4"><b>ArrayedCollection</b></span></a> : <a href="RawArray.html"><span class="s5"><b>RawArray</b></span></a></span><span class="s2"> : <a href="FloatArray.html"><span class="s3"><b>FloatArray</b></span></a></span></p>
34 <p class="p4"><br></p>
35 <p class="p1">A Signal is a FloatArray that represents a sampled function of time buffer.<span class="Apple-converted-space"> </span></p>
36 <p class="p1">Signals support math operations.</p>
37 <p class="p4"><br></p>
38 <p class="p1">See also: <a href="Wavetable.html"><span class="s3">Wavetable</span></a></p>
39 <p class="p4"><br></p>
40 <p class="p4"><br></p>
41 <p class="p5"><b><i>Creation</i></b></p>
42 <p class="p4"><br></p>
43 <p class="p1"><b>*sineFill(size, amplitudes, phases)</b></p>
44 <p class="p4"><br></p>
45 <p class="p1">Fill a Signal of the given size with a sum of sines at the given amplitudes and phases.</p>
46 <p class="p1">The Signal will be normalized.</p>
47 <p class="p1"><b>size</b> - the number of samples in the Signal.</p>
48 <p class="p1"><b>amplitudes</b> - an Array of amplitudes for each harmonic beginning with the fundamental.</p>
49 <p class="p1"><b>phases</b> - an Array of phases in radians for each harmonic beginning with the fundamental.</p>
50 <p class="p6"><br></p>
51 <p class="p7"><span class="s3">Signal</span>.sineFill(1000, 1.0/[1, 2, 3, 4, 5, 6]).plot;</p>
52 <p class="p8"><br></p>
53 <p class="p4"><br></p>
54 <p class="p1"><b>*chebyFill(size, amplitudes, phases)</b></p>
55 <p class="p4"><br></p>
56 <p class="p1">Fill a Signal of the given size with a sum of Chebyshev polynomials at the given amplitudes.</p>
57 <p class="p1">For eventual use in waveshaping by the Shaper ugen; see Shaper helpfile and Buffer:cheby too.</p>
58 <p class="p1"><b>size</b> - the number of samples in the Signal.</p>
59 <p class="p1"><b>amplitudes</b> - an Array of amplitudes for each Chebyshev polynomial beginning with order 1.</p>
60 <p class="p6"><br></p>
61 <p class="p7"><span class="s3">Signal</span>.chebyFill(1000, [1]).plot;</p>
62 <p class="p6"><br></p>
63 <p class="p7"><span class="s3">Signal</span>.chebyFill(1000, [0, 1]).plot;</p>
64 <p class="p6"><br></p>
65 <p class="p7"><span class="s3">Signal</span>.chebyFill(1000, [0, 0, 1]).plot;</p>
66 <p class="p6"><br></p>
67 <p class="p7"><span class="s3">Signal</span>.chebyFill(1000, [0.3, -0.8, 1.1]).plot;</p>
68 <p class="p6"><br></p>
69 <p class="p6"><br></p>
70 <p class="p1"><b>*hanningWindow(size, pad)</b></p>
71 <p class="p4"><br></p>
72 <p class="p1">Fill a Signal of the given size with a Hanning window.</p>
73 <p class="p1"><b>size</b> - the number of samples in the Signal.</p>
74 <p class="p1"><b>pad</b> - the number of samples of the size that is zero padding.</p>
75 <p class="p6"><br></p>
76 <p class="p7"><span class="s3">Signal</span>.hanningWindow(1024).plot;</p>
77 <p class="p6"><br></p>
78 <p class="p7"><span class="s3">Signal</span>.hanningWindow(1024, 512).plot;</p>
79 <p class="p6"><br></p>
80 <p class="p6"><br></p>
81 <p class="p1"><b>*hammingWindow(size)</b></p>
82 <p class="p4"><br></p>
83 <p class="p1">Fill a Signal of the given size with a Hamming window.</p>
84 <p class="p1"><b>size</b> - the number of samples in the Signal.</p>
85 <p class="p1"><b>pad</b> - the number of samples of the size that is zero padding.</p>
86 <p class="p6"><br></p>
87 <p class="p7"><span class="s3">Signal</span>.hammingWindow(1024).plot;</p>
88 <p class="p6"><br></p>
89 <p class="p7"><span class="s3">Signal</span>.hammingWindow(1024, 512).plot;</p>
90 <p class="p6"><br></p>
91 <p class="p6"><br></p>
92 <p class="p1"><b>*welchWindow(size)</b></p>
93 <p class="p4"><br></p>
94 <p class="p1">Fill a Signal of the given size with a Welch window.</p>
95 <p class="p1"><b>size</b> - the number of samples in the Signal.</p>
96 <p class="p1"><b>pad</b> - the number of samples of the size that is zero padding.</p>
97 <p class="p6"><br></p>
98 <p class="p7"><span class="s3">Signal</span>.welchWindow(1024).plot;</p>
99 <p class="p6"><br></p>
100 <p class="p7"><span class="s3">Signal</span>.welchWindow(1024, 512).plot;</p>
101 <p class="p6"><br></p>
102 <p class="p6"><br></p>
103 <p class="p1"><b>*rectWindow(size)</b></p>
104 <p class="p4"><br></p>
105 <p class="p1">Fill a Signal of the given size with a rectangular window.</p>
106 <p class="p1"><b>size</b> - the number of samples in the Signal.</p>
107 <p class="p1"><b>pad</b> - the number of samples of the size that is zero padding.</p>
108 <p class="p6"><br></p>
109 <p class="p7"><span class="s3">Signal</span>.rectWindow(1024).plot;</p>
110 <p class="p6"><br></p>
111 <p class="p7"><span class="s3">Signal</span>.rectWindow(1024, 512).plot;</p>
112 <p class="p6"><br></p>
113 <p class="p6"><br></p>
114 <p class="p6"><br></p>
115 <p class="p6"><br></p>
116 <p class="p6"><br></p>
117 <p class="p6"><br></p>
118 <p class="p5"><b><i>Instance Methods</i></b></p>
119 <p class="p4"><br></p>
120 <p class="p1"><b>plot(name, bounds)</b></p>
121 <p class="p4"><br></p>
122 <p class="p1">Plot the Signal in a window. The arguments are not required and if not given defaults will be used.</p>
123 <p class="p1"><b>name</b> - a String, the name of the window.</p>
124 <p class="p1"><b>bounds</b> - a Rect giving the bounds of the window.</p>
125 <p class="p6"><br></p>
126 <p class="p7"><span class="s3">Signal</span>.sineFill(512, [1]).plot;</p>
127 <p class="p6"><br></p>
128 <p class="p7"><span class="s3">Signal</span>.sineFill(512, [1]).plot(<span class="s6">"Signal 1"</span>, <span class="s3">Rect</span>(50, 50, 150, 450));</p>
129 <p class="p6"><br></p>
130 <p class="p6"><br></p>
131 <p class="p1"><b>play(loop, mul, numChannels, server)</b></p>
132 <p class="p4"><br></p>
133 <p class="p1">loads the signal into a buffer on the server and plays it.<span class="Apple-converted-space"> </span></p>
134 <p class="p1">returns the buffer so you can free it again.<span class="Apple-converted-space"> </span></p>
135 <p class="p1"><b>loop</b> - A Boolean whether to loop the entire signal or play it once. Default is to loop.</p>
136 <p class="p1"><b>mul</b> - volume at which to play it, 0.2 by default.</p>
137 <p class="p1"><b>numChannels</b> - if the signal is an interleaved multichannel file, number of channels, default is 1.</p>
138 <p class="p1"><b>server</b> - the server on which to load the signal into a buffer.<span class="Apple-converted-space"> </span></p>
139 <p class="p6"><br></p>
140 <p class="p7">b = <span class="s3">Signal</span>.sineFill(512, [1]).play(<span class="s3">true</span>, 0.2);</p>
141 <p class="p9"><span class="s2">b.free; <span class="Apple-tab-span"> </span></span>// free the buffer again.<span class="Apple-converted-space"> </span></p>
142 <p class="p6"><br></p>
143 <p class="p6"><br></p>
144 <p class="p1"><b>waveFill(function, start, end)</b></p>
145 <p class="p4"><br></p>
146 <p class="p1">Fill the Signal with a function evaluated over an interval.</p>
147 <p class="p1"><b>function</b> - a function that should calculate the value of a sample.</p>
148 <p class="p1">The function is called with two arguments.</p>
149 <p class="p1"><span class="Apple-tab-span"> </span><b>x</b> - the value along the interval.</p>
150 <p class="p1"><span class="Apple-tab-span"> </span><b>i</b> - the sample index.</p>
151 <p class="p1"><b>start</b> - the starting value of the interval</p>
152 <p class="p1"><b>end</b> - the ending value of the interval.</p>
153 <p class="p6"><span class="Apple-tab-span"> </span></p>
154 <p class="p7">(</p>
155 <p class="p7">s = <span class="s3">Signal</span>.newClear(512);</p>
156 <p class="p7">s.waveFill({ <span class="s3">arg</span> x, i; sin(x).max(0) }, 0, 3pi);</p>
157 <p class="p7">s.plot;</p>
158 <p class="p7">)</p>
159 <p class="p6"><br></p>
160 <p class="p1"><b>asWavetable</b></p>
161 <p class="p4"><br></p>
162 <p class="p1">Convert the Signal into a Wavetable.</p>
163 <p class="p6"><br></p>
164 <p class="p7"><span class="s3">Signal</span>.sineFill(512, [1]).asWavetable.plot;</p>
165 <p class="p6"><br></p>
166 <p class="p6"><br></p>
167 <p class="p1"><b>fill(val)</b></p>
168 <p class="p4"><br></p>
169 <p class="p1">Fill the Signal with a value.</p>
170 <p class="p6"><br></p>
171 <p class="p7"><span class="s3">Signal</span>.newClear(512).fill(0.2).plot;</p>
172 <p class="p6"><br></p>
173 <p class="p6"><br></p>
174 <p class="p1"><b>scale(scale)</b></p>
175 <p class="p4"><br></p>
176 <p class="p1">Scale the Signal by a factor <b>in place</b>.</p>
177 <p class="p6"><br></p>
178 <p class="p7">a = <span class="s3">Signal</span>[1, 2, 3, 4];</p>
179 <p class="p7">a.scale(0.5); a;</p>
180 <p class="p6"><br></p>
181 <p class="p6"><br></p>
182 <p class="p1"><b>offset(offset)</b></p>
183 <p class="p4"><br></p>
184 <p class="p1">Offset the Signal by a value <b>in place</b>.</p>
185 <p class="p6"><br></p>
186 <p class="p7">a = <span class="s3">Signal</span>[1, 2, 3, 4];</p>
187 <p class="p7">a.offset(0.5); a;</p>
188 <p class="p6"><br></p>
189 <p class="p6"><br></p>
190 <p class="p1"><b>peak</b></p>
191 <p class="p4"><br></p>
192 <p class="p1">Return the peak absolute value of a Signal.</p>
193 <p class="p6"><br></p>
194 <p class="p7"><span class="s3">Signal</span>[1, 2, -3, 2.5].peak;</p>
195 <p class="p6"><br></p>
196 <p class="p6"><br></p>
197 <p class="p1"><b>normalize</b></p>
198 <p class="p4"><br></p>
199 <p class="p1">Normalize the Signal <b>in place</b> such that the maximum absolute peak value is 1.</p>
200 <p class="p6"><br></p>
201 <p class="p7"><span class="s3">Signal</span>[1, 2, -4, 2.5].normalize;</p>
202 <p class="p7"><span class="s3">Signal</span>[1, 2, -4, 2.5].normalize(0, 1);<span class="Apple-tab-span"> </span><span class="s7">// normalize only a range</span></p>
203 <p class="p6"><br></p>
204 <p class="p6"><br></p>
205 <p class="p1"><b>normalizeTransfer</b></p>
206 <p class="p4"><br></p>
207 <p class="p1">Normalizes a transfer function so that the center value of the table is offset to zero</p>
208 <p class="p1">and the absolute peak value is 1. Transfer functions are meant to be used in the<span class="Apple-converted-space"> </span></p>
209 <p class="p1">Shaper ugen.</p>
210 <p class="p6"><br></p>
211 <p class="p7"><span class="s3">Signal</span>[1, 2, 3, 2.5, 1].normalizeTransfer;</p>
212 <p class="p6"><br></p>
213 <p class="p1"><b>invert</b></p>
214 <p class="p4"><br></p>
215 <p class="p1">Invert the Signal <b>in place</b>.</p>
216 <p class="p6"><br></p>
217 <p class="p7">a = <span class="s3">Signal</span>[1, 2, 3, 4];</p>
218 <p class="p7">a.invert(0.5); a;</p>
219 <p class="p6"><br></p>
220 <p class="p6"><br></p>
221 <p class="p1"><b>reverse(beginSamp, endSamp)</b></p>
222 <p class="p4"><br></p>
223 <p class="p1">Reverse a subrange of the Signal <b>in place</b>.</p>
224 <p class="p6"><br></p>
225 <p class="p7">a = <span class="s3">Signal</span>[1, 2, 3, 4];</p>
226 <p class="p7">a.reverse(1, 2); a;</p>
227 <p class="p6"><br></p>
228 <p class="p6"><br></p>
229 <p class="p1"><b>fade(beginSamp, endSamp, beginLevel, endLevel)</b></p>
230 <p class="p4"><br></p>
231 <p class="p1">Fade a subrange of the Signal <b>in place</b>.</p>
232 <p class="p6"><br></p>
233 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 1);</p>
234 <p class="p7">a.fade(0, 3);<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s7">// fade in</span></p>
235 <p class="p7">a.fade(6, 9, 1, 0);<span class="Apple-tab-span"> </span><span class="s7">// fade out</span></p>
236 <p class="p6"><br></p>
237 <p class="p6"><br></p>
238 <p class="p1"><b>integral</b></p>
239 <p class="p4"><br></p>
240 <p class="p1">Return the integral of a signal.</p>
241 <p class="p6"><br></p>
242 <p class="p7"><span class="s3">Signal</span>[1, 2, 3, 4].integral;</p>
243 <p class="p6"><br></p>
244 <p class="p6"><br></p>
245 <p class="p1"><b>overDub(aSignal, index)</b></p>
246 <p class="p4"><br></p>
247 <p class="p1">Add a signal to myself starting at the index.</p>
248 <p class="p1">If the other signal is too long only the first part is overdubbed.</p>
249 <p class="p6"><br></p>
250 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
251 <p class="p7">a.overDub(<span class="s3">Signal</span>[1, 2, 3, 4], 3);</p>
252 <p class="p6"><span class="Apple-tab-span"> </span></p>
253 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// run out of range</p>
254 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
255 <p class="p7">a.overDub(<span class="s3">Signal</span>[1, 2, 3, 4], 8);<span class="Apple-tab-span"> </span></p>
256 <p class="p6"><br></p>
257 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
258 <p class="p7">a.overDub(<span class="s3">Signal</span>[1, 2, 3, 4], -4);<span class="Apple-tab-span"> </span></p>
259 <p class="p6"><br></p>
260 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
261 <p class="p7">a.overDub(<span class="s3">Signal</span>[1, 2, 3, 4], -1);<span class="Apple-tab-span"> </span></p>
262 <p class="p6"><br></p>
263 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
264 <p class="p7">a.overDub(<span class="s3">Signal</span>[1, 2, 3, 4], -2);<span class="Apple-tab-span"> </span></p>
265 <p class="p6"><br></p>
266 <p class="p7">a = <span class="s3">Signal</span>.fill(4, 100);</p>
267 <p class="p7">a.overDub(<span class="s3">Signal</span>[1, 2, 3, 4, 5, 6, 7, 8], -2);<span class="Apple-tab-span"> </span></p>
268 <p class="p6"><br></p>
269 <p class="p6"><br></p>
270 <p class="p1"><b>overWrite(aSignal, index)</b></p>
271 <p class="p4"><br></p>
272 <p class="p1">Write a signal to myself starting at the index.</p>
273 <p class="p1">If the other signal is too long only the first part is overdubbed.</p>
274 <p class="p6"><br></p>
275 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
276 <p class="p7">a.overWrite(<span class="s3">Signal</span>[1, 2, 3, 4], 3);</p>
277 <p class="p6"><span class="Apple-tab-span"> </span></p>
278 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// run out of range</p>
279 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
280 <p class="p7">a.overWrite(<span class="s3">Signal</span>[1, 2, 3, 4], 8);<span class="Apple-tab-span"> </span></p>
281 <p class="p6"><br></p>
282 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
283 <p class="p7">a.overWrite(<span class="s3">Signal</span>[1, 2, 3, 4], -4);<span class="Apple-tab-span"> </span></p>
284 <p class="p6"><br></p>
285 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
286 <p class="p7">a.overWrite(<span class="s3">Signal</span>[1, 2, 3, 4], -1);<span class="Apple-tab-span"> </span></p>
287 <p class="p6"><br></p>
288 <p class="p7">a = <span class="s3">Signal</span>.fill(10, 100);</p>
289 <p class="p7">a.overWrite(<span class="s3">Signal</span>[1, 2, 3, 4], -2);<span class="Apple-tab-span"> </span></p>
290 <p class="p6"><br></p>
291 <p class="p7">a = <span class="s3">Signal</span>.fill(4, 100);</p>
292 <p class="p7">a.overWrite(<span class="s3">Signal</span>[1, 2, 3, 4, 5, 6, 7, 8], -2);<span class="Apple-tab-span"> </span></p>
293 <p class="p6"><br></p>
294 <p class="p6"><br></p>
295 <p class="p1"><b>blend(aSignal, blend)</b></p>
296 <p class="p4"><br></p>
297 <p class="p1">Blend two signals by some proportion.</p>
298 <p class="p6"><br></p>
299 <p class="p7"><span class="s3">Signal</span>[1, 2, 3, 4].blend(<span class="s3">Signal</span>[5, 5, 5, 0], 0);</p>
300 <p class="p7"><span class="s3">Signal</span>[1, 2, 3, 4].blend(<span class="s3">Signal</span>[5, 5, 5, 0], 0.2);</p>
301 <p class="p7"><span class="s3">Signal</span>[1, 2, 3, 4].blend(<span class="s3">Signal</span>[5, 5, 5, 0], 0.4);</p>
302 <p class="p7"><span class="s3">Signal</span>[1, 2, 3, 4].blend(<span class="s3">Signal</span>[5, 5, 5, 0], 1);</p>
303 <p class="p7"><span class="s3">Signal</span>[1, 2, 3, 4].blend(<span class="s3">Signal</span>[5, 5, 5, 0], 2);</p>
304 <p class="p6"><br></p>
305 <p class="p6"><br></p>
306 <p class="p6"><br></p>
307 <p class="p6"><br></p>
308 <p class="p5"><b><i>Fourier Transform:</i></b></p>
309 <p class="p10"><br></p>
310 <p class="p10"><br></p>
311 <p class="p1"><b>*fftCosTable(size)</b></p>
312 <p class="p4"><br></p>
313 <p class="p1">Fill a Signal with the cosine table needed by the FFT methods.</p>
314 <p class="p4"><br></p>
315 <p class="p7"><span class="s3">Signal</span>.fftCosTable(512).plot;</p>
316 <p class="p4"><br></p>
317 <p class="p4"><br></p>
318 <p class="p1"><b>fft(imag, cosTable)</b></p>
319 <p class="p4"><br></p>
320 <p class="p1">Perform an FFT on a real and imaginary signal <b>in place</b>.</p>
321 <p class="p4"><br></p>
322 <p class="p7">(</p>
323 <p class="p7"><span class="s3">var</span> size = 512, real, imag, cosTable, complex;<span class="Apple-converted-space"> </span></p>
324 <p class="p6"><br></p>
325 <p class="p7">real = <span class="s3">Signal</span>.newClear(size);<span class="Apple-converted-space"> </span></p>
326 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// some harmonics</p>
327 <p class="p7">real.sineFill2([[8], [13, 0.5], [21, 0.25], [55, 0.125, 0.5pi]]);</p>
328 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// add a little noise</p>
329 <p class="p7">real.overDub(<span class="s3">Signal</span>.fill(size, { 0.2.bilinrand }));</p>
330 <p class="p6"><br></p>
331 <p class="p7">imag = <span class="s3">Signal</span>.newClear(size);</p>
332 <p class="p7">cosTable = <span class="s3">Signal</span>.fftCosTable(size);</p>
333 <p class="p6"><br></p>
334 <p class="p7">complex = fft(real, imag, cosTable);<span class="Apple-converted-space"> </span></p>
335 <p class="p7">[real, imag, (complex.magnitude) / 100 ].flop.flat</p>
336 <p class="p7"><span class="Apple-tab-span"> </span>.plot(<span class="s6">"fft"</span>, <span class="s3">Rect</span>(0, 0, 512 + 8, 500), numChannels: 3);</p>
337 <p class="p7">)</p>
338 <p class="p8"><br></p>
339 <p class="p8"><br></p>
340 <p class="p1"><b>ifft(imag, cosTable)</b></p>
341 <p class="p4"><br></p>
342 <p class="p1">Perform an inverse FFT on a real and imaginary signal <b>in place</b>.</p>
343 <p class="p4"><br></p>
344 <p class="p7">(</p>
345 <p class="p7"><span class="s3">var</span> size = 512, real, imag, cosTable, complex, ifft;<span class="Apple-converted-space"> </span></p>
346 <p class="p6"><br></p>
347 <p class="p7">real = <span class="s3">Signal</span>.newClear(size);<span class="Apple-converted-space"> </span></p>
348 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// some harmonics</p>
349 <p class="p7">real.sineFill2([[8], [13, 0.5], [21, 0.25], [55, 0.125, 0.5pi]]);</p>
350 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// add a little noise</p>
351 <p class="p7">real.overDub(<span class="s3">Signal</span>.fill(size, { 0.2.bilinrand }));</p>
352 <p class="p6"><br></p>
353 <p class="p7">imag = <span class="s3">Signal</span>.newClear(size);</p>
354 <p class="p7">cosTable = <span class="s3">Signal</span>.fftCosTable(size);</p>
355 <p class="p6"><br></p>
356 <p class="p7">complex = fft(real, imag, cosTable).postln;</p>
357 <p class="p7">ifft = complex.real.ifft(complex.imag, cosTable);</p>
358 <p class="p6"><br></p>
359 <p class="p7">[real, ifft.real].flop.flat.plot(<span class="s6">"fft and back"</span>, <span class="s3">Rect</span>(0, 0, 512 + 8, 500), numChannels: 2);</p>
360 <p class="p7">)</p>
361 <p class="p6"><br></p>
362 <p class="p6"><br></p>
363 <p class="p4"><br></p>
364 <p class="p4"><br></p>
365 <p class="p5"><b><i>Unary Messages:</i></b></p>
366 <p class="p4"><br></p>
367 <p class="p1">Signal will respond to unary operators by returning a new Signal.</p>
368 <p class="p4"><br></p>
369 <p class="p1"><b>neg, abs, sign, squared, cubed, sqrt</b></p>
370 <p class="p1"><b>exp, log, log2, log10, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh,<span class="Apple-converted-space"> </span></b></p>
371 <p class="p1"><b>distort, softclip, nyqring, isPositive, isNegative,<span class="Apple-converted-space"> </span></b></p>
372 <p class="p1"><b>isStrictlyPositive</b></p>
373 <p class="p4"><br></p>
374 <p class="p7">x = <span class="s3">Signal</span>.sineFill(512, [0, 0, 0, 1]);</p>
375 <p class="p7">[x, x.neg, x.abs, x.sign, x.squared, x.cubed,<span class="Apple-converted-space"> </span></p>
376 <p class="p7">x.asin.normalize, x.exp.normalize, x.distort].flop.flat.plot(numChannels: 9);</p>
377 <p class="p8"><br></p>
378 <p class="p8"><br></p>
379 <p class="p8"><br></p>
380 <p class="p4"><br></p>
381 <p class="p5"><b><i>Binary Messages:</i></b></p>
382 <p class="p10"><br></p>
383 <p class="p1">Signal will respond to binary operators by returning a new Signal.</p>
384 <p class="p4"><br></p>
385 <p class="p1"><b>+, -, *, /, div, %, **, min, max, ring1, ring2, ring3, ring4,<span class="Apple-converted-space"> </span></b></p>
386 <p class="p1"><b>difsqr, sumsqr, sqrdif, absdif, amclip,<span class="Apple-converted-space"> </span></b></p>
387 <p class="p1"><b>scaleneg, clip2, excess, &lt;!</b></p>
388 <p class="p4"><br></p>
389 <p class="p7">(</p>
390 <p class="p7">x = Signal.fill(512, { rrand(0.0, 1.0) });</p>
391 <p class="p7">y = Signal.fill(512, { |i| (i * pi / 64).sin });</p>
392 <p class="p7">[x, y, (x + y) * 0.5, x * y, min(x, y), max(x, y) ].flop.flat.plot(numChannels: 6);</p>
393 <p class="p7">)<span class="Apple-converted-space"> </span></p>
394 </body>
395 </html>