Created
September 18, 2014 03:55
-
-
Save bsmithgall/2526e4a2fa5b7ca13d38 to your computer and use it in GitHub Desktop.
Wavepot (wavepot.com) WIP
This file contains hidden or 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
var bpm = 240; // beats per minute | |
var spb = 60/bpm; // seconds per beat | |
// gets note `n` frequency of `octave` | |
function note(n, octave){ | |
n += 2; | |
return Math.pow(2, (n - 33 + (12 * (octave || 0))) / 12) * 440; | |
} | |
// random noise | |
function Noise() { | |
return Math.random() * 2 - 1; | |
} | |
var noise = Noise(); | |
// simple drums from our random noise function | |
function drums(a,t) { | |
return a * (t % (1) < 1/32 ? noise 0); | |
} | |
var melody = [note(0,3), note(7,2), note(11,2), note(2,3), note(3,3), note(7,3), note(2,3), note(3,3)]; | |
var bassline = [note(3,1), note(0,1), note(-1,1), note(0,1), note(0,1), note(2,1), note(0,1), note(0,1)]; | |
function sin(a,t,f) { | |
return a * Math.sin(2 * Math.PI * t * f); | |
} | |
var counter; | |
function dsp(t) { | |
counter = Math.floor(t/spb); //How many beats have passed | |
return sin(0.11, t, melody[counter%8])// * sin(0.2, t, 4) | |
+ sin(0.11, t, bassline[counter%8]) | |
+ drums(0.11, t); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment