Skip to content

Instantly share code, notes, and snippets.

@celber
Created November 23, 2012 10:39
Show Gist options
  • Save celber/4135045 to your computer and use it in GitHub Desktop.
Save celber/4135045 to your computer and use it in GitHub Desktop.
Wylicza fale do wav, pzoniejs ie przyda
var wav = [],
c = "g05_e05_e05_f05_d05_d05_c05_e05_g05_g05_e05_e05_f05_d05_d05_c05_e05_c05".replace(/c/g, "00").replace(/d/g, "02").replace(/e/g, "04").replace(/f/g, "06").replace(/g/g, "08").replace(/a/g, "10").replace(/h/g, "12").replace(/C/g, "01").replace(/D/g, "03").replace(/E/g, "05").replace(/F/g, "07").replace(/G/g, "09").replace(/A/g, "11").replace(/H/g, "13").split("_");
const bitrate = ~~16000, f = [262, 294, 330, 350, 392, 440, 494, 523, 555]; //ostatni element tablicy jest potrzebny do wyliczenia H;
synth = function(n, o) {
var sound = (n % 1 ? ~~ ((f[parseInt(n - 1)] - f[parseInt(n + 1)]) / 2) : f[parseInt(n)]) * (o + 1),
herz = [];
for (var i = 0; i < bitrate && (buf = ~~ (((c = Math.sin(((i < ~~ (bitrate / 2) ? (1 / bitrate) : (-1 / bitrate)) * i) * sound) / 2) < 0 ? -c : c += .5) * 65535)); ++i) {
for (var a = 4 - (byte = (buf).toString(16)).length; a > 1; --a) {
byte = "0" + byte
}
herz.push(byte)
};
return herz.join("");
}
for (var i = 0;
(i < c.length) && !! (n = c[i][0] + c[i][1], d = c[i][2], o = c[i][3]); ++i) for (d = 8 - d; d > 0; --d) wav.push(synth(n, o));
console.log(wav.join(""))
@DeyV
Copy link

DeyV commented Nov 23, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment