Last active
October 13, 2015 23:28
-
-
Save eduardonunesp/f3080d788fcce089d989 to your computer and use it in GitHub Desktop.
Split 7.1 Channels (tested in Safari 9)
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
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<script> | |
function checkForEC3Support() { | |
var video = document.createElement('video'); | |
return (video.canPlayType('audio/mp4;codecs="ec-3"') !== ''); | |
} | |
window.AudioContext = window.AudioContext || window.webkitAudioContext; | |
var context = new AudioContext(); | |
var sourceBuffer; | |
var ready = false; | |
function loadAnotherSound(url) { | |
var request = new XMLHttpRequest(); | |
request.open('GET', url, true); | |
request.responseType = 'arraybuffer'; | |
var onError = function(err) { | |
console.error('error', err); | |
} | |
// Decode asynchronously | |
request.onload = function() { | |
context.decodeAudioData(request.response, function(buffer) { | |
var source = context.createBufferSource(); | |
source.buffer = buffer; | |
var splitter = context.createChannelSplitter(buffer.numberOfChannels); | |
source.connect(splitter); | |
splitter.connect(context.destination, 0); | |
splitter.connect(context.destination, 1); | |
splitter.connect(context.destination, 2); | |
splitter.connect(context.destination, 3); | |
splitter.connect(context.destination, 4); | |
splitter.connect(context.destination, 5); | |
splitter.connect(context.destination, 6); | |
splitter.connect(context.destination, 7); | |
source.noteOn(0); | |
ready = true; | |
}, onError); | |
} | |
request.send(); | |
} | |
console.log('Check', checkForEC3Support()); | |
</script> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment