-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify parsing from OHE to real values
- Loading branch information
1 parent
d4967d4
commit 032b6e2
Showing
5 changed files
with
96 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import math | ||
|
||
|
||
def note_to_freq(note_idx: int) -> float: | ||
""" | ||
Converts MIDI note index into its corresponding tone frequency. | ||
f_n = 2^(n/12)*440 | Reference: https://newt.phys.unsw.edu.au/jw/notes.html | ||
:param note_idx: MIDI note index. | ||
:return: Note frequency in Hz | ||
""" | ||
return math.pow(2, (note_idx - 69) / 12) * 440 | ||
|
||
|
||
def freq_to_note(note_freq: float) -> int: | ||
""" | ||
Converts note frequency into its corresponding MIDI tone index. | ||
f_n = 2^(n/12)*440 | Reference: https://newt.phys.unsw.edu.au/jw/notes.html | ||
:param note_freq: Note frequency in Hz. | ||
:return: MIDI note index. | ||
""" | ||
if note_freq > 0: | ||
return int(12 * math.log2(note_freq / 440)) + 69 | ||
else: | ||
return 0 |