Skip to content

Instantly share code, notes, and snippets.

@owenkellogg
Created November 11, 2014 06:29
Show Gist options
  • Save owenkellogg/46a22272e6328a8a2716 to your computer and use it in GitHub Desktop.
Save owenkellogg/46a22272e6328a8a2716 to your computer and use it in GitHub Desktop.
<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