Class ConvolverNode

java.lang.Object
com.codename1.media.audio.AudioNode
com.codename1.media.audio.ConvolverNode

public final class ConvolverNode extends AudioNode

Convolves its input with an impulse response, for reverb and cabinet or room simulation: the Web Audio ConvolverNode.

The response is a 1, 2 or 4 channel AudioData at the context's sample rate. One channel is applied to each input channel; two are a left and a right response; four are true stereo (left to left, left to right, right to left, right to right). The output is mono only for a mono response on a mono input, otherwise stereo.

OfflineAudioContext audio = new OfflineAudioContext(2, 44100, 44100);
OscillatorNode dry = audio.createOscillator();
GainNode wetGain = audio.createGain();
AudioData impulse = audio.createBuffer(2, 22050, 44100); // decoded or synthesised response
ConvolverNode hall = audio.createConvolver();
hall.setBuffer(impulse);
dry.connect(hall).connect(wetGain).connect(audio.getDestination());

Convolution is uniformly partitioned in the frequency domain, one 128 frame block at a time, so there is no added latency. Work grows linearly with the response's length; a few seconds of stereo reverb is practical, a whole cathedral on a low-end phone may not be.

  • Method Details

    • getBuffer

      public AudioData getBuffer()

      The impulse response, or null.

      Returns

      the response

    • setBuffer

      public void setBuffer(AudioData buffer)

      Sets the impulse response. It is read once, when set: later changes to its samples do not reach the node. Null silences the node.

      Parameters
      • buffer: 1, 2 or 4 channels at the context's sample rate, or null
    • isNormalize

      public boolean isNormalize()

      Whether a response set from now on is scaled to a standard loudness; true by default.

      Returns

      true to normalize

    • setNormalize

      public void setNormalize(boolean normalize)

      Sets whether a response set from now on is scaled to a standard loudness. As in the specification it applies at the next setBuffer(AudioData).

      Parameters
      • normalize: true to normalize