Created
June 24, 2014 20:53
-
-
Save wylkon/82f9151f6722402fe1ae to your computer and use it in GitHub Desktop.
Little Music
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
| /*! | |
| * | |
| * potasmic - Testing | |
| * | |
| */ | |
| var transpose = 2; | |
| var bpm = 125; | |
| var spb = 30/bpm; // Second per beat | |
| var tuning = 440; | |
| var transpose = -1; | |
| // constants | |
| var tau = 2 * Math.PI; | |
| // time coefficients | |
| var t; | |
| function clock(_t){ | |
| t = _t; | |
| t *= bpm / 120; | |
| } | |
| function arp(measure, x, y, z){ | |
| var ts = t / 2 % measure; | |
| return Math.sin(x * (Math.exp(-ts * y))) * Math.exp(-ts * z); | |
| } | |
| 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) { | |
| clock(t); | |
| var superKick = arp(1/4, 48, 10, 8); | |
| var MegaKick = arp(1/4, 48, 20, 8); | |
| var kick = arp(1/4, 48, 50, 8); | |
| counter = Math.floor(t/spb); //How many beats have passed | |
| return sqr(t,melodies[Math.floor(counter/16)%4][counter%8],0.11) | |
| + sqr(t,bassline[Math.floor(counter/16)%4][counter%8],0.11) | |
| + superKick | |
| + MegaKick | |
| + MegaKick | |
| + MegaKick | |
| + kick; //Changes note every 8beat, alter chord every 16 beats | |
| } | |
| function sin(t,f,a) { | |
| return a * Math.sin( 1 * Math.PI * t * f); | |
| } | |
| function sqr(t,f,a) { | |
| return ((sin(t,f,a)>0) *2-1) *a; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment