Class OfflineAudioContext

java.lang.Object
com.codename1.media.audio.BaseAudioContext
com.codename1.media.audio.OfflineAudioContext

public final class OfflineAudioContext extends BaseAudioContext

Renders an audio graph to memory as fast as the device can, the Web Audio OfflineAudioContext. It needs no audio hardware, so it works on every platform: use it to bounce a mix, pre-render effects, or test a graph.

OfflineAudioContext audio = new OfflineAudioContext(2, 44100, 44100);
OscillatorNode osc = audio.createOscillator();
osc.connect(audio.getDestination());
osc.start();
AudioData oneSecond = audio.startRendering();
  • Constructor Details

    • OfflineAudioContext

      public OfflineAudioContext(int numberOfChannels, int length, float sampleRate)

      Creates an offline context.

      Parameters
      • numberOfChannels: channels of the result, 1 to 32

      • length: frames to render, at least 1

      • sampleRate: frames per second, 3000 to 768000

  • Method Details

    • getLength

      public int getLength()

      The number of frames startRendering() produces.

      Returns

      frames

    • getState

      public AudioContextState getState()
      Description copied from class: BaseAudioContext

      The life cycle state.

      Returns

      the state

      Specified by:
      getState in class BaseAudioContext
    • startRendering

      public AudioData startRendering()

      Renders the whole graph on the calling thread and returns the result. onended callbacks run on this thread between render quanta. Do not call it on the EDT for long renders.

      Returns

      getLength() frames with the destination's channel count

      Throws
      • IllegalStateException: if rendering was already started