跳到主要内容

process

2024年02月06日
柏拉文
越努力,越幸运

一、认识


二、语法


xxxProcessor.js
class XxxProcessor extends AudioWorkletProcessor {
constructor(...args) {
super(...args);
this.port.onmessage = (e) => {
console.log(e.data);
this.port.postMessage("pong");
};
}
process(inputs, outputs, parameters) {
return true;
}
}

registerProcessor("xxx-processor", XxxProcessor);
const audioContext = new AudioContext();
await audioContext.audioWorklet.addModule('xxxProcessor.js');
const audioWorkletNode = new AudioWorkletNode(audioContext, 'xxx-processor', options);
audioContext.context(audioWorkletNode).context(audioContext.destination);

audioWorkletNode.port.onmessage = (e) => console.log(e.data);

2.1 inputs

inputs 是一个二维数组, 包含了多个信道的音频样本数组

2.2 outputs

2.3 parameters