AudioWorkletNode: AudioWorkletNode() constructor
The AudioWorkletNode()
constructor creates a new AudioWorkletNode object, which represents an
AudioNode that uses a JavaScript function to perform custom audio
processing.
Syntax
js
new AudioWorkletNode(context, name)
new AudioWorkletNode(context, name, options)
Parameters
context-
The
BaseAudioContextinstance this node will be associated with. name-
A string, which represents the name of the
AudioWorkletProcessorthis node will be based on. A processor with the provided name must first be registered using theAudioWorkletGlobalScope.registerProcessor()method. optionsOptional-
An object containing zero or more of the following optional properties to configure the new node:
Note: The result of the structured clone algorithm applied to the object is also internally passed into the associated
AudioWorkletProcessor()constructor — this allows custom initialization of an underlying user-definedAudioWorkletProcessor.numberOfInputsOptional-
The value to initialize the
numberOfInputsproperty to. Defaults to 1. numberOfOutputsOptional-
The value to initialize the
numberOfOutputsproperty to. Defaults to 1. outputChannelCountOptional-
An array defining the number of channels for each output. For example, outputChannelCount: [n, m] specifies the number of channels in the first output to be n and the second output to be m. The array length must match
numberOfOutputs. parameterDataOptional-
An object containing the initial values of custom
AudioParamobjects on this node (in itsparametersproperty), withkeybeing the name of a custom parameter andvaluebeing its initial value. processorOptionsOptional-
Any additional data that can be used for custom initialization of the underlying
AudioWorkletProcessor.
Exceptions
NotSupportedErrorDOMException-
The specified
options.outputChannelCountis0or larger than the current implementation supports.Both
options.numberOfInputsandoptions.numberOfOutputsare 0. IndexSizeErrorDOMException-
The length of
options.outputChannelCountarray does not matchoptions.numberOfOutputs.
Usage notes
Different options parameter values can have the following effects.
If the number of inputs and number of outputs are both set to 0, a NotSupportedError will be thrown and the node construction process aborted. If the length of the outputChannelCount array doesn't match numberOfOutputs, an IndexSizeError DOMException will be thrown.
If outputChannelCount isn't specified, and numberOfInputs and numberOfOutputs are both 1, the AudioWorkletNode's initial channel count is set to 1. This has the effect of changing the output channel count to dynamically change to the computed number of channels, based on the input's channel count and the current setting of the AudioNode property channelCountMode.
Otherwise, if outputChannelCount is provided and if the values of numberOfInputs and numberOfOutputs are both 1, the audio worklet node's channel count is set to the value of outputChannelCount. Otherwise, the channel count of each channel in the set of output channels is set to match the corresponding value in the outputChannelCount array.
Examples
For a complete example demonstrating user-defined audio processing, see the
AudioWorkletNode page.
Specifications
| Specification |
|---|
| Web Audio API # dom-audioworkletnode-audioworkletnode |
Browser compatibility
BCD tables only load in the browser