Tone.js
    Preparing search index...

    Class OfflineContext

    Wrapper around the OfflineAudioContext

    // generate a single channel, 0.5 second buffer
    const context = new Tone.OfflineContext(1, 0.5, 44100);
    const osc = new Tone.Oscillator({ context });
    context.render().then(buffer => {
    console.log(buffer.numberOfChannels, buffer.duration);
    });

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    debug: boolean = false

    Set this debug flag to log all events that happen in this class.

    isOffline: boolean = true

    Indicates if the context is an OfflineAudioContext or an AudioContext

    name: string = "OfflineContext"

    The name of the class

    version: string = version

    The version number semver

    Accessors

    • get clockSource(): TickerClockSource

      What the source of the clock is, either "worker" (default), "timeout", or "offline" (none).

      Returns TickerClockSource

    • set clockSource(type: TickerClockSource): void

      Parameters

      • type: TickerClockSource

      Returns void

    • get disposed(): boolean

      Indicates if the instance was disposed. 'Disposing' an instance means that all of the Web Audio nodes that were created for the instance are disconnected and freed for garbage collection.

      Returns boolean

    • get latencyHint(): number | AudioContextLatencyCategory

      The type of playback, which affects tradeoffs between audio output latency and responsiveness. In addition to setting the value in seconds, the latencyHint also accepts the strings "interactive" (prioritizes low latency), "playback" (prioritizes sustained playback), "balanced" (balances latency and performance).

      Returns number | AudioContextLatencyCategory

      // prioritize sustained playback
      const context = new Tone.Context({ latencyHint: "playback" });
      // set this context as the global Context
      Tone.setContext(context);
      // the global context is gettable with Tone.getContext()
      console.log(Tone.getContext().latencyHint);
    • get lookAhead(): number

      The amount of time into the future events are scheduled. Giving Web Audio a short amount of time into the future to schedule events can reduce clicks and improve performance. This value can be set to 0 to get the lowest latency. Adjusting this value also affects the updateInterval.

      Returns number

    • set lookAhead(time: number): void

      Parameters

      • time: number

      Returns void

    • get rawContext(): AnyAudioContext

      The unwrapped AudioContext or OfflineAudioContext

      Returns AnyAudioContext

    • get sampleRate(): number

      The current time in seconds of the AudioContext.

      Returns number

    • get state(): AudioContextState

      The current time in seconds of the AudioContext.

      Returns AudioContextState

    • get updateInterval(): number

      How often the interval callback is invoked. This number corresponds to how responsive the scheduling can be. Setting to 0 will result in the lowest practical interval based on context properties. context.updateInterval + context.lookAhead gives you the total latency between scheduling an event and hearing it.

      Returns number

    • set updateInterval(interval: number): void

      Parameters

      • interval: number

      Returns void

    Methods

    • Create an audio worklet node from a name and options. The module must first be loaded using addAudioWorkletModule.

      Parameters

      • name: string
      • Optionaloptions: Partial<AudioWorkletNodeOptions>

      Returns AudioWorkletNode

    • Parameters

      • real: number[] | Float32Array
      • imag: number[] | Float32Array
      • Optionalconstraints: PeriodicWaveConstraints

      Returns PeriodicWave

    • Invoke all of the callbacks bound to the event with any arguments passed in.

      Parameters

      • event: "statechange" | "tick"

        The name of the event.

      • ...args: any[]

        The arguments to pass to the functions listening.

      Returns this

    • Remove the event listener.

      Parameters

      • event: "statechange" | "tick"

        The event to stop listening to.

      • Optionalcallback: (...args: any[]) => void

        The callback which was bound to the event with Emitter.on. If no callback is given, all callbacks events are removed.

      Returns this

    • Bind a callback to a specific event.

      Parameters

      • event: "statechange" | "tick"

        The name of the event to listen for.

      • callback: (...args: any[]) => void

        The callback to invoke when the event is emitted

      Returns this

    • Bind a callback which is only invoked once

      Parameters

      • event: "statechange" | "tick"

        The name of the event to listen for.

      • callback: (...args: any[]) => void

        The callback to invoke when the event is emitted

      Returns this

    • Adds a repeating event to the context's callback clock

      Parameters

      • fn: (...args: any[]) => void
      • interval: number

      Returns number

    • A setTimeout which is guaranteed by the clock source. Also runs in the offline context.

      Parameters

      • fn: (...args: any[]) => void

        The callback to invoke

      • timeout: number

        The timeout in seconds

      Returns number

      ID to use when invoking Context.clearTimeout

    • Convert the class to a string

      Returns string

      const osc = new Tone.Oscillator();
      console.log(osc.toString());