2 summary:: Real-time convolver with linear interpolation
3 related:: Classes/Convolution, Classes/Convolution2, Classes/Convolution3, Classes/StereoConvolution2L
4 categories:: UGens>FFT, UGens>Convolution
7 Strict convolution with fixed kernel which can be updated using a trigger signal. There is a linear crossfade between the buffers upon change.
9 See emphasis:: Steven W Smith, The Scientist and Engineer's Guide to Digital Signal Processing: chapter 18:: -
10 http://www.dspguide.com/ch18.htm
21 buffer index for the fixed kernel, may be modulated in combination with the trigger
24 update the kernel on a change from <=0 to >0
27 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.
30 The number of periods over which a crossfade is made. The default is 1. This must be an integer.
39 (// allocate three buffers
40 b = Buffer.alloc(s, 2048);
41 c = Buffer.alloc(s, 2048);
42 d = Buffer.alloc(s, 2048);
50 50.do({ |it| c.set(20*it+10, 1.0.rand); });
51 3.do({ |it| b.set(400*it+100, 1); });
52 20.do({ |it| d.set(40*it+20, 1); });
57 SynthDef(\conv_test, { arg kernel, t_trig=0;
62 // must have power of two framesize
63 Out.ar(0, Convolution2L.ar(input, kernel, t_trig, 2048, 1, 0.5));
67 x = Synth(\conv_test, [\kernel, b]);
69 // changing the buffer number:
71 x.set(\t_trig, 1); // after this trigger, the change will take effect.
73 x.set(\t_trig, 1); // after this trigger, the change will take effect.
76 40.do({ |it| d.set(20*it+10, 1); });// changing the buffers' contents
77 x.set(\t_trig, 1); // after this trigger, the change will take effect.
80 x.set(\t_trig, 1); // after this trigger, the change will take effect.
88 SynthDef( \conv_test2, { arg kernel, t_trig=0;
93 // must have power of two framesize
94 Out.ar(0, Convolution2L.ar(input, kernel, t_trig, 2048, 5, 0.5));
98 x = Synth(\conv_test2, [\kernel, b]);
100 // changing the buffer number:
102 x.set(\t_trig, 1); // after this trigger, the change will take effect.
104 x.set(\t_trig, 1); // after this trigger, the change will take effect.
107 40.do({ |it| d.set(20*it+10, 1); });// changing the buffers' contents
108 x.set(\t_trig, 1); // after this trigger, the change will take effect.
111 x.set(\t_trig, 1); // after this trigger, the change will take effect.
119 b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
124 input= SoundIn.ar(0);
126 // must have power of two framesize
127 Convolution2L.ar(input, b, 0, 512, 1, 0.5);
137 // must have power of two framesize- FFT size will be sorted by Convolution2 to be double this
138 // maximum is currently a=8192 for FFT of size 16384
141 g = Buffer.alloc(s, a, 1);
146 100.do({arg i; g.set(a.rand, (i+1).reciprocal)});
150 // random impulse response
153 var input, inputAmp, threshhold, gate;
155 input = SoundIn.ar(0);
156 inputAmp = Amplitude.kr(input);
157 threshhold = 0.02; // noise gating threshold
158 gate = Lag.kr(inputAmp > threshhold, 0.01);
160 Convolution2L.ar(input*gate, g, 0, a, 1, 0.5);
169 b = Buffer.alloc(s, 512, 1);
170 b.sine1(1.0/[1, 2, 3, 4, 5, 6], true, true, true);
178 // must have power of two framesize
179 Convolution2L.ar(input, b, 0, 512, 1, 0.5);