Created
November 11, 2014 06:29
-
-
Save owenkellogg/46a22272e6328a8a2716 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
<body> | |
<script> | |
var ctx = new AudioContext(); | |
var tone = ctx.createOscillator(); | |
var gain = ctx.createGain(); | |
var high = 220; | |
var low = 22; | |
var boing = function(x) { | |
return (Math.exp(x) - 1) / (Math.E - 1); | |
}; | |
var now = function(period) { | |
return 0.5 * (Math.sin(Date.now() * period) + 1); | |
}; | |
gain.connect(ctx.destination); | |
tone.connect(gain); | |
setInterval(function() { | |
gain.gain.value = boing(now(0.002)); | |
}, 10); | |
tone.type = 'triangle'; | |
setInterval(function() { | |
tone.frequency.value = low + (high - low) * boing(now(0.001)); | |
}, 300); | |
tone.start(); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment