问题
Is there an (easy) way to take a mono input and play it only in the left or right channel? I'm thinking I can do it through the ScriptProcessing node, but if there is a node meant to handle this situation I'd really like to know. The API has a section on mixing, but I don't see any code on how to manipulate channels yourself in this fashion.
Note, I have tried the panner node, but it doesn't seem to really cut off the left the from the right channel, I don't want any sound bleeding from one channel to the other.
回答1:
You do want to use the ChannelSplitter, although there is a bug when a channel is simply not connected. See this issue: Play an Oscillation In a Single Channel.
回答2:
Take a look at the splitter node: https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#ChannelSplitterNode-section
One application for ChannelSplitterNode is for doing "matrix mixing" where individual gain control of each channel is desired.
(I haven't yet tried it, let me know : )
回答3:
You can try to use the CreatePanner()
and then setPosition()
to the desired channel. Don't forget to connect your previous node to the panner node and the panner to the context.destination
.
For example:
//Lets create a simple oscilator just to have some audio in our context
var oscillator = context.createOscillator();
//Now lets create the panner node
var pannerNode = context.createPanner();
//Connecting the nodes
oscillator.connect(pannerNode); //Connecting the oscillator output to the panner input
pannerNode.connect(context.destination); //Connecting the panner output to our sound output
//Setting the position of the sound
pannerNode.setPosition(-1, 0, 0);//If you want it to play on the left channel
pannerNode.setPosition(1, 0, 0);//If you want it to play on the right channel
//Playing the sound
oscillator.noteOn(0);
Is that what you need?
来源:https://stackoverflow.com/questions/14623947/web-audio-api-how-do-i-play-a-mono-source-in-only-left-or-right-channel