Created
March 25, 2015 07:42
-
-
Save anonymous/af8de449478565f3c2b2 to your computer and use it in GitHub Desktop.
Splitter Node Removes Pan
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
<!DOCTYPE html> | |
<head> | |
<title>Why doesn't splitter node recognize the pan?</title> | |
</head> | |
<body> | |
<script> | |
var audioContext = new (window.AudioContext || | |
window.webkitAudioContext)(); | |
// Pans and plays a sound. | |
function panAndPlay(source) { | |
// Specify a pan. | |
var panner = audioContext.createPanner(); | |
panner.panningModel = 'equalpower'; | |
panner.setPosition(1, 0, 0); | |
// Create a splitter node that is supposed to split by channel. | |
var splitter = audioContext.createChannelSplitter(); | |
// Create the audio graph: source -> panner -> splitter -> destination | |
source.connect(panner); | |
panner.connect(splitter); | |
// Try to hook up both channels outputted by the splitter to destination. | |
splitter.connect(audioContext.destination, 0); | |
splitter.connect(audioContext.destination, 1); | |
// The splitter seems to ignore the pan: You hear the pan effect if you | |
// bypass the splitter by directly connecting the panner to the | |
// destination. Why does the splitter remove the pan effect? I want to use | |
// a splitter so that I can hook up an analyzer node to each channel, but | |
// I also want the pan effect ... | |
// Start playing sound. | |
source.start(0); | |
}; | |
// Load an mp3. I got the public domain mp3 from | |
// http://soundbible.com/871-Chicken.html | |
// but any sound suffices for this example. | |
request = new XMLHttpRequest(); | |
request.open('GET', 'chickens.mp3', true); | |
request.responseType = 'arraybuffer'; | |
request.onload = function() { | |
var audioData = request.response; | |
audioContext.decodeAudioData(audioData, | |
function(buffer) { | |
var source = audioContext.createBufferSource(); | |
source.buffer = buffer; | |
panAndPlay(source); | |
}, function(e) { | |
"Error decoding: " + String(e); | |
} | |
); | |
} | |
request.send(); | |
</script> | |
<p>If working correctly, the chicken sound should be panned right.</p> | |
<p>The free mp3 is from | |
<a href='http://soundbible.com/871-Chicken.html'> | |
http://soundbible.com/871-Chicken.html | |
</a> | |
</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment