Skip to content

Commit

Permalink
pitch_hz sonification via mir_eval pitch_contour
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Aug 29, 2016
1 parent 273c2b2 commit 0090d6e
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions jams/sonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def chord(annotation, sr=22050, length=None, **kwargs):


def pitch_hz(annotation, sr=22050, length=None, **kwargs):
'''Sonify pitches in Hz'''
'''Sonify pitch contours in Hz'''

intervals, pitches = annotation.data.to_interval_values()

Expand All @@ -70,21 +70,9 @@ def pitch_hz(annotation, sr=22050, length=None, **kwargs):
intervals = intervals[good_idx]
pitches = pitches[good_idx]

# Collapse down to a unique set of frequency values
freqs = np.unique(pitches)

if freqs.size == 0:
# We have no usable data. Return an empty signal
return np.zeros(length)

# Build the piano roll
pitch_index = {p: i for i, p in enumerate(freqs)}
gram = np.zeros((len(freqs), len(pitches)))
for t, n in enumerate(pitches):
gram[pitch_index[n], t] = 1.0

return filter_kwargs(mir_eval.sonify.time_frequency,
gram, freqs, intervals,
# Sonify
return filter_kwargs(mir_eval.sonify.pitch_contour,
intervals[:, 0], pitches,
fs=sr, length=length,
**kwargs)

Expand Down

0 comments on commit 0090d6e

Please sign in to comment.