JSFiddle - React, Tailwind, and code Playground
by Ehsan Ziya
JavaScript
function mtof(m) {
return Math.pow(2, (m - 69) / 12) * 440;
}
mtof(68);
var notes = {
"c": 0,
"c#": 1,
"db": 1,
"d": 2,
"d#": 3,
"eb": 3,
"e": 4,
"f": 5,
"f#": 6,
"gb": 6,
"g": 7,
"g#": 8,
"ab": 8,
"a": 9,
"a#": 10,
"bb": 10,
"b": 11
};
function ntof(n) {
var split = n.split(/(\d+)/);
var note = notes[split[0].toLowerCase()];
var octave = parseInt(split[1], 10);
return mtof(note + octave * 12 + 12);
}
ntof('a#2');