π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Persist state between plugin renders if reset=False.
Peter Sobot206641b00894
diff --git a/pedalboard/ExternalPlugin.h b/pedalboard/ExternalPlugin.hindex b79c34f..cd6af3b 100644--- a/pedalboard/ExternalPlugin.h+++ b/pedalboard/ExternalPlugin.h@@ -222,6 +222,13 @@ public:pluginInstance->setStateInformation(savedState.getData(),savedState.getSize());++ const juce::dsp::ProcessSpec _lastSpec = lastSpec;++ // Invalidate lastSpec to force us to update the plugin state:+ lastSpec.numChannels = 0;+ prepare(_lastSpec);+pluginInstance->reset();}@@ -293,7 +300,7 @@ public:if (pluginInstance) {if (lastSpec.sampleRate != spec.sampleRate ||lastSpec.maximumBlockSize != spec.maximumBlockSize ||- spec.numChannels != lastSpec.numChannels) {+ lastSpec.numChannels != spec.numChannels) {setNumChannels(spec.numChannels);pluginInstance->setRateAndBufferSizeDetails(spec.sampleRate,spec.maximumBlockSize);diff --git a/pedalboard/Plugin.h b/pedalboard/Plugin.hindex 6392300..e9ce6f8 100644--- a/pedalboard/Plugin.h+++ b/pedalboard/Plugin.h@@ -41,6 +41,6 @@ public:std::mutex mutex;protected:- juce::dsp::ProcessSpec lastSpec;+ juce::dsp::ProcessSpec lastSpec = {0};};} // namespace Pedalboard\ No newline at end of filediff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.pyindex b2291fa..d308b38 100644--- a/tests/test_external_plugins.py+++ b/tests/test_external_plugins.py@@ -312,10 +312,10 @@ def test_plugin_state_cleared_between_invocations(plugin_filename: str):plugin = load_test_plugin(plugin_filename)sr = 44100noise = np.random.rand(sr)- slience = np.zeros_like(noise)+ silence = np.zeros_like(noise)- # Passing zero inputs should return- effected_silence = plugin(slience, sr)+ # Passing zero inputs should return silence+ effected_silence = plugin(silence, sr)plugin_noise_floor = np.amax(np.abs(effected_silence))effected = plugin(noise, sr)@@ -323,7 +323,26 @@ def test_plugin_state_cleared_between_invocations(plugin_filename: str):# Calling plugin again shouldn't allow any audio tails# to carry over from previous calls.- assert np.allclose(plugin(slience, sr), effected_silence)+ assert np.allclose(plugin(silence, sr), effected_silence)++[email protected]("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)+def test_plugin_state_not_cleared_between_invocations(plugin_filename: str):+ plugin = load_test_plugin(plugin_filename)+ sr = 44100+ noise = np.random.rand(sr)+ silence = np.zeros_like(noise)++ # Passing zero inputs should return silence+ effected_silence = plugin(silence, sr, reset=False)+ plugin_noise_floor = np.amax(np.abs(effected_silence))++ effected = plugin(noise, sr, reset=False)+ assert np.amax(np.abs(effected)) > plugin_noise_floor * 10++ # Calling plugin again shouldn't allow any audio tails+ # to carry over from previous calls.+ assert np.allclose(plugin(silence, sr), effected_silence)@pytest.mark.parametrize("value", (True, False))diff --git a/tests/test_native_module.py b/tests/test_native_module.pyindex 952ff18..9b02744 100644--- a/tests/test_native_module.py+++ b/tests/test_native_module.py@@ -18,7 +18,7 @@import osimport pytestimport numpy as np-from pedalboard import process, Distortion, Gain, Compressor, Convolution+from pedalboard import process, Distortion, Gain, Compressor, Convolution, ReverbIMPULSE_RESPONSE_PATH = os.path.join(os.path.dirname(__file__), "impulse_response.wav")@@ -89,3 +89,30 @@ def test_distortion(gain_db, shape, sr=44100):np.testing.assert_equal(result.shape, full_scale_noise.shape)gain_scale = np.power(10.0, 0.05 * gain_db)np.testing.assert_allclose(np.tanh(full_scale_noise * gain_scale), result, rtol=4e-7, atol=2e-7)++[email protected]("reset", (True, False))+def test_plugin_state_not_cleared_between_invocations(reset: bool):+ """+ Ensure that if `reset` is True, we do reset the plugin state+ (i.e.: we cut off reverb tails). If `reset` is False, plugin+ state should be maintained between calls to `render`+ (preserving tails).+ """+ reverb = Reverb()+ sr = 44100+ noise = np.random.rand(sr)+ silence = np.zeros_like(noise)++ # Assert that reverb adds nothing if no signal was present already:+ assert np.amax(np.abs(reverb(silence, sr, reset=reset))) == 0.0++ # Pass in noise followed by silence:+ reverb(noise, sr, reset=reset)+ effected_silence = reverb(silence, sr, reset=reset)+ effected_silence_noise_floor = np.amax(np.abs(effected_silence))++ if reset:+ assert effected_silence_noise_floor == 0.0+ else:+ assert effected_silence_noise_floor > 0.25