Created
December 18, 2012 05:33
-
-
Save anonymous/4325336 to your computer and use it in GitHub Desktop.
beepstep baudio track
This file contains 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 baudio = require('baudio'); | |
var player = require('plucky'); | |
var b = baudio({ rate : 44100 }); | |
var tau = 2 * Math.PI; | |
b.addChannel(function (t_) { | |
if (t_ >= 32 * 4) b.end(); | |
var t = t_ % 0.5; | |
var tt = t_ * (t_ % 32 > 16 ? 2 : 1); | |
return pluck(t, 40, 32, 20) | |
+ pluck(t, 20 * Math.pow(2, 1/2), 16, 23) * 0.5 | |
+ Math.sin(tau * t * (tt % 2 < 1 ? 180 : 150)) * 0.75 | |
+ Math.sin(tau * t * (tt % 8 >= 6 ? 186 : 183)) * 0.75 | |
+ (t_ % 16 < 8 | |
? Math.sin(tau * t * 140) | |
: Math.sin(tau * t * (tt % 0.25 < 0.1 ? 0 : 380)) | |
* Math.min(tt % 0.25, Math.abs(tt % 0.25 - 0.25)) | |
/ 0.25 | |
) | |
; | |
}); | |
var music = [ | |
function (t, clip) { | |
if (t > 1) clip.go(0); | |
var notes = [ | |
0, 0, 0, 0, | |
0, 0, 0, 0, | |
100, | |
200, | |
200 * Math.pow(2,3/5), | |
0, 0, 0, 0, | |
200 * Math.pow(2,7/5), | |
200 * Math.pow(2,5/5), | |
0, 0, 0, 0, | |
200 * Math.pow(2,11/5), | |
100 * Math.pow(2,13/5), | |
0, 0, 0, 0 | |
]; | |
var ix = Math.floor(clip.t % notes.length); | |
var note = notes[ix]; | |
return Math.min(1, Math.max(-1, | |
pluck(t, note, 12, 5) / pluck(t, note + 1/8, 32, 5) | |
)) / 8; | |
} | |
]; | |
b.push(1, player(music)); | |
b.push(1, player([ | |
function (t, clip) { | |
if (t >= 1) clip.end(); | |
return Math.sin(tau * 400 * t * (t % 1 / 8 < 1 / 16)); | |
}, | |
function (t, clip) { | |
if (t >= 1) clip.go(0); | |
return Math.sin(tau * 200 * t * (t % 1 / 8 < 1 / 24)) | |
+ Math.sin(tau * 205) | |
; | |
} | |
])); | |
if (process.stdout.isTTY) b.play(); | |
else b.pipe(process.stdout); | |
function pluck (t, freq, duration, steps) { | |
var n = duration; | |
var scalar = Math.max(0, 0.95 - (t * n) / ((t * n) + 1)); | |
var sum = 0; | |
for (var i = 0; i < steps; i++) { | |
sum += Math.sin(tau * t * (freq + i * freq)); | |
} | |
return scalar * sum / 6; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ei!!!!
b.addChannel(function (t_) {
^
TypeError: Object # has no method 'addChannel'