cmake build system: visiblity support for clang
[supercollider.git] / Help / UGens / FFT / Convolution2L.html
bloba3368995a96fab538629aecbd3820fda56143fdb
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="1038.29">
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: 9.0px Monaco; min-height: 12.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0000ee}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #ad140d}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
19 span.s1 {font: 18.0px Helvetica}
20 span.s2 {text-decoration: underline}
21 span.s3 {color: #000000}
22 span.s4 {text-decoration: underline ; color: #0044d4}
23 span.s5 {color: #001bb9}
24 span.s6 {color: #007300}
25 span.s7 {color: #2c7014}
26 span.s8 {color: #0000bf}
27 span.Apple-tab-span {white-space:pre}
28 </style>
29 </head>
30 <body>
31 <p class="p1"><span class="s1"><b>Convolution2L<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>real-time convolver with linear interpolation</b></p>
32 <p class="p2"><br></p>
33 <p class="p1"><b>Convolution2L.ar(in, kernel, trigger, framesize, crossfade, mul, add)</b></p>
34 <p class="p2"><br></p>
35 <p class="p1">Strict convolution with fixed kernel which can be updated using a trigger signal. There is a linear crossfade between the buffers upon change.</p>
36 <p class="p3"><br></p>
37 <p class="p1">See Steven W Smith, The Scientist and Engineer's Guide to Digital Signal Processing:<span class="Apple-converted-space"> </span></p>
38 <p class="p1">chapter 18: <span class="s2">http:// www.dspguide.com/ch18.htm</span><span class="Apple-converted-space"> </span></p>
39 <p class="p3"><br></p>
40 <p class="p1"><b>in</b> - processing target</p>
41 <p class="p1"><b>kernel</b>- buffer index for the fixed kernel, may be modulated in combination with the trigger</p>
42 <p class="p1"><b>trigger</b> - update the kernel on a change from &lt;=0 to &gt;0</p>
43 <p class="p1"><b>framesize </b>- size of FFT frame, must be a power of two. Convolution uses twice this number internally, maximum value you can give this argument is 2^16=65536. Note that it gets progressively more expensive to run for higher powers! 512, 1024, 2048, 4096 standard.</p>
44 <p class="p1"><b>crossfade</b> - The number of periods over which a crossfade is made. The default is 1. This must be an integer.</p>
45 <p class="p3"><br></p>
46 <p class="p4"><span class="s3">See also <a href="Convolution2.html"><span class="s4">Convolution2</span></a> and <a href="StereoConvolution2L.html"><span class="s2">StereoConvolution2L</span></a>.</span></p>
47 <p class="p2"><br></p>
48 <p class="p5">s = <span class="s5">Server</span>.local.boot;</p>
49 <p class="p2"><br></p>
50 <p class="p6"><span class="s3">(</span>// allocate three buffers</p>
51 <p class="p5">b = <span class="s5">Buffer</span>.alloc(s, 2048);</p>
52 <p class="p5">c = <span class="s5">Buffer</span>.alloc(s, 2048);</p>
53 <p class="p5">d = <span class="s5">Buffer</span>.alloc(s, 2048);</p>
54 <p class="p2"><br></p>
55 <p class="p5">b.zero;</p>
56 <p class="p5">c.zero;</p>
57 <p class="p5">d.zero;</p>
58 <p class="p5">)</p>
59 <p class="p2"><br></p>
60 <p class="p5">(</p>
61 <p class="p5">50.do({ <span class="s5">|it|</span> c.set(20*it+10, 1.0.rand); });</p>
62 <p class="p5">3.do({ <span class="s5">|it|</span> b.set(400*it+100, 1); });</p>
63 <p class="p5">20.do({ <span class="s5">|it|</span> d.set(40*it+20, 1); });</p>
64 <p class="p5">)</p>
65 <p class="p2"><br></p>
66 <p class="p2"><br></p>
67 <p class="p5">(</p>
68 <p class="p5"><span class="s5">SynthDef</span>(<span class="s6">\conv_test</span>, { <span class="s5">arg</span> kernel, t_trig=0;</p>
69 <p class="p5"><span class="Apple-tab-span"> </span><span class="s5">var</span> input;</p>
70 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
71 <p class="p5"><span class="Apple-tab-span"> </span>input=<span class="s5">Impulse</span>.ar(1);</p>
72 <p class="p2"><br></p>
73 <p class="p6"><span class="s3"><span class="Apple-tab-span"> </span></span>// must have power of two framesize</p>
74 <p class="p5"><span class="Apple-tab-span"> </span><span class="s5">Out</span>.ar(0, <span class="s5">Convolution2L</span>.ar(input, kernel, t_trig, 2048, 1, 0.5));</p>
75 <p class="p5">}).add</p>
76 <p class="p2"><br></p>
77 <p class="p5">)</p>
78 <p class="p2"><br></p>
79 <p class="p2"><br></p>
80 <p class="p5">x = <span class="s5">Synth</span>(<span class="s6">\conv_test</span>, [<span class="s7">\kernel</span>, b]);</p>
81 <p class="p2"><br></p>
82 <p class="p6">// changing the buffer number:</p>
83 <p class="p5">x.set(<span class="s7">\kernel</span>, c);</p>
84 <p class="p6"><span class="s3">x.set(</span><span class="s7">\t_trig</span><span class="s3">, 1); </span>// after this trigger, the change will take effect.</p>
85 <p class="p5">x.set(<span class="s7">\kernel</span>, d);</p>
86 <p class="p6"><span class="s3">x.set(</span><span class="s7">\t_trig</span><span class="s3">, 1); </span>// after this trigger, the change will take effect.</p>
87 <p class="p2"><br></p>
88 <p class="p5">d.zero;</p>
89 <p class="p6"><span class="s3">40.do({ </span><span class="s5">|it|</span><span class="s3"> d.set(20*it+10, 1); });</span>// changing the buffers' contents</p>
90 <p class="p6"><span class="s3">x.set(</span><span class="s7">\t_trig</span><span class="s3">, 1); </span>// after this trigger, the change will take effect.</p>
91 <p class="p2"><br></p>
92 <p class="p5">x.set(<span class="s7">\kernel</span>, b);</p>
93 <p class="p6"><span class="s3">x.set(</span><span class="s7">\t_trig</span><span class="s3">, 1); </span>// after this trigger, the change will take effect.</p>
94 <p class="p2"><br></p>
95 <p class="p5">x.free;</p>
96 <p class="p2"><br></p>
97 <p class="p6">// longer crossfade</p>
98 <p class="p5">(</p>
99 <p class="p5"><span class="s8">SynthDef</span>( <span class="s6">\conv_test2</span>, { <span class="s8">arg</span> kernel, t_trig=0;</p>
100 <p class="p5"><span class="Apple-tab-span"> </span><span class="s8">var</span> input;</p>
101 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
102 <p class="p5"><span class="Apple-tab-span"> </span>input=<span class="s8">Impulse</span>.ar(1);</p>
103 <p class="p2"><br></p>
104 <p class="p7"><span class="s3"><span class="Apple-tab-span"> </span></span>// must have power of two framesize</p>
105 <p class="p5"><span class="Apple-tab-span"> </span><span class="s8">Out</span>.ar(0, <span class="s8">Convolution2L</span>.ar(input, kernel, t_trig, 2048, 5, 0.5));</p>
106 <p class="p5">}).add</p>
107 <p class="p2"><br></p>
108 <p class="p5">)</p>
109 <p class="p2"><br></p>
110 <p class="p2"><br></p>
111 <p class="p8"><span class="s3">x = </span><span class="s8">Synth</span><span class="s3">(</span>\conv_test2<span class="s3">, [</span>\kernel<span class="s3">, b]);</span></p>
112 <p class="p2"><br></p>
113 <p class="p6">// changing the buffer number:</p>
114 <p class="p5">x.set(<span class="s7">\kernel</span>, c);</p>
115 <p class="p6"><span class="s3">x.set(</span><span class="s7">\t_trig</span><span class="s3">, 1); </span>// after this trigger, the change will take effect.</p>
116 <p class="p5">x.set(<span class="s7">\kernel</span>, d);</p>
117 <p class="p6"><span class="s3">x.set(</span><span class="s7">\t_trig</span><span class="s3">, 1); </span>// after this trigger, the change will take effect.</p>
118 <p class="p2"><br></p>
119 <p class="p5">d.zero;</p>
120 <p class="p6"><span class="s3">40.do({ </span><span class="s5">|it|</span><span class="s3"> d.set(20*it+10, 1); });</span>// changing the buffers' contents</p>
121 <p class="p6"><span class="s3">x.set(</span><span class="s7">\t_trig</span><span class="s3">, 1); </span>// after this trigger, the change will take effect.</p>
122 <p class="p2"><br></p>
123 <p class="p5">x.set(<span class="s7">\kernel</span>, b);</p>
124 <p class="p6"><span class="s3">x.set(</span><span class="s7">\t_trig</span><span class="s3">, 1); </span>// after this trigger, the change will take effect.</p>
125 <p class="p2"><br></p>
126 <p class="p5">x.free;</p>
127 <p class="p2"><br></p>
128 <p class="p6">// // next example</p>
129 <p class="p2"><br></p>
130 <p class="p9"><span class="s3">b = </span><span class="s5">Buffer</span><span class="s3">.read(s, </span>"sounds/a11wlk01.wav"<span class="s3">);</span></p>
131 <p class="p2"><br></p>
132 <p class="p5">(</p>
133 <p class="p5"><span class="Apple-tab-span"> </span>{ <span class="s5">var</span> input, kernel;</p>
134 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
135 <p class="p5"><span class="Apple-tab-span"> </span>input= <span class="s5">SoundIn</span>.ar(0);</p>
136 <p class="p2"><br></p>
137 <p class="p6"><span class="s3"><span class="Apple-tab-span"> </span></span>// must have power of two framesize</p>
138 <p class="p5"><span class="Apple-tab-span"> </span><span class="s5">Convolution2L</span>.ar(input, b, 0, 512, 1, 0.5);</p>
139 <p class="p5"><span class="Apple-tab-span"> </span>}.play;</p>
140 <p class="p2"><br></p>
141 <p class="p5">)</p>
142 <p class="p2"><br></p>
143 <p class="p2"><br></p>
144 <p class="p6">// another example</p>
145 <p class="p2"><br></p>
146 <p class="p5">(</p>
147 <p class="p6">// must have power of two framesize- FFT size will be sorted by Convolution2 to be double this</p>
148 <p class="p6">// maximum is currently a=8192 for FFT of size 16384</p>
149 <p class="p5">a=2048;</p>
150 <p class="p6">// kernel buffer</p>
151 <p class="p5">g = <span class="s5">Buffer</span>.alloc(s, a, 1);</p>
152 <p class="p5">)</p>
153 <p class="p2"><br></p>
154 <p class="p5">(</p>
155 <p class="p5">g.set(0, 1.0);</p>
156 <p class="p5">100.do({<span class="s5">arg</span> i; g.set(a.rand, (i+1).reciprocal)});</p>
157 <p class="p5">)</p>
158 <p class="p2"><br></p>
159 <p class="p5">(</p>
160 <p class="p6">// random impulse response</p>
161 <p class="p2"><br></p>
162 <p class="p5"><span class="Apple-tab-span"> </span>{</p>
163 <p class="p5"><span class="Apple-tab-span"> </span><span class="s5">var</span> input, inputAmp, threshhold, gate;</p>
164 <p class="p2"><br></p>
165 <p class="p5"><span class="Apple-tab-span"> </span>input = <span class="s5">SoundIn</span>.ar(0);<span class="Apple-converted-space"> </span></p>
166 <p class="p5"><span class="Apple-tab-span"> </span>inputAmp = <span class="s5">Amplitude</span>.kr(input);</p>
167 <p class="p6"><span class="s3"><span class="Apple-tab-span"> </span>threshhold = 0.02;<span class="Apple-tab-span"> </span></span>// noise gating threshold</p>
168 <p class="p5"><span class="Apple-tab-span"> </span>gate = <span class="s5">Lag</span>.kr(inputAmp &gt; threshhold, 0.01);<span class="Apple-tab-span"> </span></p>
169 <p class="p2"><span class="Apple-tab-span"> </span></p>
170 <p class="p5"><span class="Apple-tab-span"> </span><span class="s5">Convolution2L</span>.ar(input*gate, g, 0, a, 1, 0.5);</p>
171 <p class="p5"><span class="Apple-tab-span"> </span>}.play;</p>
172 <p class="p2"><br></p>
173 <p class="p5">)</p>
174 <p class="p2"><br></p>
175 <p class="p2"><br></p>
176 <p class="p2"><br></p>
177 <p class="p2"><br></p>
178 <p class="p2"><br></p>
179 <p class="p2"><br></p>
180 <p class="p6">// one last example</p>
181 <p class="p5">(</p>
182 <p class="p5">b = <span class="s5">Buffer</span>.alloc(s, 512, 1);</p>
183 <p class="p5">b.sine1(1.0/[1, 2, 3, 4, 5, 6], <span class="s5">true</span>, <span class="s5">true</span>, <span class="s5">true</span>);</p>
184 <p class="p5">)</p>
185 <p class="p2"><br></p>
186 <p class="p5">(</p>
187 <p class="p5"><span class="Apple-tab-span"> </span>{ <span class="s5">var</span> input, kernel;</p>
188 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
189 <p class="p5"><span class="Apple-tab-span"> </span>input=<span class="s5">SoundIn</span>.ar(0);</p>
190 <p class="p2"><br></p>
191 <p class="p6"><span class="s3"><span class="Apple-tab-span"> </span></span>// must have power of two framesize</p>
192 <p class="p5"><span class="Apple-tab-span"> </span><span class="s5">Convolution2L</span>.ar(input, b, 0, 512, 1, 0.5);</p>
193 <p class="p5"><span class="Apple-tab-span"> </span>}.play;</p>
194 <p class="p2"><br></p>
195 <p class="p5">)</p>
196 <p class="p2"><br></p>
197 </body>
198 </html>