The AudioWorkletNode()
constructor creates a new AudioWorkletNode
object, which represents an AudioNode
that uses a JavaScript function to perform custom audio processing.
Syntax
var node = new AudioWorkletNode(context, name); var node = new AudioWorkletNode(context, name, options);
Parameters
context
- The
BaseAudioContext
instance this node will be associated with. name
- A string, which represents the name of the
AudioWorkletProcessor
this node will be based on. A processor with the provided name must first be registered using theAudioWorkletGlobalScope.registerProcessor()
method. options
Optional- An object based on the
AudioWorkletNodeOptions
dictionary, which contains zero or more optional properties to configure the new node. The result of the structured clone algorithm applied to the object is also internally passed into the associatedAudioWorkletProcessor()
constructor — this allows custom initialization of an underlying user-definedAudioWorkletProcessor
. Available properties are as follows:numberOfInputs
Optional- The value to initialize the
numberOfInputs
property to. Defaults to 1. numberOfOutputs
Optional- The value to initialize the
numberOfOutputs
property to. Defaults to 1. outputChannelCount
Optional- 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
. parameterData
Optional- An object containing the initial values of custom
AudioParam
objects on this node (in itsparameters
property), withkey
being the name of a custom parameter andvalue
being its initial value. processorOptions
Optional- Any additional data that can be used for custom initialization of the underlying
AudioWorkletProcessor
.
Return value
The newly constructed AudioWorkletNode
instance.
Exceptions
NotSupportedError
- The specified
options.outputChannelCount
is0
or larger than the current implementation supports. IndexSizeError
- The length of
options.outputChannelCount
array does not matchoptions.numberOfOutputs
.
Example
For a complete example demonstrating user-defined audio processing, see the AudioWorkletNode
page.
Specifications
Specification | Status | Comment |
---|---|---|
Web Audio API The definition of 'AudioWorkletNode()' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
AudioWorkletNode() constructor | Chrome Full support 66 | Edge Full support 79 | Firefox Full support 76 | IE No support No | Opera ? | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown