AudioContext
An audio-processing graph built from audio modules (AudioNodes) linked together, rendered in real-time to the console's audio output.
Example
const ctx = new AudioContext();
const res = await fetch('romfs:/jump.ogg');
const buffer = await ctx.decodeAudioData(await res.arrayBuffer());
const source = ctx.createBufferSource();
source.buffer = buffer;
source.connect(ctx.destination);
source.start();See
https://developer.mozilla.org/docs/Web/API/AudioContext
Extends
Implements
Constructors
new AudioContext()
new AudioContext(options): AudioContext
Parameters
| Parameter | Type |
|---|---|
options | AudioContextOptions |
Returns
Overrides
BaseAudioContext.constructor
See
https://developer.mozilla.org/docs/Web/API/AudioContext/AudioContext
Properties
| Property | Type | Description | Inherited from |
|---|---|---|---|
onstatechange | null | (this, ev) => any | MDN Reference | globalThis.AudioContext.onstatechange BaseAudioContext.onstatechange |
Accessors
audioWorklet
get audioWorklet(): AudioWorklet
Available only in secure contexts.
Returns
Implementation of
globalThis.AudioContext.audioWorklet
Inherited from
baseLatency
get baseLatency(): number
The number of seconds of processing latency incurred by the audio graph itself (one render quantum).
See
https://developer.mozilla.org/docs/Web/API/AudioContext/baseLatency
Returns
number
Implementation of
globalThis.AudioContext.baseLatency
currentTime
get currentTime(): number
The time, in seconds, of the sample frame currently being processed by
the audio graph. Starts at 0 and increases in real-time while the
context is running.
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/currentTime
Returns
number
Implementation of
globalThis.AudioContext.currentTime
Inherited from
destination
get destination(): AudioDestinationNode
The final destination of the audio graph (the audio output device).
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/destination
Returns
Implementation of
globalThis.AudioContext.destination
Inherited from
listener
get listener(): AudioListener
Returns
Implementation of
globalThis.AudioContext.listener
Inherited from
outputLatency
get outputLatency(): number
Estimated output latency: the double-buffered (2 × 1024 frame) audio output stream.
See
https://developer.mozilla.org/docs/Web/API/AudioContext/outputLatency
Returns
number
Implementation of
globalThis.AudioContext.outputLatency
sampleRate
get sampleRate(): number
The sample rate (in samples per second) used by all nodes in this context.
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/sampleRate
Returns
number
Implementation of
globalThis.AudioContext.sampleRate
Inherited from
state
get state(): AudioContextState
The current state of the audio context: "suspended", "running" or
"closed".
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/state
Returns
AudioContextState
Implementation of
globalThis.AudioContext.state
Inherited from
Methods
addEventListener()
addEventListener(type, callback, options?): void
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
Parameters
| Parameter | Type |
|---|---|
type | string |
callback | null | EventListenerOrEventListenerObject<any> |
options? | boolean | AddEventListenerOptions |
Returns
void
Implementation of
globalThis.AudioContext.addEventListener
Inherited from
BaseAudioContext.addEventListener
See
https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener
close()
close(): Promise<void>
Closes the audio context, releasing the audio output resources that it uses.
Returns
Promise<void>
Implementation of
globalThis.AudioContext.close
See
https://developer.mozilla.org/docs/Web/API/AudioContext/close
createAnalyser()
createAnalyser(): AnalyserNode
Returns
Implementation of
globalThis.AudioContext.createAnalyser
Inherited from
BaseAudioContext.createAnalyser
createBiquadFilter()
createBiquadFilter(): BiquadFilterNode
Returns
Implementation of
globalThis.AudioContext.createBiquadFilter
Inherited from
BaseAudioContext.createBiquadFilter
createBuffer()
createBuffer(numberOfChannels, length, sampleRate): AudioBuffer
Creates a new, empty AudioBuffer, which can be filled with data and played via an AudioBufferSourceNode.
Parameters
| Parameter | Type |
|---|---|
numberOfChannels | number |
length | number |
sampleRate | number |
Returns
Implementation of
globalThis.AudioContext.createBuffer
Inherited from
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/createBuffer
createBufferSource()
createBufferSource(): AudioBufferSourceNode
Creates an AudioBufferSourceNode for playing an AudioBuffer.
Returns
Implementation of
globalThis.AudioContext.createBufferSource
Inherited from
BaseAudioContext.createBufferSource
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/createBufferSource
createChannelMerger()
createChannelMerger(numberOfInputs?): ChannelMergerNode
Parameters
| Parameter | Type |
|---|---|
numberOfInputs? | number |
Returns
Implementation of
globalThis.AudioContext.createChannelMerger
Inherited from
BaseAudioContext.createChannelMerger
createChannelSplitter()
createChannelSplitter(numberOfOutputs?): ChannelSplitterNode
Parameters
| Parameter | Type |
|---|---|
numberOfOutputs? | number |
Returns
Implementation of
globalThis.AudioContext.createChannelSplitter
Inherited from
BaseAudioContext.createChannelSplitter
createConstantSource()
createConstantSource(): ConstantSourceNode
Returns
Implementation of
globalThis.AudioContext.createConstantSource
Inherited from
BaseAudioContext.createConstantSource
createConvolver()
createConvolver(): ConvolverNode
Returns
Implementation of
globalThis.AudioContext.createConvolver
Inherited from
BaseAudioContext.createConvolver
createDelay()
createDelay(maxDelayTime?): DelayNode
Parameters
| Parameter | Type |
|---|---|
maxDelayTime? | number |
Returns
Implementation of
globalThis.AudioContext.createDelay
Inherited from
createDynamicsCompressor()
createDynamicsCompressor(): DynamicsCompressorNode
Returns
Implementation of
globalThis.AudioContext.createDynamicsCompressor
Inherited from
BaseAudioContext.createDynamicsCompressor
createGain()
createGain(): GainNode
Creates a GainNode for controlling volume.
Returns
Implementation of
globalThis.AudioContext.createGain
Inherited from
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/createGain
createIIRFilter()
createIIRFilter(feedforward, feedback): IIRFilterNode
Parameters
| Parameter | Type |
|---|---|
feedforward | Iterable<number, any, any> | number[] |
feedback | Iterable<number, any, any> | number[] |
Returns
Implementation of
globalThis.AudioContext.createIIRFilter
Inherited from
BaseAudioContext.createIIRFilter
createMediaElementSource()
createMediaElementSource(mediaElement): MediaElementAudioSourceNode
Parameters
| Parameter | Type |
|---|---|
mediaElement | HTMLMediaElement |
Returns
Implementation of
globalThis.AudioContext.createMediaElementSource
createMediaStreamDestination()
createMediaStreamDestination(): MediaStreamAudioDestinationNode
Returns
MediaStreamAudioDestinationNode
Implementation of
globalThis.AudioContext.createMediaStreamDestination
createMediaStreamSource()
createMediaStreamSource(mediaStream): MediaStreamAudioSourceNode
Parameters
| Parameter | Type |
|---|---|
mediaStream | MediaStream |
Returns
Implementation of
globalThis.AudioContext.createMediaStreamSource
createOscillator()
createOscillator(): OscillatorNode
Returns
Implementation of
globalThis.AudioContext.createOscillator
Inherited from
BaseAudioContext.createOscillator
createPanner()
createPanner(): PannerNode
Returns
Implementation of
globalThis.AudioContext.createPanner
Inherited from
createPeriodicWave()
createPeriodicWave(real, imag, constraints?): PeriodicWave
Parameters
| Parameter | Type |
|---|---|
real | Iterable<number, any, any> | number[] | Float32Array |
imag | Iterable<number, any, any> | number[] | Float32Array |
constraints? | PeriodicWaveConstraints |
Returns
Implementation of
globalThis.AudioContext.createPeriodicWave
Inherited from
BaseAudioContext.createPeriodicWave
createScriptProcessor()
createScriptProcessor(bufferSize?, numberOfInputChannels?, numberOfOutputChannels?): ScriptProcessorNode
Parameters
| Parameter | Type |
|---|---|
bufferSize? | number |
numberOfInputChannels? | number |
numberOfOutputChannels? | number |
Returns
Implementation of
globalThis.AudioContext.createScriptProcessor
Inherited from
BaseAudioContext.createScriptProcessor
Deprecated
createStereoPanner()
createStereoPanner(): StereoPannerNode
Creates a StereoPannerNode for panning across the stereo field.
Returns
Implementation of
globalThis.AudioContext.createStereoPanner
Inherited from
BaseAudioContext.createStereoPanner
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/createStereoPanner
createWaveShaper()
createWaveShaper(): WaveShaperNode
Returns
Implementation of
globalThis.AudioContext.createWaveShaper
Inherited from
BaseAudioContext.createWaveShaper
decodeAudioData()
decodeAudioData(audioData, successCallback?, errorCallback?): Promise<AudioBuffer>
Asynchronously decodes audio file data contained in an ArrayBuffer
into an AudioBuffer.
Supported Audio Formats
Any audio container/codec supported by FFmpeg, including MP3, WAV, OGG Vorbis, Opus, FLAC and AAC/M4A.
Note
Unlike browsers, nx.js does NOT resample the decoded data to the context's sample rate — the returned buffer keeps the file's native rate (resampling happens at playback time).
Parameters
| Parameter | Type |
|---|---|
audioData | ArrayBuffer |
successCallback? | null | DecodeSuccessCallback |
errorCallback? | null | DecodeErrorCallback |
Returns
Implementation of
globalThis.AudioContext.decodeAudioData
Inherited from
BaseAudioContext.decodeAudioData
See
https://developer.mozilla.org/docs/Web/API/BaseAudioContext/decodeAudioData
dispatchEvent()
dispatchEvent(event): boolean
Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
Parameters
| Parameter | Type |
|---|---|
event | Event |
Returns
boolean
Implementation of
globalThis.AudioContext.dispatchEvent
Inherited from
BaseAudioContext.dispatchEvent
See
https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent
getOutputTimestamp()
getOutputTimestamp(): AudioTimestamp
Returns a new AudioTimestamp containing two correlated context/
performance timestamp values.
Returns
AudioTimestamp
Implementation of
globalThis.AudioContext.getOutputTimestamp
See
https://developer.mozilla.org/docs/Web/API/AudioContext/getOutputTimestamp
removeEventListener()
removeEventListener(type, callback, options?): void
Removes the event listener in target's event listener list with the same type, callback, and options.
Parameters
| Parameter | Type |
|---|---|
type | string |
callback | null | EventListenerOrEventListenerObject<any> |
options? | boolean | EventListenerOptions |
Returns
void
Implementation of
globalThis.AudioContext.removeEventListener
Inherited from
BaseAudioContext.removeEventListener
See
https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener
resume()
resume(): Promise<void>
Resumes the progression of time in an audio context that has previously been suspended.
Returns
Promise<void>
Implementation of
globalThis.AudioContext.resume
See
https://developer.mozilla.org/docs/Web/API/AudioContext/resume
suspend()
suspend(): Promise<void>
Suspends the progression of time in the audio context, temporarily halting audio rendering (and reducing CPU/battery usage).
Returns
Promise<void>
Implementation of
globalThis.AudioContext.suspend
See
https://developer.mozilla.org/docs/Web/API/AudioContext/suspend