Created
May 8, 2013 18:47
-
-
Save mbarton/5542642 to your computer and use it in GitHub Desktop.
Page to reproduce weirdness where the input to the cue node is heard on all 4 channels coming out of the merger node
This file contains hidden or 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
<head> | |
<title>Cue Test</title> | |
</head> | |
<body> | |
<button id="main">Start Main</button> | |
<button id="cue">Start Cue</button> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script> | |
var ctx = new webkitAudioContext(); | |
ctx.destination.channelCount = 4; | |
ctx.destination.channelCountMode = "explicit"; | |
ctx.destination.channelInterpretation = "discrete"; | |
var merger = ctx.createChannelMerger(2); | |
merger.connect(ctx.destination); | |
var mixer_inputs = {} | |
function createMixerInput(name, index){ | |
mixer_inputs[name] = ctx.createGainNode(); | |
mixer_inputs[name].channelCount = 2; | |
mixer_inputs[name].channelCountMode = "explicit"; | |
mixer_inputs[name].channelInterpretation = "speakers"; | |
mixer_inputs[name].connect(merger, 0, index); | |
} | |
createMixerInput("main", 0); | |
createMixerInput("cue", 1); | |
var sources = {} | |
function downloadAudio(name){ | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', '' + name + '.mp3', true); | |
xhr.responseType = 'arraybuffer'; | |
xhr.onload = function(e) { | |
ctx.decodeAudioData(this.response, function(data){ | |
sources[name] = ctx.createBufferSource(); | |
sources[name].buffer = data; | |
sources[name].loop = true; | |
sources[name].connect(mixer_inputs[name]); | |
}); | |
}; | |
xhr.send(); | |
} | |
downloadAudio("main"); | |
downloadAudio("cue"); | |
$("button").click(function(){ | |
sources[$(this).attr("id")].start(0); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment