Skip to content
Tone.js

BaseContext

class Core ↳ extends Emitter<"statechange" | "tick">

Emitter gives classes which extend it the ability to listen for and emit events. Inspiration and reference from Jerome Etienne’s MicroEvent. MIT (c) 2011 Jerome Etienne.

new BaseContext()

read-only

isOffline: boolean

Default: false

latencyHint: number | AudioContextLatencyCategory
lookAhead: number

read-only ↳ inherited from Emitter

name: string

The name of the class

Default: "Emitter"

read-only

currentTime: number

The currentTime read-only property of the BaseAudioContext interface returns a double representing an ever-increasing hardware timestamp in seconds that can be used for scheduling audio playback, visualizing timelines, etc. It starts at 0.

MDN Reference

read-only

destination: DestinationClass

read-only

draw: DrawClass

read-only

listener: ListenerClass

read-only

rawContext: AnyAudioContext

read-only

sampleRate: number

The sampleRate property of the BaseAudioContext interface returns a floating point number representing the sample rate, in samples per second, used by all nodes in this audio context. This limitation means that sample-rate converters are not supported.

MDN Reference

read-only

state: AudioContextState

The state read-only property of the BaseAudioContext interface returns the current state of the AudioContext.

MDN Reference

read-only

transport: TransportClass
addAudioWorkletModule(_url: string): Promise<void>

Parameters

  • _url string

Returns Promise<void>

clearInterval(_id: number): this

Parameters

  • _id number

Returns this

clearTimeout(_id: number): this

Parameters

  • _id number

Returns this

createAnalyser(): AnalyserNode

The createAnalyser() method of the BaseAudioContext interface creates an AnalyserNode, which can be used to expose audio time and frequency data and create data visualizations.

MDN Reference

Returns AnalyserNode

createAudioWorkletNode(_name: string, _options?: Partial<AudioWorkletNodeOptions>): AudioWorkletNode

Parameters

  • _name string
  • _options Partial<AudioWorkletNodeOptions> optional

Returns AudioWorkletNode

createBiquadFilter(): BiquadFilterNode

The createBiquadFilter() method of the BaseAudioContext interface creates a BiquadFilterNode, which represents a second order filter configurable as several different common filter types.

MDN Reference

Returns BiquadFilterNode

createBuffer(_numberOfChannels: number, _length: number, _sampleRate: number): AudioBuffer

The createBuffer() method of the BaseAudioContext Interface is used to create a new, empty AudioBuffer object, which can then be populated by data, and played via an AudioBufferSourceNode.

MDN Reference

Parameters

  • _numberOfChannels number
  • _length number
  • _sampleRate number

Returns AudioBuffer

createBufferSource(): AudioBufferSourceNode

The createBufferSource() method of the BaseAudioContext Interface is used to create a new AudioBufferSourceNode, which can be used to play audio data contained within an AudioBuffer object. AudioBuffers are created using BaseAudioContext.createBuffer or returned by BaseAudioContext.decodeAudioData when it successfully decodes an audio track.

MDN Reference

Returns AudioBufferSourceNode

createChannelMerger(_numberOfInputs?: number): ChannelMergerNode

The createChannelMerger() method of the BaseAudioContext interface creates a ChannelMergerNode, which combines channels from multiple audio streams into a single audio stream.

MDN Reference

Parameters

  • _numberOfInputs number optional

Returns ChannelMergerNode

createChannelSplitter(_numberOfOutputs?: number): ChannelSplitterNode

The createChannelSplitter() method of the BaseAudioContext Interface is used to create a ChannelSplitterNode, which is used to access the individual channels of an audio stream and process them separately.

MDN Reference

Parameters

  • _numberOfOutputs number optional

Returns ChannelSplitterNode

createConstantSource(): ConstantSourceNode

The createConstantSource() property of the BaseAudioContext interface creates a ConstantSourceNode object, which is an audio source that continuously outputs a monaural (one-channel) sound signal whose samples all have the same value.

MDN Reference

Returns ConstantSourceNode

createConvolver(): ConvolverNode

The createConvolver() method of the BaseAudioContext interface creates a ConvolverNode, which is commonly used to apply reverb effects to your audio. See the spec definition of Convolution for more information.

MDN Reference

Returns ConvolverNode

createDelay(_maxDelayTime?: number): DelayNode

The createDelay() method of the BaseAudioContext Interface is used to create a DelayNode, which is used to delay the incoming audio signal by a certain amount of time.

MDN Reference

Parameters

  • _maxDelayTime number optional

Returns DelayNode

createDynamicsCompressor(): DynamicsCompressorNode

The createDynamicsCompressor() method of the BaseAudioContext Interface is used to create a DynamicsCompressorNode, which can be used to apply compression to an audio signal.

MDN Reference

Returns DynamicsCompressorNode

createGain(): GainNode

The createGain() method of the BaseAudioContext interface creates a GainNode, which can be used to control the overall gain (or volume) of the audio graph.

MDN Reference

Returns GainNode

createIIRFilter(_feedForward: number[] | Float32Array<ArrayBuffer>, _feedback: number[] | Float32Array<ArrayBuffer>): IIRFilterNode

The createIIRFilter() method of the BaseAudioContext interface creates an IIRFilterNode, which represents a general infinite impulse response (IIR) filter which can be configured to serve as various types of filter.

MDN Reference

Parameters

  • _feedForward number[] | Float32Array<ArrayBuffer>
  • _feedback number[] | Float32Array<ArrayBuffer>

Returns IIRFilterNode

createMediaElementSource(_element: HTMLMediaElement): MediaElementAudioSourceNode

Parameters

  • _element HTMLMediaElement

Returns MediaElementAudioSourceNode

createMediaStreamDestination(): MediaStreamAudioDestinationNode

Returns MediaStreamAudioDestinationNode

createMediaStreamSource(_stream: MediaStream): MediaStreamAudioSourceNode

Parameters

  • _stream MediaStream

Returns MediaStreamAudioSourceNode

createOscillator(): OscillatorNode

The createOscillator() method of the BaseAudioContext interface creates an OscillatorNode, a source representing a periodic waveform. It basically generates a constant tone.

MDN Reference

Returns OscillatorNode

createPanner(): PannerNode

The createPanner() method of the BaseAudioContext Interface is used to create a new PannerNode, which is used to spatialize an incoming audio stream in 3D space.

MDN Reference

Returns PannerNode

createPeriodicWave(_real: number[] | Float32Array<ArrayBuffer>, _imag: number[] | Float32Array<ArrayBuffer>, _constraints?: PeriodicWaveConstraints): PeriodicWave

The createPeriodicWave() method of the BaseAudioContext interface is used to create a PeriodicWave. This wave is used to define a periodic waveform that can be used to shape the output of an OscillatorNode.

MDN Reference

Parameters

  • _real number[] | Float32Array<ArrayBuffer>
  • _imag number[] | Float32Array<ArrayBuffer>
  • _constraints PeriodicWaveConstraints optional

Returns PeriodicWave

createStereoPanner(): StereoPannerNode

The createStereoPanner() method of the BaseAudioContext interface creates a StereoPannerNode, which can be used to apply stereo panning to an audio source. It positions an incoming audio stream in a stereo image using a low-cost panning algorithm.

MDN Reference

Returns StereoPannerNode

createWaveShaper(): WaveShaperNode

The createWaveShaper() method of the BaseAudioContext interface creates a WaveShaperNode, which represents a non-linear distortion. It is used to apply distortion effects to your audio.

MDN Reference

Returns WaveShaperNode

decodeAudioData(_audioData: ArrayBuffer): Promise<AudioBuffer>

The decodeAudioData() method of the BaseAudioContext Interface is used to asynchronously decode audio file data contained in an ArrayBuffer that is loaded from fetch(), XMLHttpRequest, or FileReader. The decoded AudioBuffer is resampled to the AudioContext’s sampling rate, then passed to a callback or promise.

MDN Reference

Parameters

  • _audioData ArrayBuffer

Returns Promise<AudioBuffer>

↳ inherited from Emitter

dispose(): this

Clean up

Returns this

↳ inherited from Emitter

emit(event: "statechange" | "tick", ...args: any[]): this

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

getConstant(_val: number): AudioBufferSourceNode

Parameters

  • _val number

Returns AudioBufferSourceNode

immediate(): number

Returns number

now(): number

Returns number

↳ inherited from Emitter

off(event: "statechange" | "tick", callback?: (...args: any[]) => void): this

Remove the event listener.

Parameters

  • event "statechange" | "tick"

    The event to stop listening to.

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

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

Returns this

↳ inherited from Emitter

on(event: "statechange" | "tick", callback: (...args: any[]) => void): 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

↳ inherited from Emitter

once(event: "statechange" | "tick", callback: (...args: any[]) => void): 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

resume(): Promise<void>

Returns Promise<void>

setInterval(_fn: (...args: any[]) => void, _interval: number): number

Parameters

  • _fn (…args: any[]) => void
  • _interval number

Returns number

setTimeout(_fn: (...args: any[]) => void, _timeout: number): number

Parameters

  • _fn (…args: any[]) => void
  • _timeout number

Returns number

toJSON(): Record<string, any>

Returns Record<string, any>

static ↳ inherited from Emitter

mixin(constr: any): void

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

Parameters

  • constr any