AudioContext Class

An audio context that renders its graph in real time (https://webaudio.github.io/web-audio-api/#AudioContext). There is no audio device: the audio is rendered and discarded, at the pace of the clock of the event loop (DomEventLoop.TimeProvider), so that the time of the context progresses as in a browser.

public sealed class AudioContext : BaseAudioContext

Remarks

The rendering runs in timer tasks of the event loop of the window of the context: a task renders the render quanta whose time has elapsed. A context is allowed to start: it starts running after its construction. A context created by .NET code without window does not render (its time does not progress), but its state changes.

See also

Inheritance
BaseAudioContext AudioContext

Constructors

NameDescription
AudioContext(AudioContextOptions?)Creates a realtime context, which starts running.

AudioContext(AudioContextOptions?)

AudioContext.cs

Creates a realtime context, which starts running.

public AudioContext(AudioContextOptions? contextOptions = null)

Parameters

contextOptions AudioContextOptions?

Exceptions

DomException
The sample rate or the render quantum size is not supported (a NotSupportedError), or the document is not fully active (an InvalidStateError).

See also

Properties

NameDescription
BaseLatencyGets the latency in seconds of the processing of the audio by the context (the latency of the hint, rounded to render quanta).
OnErrorGets or sets the event handler of the error event.
OnSinkChangeGets or sets the event handler of the sinkchange event.
OutputLatencyGets the latency in seconds of the audio output: 0, as there is no audio device.
PlaybackStatsGets the statistics of the playback.
SinkIdGets the audio output device: the identifier of a device (the empty string for the default device), or an AudioSinkInfo.

BaseLatency

AudioContext.cs

Gets the latency in seconds of the processing of the audio by the context (the latency of the hint, rounded to render quanta).

public double BaseLatency { get; }

Gets or sets the event handler of the error event.

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

OnSinkChange

AudioContext.cs

Gets or sets the event handler of the sinkchange event.

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

OutputLatency

AudioContext.cs

Gets the latency in seconds of the audio output: 0, as there is no audio device.

public double OutputLatency { get; }

PlaybackStats

AudioContext.cs

Gets the statistics of the playback.

public AudioPlaybackStats PlaybackStats { get; }

Gets the audio output device: the identifier of a device (the empty string for the default device), or an AudioSinkInfo.

public StringOrAudioSinkInfo SinkId { get; }

Methods

NameDescription
Close()Closes the context: the rendering stops, and the context cannot be resumed.
GetOutputTimestamp()Returns the time of the last rendered frame, and the time of the performance timeline at which it is output (both 0 before the first render quantum).
Resume()Resumes the rendering suspended by AudioContext.Suspend.
SetSinkId(StringOrAudioSinkOptions)Changes the audio output device: the empty string for the default device, or the options of a sink without device.
Suspend()Suspends the rendering: the time of the context stops progressing.

Closes the context: the rendering stops, and the context cannot be resumed.

public Task Close()

Returns

Task A task completed once the context is closed.

See also

GetOutputTimestamp()

AudioContext.cs

Returns the time of the last rendered frame, and the time of the performance timeline at which it is output (both 0 before the first render quantum).

public AudioTimestamp GetOutputTimestamp()

Resumes the rendering suspended by AudioContext.Suspend.

public Task Resume()

Returns

Task A task completed once the context is running.

See also

SetSinkId(StringOrAudioSinkOptions)

AudioContext.cs

Changes the audio output device: the empty string for the default device, or the options of a sink without device.

public Task SetSinkId(StringOrAudioSinkOptions sinkId)

Parameters

sinkId StringOrAudioSinkOptions

Returns

Task A task completed once the device is changed: failed with a NotAllowedError when the speaker-selection feature is not allowed, or a NotFoundError for an unknown device.

See also

Suspends the rendering: the time of the context stops progressing.

public Task Suspend()

Returns

Task A task completed once the context is suspended.

See also