Skip to content

Instantly share code, notes, and snippets.

View CGrassin's full-sized avatar

Charles Grassin CGrassin

View GitHub Profile
@CGrassin
CGrassin / note_to_freq.py
Created April 14, 2020 17:45
Convert a note + octave to its frequency.
# MIT License
# Python to convert a string note (eg. "A4") to a frequency (eg. 440).
# Inspired by https://gist.github.com/stuartmemo/3766449
def getFrequency(note, A4=440):
notes = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']
octave = int(note[2]) if len(note) == 3 else int(note[1])
keyNumber = notes.index(note[0:-1]);