Skip to content

Commit

Permalink
Merge pull request mir-evaluation#157 from craffel/sonify_kwargs
Browse files Browse the repository at this point in the history
Pass **kwargs from sonify.chroma and sonify.chords to sonify.time_frequency
  • Loading branch information
craffel committed Nov 10, 2015
2 parents 4a35625 + 81a3bfb commit 536d0fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mir_eval/sonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _fast_synthesize(frequency):
return output


def chroma(chromagram, times, fs):
def chroma(chromagram, times, fs, **kwargs):
"""Reverse synthesis of a chromagram (semitone matrix)
Parameters
Expand All @@ -138,6 +138,9 @@ def chroma(chromagram, times, fs):
The start time of each column in the chromagram
fs : int
Sampling rate to synthesize audio data at
kwargs
Additional keyword arguments to pass to
:func:`mir_eval.sonify.time_frequency`
Returns
-------
Expand Down Expand Up @@ -165,10 +168,10 @@ def chroma(chromagram, times, fs):
gram *= shepard_weight.reshape(-1, 1)
# Compute frequencies
frequencies = 440.0*(2.0**((notes - 69)/12.0))
return time_frequency(gram, frequencies, times, fs)
return time_frequency(gram, frequencies, times, fs, **kwargs)


def chords(chord_labels, intervals, fs):
def chords(chord_labels, intervals, fs, **kwargs):
"""Synthesizes chord labels
Parameters
Expand All @@ -179,6 +182,9 @@ def chords(chord_labels, intervals, fs):
Start and end times of each chord label
fs : int
Sampling rate to synthesize at
kwargs
Additional keyword arguments to pass to
:func:`mir_eval.sonify.time_frequency`
Returns
-------
Expand All @@ -200,4 +206,4 @@ def chords(chord_labels, intervals, fs):
chromagram = np.array([np.roll(interval_bitmap, root)
for (interval_bitmap, root)
in zip(interval_bitmaps, roots)]).T
return chroma(chromagram, times, fs)
return chroma(chromagram, times, fs, **kwargs)
8 changes: 8 additions & 0 deletions tests/test_sonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def test_chroma():
np.random.standard_normal((12, 1000)),
np.linspace(0, 10, 1000), fs)
assert len(signal) == 10*fs
signal = mir_eval.sonify.chroma(
np.random.standard_normal((12, 1000)),
np.linspace(0, 10, 1000), fs, length=fs*11)
assert len(signal) == 11*fs


def test_chords():
Expand All @@ -45,3 +49,7 @@ def test_chords():
['C', 'C:maj', 'D:min7', 'E:min', 'C#', 'C', 'C', 'C', 'C', 'C'],
intervals, fs)
assert len(signal) == 10*fs
signal = mir_eval.sonify.chords(
['C', 'C:maj', 'D:min7', 'E:min', 'C#', 'C', 'C', 'C', 'C', 'C'],
intervals, fs, length=fs*11)
assert len(signal) == 11*fs

0 comments on commit 536d0fb

Please sign in to comment.