Created
February 27, 2015 01:13
-
-
Save matt-in-a-hat/52abaf1d213bc4506ddc to your computer and use it in GitHub Desktop.
A very crude Darude - Sandstorm for Substack's http://studio.substack.net
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
// Darude - Sandstorm | |
// For http://studio.substack.net/ | |
return function (t) { | |
function sin (x) { return Math.sin(2 * Math.PI * t * x) } | |
var b = 0.25; | |
var beatFn = t % 1 < b*3 ? fastBeep : sustainedBeep | |
var pitch | |
var pitchChunk = t % (32*b) | |
if (pitchChunk >= 0 && pitchChunk < 0.25) { | |
pitch = 800 | |
beatFn = sustainedBeep | |
} else if (pitchChunk >= 4 && pitchChunk < 4.25) { | |
beatFn = sustainedBeep | |
pitch = 500 | |
} else if (pitchChunk < 2) { | |
pitch = 600 | |
} else if (pitchChunk < 3) { | |
pitch = 800 | |
} else if (pitchChunk < 4) { | |
pitch = 700 | |
} else if (pitchChunk >= 6 && pitchChunk < 6.25) { | |
pitch = 800 | |
beatFn = sustainedBeep | |
} else { | |
pitch = 600 | |
} | |
function fastBeep() { | |
var tb = t % b | |
return tb < b/4 || (tb >= b/2 && tb < 3*b/4) ? sin(pitch) : 0 | |
} | |
function sustainedBeep() { | |
return t % b < 3*b/5 ? sin(pitch) : 0 | |
} | |
return beatFn(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment