Skip to content

Commit

Permalink
use mir_eval kwarg filtering on sonify functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Feb 4, 2016
1 parent 6abed2a commit 57d7e49
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions jams/sonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,34 @@
import six
import numpy as np
import mir_eval.sonify
from mir_eval.util import filter_kwargs
from .eval import validate_annotation
from .exceptions import NamespaceError

__all__ = ['sonify']



def clicks(annotation, sr=22050, length=None, **kwargs):
'''Sonify clicks timings
'''

interval, _ = annotation.data.to_interval_values()

return mir_eval.sonify.clicks(interval[:, 0], fs=sr, length=length, **kwargs)
return filter_kwargs(mir_eval.sonify.clicks, interval[:, 0],
fs=sr, length=length, **kwargs)


def chord(annotation, sr=22050, length=None, **kwargs):
'''Sonify chords'''

intervals, chords = annotation.data.to_interval_values()

return mir_eval.sonify.chords(chords, intervals, fs=sr, length=length, **kwargs)
return filter_kwargs(mir_eval.sonify.chords,
chords, intervals,
fs=sr, length=length,
**kwargs)


def pitch_midi(annotation, sr=22050, length=None, **kwargs):
Expand All @@ -49,8 +55,21 @@ def pitch_midi(annotation, sr=22050, length=None, **kwargs):
for t, n in enumerate(notes):
gram[n, t] = 1.0

return mir_eval.sonify.time_frequency(gram, freqs, intervals[:, 0],
fs=sr, length=length, **kwargs)
# Compress for efficiency
idx = gram.max(axis=1) > 0

gram = gram[idx]
freqs = freqs[idx]

return filter_kwargs(mir_eval.sonify.time_frequency,
gram, freqs, intervals,
fs=sr, length=length,
**kwargs)


SONIFY_MAPPING = {'beat.*|segment.*|onset.*': clicks,
'chord|chord_harte': chord,
'pitch_midi': pitch_midi}


def sonify(annotation, sr=22050, duration=None, **kwargs):
Expand Down Expand Up @@ -81,9 +100,6 @@ def sonify(annotation, sr=22050, duration=None, **kwargs):
If the annotation has an un-sonifiable namespace
'''

SONIFY_MAPPING = {'beat.*|segment.*|onset.*': clicks,
'chord|chord_harte': chord,
'pitch_midi': pitch_midi}
length = None
if duration is not None:
length = int(duration * sr)
Expand Down

0 comments on commit 57d7e49

Please sign in to comment.