Created
June 11, 2018 01:48
-
-
Save markotom/2e676960f1162c043c39efa9049327d3 to your computer and use it in GitHub Desktop.
Baudio Experiment
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
let c3 = 130.81 | |
let c4 = 261.63 | |
let e3 = 164.81 | |
let e4 = 329.628 | |
let b2 = 123.47 | |
let b4 = 493.88 | |
let melody1 = [c3, e3, b2, c3] | |
let melody2 = [e4, e4, b4, c4] | |
let melody3 = [[e4, 3], [e4, 4], [b4, 2], [c4, 6]] | |
let melody4 = [c3, e3, b2] | |
const saw_ = (x, t) => t % (1 / x) * x * 1 - 1 | |
const sin_ = (x, t) => Math.sin(2 * Math.PI * t * x) | |
const tri_ = (x, t) => Math.abs(1 - t % (1 / x) * x * 2) * 2 - 1 | |
return function (t, i) { | |
t *= 40 / 60 | |
let a1 = melody1[Math.floor(t / 8) % melody1.length] | |
let a2 = melody2[Math.floor(t) % melody2.length] | |
let a3 = melody3[Math.floor(t) % melody3.length] | |
let a4 = melody4[Math.floor(t / 4) % melody4.length] | |
let saw = x => saw_(x, t) | |
let sin = x => sin_(x, t) | |
let tri = x => tri_(x, t) | |
let reverb = 0.5 | |
if (t > 64) { | |
reverb = 0 | |
} else if (t > 32 && t < 48) { | |
reverb = Math.floor(t * 2) % 12 | |
} else if (t > 24 && t < 64) { | |
reverb = Math.floor(t * 3) % 6 | |
} else if (t > 8) { | |
reverb = Math.floor(t * 3) % 3 | |
} | |
return ( | |
sin(a1) * 0.03 * (t < 80) + | |
sin(a2) * tri(reverb) * 0.05 * (t < 80) + | |
sin(a3[0]) * saw(a3[1]) * 0.1 * (t > 24 && t < 64) + | |
sin(a4) * saw(2) * 0.5 * (t / Math.pow(2.2, t * 0.1)) * (t > 80) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment