Skip to content

Commit

Permalink
Merge pull request #374 from bmcfee/fix-371
Browse files Browse the repository at this point in the history
Fix length error in sonify.time_frequency
  • Loading branch information
bmcfee authored Mar 26, 2024
2 parents 7997fdf + 4713dda commit e299244
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
11 changes: 4 additions & 7 deletions mir_eval/sonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,10 @@ def __interpolator(x):

# Create the time-varying scaling for the entire time interval by the piano roll
# magnitude and add to the accumulating waveform.
# FIXME: this logic is broken when length
# does not match the final sample interval
output += wave[:length] * gram_interpolator(
np.arange(
max(sample_intervals[0][0], 0), min(sample_intervals[-1][-1], length)
)
)
t_in = max(sample_intervals[0][0], 0)
t_out = min(sample_intervals[-1][-1], length)
signal = gram_interpolator(np.arange(t_in, t_out))
output[t_in:t_out] += wave[: len(signal)] * signal

# Normalize, but only if there's non-zero values
norm = np.abs(output).max()
Expand Down
14 changes: 12 additions & 2 deletions tests/test_sonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_time_frequency(fs):
fs,
)
assert len(signal) == 10 * fs

# Make one longer
signal = mir_eval.sonify.time_frequency(
np.random.standard_normal((100, 1000)),
np.arange(1, 101),
Expand All @@ -37,6 +39,16 @@ def test_time_frequency(fs):
)
assert len(signal) == 11 * fs

# Make one shorter
signal = mir_eval.sonify.time_frequency(
np.random.standard_normal((100, 1000)),
np.arange(1, 101),
np.linspace(0, 10, 1000),
fs,
length=fs * 5,
)
assert len(signal) == 5 * fs


@pytest.mark.parametrize("fs", [8000, 44100])
def test_chroma(fs):
Expand All @@ -54,8 +66,6 @@ def test_chroma(fs):


@pytest.mark.parametrize("fs", [8000, 44100])
# FIXME: #371
@pytest.mark.skip(reason="Skipped until #371 is fixed")
def test_chords(fs):
intervals = np.array([np.arange(10), np.arange(1, 11)]).T
signal = mir_eval.sonify.chords(
Expand Down

0 comments on commit e299244

Please sign in to comment.