nx.js
Classes

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

ParameterType
optionsAudioContextOptions

Returns

AudioContext

Overrides

BaseAudioContext.constructor

See

https://developer.mozilla.org/docs/Web/API/AudioContext/AudioContext

Properties

PropertyTypeDescriptionInherited from
onstatechangenull | (this, ev) => anyMDN ReferenceglobalThis.AudioContext.onstatechange BaseAudioContext.onstatechange

Accessors

audioWorklet

get audioWorklet(): AudioWorklet

Available only in secure contexts.

MDN Reference

Returns

AudioWorklet

Implementation of

globalThis.AudioContext.audioWorklet

Inherited from

BaseAudioContext.audioWorklet


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

BaseAudioContext.currentTime


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

AudioDestinationNode

Implementation of

globalThis.AudioContext.destination

Inherited from

BaseAudioContext.destination


listener

get listener(): AudioListener

MDN Reference

Returns

AudioListener

Implementation of

globalThis.AudioContext.listener

Inherited from

BaseAudioContext.listener


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

BaseAudioContext.sampleRate


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

BaseAudioContext.state

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

ParameterType
typestring
callbacknull | 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

MDN Reference

Returns

AnalyserNode

Implementation of

globalThis.AudioContext.createAnalyser

Inherited from

BaseAudioContext.createAnalyser


createBiquadFilter()

createBiquadFilter(): BiquadFilterNode

MDN Reference

Returns

BiquadFilterNode

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

ParameterType
numberOfChannelsnumber
lengthnumber
sampleRatenumber

Returns

AudioBuffer

Implementation of

globalThis.AudioContext.createBuffer

Inherited from

BaseAudioContext.createBuffer

See

https://developer.mozilla.org/docs/Web/API/BaseAudioContext/createBuffer


createBufferSource()

createBufferSource(): AudioBufferSourceNode

Creates an AudioBufferSourceNode for playing an AudioBuffer.

Returns

AudioBufferSourceNode

Implementation of

globalThis.AudioContext.createBufferSource

Inherited from

BaseAudioContext.createBufferSource

See

https://developer.mozilla.org/docs/Web/API/BaseAudioContext/createBufferSource


createChannelMerger()

createChannelMerger(numberOfInputs?): ChannelMergerNode

MDN Reference

Parameters

ParameterType
numberOfInputs?number

Returns

ChannelMergerNode

Implementation of

globalThis.AudioContext.createChannelMerger

Inherited from

BaseAudioContext.createChannelMerger


createChannelSplitter()

createChannelSplitter(numberOfOutputs?): ChannelSplitterNode

MDN Reference

Parameters

ParameterType
numberOfOutputs?number

Returns

ChannelSplitterNode

Implementation of

globalThis.AudioContext.createChannelSplitter

Inherited from

BaseAudioContext.createChannelSplitter


createConstantSource()

createConstantSource(): ConstantSourceNode

MDN Reference

Returns

ConstantSourceNode

Implementation of

globalThis.AudioContext.createConstantSource

Inherited from

BaseAudioContext.createConstantSource


createConvolver()

createConvolver(): ConvolverNode

MDN Reference

Returns

ConvolverNode

Implementation of

globalThis.AudioContext.createConvolver

Inherited from

BaseAudioContext.createConvolver


createDelay()

createDelay(maxDelayTime?): DelayNode

MDN Reference

Parameters

ParameterType
maxDelayTime?number

Returns

DelayNode

Implementation of

globalThis.AudioContext.createDelay

Inherited from

BaseAudioContext.createDelay


createDynamicsCompressor()

createDynamicsCompressor(): DynamicsCompressorNode

MDN Reference

Returns

DynamicsCompressorNode

Implementation of

globalThis.AudioContext.createDynamicsCompressor

Inherited from

BaseAudioContext.createDynamicsCompressor


createGain()

createGain(): GainNode

Creates a GainNode for controlling volume.

Returns

GainNode

Implementation of

globalThis.AudioContext.createGain

Inherited from

BaseAudioContext.createGain

See

https://developer.mozilla.org/docs/Web/API/BaseAudioContext/createGain


createIIRFilter()

createIIRFilter(feedforward, feedback): IIRFilterNode

MDN Reference

Parameters

ParameterType
feedforwardIterable<number, any, any> | number[]
feedbackIterable<number, any, any> | number[]

Returns

IIRFilterNode

Implementation of

globalThis.AudioContext.createIIRFilter

Inherited from

BaseAudioContext.createIIRFilter


createMediaElementSource()

createMediaElementSource(mediaElement): MediaElementAudioSourceNode

MDN Reference

Parameters

ParameterType
mediaElementHTMLMediaElement

Returns

MediaElementAudioSourceNode

Implementation of

globalThis.AudioContext.createMediaElementSource


createMediaStreamDestination()

createMediaStreamDestination(): MediaStreamAudioDestinationNode

MDN Reference

Returns

MediaStreamAudioDestinationNode

Implementation of

globalThis.AudioContext.createMediaStreamDestination


createMediaStreamSource()

createMediaStreamSource(mediaStream): MediaStreamAudioSourceNode

MDN Reference

Parameters

ParameterType
mediaStreamMediaStream

Returns

MediaStreamAudioSourceNode

Implementation of

globalThis.AudioContext.createMediaStreamSource


createOscillator()

createOscillator(): OscillatorNode

MDN Reference

Returns

OscillatorNode

Implementation of

globalThis.AudioContext.createOscillator

Inherited from

BaseAudioContext.createOscillator


createPanner()

createPanner(): PannerNode

MDN Reference

Returns

PannerNode

Implementation of

globalThis.AudioContext.createPanner

Inherited from

BaseAudioContext.createPanner


createPeriodicWave()

createPeriodicWave(real, imag, constraints?): PeriodicWave

MDN Reference

Parameters

ParameterType
realIterable<number, any, any> | number[] | Float32Array
imagIterable<number, any, any> | number[] | Float32Array
constraints?PeriodicWaveConstraints

Returns

PeriodicWave

Implementation of

globalThis.AudioContext.createPeriodicWave

Inherited from

BaseAudioContext.createPeriodicWave


createScriptProcessor()

createScriptProcessor(bufferSize?, numberOfInputChannels?, numberOfOutputChannels?): ScriptProcessorNode

Parameters

ParameterType
bufferSize?number
numberOfInputChannels?number
numberOfOutputChannels?number

Returns

ScriptProcessorNode

Implementation of

globalThis.AudioContext.createScriptProcessor

Inherited from

BaseAudioContext.createScriptProcessor

Deprecated

MDN Reference


createStereoPanner()

createStereoPanner(): StereoPannerNode

Creates a StereoPannerNode for panning across the stereo field.

Returns

StereoPannerNode

Implementation of

globalThis.AudioContext.createStereoPanner

Inherited from

BaseAudioContext.createStereoPanner

See

https://developer.mozilla.org/docs/Web/API/BaseAudioContext/createStereoPanner


createWaveShaper()

createWaveShaper(): WaveShaperNode

MDN Reference

Returns

WaveShaperNode

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

ParameterType
audioDataArrayBuffer
successCallback?null | DecodeSuccessCallback
errorCallback?null | DecodeErrorCallback

Returns

Promise<AudioBuffer>

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

ParameterType
eventEvent

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

ParameterType
typestring
callbacknull | 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

On this page