Skip to content

Instantly share code, notes, and snippets.

@khoin
Created August 11, 2014 14:27
Show Gist options
  • Select an option

  • Save khoin/5c0ea68ddb167de99bdf to your computer and use it in GitHub Desktop.

Select an option

Save khoin/5c0ea68ddb167de99bdf to your computer and use it in GitHub Desktop.

Revisions

  1. khoin created this gist Aug 11, 2014.
    43 changes: 43 additions & 0 deletions gistfile1.js
    Original 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 ) ;
    }