BaseAudioContext Class

The base of the audio contexts (https://webaudio.github.io/web-audio-api/#BaseAudioContext): a graph of AudioNode objects rendered in blocks of sample frames (render quanta) to its BaseAudioContext.Destination, with a time that starts at 0 and advances as the graph is rendered.

public abstract class BaseAudioContext : EventTarget

Remarks

The graph is rendered on the thread of the event loop of the window of the context, never concurrently with its scripts. A context created by .NET code without window renders when its methods are called.

See also

Inheritance
EventTarget BaseAudioContext

Properties

NameDescription
AudioWorkletGets the worklet of the AudioWorkletProcessor classes of the context.
CurrentTimeGets the time of the context in seconds: the time of the next sample frame to render.
DestinationGets the node to which the audio of the graph is rendered.
ListenerGets the listener of the spatialization of the PannerNode objects.
OnStateChangeGets or sets the event handler of the statechange event.
RenderQuantumSizeGets the number of sample frames of a render quantum.
SampleRateGets the sample rate of the context in Hz.
StateGets the state of the context.

Gets the worklet of the AudioWorkletProcessor classes of the context.

public AudioWorklet AudioWorklet { get; }

Property value

AudioWorklet

Exceptions

InvalidOperationException
The context was created by .NET code without window: there is no script engine.

See also

Gets the time of the context in seconds: the time of the next sample frame to render.

public double CurrentTime { get; }

Gets the node to which the audio of the graph is rendered.

public AudioDestinationNode Destination { get; }

Gets the listener of the spatialization of the PannerNode objects.

public AudioListener Listener { get; }

OnStateChange

BaseAudioContext.cs

Gets or sets the event handler of the statechange event.

public Action<Event>? OnStateChange { get; set; }

RenderQuantumSize

BaseAudioContext.cs

Gets the number of sample frames of a render quantum.

public uint RenderQuantumSize { get; }

Gets the sample rate of the context in Hz.

public float SampleRate { get; }

Gets the state of the context.

public AudioContextState State { get; }

Methods

NameDescription
CreateAnalyser()Creates a node that provides the time-domain and frequency-domain data of its input.
CreateBiquadFilter()Creates a second-order filter.
CreateBuffer(uint, uint, float)Creates a buffer of silence.
CreateBufferSource()Creates a node that plays an AudioBuffer.
CreateChannelMerger(uint)Creates a node that combines its inputs into the channels of its output.
CreateChannelSplitter(uint)Creates a node whose outputs are the channels of its input.
CreateConstantSource()Creates a node that outputs a constant value.
CreateConvolver()Creates a node that convolves its input with an impulse response.
CreateDelay(double)Creates a node that delays its input.
CreateDynamicsCompressor()Creates a dynamics compressor.
CreateGain()Creates a node that multiplies its input by a gain.
CreateIIRFilter(IReadOnlyList<double>, IReadOnlyList<double>)Creates a general infinite impulse response filter.
CreateOscillator()Creates a source of a periodic waveform.
CreatePanner()Creates a node that spatializes its input relative to the listener.
CreatePeriodicWave(IReadOnlyList<float>, IReadOnlyList<float>, PeriodicWaveConstraints?)Creates a periodic waveform from the coefficients of its Fourier series.
CreateScriptProcessor(uint, uint, uint)Creates a node that processes its input with the audioprocess events (deprecated).
CreateStereoPanner()Creates a node that pans its input in a stereo image.
CreateWaveShaper()Creates a node that applies a distortion curve to its input.
DecodeAudioData(ReadOnlyMemory<byte>)Decodes an audio file to an AudioBuffer at the sample rate of the context: WAV (integer PCM of 8 to 32 bits, floats, A-law and µ-law) or FLAC.
DecodeAudioDataArray(object, DecodeSuccessCallback?, DecodeErrorCallback?)Decodes an audio file (WAV or FLAC) for the scripts, and detaches its ArrayBuffer: use BaseAudioContext.DecodeAudioData in .NET code.

CreateAnalyser()

BaseAudioContext.cs

Creates a node that provides the time-domain and frequency-domain data of its input.

public AnalyserNode CreateAnalyser()

CreateBiquadFilter()

BaseAudioContext.cs

CreateBuffer(uint, uint, float)

BaseAudioContext.cs

Creates a buffer of silence.

public AudioBuffer CreateBuffer(uint numberOfChannels, uint length, float sampleRate)

CreateBufferSource()

BaseAudioContext.cs

CreateChannelMerger(uint)

BaseAudioContext.cs

Creates a node that combines its inputs into the channels of its output.

public ChannelMergerNode CreateChannelMerger(uint numberOfInputs = 6U)

CreateChannelSplitter(uint)

BaseAudioContext.cs

Creates a node whose outputs are the channels of its input.

public ChannelSplitterNode CreateChannelSplitter(uint numberOfOutputs = 6U)

CreateConstantSource()

BaseAudioContext.cs

Creates a node that outputs a constant value.

public ConstantSourceNode CreateConstantSource()

CreateConvolver()

BaseAudioContext.cs

Creates a node that convolves its input with an impulse response.

public ConvolverNode CreateConvolver()

CreateDelay(double)

BaseAudioContext.cs

Creates a node that delays its input.

public DelayNode CreateDelay(double maxDelayTime = 1d)

CreateDynamicsCompressor()

BaseAudioContext.cs

Creates a node that multiplies its input by a gain.

public GainNode CreateGain()

CreateIIRFilter(IReadOnlyList<double>, IReadOnlyList<double>)

BaseAudioContext.cs

Creates a general infinite impulse response filter.

public IIRFilterNode CreateIIRFilter(IReadOnlyList<double> feedforward, IReadOnlyList<double> feedback)

CreateOscillator()

BaseAudioContext.cs

Creates a source of a periodic waveform.

public OscillatorNode CreateOscillator()

CreatePanner()

BaseAudioContext.cs

Creates a node that spatializes its input relative to the listener.

public PannerNode CreatePanner()

CreatePeriodicWave(IReadOnlyList<float>, IReadOnlyList<float>, PeriodicWaveConstraints?)

BaseAudioContext.cs

Creates a periodic waveform from the coefficients of its Fourier series.

public PeriodicWave CreatePeriodicWave(IReadOnlyList<float> real, IReadOnlyList<float> imag, PeriodicWaveConstraints? constraints = null)

Parameters

real IReadOnlyList<float>
imag IReadOnlyList<float>
constraints PeriodicWaveConstraints?

Returns

PeriodicWave

Exceptions

DomException
The arrays have different lengths, or a length less than 2 (an IndexSizeError).

See also

CreateScriptProcessor(uint, uint, uint)

BaseAudioContext.cs

Creates a node that processes its input with the audioprocess events (deprecated).

public ScriptProcessorNode CreateScriptProcessor(uint bufferSize = 0U, uint numberOfInputChannels = 2U, uint numberOfOutputChannels = 2U)

Parameters

bufferSize uint
The number of frames of the buffers of the events (a power of two from 256 to 16384), or 0 to let the implementation choose.
numberOfInputChannels uint
The number of channels of the input.
numberOfOutputChannels uint
The number of channels of the output.

Returns

ScriptProcessorNode

Exceptions

DomException
An argument is out of its range (an IndexSizeError), or the buffer size is not a multiple of the render quantum size (a NotSupportedError).

See also

CreateStereoPanner()

BaseAudioContext.cs

Creates a node that pans its input in a stereo image.

public StereoPannerNode CreateStereoPanner()

CreateWaveShaper()

BaseAudioContext.cs

Creates a node that applies a distortion curve to its input.

public WaveShaperNode CreateWaveShaper()

DecodeAudioData(ReadOnlyMemory<byte>)

BaseAudioContext.cs

Decodes an audio file to an AudioBuffer at the sample rate of the context: WAV (integer PCM of 8 to 32 bits, floats, A-law and µ-law) or FLAC.

public Task<AudioBuffer> DecodeAudioData(ReadOnlyMemory<byte> audioData)

Parameters

audioData ReadOnlyMemory<byte>

Returns

Task<AudioBuffer> A task completed with the buffer, or failed with a DomException: an EncodingError when the file cannot be decoded, an InvalidStateError when the document is not fully active.

See also

DecodeAudioDataArray(object, DecodeSuccessCallback?, DecodeErrorCallback?)

BaseAudioContext.cs

Decodes an audio file (WAV or FLAC) for the scripts, and detaches its ArrayBuffer: use BaseAudioContext.DecodeAudioData in .NET code.

public Task<AudioBuffer> DecodeAudioDataArray(object audioData, DecodeSuccessCallback? successCallback = null, DecodeErrorCallback? errorCallback = null)