Repository: craffel/mir_eval

Issue:
sonify.chroma and sonify.chords should pass **kwargs to time_frequency
So that `length` and `function` can be set.

Discussion:

Patch:
diff --git a/mir_eval/sonify.py b/mir_eval/sonify.py
index 23703e3..66a8319 100644
--- a/mir_eval/sonify.py
+++ b/mir_eval/sonify.py
@@ -125,7 +125,7 @@ def time_frequency(gram, frequencies, times, fs, function=np.sin, length=None):
     return output
 
 
-def chroma(chromagram, times, fs):
+def chroma(chromagram, times, fs, **kwargs):
     """Reverse synthesis of a chromagram (semitone matrix)
 
     Parameters
@@ -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
     -------
@@ -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
@@ -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
     -------
@@ -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)


Test patch:
diff --git a/tests/test_sonify.py b/tests/test_sonify.py
index 03a2ec4..a1975c9 100644
--- a/tests/test_sonify.py
+++ b/tests/test_sonify.py
@@ -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():
@@ -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