Skip to main content

BaseAudioContext

The BaseAudioContext interface acts as a supervisor of audio-processing graphs. It provides key processing parameters such as current time, output destination or sample rate. Additionally, it is responsible for nodes creation and audio-processing graph's lifecycle management. However, BaseAudioContext itself cannot be directly utilized, instead its functionalities must be accessed through one of its derived interfaces: AudioContext, OfflineAudioContext.

Audio graph

An audio graph is a structured representation of audio processing elements and their connections within an audio context. The graph consists of various types of nodes, each performing specific audio operations, connected in a network that defines the audio signal flow. In general we can distinguish four types of nodes:

Rendering audio graph

Audio graph rendering is done in blocks of sample-frames. The number of sample-frames in a block is called render quantum size, and the block itself is called a render quantum. By default render quantum size value is 128 and it is constant.

The AudioContext rendering thread is driven by a system-level audio callback. Each call has a system-level audio callback buffer size, which is a varying number of sample-frames that needs to be computed on time before the next system-level audio callback arrives, but render quantum size does not have to be a divisor of the system-level audio callback buffer size.

info

Concept of system-level audio callback does not apply to OfflineAudioContext.

Properties

NameTypeDescription
currentTimenumberDouble value representing an ever-increasing hardware time in seconds, starting from 0.
Read only
destinationAudioDestinationNodeFinal output destination associated with the context.
Read only
sampleRatenumberFloat value representing the sample rate (in samples per seconds) used by all nodes in this context.
Read only
stateContextStateEnumerated value represents the current state of the context.
Read only

Methods

createAnalyser

The above method lets you create AnalyserNode.

Returns AnalyserNode.

createBiquadFilter

The above method lets you create BiquadFilterNode.

Returns BiquadFilterNode.

createBuffer

The above method lets you create AudioBuffer.

ParametersTypeDescription
numOfChannelsnumberAn integer representing the number of channels of the buffer.
lengthnumberAn integer representing the length of the buffer in sampleFrames. Two seconds buffer has length equals to 2 * sampleRate.
sampleRatenumberA float representing the sample rate of the buffer.

Errors

Error typeDescription
NotSupportedErrornumOfChannels is outside the nominal range [1, 32].
NotSupportedErrorsampleRate is outside the nominal range [8000, 96000].
NotSupportedErrorlength is less then 1.

Returns AudioBuffer.

createBufferSource

The above method lets you create AudioBufferSourceNode.

ParametersTypeDescription
pitchCorrection
Optional
AudioBufferSourceNodeOptionsDictionary object that specifies if pitch correction has to be available.

Returns AudioBufferSourceNode.

createGain

The above method lets you create GainNode.

Returns GainNode.

createOscillator

The above method lets you create OscillatorNode.

Returns OscillatorNode.

createPeriodicWave

The above method lets you create PeriodicWave.

ParametersTypeDescription
realFloat32ArrayAn array of cosine terms.
imagFloat32ArrayAn array of sine terms.
constraints
Optional
PeriodicWaveConstraintsAn object that specifies if normalization is disabled.

Errors

Error typeDescription
InvalidAccessErrorreal and imag arrays do not have same length.

Returns PeriodicWave.

createStereoPanner

The above method lets you create StereoPannerNode.

Returns StereoPannerNode.

decodeAudioData

The above method lets you decode audio data. It decodes with in memory audio data block.

ParametersTypeDescription
arrayBufferArrayBufferArrayBuffer with audio data.

Returns Promise<AudioBuffer>.

decodeAudioDataSource

The above method lets you decode audio data file. It saves file in the device file system.

ParametersTypeDescription
sourcePathstringPath to audio file located on the device.

Returns Promise<AudioBuffer>.

Remarks

currentTime

  • Timer starts when context is created, stops when context is suspended.