convolve


convolution: The process of multiplying two FFT's (one derived from a source sound and another derived from a sound used as an impulse response). The result is a blend of the two sounds, and is an algorithm used frequently in cross-synthesis and reverb simulation. The convolve instrument takes two soundfiles as input, performs an FFT on them both, and then uses a fast convolution algorithm to multiply the two FFT's, using a weighted moving average. The impulse response FFT is flipped back-to-front, with each frame of its FFT multiplying a corresponding frame of the source FFT. The result is then integrated, resulting in the frequency specta of the two signals being multiplied.

True convolution requires a serious amount of processing power, and convolve will run fairly slowly if you use large files. If you use a small impulse response, this will save time.

Syntax:


input("source_soundfile")
input("impulse_response_soundfile", 2) /* note that you open two soundfiles */
output("output_soundfile")

setwindow(0, d, t0, a0, t1, a1...) /* defines the FFT window for the source soundfile - d is the size of the window in seconds, and tN and aN are time/amplitude pairs defining the window envelope */
setwindow(1, d, t0, a0, t1, a1...) /* defines the FFT window for the impulse response file */

convolve(outskip, source_duration, source_inskip, impulse_number, impulse_duration, impulse_inskip, gain, i, dry, spread) /* impulse_number is the file number of the impulse response file (usually set to two, depending on your input() call, i is an invert flag, where the two soundfiles are switched, and dry is a number between 0 and 1 setting the amount of original source signal to be present in the output */

in comment form:

/* source window (2nd arg is duration)
   setwindow(0, dur, time1, amp1, time2, amp2...)
   impulse window (2nd arg is duration)
   setwindow(1, dur, time1, amp1, time2, amp2...) */

/* convolve
*
*  p0 = output skip
*  p1 = source input skip
*  p2 = output duration
*  p3 = impulse file number (p1 on the input() command)
*  p4 = impulse window number (p0 on the setwindow() command)
*  p5 = impulse input skip
*  p6 = amplitude multiplier
*  p7 = invert flag (0 or 1, swaps the imp + src, I think)
*	-- usually "0"
*  p8 = "dry" (usually 0)
*  p9 = outpan (0-1)
*
*/

An example score:

load("convolve")
input("/sndh/bob.dole.mono.snd")
output("/sndh/moderate.snd")
input("/sndh/clinton.blabs.snd", 2)

setwindow(0, 0.2, 0,0, 20,1, 80,1, 100,0)
setwindow(1, 0.2, 0,0, 20,1, 80,1, 100,0)

outsk = 0.0
srcinsk = 0.0
impinsk = 0.0
for(i = 0; i < 30; i = i + 1) { /*  0.1 skips means 3 seconds done */
	convolve(outsk, srcinsk, 0.1, 2, 1, impinsk, 1, 0, 0, 0.5)
	outsk = outsk + 0.1
	srcinsk = srcinsk + 0.1
	impinsk = impinsk + 0.1
	}

Another score, using an FFT window the size of the entire file (will take a long time to compute):

load("convolve")
input("/sndh/luke/source.snd")
input("/sndh/luke/impulse.snd",2)
output("/sndh/luke/convolve.snd")
/* impulse response que       */
outskip    = 0
src_dur    = dur[0] /* set the FFT size to the entire file */
src_inskip = 0
imp_num    = 2
imp_dur    = dur[2] /* set the FFT size to the entire file - must be smaller than the source */
imp_inskip = 0
gain       = .5
i          = 0
dry        = 0
outpan     = .5
/* optional window functions (0) src,  (1) impulse.
    args = [1] function # , [2] dur, setline args    */
setwindow(0,src_dur,0,0,20,1,95,1,100,0)
setwindow(1,imp_dur,0,0,20,1,95,1,100,0)

convolve(outskip,src_inskip,src_dur,imp_num,imp_dur,imp_inskip,gain,i,dry,outpan)