Created
May 7, 2013 04:49
-
-
Save srikumarks/5530312 to your computer and use it in GitHub Desktop.
Fixed multi-channel sine wave test of Web Audio API glitching.
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> | |
<body> | |
<script> | |
var N = 1; | |
try { | |
var ctx = new AudioContext(); | |
} catch (e) { | |
ctx = new webkitAudioContext(); | |
} | |
var ctr = [0,0]; | |
for (var i = 0; i < N; ++i) { | |
var sp = ctx.createScriptProcessor(1024*4); | |
sp.connect(ctx.destination); | |
sp.onaudioprocess = function(e) { | |
for (var i = 0; i < e.outputBuffer.numberOfChannels; ++i) { | |
var ctr_channel = ctr[i]; | |
for (var j = 0; j < e.outputBuffer.getChannelData(i).length; ++j) { | |
e.outputBuffer.getChannelData(i)[j] = Math.sin((ctr_channel++/ctx.sampleRate)*Math.PI*2*3000); | |
} | |
ctr[i] = ctr_channel; | |
} | |
}; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment