Skip to content

Instantly share code, notes, and snippets.

@srikumarks
Created May 7, 2013 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srikumarks/5530312 to your computer and use it in GitHub Desktop.
Save srikumarks/5530312 to your computer and use it in GitHub Desktop.
Fixed multi-channel sine wave test of Web Audio API glitching.
<!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