A coding competition
The Song of Time from The Legend of Zelda: Ocarina of Time. Instead of playing with the duration of notes, I left the algorithm be. I added sufficient entries to account for proper durations in eigth notes. Sourced from: https://musescore.com/user/2114686/scores/780466
index.js
// Song of Time entry
n = 10, rate = 44100;
f = n => Math.pow(2, (n-49)/12)*440;
song = [61,61,54,54,54,54,57,57,61,61,54,54,54,54,57,57,61,64,63,63,59,59,57,59,61,61,54,54,52,56,54,54,54,54,54,54,54,54,54,54];
for (i = 0; i < song.length; i++) {
var n = song[i], l = Math.round(rate / f(n));
var arr = new Array(1600);
if (n > 0) for (var x = 0; x < l; x++){
arr[x] = Math.random();
}
for (t = 0; t < 20000; t++) {
var y = arr[t % l];
process.stdout.write(Buffer.from(Float32Array.of(y).buffer));
arr[t % l] = (arr[t % l] + arr[(t + 1) % l]) / 2 * .998
}
}
JavaScript
614
Sample Rate: | 44100 Hz |
Sample Size: | 32 bits |
Channels: | 2 (stereo) |
Encoding: | floating-point |
Run
node .