Skip to content

Instantly share code, notes, and snippets.

@devongovett
Created September 26, 2012 18:38
Show Gist options
  • Save devongovett/3789735 to your computer and use it in GitHub Desktop.
Save devongovett/3789735 to your computer and use it in GitHub Desktop.
<!doctype html>
<script>
function pause() {
console.log('pause')
node.disconnect()
}
function play() {
console.log('play');
context = new webkitAudioContext();
node = context.createJavaScriptNode(4096, 2, 2);
var freq = context.sampleRate / (440 * 2 * Math.PI);
var x = 0;
node.onaudioprocess = function(e) {
console.log('process')
var data = e.outputBuffer.getChannelData(0);
for (var i = 0; i < data.length; ++i) {
data[i] = Math.sin(x++ / freq);
}
}
node.connect(context.destination);
}
</script>
<button onclick="play()">Play</button>
<button onclick="pause()">Pause</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment