From 1dd25d7451b77a43b3ad2a5b7f1f140315177481 Mon Sep 17 00:00:00 2001 From: Peter Sobot Date: Wed, 26 Jan 2022 13:51:56 -0500 Subject: [PATCH 1/3] Support external plugins with latency greater than a single buffer. --- pedalboard/ExternalPlugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pedalboard/ExternalPlugin.h b/pedalboard/ExternalPlugin.h index 6394deea..606c9f2a 100644 --- a/pedalboard/ExternalPlugin.h +++ b/pedalboard/ExternalPlugin.h @@ -620,7 +620,7 @@ template class ExternalPlugin : public Plugin { // To compensate for any latency added by the plugin, // only tell Pedalboard to use the last _n_ samples. long usableSamplesProduced = - samplesProvided - pluginInstance->getLatencySamples(); + std::max(0L, samplesProvided - pluginInstance->getLatencySamples()); return static_cast( std::min(usableSamplesProduced, (long)outputBlock.getNumSamples())); } From 2ddcffa6f2a94e9af4d2640199960f321c6d4ade Mon Sep 17 00:00:00 2001 From: Peter Sobot Date: Wed, 26 Jan 2022 14:08:38 -0500 Subject: [PATCH 2/3] Add test for negative sample counts being returned by external plugins. --- pedalboard/process.h | 6 ++++++ tests/test_external_plugins.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pedalboard/process.h b/pedalboard/process.h index c34e9aa2..56830aa9 100644 --- a/pedalboard/process.h +++ b/pedalboard/process.h @@ -317,6 +317,12 @@ process(const py::array_t inputArray, juce::dsp::ProcessContextReplacing context(ioBlock); int outputSamples = plugin->process(context); + if (outputSamples < 0) { + throw std::runtime_error( + "A plugin returned a negative number of output samples! " + "This is an internal Pedalboard error and should be reported." + ); + } pluginSamplesReceived += outputSamples; int missingSamples = blockSize - outputSamples; diff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.py index 6b7bd426..5cf66d56 100644 --- a/tests/test_external_plugins.py +++ b/tests/test_external_plugins.py @@ -603,7 +603,7 @@ def test_parameter_name_normalization(_input: str, expected: str): @pytest.mark.skipif(not plugin_named("CHOWTapeModel"), reason="Missing CHOWTapeModel plugin.") -@pytest.mark.parametrize("buffer_size", [128, 8192, 65536]) +@pytest.mark.parametrize("buffer_size", [16, 128, 8192, 65536]) @pytest.mark.parametrize("oversampling", [1, 2, 4, 8, 16]) def test_external_plugin_latency_compensation(buffer_size: int, oversampling: int): """ From b8250a5c6b64cde600eed4c1cd8dda47dc92b0ba Mon Sep 17 00:00:00 2001 From: Peter Sobot Date: Thu, 27 Jan 2022 22:56:15 -0500 Subject: [PATCH 3/3] Clang-format. --- pedalboard/process.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pedalboard/process.h b/pedalboard/process.h index 56830aa9..329aab9b 100644 --- a/pedalboard/process.h +++ b/pedalboard/process.h @@ -319,9 +319,8 @@ process(const py::array_t inputArray, int outputSamples = plugin->process(context); if (outputSamples < 0) { throw std::runtime_error( - "A plugin returned a negative number of output samples! " - "This is an internal Pedalboard error and should be reported." - ); + "A plugin returned a negative number of output samples! " + "This is an internal Pedalboard error and should be reported."); } pluginSamplesReceived += outputSamples;