Skip to content

Commit 1054df2

Browse files
committed
adding tests and formatting
1 parent 14c94b3 commit 1054df2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

mir_eval/sonify.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ def time_frequency(
116116

117117
# Default value for length
118118
if length is None:
119-
length = int(times[-1, 1] * fs)
119+
length = int(np.max(times) * fs)
120120

121121
last_time_in_secs = float(length) / fs
122122

123123
if time_converted and times.shape[0] != gram.shape[1]:
124-
times = np.vstack((times, [times[-1, 1], last_time_in_secs]))
124+
times = np.vstack((times, [np.max(times), last_time_in_secs]))
125125

126126
if times.shape[0] != gram.shape[1]:
127127
raise ValueError(

tests/test_sonify.py

+22
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ def test_time_frequency(fs):
5050
assert len(signal) == 5 * fs
5151

5252

53+
def test_time_frequency_const():
54+
55+
# Sonify with a single interval to hit the const interpolator
56+
s1 = mir_eval.sonify.time_frequency(
57+
np.ones((1, 1)),
58+
np.array([60]),
59+
np.array([[0, 1]]),
60+
8000,
61+
)
62+
# Sonify with two tiem intervals to hit the regular interpolator
63+
# but the second frequency will have no energy, so it doesn't
64+
# change the resulting signal
65+
s2 = mir_eval.sonify.time_frequency(
66+
np.array([[1, 1], [0, 0]]),
67+
np.array([60, 90]),
68+
np.array([[0, 1], [0, 1]]),
69+
8000,
70+
)
71+
72+
assert np.allclose(s1, s2)
73+
74+
5375
def test_time_frequency_offset():
5476
fs = 8000
5577
# Length is 3 seconds, first interval starts at 5.

0 commit comments

Comments
 (0)