Skip to content

πŸŽ› πŸ”Š A Python library for audio.

Prevent the reverb tail from being cleared if a smaller buffer is passed.

Peter Sobot5edc22e637ca
diff --git a/pedalboard/ExternalPlugin.h b/pedalboard/ExternalPlugin.h
index 06eebbe..83841ef 100644
--- a/pedalboard/ExternalPlugin.h
+++ b/pedalboard/ExternalPlugin.h
@@ -299,7 +299,7 @@ public:
void prepare(const juce::dsp::ProcessSpec &spec) override {
if (pluginInstance) {
if (lastSpec.sampleRate != spec.sampleRate ||
- lastSpec.maximumBlockSize != spec.maximumBlockSize ||
+ lastSpec.maximumBlockSize < spec.maximumBlockSize ||
lastSpec.numChannels != spec.numChannels) {
setNumChannels(spec.numChannels);
pluginInstance->setRateAndBufferSizeDetails(spec.sampleRate,
diff --git a/pedalboard/JucePlugin.h b/pedalboard/JucePlugin.h
index dae52aa..6fad019 100644
--- a/pedalboard/JucePlugin.h
+++ b/pedalboard/JucePlugin.h
@@ -51,7 +51,7 @@ public:
void prepare(const juce::dsp::ProcessSpec &spec) override {
if (lastSpec.sampleRate != spec.sampleRate ||
- lastSpec.maximumBlockSize != spec.maximumBlockSize ||
+ lastSpec.maximumBlockSize < spec.maximumBlockSize ||
spec.numChannels != lastSpec.numChannels) {
dspBlock.prepare(spec);
lastSpec = spec;
diff --git a/tests/test_native_module.py b/tests/test_native_module.py
index 9b02744..4df3863 100644
--- a/tests/test_native_module.py
+++ b/tests/test_native_module.py
@@ -116,3 +116,24 @@ def test_plugin_state_not_cleared_between_invocations(reset: bool):
assert effected_silence_noise_floor == 0.0
else:
assert effected_silence_noise_floor > 0.25
+
+
+def test_plugin_state_not_cleared_if_passed_smaller_buffer():
+ """
+ Ensure that if `reset` is False, a smaller buffer size can be
+ passed without clearing the plugin's internal state:
+ """
+ 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=False))) == 0.0
+
+ # Pass in noise followed by silence, but less silence:
+ reverb(noise, sr, reset=False)
+ effected_silence = reverb(silence[: int(len(silence) / 2)], sr, reset=False)
+ effected_silence_noise_floor = np.amax(np.abs(effected_silence))
+
+ assert effected_silence_noise_floor > 0.25