Skip to content

Instantly share code, notes, and snippets.

@matt-in-a-hat
Created February 27, 2015 01:13
Show Gist options
  • Save matt-in-a-hat/52abaf1d213bc4506ddc to your computer and use it in GitHub Desktop.
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
// 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