我正在尝试实现一个具有两个输入通道和一个输出通道的ScriptProcessorNode。
var source = new Array(2);
source[0] = context.createBufferSource();
source[0].buffer = buffer[0];
source[1] = context.createBufferSource();
source[1].buffer = buffer[1];
var test = context.createScriptProcessor(4096, 2, 1);
source[0].connect(test, 0, 0);
source[1].connect(test, 0, 1);
test.connect(context.destination);
source[0].start();
source[1].start();
当我在Google Chrome和Mozilla Firefox中运行此代码时,出现以下错误。它告诉我我的test
节点只有一个输入通道。
Uncaught IndexSizeError: Failed to execute 'connect' on 'AudioNode': input index (1) exceeds number of inputs (1).
当我进行控制台打印时,ScriptProcessorNode的输入通道数test
达到了两个输入通道。
test.onaudioprocess = function(evt){
console.log("number of input channels: " + evt.inputBuffer.numberOfChannels);
}
但是,将两个节点连接到该节点的输入test
无法像我那样工作。我想在ScriptProcessorNode内部编程声码器。如何创建具有两个输入通道和一个输出通道的ScriptProcessorNode并连接两个源节点作为输入通道和context.destination
as输出通道?
的第二个参数createScriptProcessor
是到节点的单个输入的输入通道数,而不是到节点的输入数。
因此,执行此操作的方法是使用ChannelMergerNode
带有两个输入的a。将您的两个源连接到合并节点的每个输入。合并的输出应连接到脚本处理器节点。该onaudioprocess
回调将具有一个AudioBuffer
包含两个通道的。然后,您可以根据需要处理这两个通道。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句