1
votes

I am using the channel splitter and merger to attempt to split a stereo file into two discrete channels and then funnel them back into the node graph as a "mono" input source that plays in both the left and right monitors. I figured out a way to do it but it uses the stereoPanner node set to 0.5 , and it feels a bit "hacky". How would I do this without using the stereoPanner node ?

//____________________________________________BEGIN Setup

var merger = audioContext.createChannelMerger();
var stereoPanner = audioContext.createStereoPanner();
var stereoInputSource = audioContext.createBufferSource();
stereoInputSource.buffer = soundObj.soundToPlay;

//____________________________________________END Setup


stereoInputSource.connect(merger, 0, 0);
merger.connect(stereoPanner);

stereoPanner.pan.value = 0.5;

stereoPanner.connect(audioContext.destination);
3

3 Answers

1
votes

Create a ChannelMerger with only one channel and use to to force downmixing?

0
votes

Just take the mean (average) of the left and right sample.

0
votes

I guess I was over thinking this. The following seems to work. I guess the names of the nodes are what is a bit confusing. I would have though I would need a merge node for this

stereoInputSource.connect(splitter);

splitter.connect(monoGain, 0); // left output
splitter.connect(monoGain, 1); // right output

monoGain.connect(audioContext.destination);

EDIT

The "correct" way is what Chris mentioned. Explicitly setting the output channel on the merge node invocation is what confused me.

var stereoInputSource = audioContext.createBufferSource();
var merger = audioContext.createChannelMerger(1); // Set number of channels

stereoInputSource.buffer = soundObj.soundToPlay;
stereoInputSource.connect(merger);
merger.connect(audioContext.destination)