Created
September 26, 2012 18:38
-
-
Save devongovett/3789735 to your computer and use it in GitHub Desktop.
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> | |
<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