OfflineContext

Wrapper around the OfflineAudioContext

Hierarchy

  • Context
    • OfflineContext

Constructor

new OfflineContext (
channels:number ,

The number of channels to render

duration:Seconds ,

The duration to render in seconds

sampleRate:number

the sample rate to render at

) => OfflineContext
new OfflineContext (
context:OfflineAudioContext
) => OfflineContext

Properties

clockSource #

TickerClockSource

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

currentTime #

readonly Seconds

Same as this.now()

debug #

boolean

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

destination #

Destination

A reference to the Context's destination node.

disposed #

readonly 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.

latencyHint #

ContextLatencyHint | Seconds

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), and "fastest" (lowest latency, might glitch more often).


//set the lookAhead to 0.3 seconds
Tone.context.latencyHint = 0.3;

listener #

readonly AudioListener

The listener

lookAhead #

Seconds

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.

rawContext #

readonly AnyAudioContext

The unwrapped AudioContext.

sampleRate #

readonly number

The current time in seconds of the AudioContext.

state #

readonly AudioContextState

The current time in seconds of the AudioContext.

transport #

Transport

There is only one Transport per Context. It is created on initialization.

updateInterval #

Seconds

How often the interval callback is invoked. This number corresponds to how responsive the scheduling can be. context.updateInterval + context.lookAhead gives you the total latency between scheduling an event and hearing it.

static version #

string

The version number semver

Methods

clearInterval #

Clear the function scheduled by setInterval

clearInterval (
id:number
) => this

clearTimeout #

Clears a previously scheduled timeout with Tone.context.setTimeout

clearTimeout (
id:number

The ID returned from setTimeout

) => this

close #

Close the context

close ( ) => Promise<void >

createAnalyser #

createAnalyser ( ) => AnalyserNode

createBiquadFilter #

createBiquadFilter ( ) => BiquadFilterNode

createBuffer #

createBuffer (
numberOfChannels:number ,
length:number ,
sampleRate:number
) => AudioBuffer

createBufferSource #

createBufferSource ( ) => AudioBufferSourceNode

createChannelMerger #

createChannelMerger (
numberOfInputs?:number | undefined
) => ChannelMergerNode

createChannelSplitter #

createChannelSplitter (
numberOfOutputs?:number | undefined
) => ChannelSplitterNode

createConstantSource #

createConstantSource ( ) => ConstantSourceNode

createConvolver #

createConvolver ( ) => ConvolverNode

createDelay #

createDelay (
maxDelayTime?:number | undefined
) => DelayNode

createDynamicsCompressor #

createDynamicsCompressor ( ) => DynamicsCompressorNode

createGain #

createGain ( ) => GainNode

createIIRFilter #

createIIRFilter (
feedForward:number [] | Float32Array ,
feedback:number [] | Float32Array
) => IIRFilterNode

createMediaStreamSource #

createMediaStreamSource (
stream:MediaStream
) => MediaStreamAudioSourceNode

createOscillator #

createOscillator ( ) => OscillatorNode

createPanner #

createPanner ( ) => PannerNode

createPeriodicWave #

createPeriodicWave (
real:number [] | Float32Array ,
imag:number [] | Float32Array ,
constraints?:PeriodicWaveConstraints | undefined
) => PeriodicWave

createStereoPanner #

createStereoPanner ( ) => StereoPannerNode

createWaveShaper #

createWaveShaper ( ) => WaveShaperNode

decodeAudioData #

decodeAudioData (
audioData:ArrayBuffer
) => Promise<AudioBuffer >

dispose #

Clean up. Also closes the audio context.

dispose ( ) => this

emit #

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

emit (
event:any ,

The name of the event.

...args:any []

The arguments to pass to the functions listening.

) => this

getConstant #

Generate a looped buffer at some constant value.

getConstant (
val:number
) => AudioBufferSourceNode

static getDefaults #

Returns all of the default options belonging to the class.

getDefaults ( ) => ContextOptions

initialize #

Finish setting up the context. You usually do not need to do this manually.

initialize ( ) => this

static mixin #

Add Emitter functions (on/off/emit) to the object

mixin (
constr:any
) => void

now #

Override the now method to point to the internal clock time

now ( ) => Seconds

off #

Remove the event listener.

off (
event:"statechange" | "tick" ,

The event to stop listening to.

callback?:undefined | (args) => void

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

) => this

on #

Bind a callback to a specific event.

on (
event:"statechange" | "tick" ,

The name of the event to listen for.

callback:(args) => void

The callback to invoke when the event is emitted

) => this

once #

Bind a callback which is only invoked once

once (
event:"statechange" | "tick" ,

The name of the event to listen for.

callback:(args) => void

The callback to invoke when the event is emitted

) => this

render #

Render the output of the OfflineContext

render ( ) => Promise<AudioBuffer >

resume #

Starts the audio context from a suspended state. This is required to initially start the AudioContext.

resume ( ) => Promise<void >

setInterval #

Adds a repeating event to the context's callback clock

setInterval (
fn:(args) => void ,
interval:Seconds
) => number

setTimeout #

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

setTimeout (
fn:(args) => void ,

The callback to invoke

timeout:Seconds

The timeout in seconds

) => number
ID to use when invoking Context.clearTimeout

toString #

Convert the class to a string


const osc = new Oscillator()
osc.toString() // "Oscillator"
toString ( ) => string