Skip to content

Commit

Permalink
Include note name in estimated pitch label.
Browse files Browse the repository at this point in the history
e.g. it might show "440Hz (A4)"
This should fulfill tlecomte#234
  • Loading branch information
celeste-sinead committed Mar 8, 2024
1 parent a407c59 commit 416ae7c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions friture/spectrumPlotWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ def set_baseline_displayUnits(self, baseline):
def set_baseline_dataUnits(self, baseline):
self._baseline = Baseline.DATA_ZERO



def freq_to_note(freq: float) -> str:
# number of semitones from C4
# A4 = 440Hz and is 9 semitones above C4
semitone = round(np.log2(freq/440) * 12) + 9
# now, from C4
semitone += 9
octave = int(np.floor(semitone / 12)) + 4
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
return f'{notes[semitone % 12]}{octave}'

def setdata(self, x, y, fmax, fpitch):
if not self.paused:
if fmax < 2e2:
Expand Down

0 comments on commit 416ae7c

Please sign in to comment.