Skip to content

Commit

Permalink
Update hz2midi to avoid log2(0) warnings
Browse files Browse the repository at this point in the history
Behavior should remain unchanged
  • Loading branch information
justinsalamon committed Apr 23, 2018
1 parent a4039f8 commit 4821cde
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions audio_to_midi_melodia.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ def hz2midi(hz):

# convert from Hz to midi note
hz_nonneg = hz.copy()
hz_nonneg[hz <= 0] = 0
idx = hz_nonneg <= 0
hz_nonneg[idx] = 1
midi = 69 + 12*np.log2(hz_nonneg/440.)
midi[midi <= 0] = 0
midi[idx] = 0

# round
midi = np.round(midi)
Expand Down

0 comments on commit 4821cde

Please sign in to comment.