2 summary:: Real-time partitioned convolution
3 categories:: UGens>FFT, UGens>Convolution
4 related:: Classes/Convolution, Classes/Convolution2, Classes/Convolution2L, Classes/Convolution3
7 Partitioned convolution. Various additional buffers must be supplied.
9 Mono impulse response only! If inputting multiple channels, you'll need independent PartConvs, one for each channel.
11 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).
13 Normalisation factors difficult to anticipate; convolution piles up multiple copies of the input on top of itself, so can easily overload.
21 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).
23 prepared buffer of spectra for each partition of the inpulse response.
29 // 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.
31 ~fftsize=2048; // also 4096 works on my machine; 1024 too often and amortisation too pushed, 8192 more high load FFT
36 var ir, irbuffer, bufsize;
39 // pre-existing impulse response sound files
40 // (could also use any general soundfile too for cross-synthesis effects)
41 // irbuffer= Buffer.read(s, "/Volumes/data/audio/ir/ir2.wav");
42 // irbuffer= Buffer.read(s, "/Volumes/data/audio/ir/ir.wav");
43 // this is a two second long hall IR
44 // irbuffer= Buffer.read(s, "/Volumes/data/audio/ir/bighall2.wav");
47 // synthesise the honourable 'Dan Stowell' impulse response
49 ir = ([1] ++0.dup(100) ++ ((1, 0.99998 .. 0).collect{|f| f =
50 f.squared.squared; f = if(f.coin){0}{f.squared}; f =
51 if(0.5.coin){0-f}{f} } * 0.1)).normalizeSum;
54 irbuffer = Buffer.loadCollection(s, ir);
58 bufsize= PartConv.calcBufSize(~fftsize, irbuffer);
60 // ~numpartitions= PartConv.calcNumPartitions(~fftsize, irbuffer);
62 ~irspectrum= Buffer.alloc(s, bufsize, 1);
64 ~irspectrum.preparePartConv(irbuffer, ~fftsize);
68 irbuffer.free; // don't need time domain data anymore, just needed spectral version
77 ~target= Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
78 // ~target= Buffer.read(s, "sounds/break");
84 input= PlayBuf.ar(1, ~target, loop:1);
86 Out.ar(0, PartConv.ar(input, ~fftsize, ~irspectrum.bufnum, 0.5));
92 // convolve with live input
99 Out.ar(0, PartConv.ar(input, ~fftsize, ~irspectrum.bufnum));
104 // should get back original impulse response (once every four seconds)
109 input= Impulse.ar(0.25);
111 Out.ar(0, PartConv.ar(input, ~fftsize, ~irspectrum.bufnum));
117 // only free buffers once you're finished with examples
118 // if you free whilst PartConv is still running, the server won't crash, but PartConv output will go to zero abruptly
122 currentEnvironment.clear;