Web/API/AudioWorkletGlobalScope/registerProcessor
The registerProcessor
method of the AudioWorkletGlobalScope
interface registers a class constructor derived from AudioWorkletProcessor
interface under a specified name.
Syntax
AudioWorkletGlobalScope.registerProcessor(name, processorCtor);
Parameters
name
- A string representing the name under which the processor will be registered.
processorCtor
- The constructor of a class derived from
AudioWorkletProcessor
.
Note: A key-value pair { name: constructor }
is saved internally in the AudioWorkletGlobalScope
once the processor is registered. The name is to be referred to when creating an AudioWorkletNode
based on the registered processor. A new processor by the given name is internally created and associated with the new node.
Return value
Exceptions
NotSupportedError
- ;* The name is an empty string, or
- a constructor under the given name is already registered. Registering the same name twice is not allowed.
TypeError
- ;* The processorCtor is not a callable constructor, or
- the
parameterDescriptors
property of the constructor exists and doesn't return an array ofAudioParamDescriptor
-based objects.
- the
Examples
In this example we create a custom AudioWorkletNode
that outputs silence.
First, we need to define a custom AudioWorkletProcessor
and register it. Note that this should be done in a separate file.
// test-processor.js
class TestProcessor extends AudioWorkletProcessor {
process (inputs, outputs, parameters) {
return true
}
}
registerProcessor('test-processor', TestProcessor)
Next, in our main script file we'll load the processor, create an instance of AudioWorkletNode
— passing it the processor name that we used when calling registerProcessor
— and connect it to an audio graph.
const audioContext = new AudioContext()
await audioContext.audioWorklet.addModule('test-processor.js')
const node = new AudioWorkletNode(audioContext, 'test-processor')
node.connect(audioContext.destination)
Specifications
Specification | Status | Comment |
Web Audio APIThe definition of 'registerProcessor()' in that specification. | Working Draft |
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.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
registerProcessor
|
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
Full support 76 |
IE
No support No |
Opera
Full support 53 |
Safari
No support No |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
No support No |
Opera Android
Full support 47 |
Safari iOS
No support No |
Samsung Internet Android
Full support 9.0 |
Legend
- Full support
- Full support
- No support
- No support
See also
AudioWorkletGlobalScope.registerProcessor by Mozilla Contributors is licensed under CC-BY-SA 2.5.