1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"949.43">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.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
}
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: 9.0px Monaco
; color: #ad140d}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #ad140d; min-height: 12.0px}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #606060}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #90251e}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000}
20 span
.s1
{color: #000000}
21 span
.s2
{color: #001bb9}
22 span
.s3
{color: #ad140d}
23 span
.Apple-tab-span
{white-space:pre
}
27 <p class=
"p1"><b>PartConv
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>real-time partitioned convolution
</b></p>
28 <p class=
"p2"><br></p>
29 <p class=
"p3"><b>PartConv.ar(in, fftsize, irbufnum, mul, add)
</b></p>
30 <p class=
"p2"><br></p>
31 <p class=
"p3">Partitioned convolution. Various additional buffers must be supplied.
<span class=
"Apple-converted-space"> </span></p>
32 <p class=
"p4"><br></p>
33 <p class=
"p3">Mono impulse response only! If inputting multiple channels, you'll need independent PartConvs, one for each channel.
</p>
34 <p class=
"p4"><br></p>
35 <p class=
"p3">But the charm is: impulse response can be as large as you like (CPU load increases with IR size. Various tradeoffs based on fftsize choice, due to rarer but larger FFTs. This plug-in uses amortisation to spread processing and avoid spikes).
</p>
36 <p class=
"p4"><br></p>
37 <p class=
"p3">Normalisation factors difficult to anticipate; convolution piles up multiple copies of the input on top of itself, so can easily overload.
<span class=
"Apple-converted-space"> </span></p>
38 <p class=
"p4"><br></p>
39 <p class=
"p3"><b>in
</b> - processing target
</p>
40 <p class=
"p3"><b>fftsize
</b>- spectral convolution partition size (twice partition size). You must ensure that the blocksize divides the partition size and there are at least two blocks per partition (to allow for amortisation)
</p>
41 <p class=
"p3"><b>irbufnum
</b>- Prepared buffer of spectra for each partition of the inpulse response
</p>
42 <p class=
"p2"><br></p>
43 <p class=
"p2"><br></p>
44 <p class=
"p2"><br></p>
45 <p class=
"p2"><br></p>
46 <p class=
"p2"><br></p>
47 <p class=
"p5">// preparation; essentially, allocate an impulse response buffer, then follow a special buffer preparation step to set up the data the plugin needs. Different options are provided commented out for loading impulse responses from soundfiles.
</p>
49 <p class=
"p5"><span class=
"s1">~fftsize=
2048;
</span>// also
4096 works on my machine;
1024 too often and amortisation too pushed,
8192 more high load FFT
</p>
50 <p class=
"p2"><br></p>
51 <p class=
"p6">s.waitForBoot {
</p>
52 <p class=
"p2"><br></p>
54 <p class=
"p6"><span class=
"s2">var
</span> ir, irbuffer, bufsize;
<span class=
"Apple-converted-space"> </span></p>
55 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
56 <p class=
"p5"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// // MONO ONLY
</p>
57 <p class=
"p5"><span class=
"Apple-tab-span"> </span>// pre-existing impulse response sound files
<span class=
"Apple-converted-space"> </span></p>
58 <p class=
"p5"><span class=
"Apple-tab-span"> </span>// (could also use any general soundfile too for cross-synthesis effects)
</p>
59 <p class=
"p5"><span class=
"Apple-tab-span"> </span>// irbuffer= Buffer.read(s,
"/Volumes/data/audio/ir/ir2.wav");
</p>
60 <p class=
"p5"><span class=
"Apple-tab-span"> </span>// irbuffer= Buffer.read(s,
"/Volumes/data/audio/ir/ir.wav");
</p>
61 <p class=
"p5"><span class=
"Apple-tab-span"> </span>// this is a two second long hall IR
</p>
62 <p class=
"p5"><span class=
"Apple-tab-span"> </span>// irbuffer= Buffer.read(s,
"/Volumes/data/audio/ir/bighall2.wav");
</p>
63 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
64 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
65 <p class=
"p5"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// synthesise the honourable 'Dan Stowell' impulse response
</p>
66 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
67 <p class=
"p6"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>ir = ([
1] ++
0.dup(
100) ++ ((
1,
0.99998 ..
0).collect{
<span class=
"s2">|f|
</span> f =
</p>
68 <p class=
"p6"><span class=
"Apple-tab-span"> </span>f.squared.squared; f = if(f.coin){
0}{f.squared}; f =
</p>
69 <p class=
"p6"><span class=
"Apple-tab-span"> </span>if(
0.5.coin){
0-f}{f} } *
0.1)).normalizeSum;
</p>
70 <p class=
"p5"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// ir.plot;
</p>
71 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
72 <p class=
"p6"><span class=
"s3"><span class=
"Apple-tab-span"> </span></span>irbuffer =
<span class=
"s2">Buffer
</span>.loadCollection(s, ir);
</p>
73 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
74 <p class=
"p6"><span class=
"Apple-tab-span"> </span>s.sync;
</p>
75 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
76 <p class=
"p6"><span class=
"Apple-tab-span"> </span>bufsize=
<span class=
"s2">PartConv
</span>.calcBufSize(~fftsize, irbuffer);
</p>
77 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
78 <p class=
"p5"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// ~numpartitions= PartConv.calcNumPartitions(~fftsize, irbuffer);
</p>
79 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
80 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~irspectrum=
<span class=
"s2">Buffer
</span>.alloc(s, bufsize,
1);
</p>
81 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
82 <p class=
"p6"><span class=
"Apple-tab-span"> </span>~irspectrum.preparePartConv(irbuffer, ~fftsize);
</p>
83 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
84 <p class=
"p6"><span class=
"Apple-tab-span"> </span>s.sync;
<span class=
"Apple-converted-space"> </span></p>
85 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
86 <p class=
"p5"><span class=
"s1"><span class=
"Apple-tab-span"> </span>irbuffer.free;
</span>// don't need time domain data anymore, just needed spectral version
</p>
87 <p class=
"p6">}.fork;
</p>
88 <p class=
"p2"><br></p>
90 <p class=
"p2"><br></p>
92 <p class=
"p2"><br></p>
93 <p class=
"p2"><br></p>
94 <p class=
"p2"><br></p>
95 <p class=
"p8"><span class=
"s1">~target=
</span><span class=
"s2">Buffer
</span><span class=
"s1">.read(s,
</span>"sounds/a11wlk01.wav"<span class=
"s1">);
</span></p>
96 <p class=
"p5">// ~target= Buffer.read(s,
"sounds/break");
</p>
97 <p class=
"p2"><br></p>
99 <p class=
"p2"><br></p>
100 <p class=
"p6">{
<span class=
"s2">var
</span> input, kernel;
</p>
101 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
102 <p class=
"p6">input=
<span class=
"s2">PlayBuf
</span>.ar(
1, ~target, loop:
1);
<span class=
"Apple-tab-span"> </span></p>
103 <p class=
"p2"><br></p>
104 <p class=
"p6"><span class=
"s2">Out
</span>.ar(
0,
<span class=
"s2">PartConv
</span>.ar(input, ~fftsize, ~irspectrum.bufnum,
0.5));
</p>
105 <p class=
"p6"><span class=
"Apple-converted-space"> </span>}.play;
</p>
106 <p class=
"p2"><br></p>
108 <p class=
"p2"><br></p>
109 <p class=
"p2"><br></p>
110 <p class=
"p5">// convolve with live input
</p>
112 <p class=
"p2"><br></p>
113 <p class=
"p6">{
<span class=
"s2">var
</span> input, kernel;
</p>
114 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
115 <p class=
"p6">input=
<span class=
"s2">SoundIn
</span>.ar(
0);
<span class=
"Apple-tab-span"> </span></p>
116 <p class=
"p2"><br></p>
117 <p class=
"p6"><span class=
"s2">Out
</span>.ar(
0,
<span class=
"s2">PartConv
</span>.ar(input, ~fftsize, ~irspectrum.bufnum));
</p>
118 <p class=
"p6">}.play;
</p>
120 <p class=
"p2"><br></p>
121 <p class=
"p2"><br></p>
122 <p class=
"p5">// should get back original impulse response (once every four seconds)
</p>
124 <p class=
"p2"><br></p>
125 <p class=
"p6">{
<span class=
"s2">var
</span> input, kernel;
</p>
126 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
127 <p class=
"p6">input=
<span class=
"s2">Impulse
</span>.ar(
0.25);
<span class=
"Apple-tab-span"> </span></p>
128 <p class=
"p2"><br></p>
129 <p class=
"p6"><span class=
"s2">Out
</span>.ar(
0,
<span class=
"s2">PartConv
</span>.ar(input, ~fftsize, ~irspectrum.bufnum));
</p>
130 <p class=
"p6"><span class=
"Apple-converted-space"> </span>}.play;
</p>
131 <p class=
"p2"><br></p>
133 <p class=
"p2"><br></p>
134 <p class=
"p2"><br></p>
135 <p class=
"p9">// only free buffers once you're finished with examples
</p>
136 <p class=
"p9">// if you free whilst PartConv is still running, the server won't crash, but PartConv output will go to zero abruptly
</p>
138 <p class=
"p10">~irspectrum.free;
</p>
139 <p class=
"p10">~target.free;
</p>
140 <p class=
"p10">currentEnvironment.clear;
</p>
142 <p class=
"p2"><br></p>
143 <p class=
"p2"><br></p>
144 <p class=
"p2"><br></p>
145 <p class=
"p2"><br></p>
146 <p class=
"p2"><br></p>
147 <p class=
"p2"><br></p>
148 <p class=
"p2"><br></p>