convolution takes two arguments, a real vector v of length n and a real vector w of length m , and returns their convolution z=v∗w which is the vector of length N=n+m−1 defined as :
zk= |
| vi wk−i, k=0,1,…,N−1, |
such that vj=0 for j≥ n and wj=0 for j≥ m .
For example, input :
Output :
In the following example convolution is used for reverberation. Assume that the directory sounds contains two files, a dry, mono recording of a guitar stored in guitar.wav and a two-channel impulse response recorded in a French 18th century salon and stored in salon-ir.wav. Files are loaded with the following command lines :
Input :
Output :
Input :
Output :
Convolving the data from clip with both channels in ir produces a reverberated variant of the recording, in stereo. Input :
The convolved signals L and R now become the left and right channel of a new audio clip, respectively. The normalize option is used because convolution usually results in a huge increase of sample values (which is clear from the definition). Input :
The result sounds as it was recorded in the same salon as the impulse response. Furthermore, it is a true stereo sound. To visualize it, input :
Output :
Note that the resulting audio is longer than the input (for the length of the impulse response).