Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

drome

View drome.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
var melody = [ 1, 1, 2, 2, 3/2, 3/2, 3/2, 3/2, 4, 1, 5, 5, 5, 5, 2, 2 ];
var rhythm = [ 2, 4, 2, 4, 30, 2, 20, 10, 2, 4 ];
var xrhythm = [ 8, 16, 1 ];
var phase = [ 0, 1, 0, 4, 0, 3, 1 ];
var d = snare(), e = snare();
 
return function (t) {
var m = melody[Math.floor(t * 2) % melody.length];
var r = rhythm[Math.floor(t * 2) % rhythm.length];
var q = xrhythm[Math.floor(t * 2) % xrhythm.length];
var p = t > 24 ? phase[Math.floor(t * r) % phase.length] : 1;
return synth(121*m) * (t > 8)
+ d(t % (1/r/2)) * 0.5 * (t > 4)
+ e(t % (1/q)) * 0.5
;
function synth (x) {
return saw(x) * 0.1
+ saw(x + x/m * p) * 0.25 * (t > 12)
+ sin(x*3 + saw(1/x/10)) * 0.2 * (t > 16)
+ sin(x*4 + x/m * p) * 0.1 * (t > 20)
+ sin(x*5 + 1/2) * 0.05 * (t > 24)
+ saw(x*7 + 1) * 0.1 * (t > 24)
;
}
function sin (x) { return Math.sin(2 * Math.PI * t * x) }
function saw (x) { return 1 - t % (1/x) * x * 2 }
}
 
function snare () {
var low0 = lowpass(30);
var low1 = lowpass(80);
var low2 = lowpass(20);
return function (t) {
return low0(snare(80, t))*5
+ low1(snare(40, t+1/60))*10
+ low2(snare(80, t+1/30))*5
;
function snare (n, o) {
var scalar = Math.max(0, 0.95 - (o * n) / ((o * n) + 1));
return sin(sin(sin(137)*139)*4217) * scalar;
}
function sin (x) { return Math.sin(2 * Math.PI * t * x) }
};
function lowpass (n) {
var value = 0;
return function (x) { return value += (x - value) / 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.