Skip to content

Commit

Permalink
Set midi messages timestamp relative to buffer start (#259)
Browse files Browse the repository at this point in the history
* Set midi messages timestamp relative to buffer start

* Add test for notes that span across buffers.

---------

Co-authored-by: Peter Sobot <psobot@spotify.com>
  • Loading branch information
DamRsn and psobot authored Oct 6, 2023
1 parent ba844a6 commit ce16742
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pedalboard/ExternalPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ class ExternalPlugin : public AbstractExternalPlugin {
channelPointers.data(), channelPointers.size(), chunkSampleCount);

juce::MidiBuffer midiChunk;
midiChunk.addEvents(midiInputBuffer, i, chunkSampleCount, 0);
midiChunk.addEvents(midiInputBuffer, i, chunkSampleCount, -i);

pluginInstance->processBlock(audioChunk, midiChunk);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/test_external_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,23 @@ def test_explicit_instrument_reset():
assert max_volume_of(plugin([], 5.0, sr, reset=False)) < 0.00001


@pytest.mark.skipif(not plugin_named("Magical8BitPlug"), reason="Missing Magical8BitPlug 2 plugin.")
@pytest.mark.parametrize("buffer_size", [1, 10, 10000])
def test_instrument_notes_span_across_buffers(buffer_size: int):
plugin = load_test_plugin(plugin_named("Magical8BitPlug"), disable_caching=True)
sr = 44100
notes = [
mido.Message("note_on", note=127, velocity=127, time=0.5),
mido.Message("note_off", note=127, velocity=127, time=1.0),
]

output = plugin(notes, duration=2, sample_rate=sr, buffer_size=buffer_size)
output /= np.amax(np.abs(output))
assert np.mean(np.abs(output[:, : int(sr * 0.5)])) < 0.001
assert np.mean(np.abs(output[:, int(sr * 0.5) : int(sr * 1)])) > 0.999
assert np.mean(np.abs(output[:, int(sr * 1) :])) < 0.001


@pytest.mark.parametrize("plugin_filename", AVAILABLE_EFFECT_PLUGINS_IN_TEST_ENVIRONMENT)
def test_explicit_reset_in_pedalboard(plugin_filename: str):
sr = 44100
Expand Down

0 comments on commit ce16742

Please sign in to comment.