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 testnode 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 testnode 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.destinationas 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 testnode 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 testnode 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.destinationas output channel?

Share Improve this question asked May 29, 2016 at 9:02 thiloilgthiloilg 2,2133 gold badges19 silver badges25 bronze badges 5
  • 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 ScriptProcessorNodes 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 two ScriptProcessorNodesseparately 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
Add a ment  | 

1 Answer 1

Reset to default 6

The 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 testnode 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 testnode 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.destinationas 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 testnode 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 testnode 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.destinationas output channel?

Share Improve this question asked May 29, 2016 at 9:02 thiloilgthiloilg 2,2133 gold badges19 silver badges25 bronze badges 5
  • 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 ScriptProcessorNodes 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 two ScriptProcessorNodesseparately 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
Add a ment  | 

1 Answer 1

Reset to default 6

The 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.

本文标签: