Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Audio: No sound in right channel

I'm trying to create a custom panning control using the Web Audio API, but I can't get any sound to come out of the right channel using the channel splitter and merger nodes:

var context = new webkitAudioContext(),
    destination = context.destination,
    osc = context.createOscillator(),
    gainL = context.createGainNode(),
    gainR = context.createGainNode(),
    splitter = context.createChannelSplitter(2),
    merger = context.createChannelMerger(2);

osc.frequency.value = 500;

osc.connect(splitter);

splitter.connect(gainL, 0);
splitter.connect(gainR, 1);

gainL.connect(merger, 0, 0);
gainR.connect(merger, 0, 1);

osc.noteOn(0);

gainL.gain.value = 0.1;
gainR.gain.value = 0.5;

osc.noteOff(2);

merger.connect(destination);

Am I missing something obvious here? There's a JSBin preview of the above code here: http://jsbin.com/ayijoy/1/

I'm running Chrome v24.0.1312.57, just in case that's of any use.

like image 671
SquareFeet Avatar asked Nov 04 '22 04:11

SquareFeet


1 Answers

My best guess is this happens because the Oscillator outputs a mono signal. Try using a stereo source and you should probably have more luck.

Edit: here's how you can pan a "mono" signal (bypass the splitter, since there is no stereo signal to split, and connect the oscillator directly to the two gains. Then connect the two mono signals to the merger after adjusting the gain for each channel) http://jsbin.com/ayijoy/16/

like image 67
Oskar Eriksson Avatar answered Nov 10 '22 16:11

Oskar Eriksson