Created
August 11, 2014 14:27
-
-
Save khoin/5c0ea68ddb167de99bdf to your computer and use it in GitHub Desktop.
Revisions
-
khoin created this gist
Aug 11, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ /*! * * potasmic - afternoon walk (remix) * */ var transpose = 2; var bpm = 314; // Beats per minute var spb = 60/bpm; // Second per beat function note(n, octave){ n += transpose; return Math.pow(2, (n - 33 + (12 * (octave || 0))) / 12) * 440; } var melodies = [ [note(3,2), note(7,2), note(10,2), note(2,3), note(3,3), note(7,3), note(3,3), note(2,3)], [note(0,2), note(3,2), note(7,2), note(10,2), note(0,3), note(7,2), note(3,2), note(7,2)], [note(8,1), note(0,2), note(3,2), note(7,2), note(8,2), note(7,2), note(8,2), note(7,2)], [note(5,1), note(10,2), note(2,2), note(5,2), note(10,3), note(2,3), note(5,3), note(2,3)] ]; var bassline = [ [note(3,1),note(3,1),note(3,1),note(3,1),note(3,1),note(3,1),note(3,1),note(2,1)], [note(0,1),note(0,1),note(0,1),note(0,1),note(0,1),note(0,1),note(0,1),note(-2,1)], [note(8,0),note(8,0),note(8,0),note(8,0),note(8,0),note(8,0),note(8,0),note(7,0)], [note(5,0),note(5,0),note(5,0),note(5,0),note(8,0),note(5,0),note(8,0),note(2,1)] ]; var counter; function dsp(t) { counter = Math.floor(t/spb); return sin(t,melodies[Math.floor(counter/16)%4][counter%8],0.11) + sin(t,bassline[Math.floor(counter/16)%4][counter%8],0.11) ; } function sin(t,f,a) { return a * Math.sin(2 * Math.PI * (t%(spb/23.46)) * f * Math.sqrt(0.2) * (counter%4) >> 64 ) ; }