Created
November 7, 2017 12:28
-
-
Save Zalastax/09f04c04735a930b089bea8aed2be5c8 to your computer and use it in GitHub Desktop.
Make YouTube videos with mono sounds be stereo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://stackoverflow.com/questions/20287890/audiocontext-panning-audio-of-playing-media | |
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