Skip to content

@substack /wave.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
wave loops
var baudio = require('baudio');
var tau = Math.PI * 2;
var b = baudio(function (t) {
if (t > 30) return b.end();
return beep(t) * 0.25 + boop(t) * 0.25 + wub(t) * 0.5;
});
b.record('400.ogg');
function beep (t) {
var riff = [ 1, 2/3, 0, 0, 2/3, 1, 0, 0 ];
var note = riff[Math.floor(t % riff.length)];
if (note === 0) return 0;
if (t % 0.5 > 0.25) return 0;
return Math.sin(tau * t * 200 * Math.pow(2, note / 12)) * 0.05
+ Math.sin(tau * t * 400 * Math.pow(2, note / 12)) * 0.01
+ Math.sin(tau * t * 6400 * Math.pow(2, note / 12)) * 0.0625
;
}
function boop (t) {
var riff = [ 1, 3 / 2, 5 / 4, 0, 6 / 5, 3 / 2, 5 / 3, 0 ];
var note = riff[Math.floor(t % riff.length)];
if (note === 0) return 0;
return Math.sin(tau * t * 6400 * note) * 0.125
* Math.sin(tau * t * 8)
;
}
function wub (t) {
var x = Math.sin(tau * t * 80);
var y = Math.sin(tau * t * 85);
var n = [ 12, 3 ][Math.floor(t / 4 % 2)];
return (x + y) / 2 * Math.sqrt(Math.sin(t * tau * (t % 4 < 3 ? 2 : n)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.