Class AudioBufferSourceNode


public final class AudioBufferSourceNode extends AudioScheduledSourceNode

Plays AudioData, the Web Audio AudioBufferSourceNode. Its output has the data's channel count. Data at another sample rate is resampled with linear interpolation.

OfflineAudioContext audio = new OfflineAudioContext(2, 44100, 44100);
AudioData clip = audio.createBuffer(1, 44100, 44100); // or decodeAudioData
AudioBufferSourceNode src = audio.createBufferSource();
src.setBuffer(clip);
src.getPlaybackRate().setValue(1.5f);
src.connect(audio.getDestination());
src.start(audio.getCurrentTime() + 0.1);
  • Method Details

    • getPlaybackRate

      public AudioParam getPlaybackRate()

      The speed factor, 1 by default; negative plays backwards. A control rate parameter.

      Returns

      the parameter

    • getDetune

      public AudioParam getDetune()

      A detune in cents, combined with the playback rate; a control rate parameter.

      Returns

      the parameter

    • getBuffer

      public AudioData getBuffer()

      The audio played.

      Returns

      the data, or null

    • setBuffer

      public void setBuffer(AudioData buffer)

      Sets the audio to play. It can be set once; a source without data plays one channel of silence.

      Parameters
      • buffer: the data
    • isLoop

      public boolean isLoop()

      Whether playback loops between getLoopStart() and getLoopEnd().

      Returns

      true when looping

    • setLoop

      public void setLoop(boolean loop)

      Turns looping on or off.

      Parameters
      • loop: true to loop
    • getLoopStart

      public double getLoopStart()

      The start of the loop in seconds of the data.

      Returns

      seconds

    • setLoopStart

      public void setLoopStart(double loopStart)

      Sets the start of the loop.

      Parameters
      • loopStart: seconds of the data
    • getLoopEnd

      public double getLoopEnd()

      The end of the loop in seconds of the data; 0 (the default), or any value not after the start, means the end of the data.

      Returns

      seconds

    • setLoopEnd

      public void setLoopEnd(double loopEnd)

      Sets the end of the loop.

      Parameters
      • loopEnd: seconds of the data
    • start

      public void start(double when, double offset)

      Starts playing at when from offset seconds into the data.

      Parameters
      • when: context time in seconds

      • offset: where in the data to start

    • start

      public void start(double when, double offset, double duration)

      Starts playing at when from offset seconds into the data, for duration seconds of the data (loops included).

      Parameters
      • when: context time in seconds

      • offset: where in the data to start, 0 or more

      • duration: how much of the data to play, more than 0