Create a gist now

Instantly share code, notes, and snippets.

Embed
<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