Skip to content

Instantly share code, notes, and snippets.

@hsingtism
Created May 31, 2024 01:57
Show Gist options
  • Select an option

  • Save hsingtism/5549e94b2e2865cbd0ce1a7bcd804d79 to your computer and use it in GitHub Desktop.

Select an option

Save hsingtism/5549e94b2e2865cbd0ce1a7bcd804d79 to your computer and use it in GitHub Desktop.
const noteToHz = note => 440 * 2 ** (
("C-D-EF-G-A-B".indexOf(note[0]) + (note.match(/#/g) || []).length - (note.match(/b/g) || []).length - 9) / 12
+ (Number((note.match(/\d|-/g) || ['4']).join('')) - 4)
)
noteToHz.validate = s => /^[A-G][#b]*-?\d*$/g.test(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment