AudioWorkletProcessor()
构造函数创建新
AudioWorkletProcessor
object, which represents an underlying audio processing mechanism of an
AudioWorkletNode
.
AudioWorkletProcessor
and classes that derive from it cannot be instantiated directly from a user-supplied code. Instead, they are created only internally by the creation of an associated
AudioWorkletNode
。
var processor = new AudioWorkletProcessor(options);
选项
AudioWorkletNode constructor
and passed through
the structured clone algorithm
. The object is based on
AudioWorkletNodeOptions
dictionary. Available properties are as follows:
numberOfInputs
可选
numberOfInputs
property to. Defaults to 1.
numberOfOutputs
可选
numberOfOutputs
property to. Defaults to 1.
outputChannelCount
可选
numberOfOutputs
.
parameterData
可选
AudioParam
objects on this node (in its
参数
property), with
key
being the name of a custom parameter and
value
being its initial value.
processorOptions
可选
AudioWorkletProcessor
.
AudioWorkletNode constructor
,
选项
object passed by the node to the
AudioWorkletProcessor
constructor will exist and at minimum have
numberOfInputs
and
numberOfOutputs
.
The newly constructed
AudioWorkletProcessor
实例。
In this example we pass custom options to the
AudioWorkletNode constructor
and observe how a
structured clone
of them gets passed to our
AudioWorkletProcessor
构造函数。
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 {
constructor (options) {
super()
console.log(options.numberOfInputs)
console.log(options.processorOptions.someUsefulVariable)
}
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 name of the processor and
选项
对象。
在
选项
object we pass
processorOptions
采用
地图
instance under
someUsefulVariable
key. We don't pass
numberOfInputs
and see how it gets its default value.
const audioContext = new AudioContext()
await audioContext.audioWorklet.addModule('test-processor.js')
const testNode = new AudioWorkletNode(audioContext, 'test-processor', {
processorOptions: {
someUsefulVariable: new Map([[1, 'one'], [2, 'two']])
}
})
The console output will be as follows:
> 1 // AudioWorkletNode options.numberOfInputs set to default
> Map(2) {1 => "one", 2 => "two"} // A cloned map under someUsefulVariable
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'AudioWorkletProcessor()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
AudioWorkletProcessor()
构造函数
|
Chrome 64 | Edge 79 | Firefox 76 | IE 不支持 No | Opera ? | Safari 不支持 No | WebView Android 64 | Chrome Android 64 | Firefox Android 不支持 No | Opera Android ? | Safari iOS 不支持 No | Samsung Internet Android 9.0 |
完整支持
不支持
兼容性未知
AudioWorkletNode
interface
AudioWorkletProcessor
AudioWorkletProcessor()
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContext
AudioContextOptions
AudioDestinationNode
AudioListener
AudioNode
AudioNodeOptions
AudioParam
AudioProcessingEvent
AudioScheduledSourceNode
AudioWorklet
AudioWorkletGlobalScope
AudioWorkletNode
BaseAudioContext
BiquadFilterNode
ChannelMergerNode
ChannelSplitterNode
ConstantSourceNode
ConvolverNode
DelayNode
DynamicsCompressorNode
GainNode
IIRFilterNode
MediaElementAudioSourceNode
MediaStreamAudioDestinationNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
OscillatorNode
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode