Skip to content

Instantly share code, notes, and snippets.

View brookjordan's full-sized avatar

Brook Jordan brookjordan

View GitHub Profile
@brookjordan
brookjordan / noteFrequency.js
Last active October 27, 2022 03:05
Get the wavelength of a note in the Chromatic scale
function noteFrequency(offset) {
// A4 has a defined, integer frequency. Let's use this as the base for calculations
const A4Frequency = 440;
// Allows:
// - multiple flats and sharps in any order
// - usage of '♭' or lowercase 'B' as flat
const noteRegExp = /^([a-gA-G])([♭b♯#]*)(-?\d+)?$/;
const semitoneMultiplier = 2 ** (1/12);
const scaleNoteCount = 12;
// Pre calculate offsets of each note from A