admin管理员组文章数量:1026989
I am trying to implement a ScriptProcessorNode with two input and one output channels.
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();
When I run this code in Google Chrome as well as in Mozilla Firefox I get the following error thrown. It tells me my test
node has only one input channel.
Uncaught IndexSizeError: Failed to execute 'connect' on 'AudioNode': input index (1) exceeds number of inputs (1).
When I console print the number of input channels of the ScriptProcessorNode test
I get two input channels.
test.onaudioprocess = function(evt){
console.log("number of input channels: " + evt.inputBuffer.numberOfChannels);
}
Nevertheless connecting two nodes to the input of the test
node does not work the way I do it. I want to program a vocoder inside the ScriptProcessorNode. How can I create a ScriptProcessorNode with two input and one output channels and connect two source nodes as input channel and the context.destination
as output channel?
I am trying to implement a ScriptProcessorNode with two input and one output channels.
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();
When I run this code in Google Chrome as well as in Mozilla Firefox I get the following error thrown. It tells me my test
node has only one input channel.
Uncaught IndexSizeError: Failed to execute 'connect' on 'AudioNode': input index (1) exceeds number of inputs (1).
When I console print the number of input channels of the ScriptProcessorNode test
I get two input channels.
test.onaudioprocess = function(evt){
console.log("number of input channels: " + evt.inputBuffer.numberOfChannels);
}
Nevertheless connecting two nodes to the input of the test
node does not work the way I do it. I want to program a vocoder inside the ScriptProcessorNode. How can I create a ScriptProcessorNode with two input and one output channels and connect two source nodes as input channel and the context.destination
as output channel?
- developer.mozilla/en-US/docs/Web/API/ChannelMergerNode Have you considered this? – Patrick Roberts Commented May 29, 2016 at 9:09
- I need both input channels in the function which gets triggered by onaudioprocess to connect them in a specific way together. I could create two ScriptProcessorNodes and merge them afterwards but I do not know how to run two ScriptProcessorNodes parallel. – thiloilg Commented May 29, 2016 at 9:20
-
What I'm understanding you to say is that you want both channels processed separately? In that case you probably want developer.mozilla/en-US/docs/Web/API/ChannelSplitterNode and two different
ScriptProcessorNode
s to process each mono audio stream. – Patrick Roberts Commented May 29, 2016 at 9:27 -
I need to process all the samples of both inputs together. Something like
output[i] = inputOne[i] * inputTwo[i];
. What I want is a ScriptProcessorNode with two inputs and one output. If I run twoScriptProcessorNodes
separately I don't think it is possible to take the values out of each sample of both nodes and calculate them together. – thiloilg Commented May 29, 2016 at 9:53 - I don't think that's currently possible. – Patrick Roberts Commented May 29, 2016 at 10:01
1 Answer
Reset to default 6The second parameter of createScriptProcessor
is the number of input channels to the single input of the node, not the number of inputs to the node.
So the way to do this is to use a ChannelMergerNode
with two inputs. Connect your two sources to each of the inputs of the merger node. The output of the merger should be connected to your script processor node. The onaudioprocess
callback will be given an AudioBuffer
that has two channels in it. You can then process these two channels however you want.
I am trying to implement a ScriptProcessorNode with two input and one output channels.
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();
When I run this code in Google Chrome as well as in Mozilla Firefox I get the following error thrown. It tells me my test
node has only one input channel.
Uncaught IndexSizeError: Failed to execute 'connect' on 'AudioNode': input index (1) exceeds number of inputs (1).
When I console print the number of input channels of the ScriptProcessorNode test
I get two input channels.
test.onaudioprocess = function(evt){
console.log("number of input channels: " + evt.inputBuffer.numberOfChannels);
}
Nevertheless connecting two nodes to the input of the test
node does not work the way I do it. I want to program a vocoder inside the ScriptProcessorNode. How can I create a ScriptProcessorNode with two input and one output channels and connect two source nodes as input channel and the context.destination
as output channel?
I am trying to implement a ScriptProcessorNode with two input and one output channels.
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();
When I run this code in Google Chrome as well as in Mozilla Firefox I get the following error thrown. It tells me my test
node has only one input channel.
Uncaught IndexSizeError: Failed to execute 'connect' on 'AudioNode': input index (1) exceeds number of inputs (1).
When I console print the number of input channels of the ScriptProcessorNode test
I get two input channels.
test.onaudioprocess = function(evt){
console.log("number of input channels: " + evt.inputBuffer.numberOfChannels);
}
Nevertheless connecting two nodes to the input of the test
node does not work the way I do it. I want to program a vocoder inside the ScriptProcessorNode. How can I create a ScriptProcessorNode with two input and one output channels and connect two source nodes as input channel and the context.destination
as output channel?
- developer.mozilla/en-US/docs/Web/API/ChannelMergerNode Have you considered this? – Patrick Roberts Commented May 29, 2016 at 9:09
- I need both input channels in the function which gets triggered by onaudioprocess to connect them in a specific way together. I could create two ScriptProcessorNodes and merge them afterwards but I do not know how to run two ScriptProcessorNodes parallel. – thiloilg Commented May 29, 2016 at 9:20
-
What I'm understanding you to say is that you want both channels processed separately? In that case you probably want developer.mozilla/en-US/docs/Web/API/ChannelSplitterNode and two different
ScriptProcessorNode
s to process each mono audio stream. – Patrick Roberts Commented May 29, 2016 at 9:27 -
I need to process all the samples of both inputs together. Something like
output[i] = inputOne[i] * inputTwo[i];
. What I want is a ScriptProcessorNode with two inputs and one output. If I run twoScriptProcessorNodes
separately I don't think it is possible to take the values out of each sample of both nodes and calculate them together. – thiloilg Commented May 29, 2016 at 9:53 - I don't think that's currently possible. – Patrick Roberts Commented May 29, 2016 at 10:01
1 Answer
Reset to default 6The second parameter of createScriptProcessor
is the number of input channels to the single input of the node, not the number of inputs to the node.
So the way to do this is to use a ChannelMergerNode
with two inputs. Connect your two sources to each of the inputs of the merger node. The output of the merger should be connected to your script processor node. The onaudioprocess
callback will be given an AudioBuffer
that has two channels in it. You can then process these two channels however you want.
本文标签:
版权声明:本文标题:google chrome - How can I connect two input channels to the ScriptProcessorNode? (Web Audio Api, JavaScript) - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745121946a2135632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论