note-to-frequency
Version:
🎼 converts a note (scientific pitch notation) to a frequency
27 lines (22 loc) • 846 B
JavaScript
import validateNote from 'validate-note';
import getPosition from './lib/getPosition';
export default (function (note) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$base = _ref.base,
base = _ref$base === undefined ? 440 : _ref$base,
_ref$maxOctave = _ref.maxOctave,
maxOctave = _ref$maxOctave === undefined ? 8 : _ref$maxOctave;
var _validateNote = validateNote(note, {
flatToSharp: true,
maxOctave: maxOctave,
octave: true
}),
letter = _validateNote.letter,
octave = _validateNote.octave,
signature = _validateNote.signature;
var pos = getPosition(letter, octave, signature);
var basePos = getPosition('A', 4);
var diff = pos - basePos;
var a = Math.pow(2, 1 / 12);
return Math.round(base * Math.pow(a, diff) * 100) / 100;
});