Skip to content

Instantly share code, notes, and snippets.

@notgiorgi
Created February 9, 2017 20:02
Show Gist options
  • Save notgiorgi/5036dad6409bf5fc3415795193155b34 to your computer and use it in GitHub Desktop.
Save notgiorgi/5036dad6409bf5fc3415795193155b34 to your computer and use it in GitHub Desktop.
window.audioContext = window.audioContext||window.webkitAudioContext; //fallback for older chrome browsers
var context = new AudioContext();
context.createGain = context.createGain||context.createGainNode; //fallback for gain naming
var gainL = context.createGain();
var gainR = context.createGain();
var splitter = this.context.createChannelSplitter(2);
//Connect to source
var source = context.createMediaElementSource(document.querySelector('video'));
//Connect the source to the splitter
source.connect(splitter, 0, 0);
//Connect splitter' outputs to each Gain Nodes
splitter.connect(gainL, 0);
splitter.connect(gainR, 1);
//Connect Left and Right Nodes to the output
//Assuming stereo as initial status
gainL.connect(context.destination, 0);
gainR.connect(context.destination, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment