Reference p5.Convolver

p5.Convolver

p5.Convolver extends p5.Reverb. It can emulate the sound of real physical spaces through a process called convolution.

Convolution multiplies any audio input by an "impulse response" to simulate the dispersion of sound over time. The impulse response is generated from an audio file that you provide. One way to generate an impulse response is to pop a balloon in a reverberant space and record the echo. Convolution can also be used to experiment with sound.

Use the method createConvolution(path) to instantiate a p5.Convolver with a path to your impulse response audio file.

Examples

Syntax

p5.Convolver(path, [callback], [errorCallback])

Parameters

path
String:

path to a sound file

callback
Function:

function to call when loading succeeds

errorCallback
Function:

function to call if loading fails. This function will receive an error or XMLHttpRequest object with information about what went wrong.

Fields

convolverNode

Internally, the p5.Convolver uses the a Web Audio Convolver Node.

impulses

If you load multiple impulse files using the .addImpulse method, they will be stored as Objects in this Array. Toggle between them with the toggleImpulse(id) method.

Methods

process

Connect a source to the convolver.

addImpulse

Load and assign a new Impulse Response to the p5.Convolver. The impulse is added to the .impulses array. Previous impulses can be accessed with the .toggleImpulse(id) method.

resetImpulse

Similar to .addImpulse, except that the .impulses Array is reset to save memory. A new .impulses array is created with this impulse as the only item.

toggleImpulse

If you have used .addImpulse() to add multiple impulses to a p5.Convolver, then you can use this method to toggle between the items in the .impulses Array. Accepts a parameter to identify which impulse you wish to use, identified either by its original filename (String) or by its position in the .impulses Array (Number).
You can access the objects in the .impulses Array directly. Each Object has two attributes: an .audioBuffer (type: Web Audio AudioBuffer) and a .name, a String that corresponds with the original filename.

Notice any errors or typos? Please let us know. Please feel free to edit lib/addons/p5.sound.js and open a pull request!

Related References