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.
27 // 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.
29 ~fftsize=2048; // also 4096 works on my machine; 1024 too often and amortisation too pushed, 8192 more high load FFT
34 var ir, irbuffer, bufsize;
37 // pre-existing impulse response sound files
38 // (could also use any general soundfile too for cross-synthesis effects)
39 // irbuffer= Buffer.read(s, "/Volumes/data/audio/ir/ir2.wav");
40 // irbuffer= Buffer.read(s, "/Volumes/data/audio/ir/ir.wav");
41 // this is a two second long hall IR
42 // irbuffer= Buffer.read(s, "/Volumes/data/audio/ir/bighall2.wav");
45 // synthesise the honourable 'Dan Stowell' impulse response
47 ir = ([1] ++0.dup(100) ++ ((1, 0.99998 .. 0).collect{|f| f =
48 f.squared.squared; f = if(f.coin){0}{f.squared}; f =
49 if(0.5.coin){0-f}{f} } * 0.1)).normalizeSum;
52 irbuffer = Buffer.loadCollection(s, ir);
56 bufsize= PartConv.calcBufSize(~fftsize, irbuffer);
58 // ~numpartitions= PartConv.calcNumPartitions(~fftsize, irbuffer);
60 ~irspectrum= Buffer.alloc(s, bufsize, 1);
62 ~irspectrum.preparePartConv(irbuffer, ~fftsize);
66 irbuffer.free; // don't need time domain data anymore, just needed spectral version
75 ~target= Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
76 // ~target= Buffer.read(s, "sounds/break");
82 input= PlayBuf.ar(1, ~target, loop:1);
84 Out.ar(0, PartConv.ar(input, ~fftsize, ~irspectrum.bufnum, 0.5));
90 // convolve with live input
97 Out.ar(0, PartConv.ar(input, ~fftsize, ~irspectrum.bufnum));
102 // should get back original impulse response (once every four seconds)
107 input= Impulse.ar(0.25);
109 Out.ar(0, PartConv.ar(input, ~fftsize, ~irspectrum.bufnum));
115 // only free buffers once you're finished with examples
116 // if you free whilst PartConv is still running, the server won't crash, but PartConv output will go to zero abruptly
120 currentEnvironment.clear;