π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Force-reload plugins only if they persist audio across render calls.
Peter Sobot829cb340dd18
diff --git a/pedalboard/ExternalPlugin.h b/pedalboard/ExternalPlugin.hindex 83841ef..079cde7 100644--- a/pedalboard/ExternalPlugin.h+++ b/pedalboard/ExternalPlugin.h@@ -110,6 +110,29 @@ private:};#endif+enum class ExternalPluginReloadType {+ /**+ * Unknown: we need to determine the reload type.+ */+ Unknown,++ /**+ * Most plugins are of this type: calling .reset() on them will clear their internal state.+ * This is quick and easy: to start processing a new buffer, all we need to do is call+ * .reset() and optionally prepareToPlay().+ */+ ClearsAudioOnReset,++ /**+ * This plugin type is a bit more of a pain to deal with; it could be argued that plugins+ * that don't clear their internal buffers when reset() is called are buggy.+ * To start processing a new buffer, we'll have to find another way to clear the buffer,+ * usually by reloading the plugin from scratch and persisting its parameters somehow.+ */+ PersistsAudioOnReset,+};++template <typename ExternalPluginType> class ExternalPlugin : public Plugin {public:ExternalPlugin(std::string &_pathToPluginFile)@@ -193,9 +216,15 @@ public:void reinstantiatePlugin() {// If we have an existing plugin, save its state and reload its state later:juce::MemoryBlock savedState;+ std::map<int, float> currentParameters;+if (pluginInstance) {pluginInstance->getStateInformation(savedState);+ for (auto *parameter : pluginInstance->getParameters()) {+ currentParameters[parameter->getParameterIndex()] = parameter->getValue();+ }+{std::lock_guard<std::mutex> lock(EXTERNAL_PLUGIN_MUTEX);// Delete the plugin instance itself:@@ -217,17 +246,62 @@ public:loadError.toStdString());}+ auto mainInputBus = pluginInstance->getBus(true, 0);+ auto mainOutputBus = pluginInstance->getBus(false, 0);++ if (!mainInputBus) {+ auto exception = std::invalid_argument(+ "Plugin '" + pluginInstance->getName().toStdString() ++ "' does not accept audio input. It may be an instrument plug-in "+ "and not an audio effect processor.");+ pluginInstance.reset();+ throw exception;+ }++ if (!mainOutputBus) {+ auto exception = std::invalid_argument(+ "Plugin '" + pluginInstance->getName().toStdString() ++ "' does not produce audio output.");+ pluginInstance.reset();+ throw exception;+ }++ if (reloadType == ExternalPluginReloadType::Unknown) {+ reloadType = detectReloadType();+ if (reloadType == ExternalPluginReloadType::PersistsAudioOnReset) {+ // Reload again, as we just passed audio into a plugin that+ // we know doesn't reset itself cleanly!+ pluginInstance = pluginFormatManager.createPluginInstance(+ foundPluginDescription, ExternalLoadSampleRate,+ ExternalLoadMaximumBlockSize, loadError);++ if (!pluginInstance) {+ throw pybind11::import_error("Unable to load plugin " ++ pathToPluginFile.toStdString() + ": " ++ loadError.toStdString());+ }+ }+ }++NUM_ACTIVE_EXTERNAL_PLUGINS++;}pluginInstance->setStateInformation(savedState.getData(),savedState.getSize());- const juce::dsp::ProcessSpec _lastSpec = lastSpec;+ for (auto *parameter : pluginInstance->getParameters()) {+ if (currentParameters.count(parameter->getParameterIndex()) > 0) {+ parameter->setValue(currentParameters[parameter->getParameterIndex()]);+ }+ }- // Invalidate lastSpec to force us to update the plugin state:- lastSpec.numChannels = 0;- prepare(_lastSpec);+ if (lastSpec.numChannels != 0) {+ const juce::dsp::ProcessSpec _lastSpec = lastSpec;+ // Invalidate lastSpec to force us to update the plugin state:+ lastSpec.numChannels = 0;+ prepare(_lastSpec);+ }pluginInstance->reset();}@@ -236,6 +310,9 @@ public:if (!pluginInstance)return;+ if (numChannels == 0)+ return;+pluginInstance->disableNonMainBuses();auto mainInputBus = pluginInstance->getBus(true, 0);@@ -258,6 +335,15 @@ public:pluginInstance->getBus(false, i)->enable(false);}+ if (mainInputBus->getNumberOfChannels() == numChannels &&+ mainOutputBus->getNumberOfChannels() == numChannels) {+ return;+ }++ // Cache these values in case the plugin fails to update:+ auto previousInputChannelCount = mainInputBus->getNumberOfChannels();+ auto previousOutputChannelCount = mainOutputBus->getNumberOfChannels();+// Try to change the input and output bus channel counts...mainInputBus->setNumberOfChannels(numChannels);mainOutputBus->setNumberOfChannels(numChannels);@@ -267,6 +353,11 @@ public:if (mainInputBus->getNumberOfChannels() != numChannels ||mainOutputBus->getNumberOfChannels() != numChannels) {+ // Reset the bus configuration to what it was before, so we don't+ // leave one of the buses smaller than the other:+ mainInputBus->setNumberOfChannels(previousInputChannelCount);+ mainOutputBus->setNumberOfChannels(previousOutputChannelCount);+throw std::invalid_argument("Plugin '" + pluginInstance->getName().toStdString() +"' does not support " + std::to_string(numChannels) +@@ -296,98 +387,209 @@ public:return mainInputBus->getNumberOfChannels();}- void prepare(const juce::dsp::ProcessSpec &spec) override {- if (pluginInstance) {- if (lastSpec.sampleRate != spec.sampleRate ||- lastSpec.maximumBlockSize < spec.maximumBlockSize ||- lastSpec.numChannels != spec.numChannels) {- setNumChannels(spec.numChannels);- pluginInstance->setRateAndBufferSizeDetails(spec.sampleRate,- spec.maximumBlockSize);- pluginInstance->prepareToPlay(spec.sampleRate, spec.maximumBlockSize);- pluginInstance->setNonRealtime(true);- lastSpec = spec;+ /**+ * Send some audio through the plugin to detect if the ->reset() call+ * actually resets internal buffers. This determines how quickly we+ * can reset the plugin and is only called on instantiation.+ */+ ExternalPluginReloadType detectReloadType() {+ const int numInputChannels = pluginInstance->getMainBusNumInputChannels();+ const int bufferSize = 512;+ const float sampleRate = 44100.0f;++ if (numInputChannels == 0) {+ return ExternalPluginReloadType::Unknown;+ }++ // Set input and output busses/channels appropriately:+ setNumChannels(numInputChannels);+ pluginInstance->setNonRealtime(true);+ pluginInstance->prepareToPlay(sampleRate, bufferSize);++ // Send in a buffer full of silence to get a baseline noise level:+ juce::AudioBuffer<float> audioBuffer(numInputChannels, bufferSize);+ juce::MidiBuffer emptyMidiBuffer;++ // Process the silent buffer a couple of times to give the plugin time to "warm up"+ for (int i = 0; i < 5; i++) {+ audioBuffer.clear();+ {+ juce::dsp::AudioBlock<float> block(audioBuffer);+ juce::dsp::ProcessContextReplacing<float> context(block);+ process(context);}}++ // Measure the noise floor of the plugin:+ auto noiseFloor = audioBuffer.getMagnitude(0, bufferSize);++ // Reset:+ pluginInstance->releaseResources();+ pluginInstance->setNonRealtime(true);+ pluginInstance->prepareToPlay(sampleRate, bufferSize);++ juce::Random random;++ // Send noise into the plugin:+ for (int i = 0; i < 5; i++) {+ for (auto i = 0; i < bufferSize; i++) {+ for (int c = 0; c < numInputChannels; c++) {+ audioBuffer.setSample(c, i, (random.nextFloat() * 2.0f) - 1.0f);+ }+ }+ juce::dsp::AudioBlock<float> block(audioBuffer);+ juce::dsp::ProcessContextReplacing<float> context(block);+ process(context);+ }++ auto signalVolume = audioBuffer.getMagnitude(0, bufferSize);++ // Reset again, and send in silence:+ pluginInstance->releaseResources();+ pluginInstance->setNonRealtime(true);+ pluginInstance->prepareToPlay(sampleRate, bufferSize);+ audioBuffer.clear();+ {+ juce::dsp::AudioBlock<float> block(audioBuffer);+ juce::dsp::ProcessContextReplacing<float> context(block);+ process(context);+ }++ auto magnitudeOfSilentBuffer = audioBuffer.getMagnitude(0, bufferSize);++ // If the silent buffer we passed in post-reset is noticeably louder+ // than the first buffer we passed in, this plugin probably persists+ // internal state across calls to releaseResources().+ bool pluginPersistsAudioOnReset = magnitudeOfSilentBuffer > noiseFloor * 5;++ if (pluginPersistsAudioOnReset) {+ return ExternalPluginReloadType::PersistsAudioOnReset;+ } else {+ return ExternalPluginReloadType::ClearsAudioOnReset;+ }}+ /**+ * reset() is only called if reset=True is passed.+ */void reset() noexcept override {if (pluginInstance) {- // Some VSTs don't actually clear their internal state when calling- // reset(). Here, we force a reset by reinstantiating the plugin.- pluginInstance->reset();- reinstantiatePlugin();+ switch (reloadType) {+ case ExternalPluginReloadType::ClearsAudioOnReset:+ pluginInstance->reset();+ pluginInstance->releaseResources();+ break;++ case ExternalPluginReloadType::Unknown:+ case ExternalPluginReloadType::PersistsAudioOnReset:+ pluginInstance->releaseResources();+ reinstantiatePlugin();+ break;+ default:+ throw std::runtime_error("Plugin reload type is an invalid value (" + std::to_string((int) reloadType) + ") - this likely indicates a programming error or memory corruption.");+ }++ // Force prepare() to be called again later by invalidating lastSpec:+ lastSpec.maximumBlockSize = 0;}}+ /**+ * prepare() is called on every render call, regardless of if the plugin has been reset.+ */+ void prepare(const juce::dsp::ProcessSpec &spec) override {+ if (!pluginInstance) {+ return;+ }++ if (lastSpec.sampleRate != spec.sampleRate ||+ lastSpec.maximumBlockSize < spec.maximumBlockSize ||+ lastSpec.numChannels != spec.numChannels) {++ // Changing the number of channels requires releaseResources to be called:+ if (lastSpec.numChannels != spec.numChannels) {+ pluginInstance->releaseResources();+ setNumChannels(spec.numChannels);+ }++ pluginInstance->setNonRealtime(true);+ pluginInstance->prepareToPlay(spec.sampleRate, spec.maximumBlockSize);++ lastSpec = spec;+ }+ }++voidprocess(const juce::dsp::ProcessContextReplacing<float> &context) override {+if (pluginInstance) {juce::MidiBuffer emptyMidiBuffer;if (context.usesSeparateInputAndOutputBlocks()) {throw std::runtime_error("Not implemented yet - ""no support for using separate ""input and output blocks.");- } else {- size_t pluginBufferChannelCount = 0;- // Iterate through all input busses and add their input channels to our- // buffer:- for (size_t i = 0;- i < static_cast<size_t>(pluginInstance->getBusCount(true)); i++) {- if (pluginInstance->getBus(true, i)->isEnabled()) {- pluginBufferChannelCount +=- pluginInstance->getBus(true, i)->getNumberOfChannels();- }- }-- juce::dsp::AudioBlock<float> &outputBlock = context.getOutputBlock();+ }- std::vector<float *> channelPointers(pluginBufferChannelCount);+ juce::dsp::AudioBlock<float> &outputBlock = context.getOutputBlock();++ // This should already be true, as prepare() should have been called before this!+ if ((size_t)pluginInstance->getMainBusNumInputChannels() !=+ outputBlock.getNumChannels()) {+ throw std::invalid_argument(+ "Plugin '" + pluginInstance->getName().toStdString() ++ "' was instantiated with " ++ std::to_string(pluginInstance->getMainBusNumInputChannels()) ++ "-channel input, but data provided was " ++ std::to_string(outputBlock.getNumChannels()) + "-channel.");+ }- for (size_t i = 0; i < outputBlock.getNumChannels(); i++) {- channelPointers[i] = outputBlock.getChannelPointer(i);- }+ if ((size_t)pluginInstance->getMainBusNumOutputChannels() <+ outputBlock.getNumChannels()) {+ throw std::invalid_argument(+ "Plugin '" + pluginInstance->getName().toStdString() ++ "' produces " ++ std::to_string(pluginInstance->getMainBusNumOutputChannels()) ++ "-channel output, but data provided was " ++ std::to_string(outputBlock.getNumChannels()) ++ "-channel. (The number of channels returned must match the "+ "number of channels passed in.)");+ }- // Depending on the bus layout, we may have to pass extra buffers to the- // plugin that we don't use. Use vector here to ensure the memory is- // freed via RAII.- std::vector<std::vector<float>> dummyChannels;- for (size_t i = outputBlock.getNumChannels();- i < pluginBufferChannelCount; i++) {- std::vector<float> dummyChannel(outputBlock.getNumSamples());- channelPointers[i] = dummyChannel.data();- dummyChannels.push_back(dummyChannel);+ size_t pluginBufferChannelCount = 0;+ // Iterate through all input busses and add their input channels to our+ // buffer:+ for (size_t i = 0;+ i < static_cast<size_t>(pluginInstance->getBusCount(true)); i++) {+ if (pluginInstance->getBus(true, i)->isEnabled()) {+ pluginBufferChannelCount +=+ pluginInstance->getBus(true, i)->getNumberOfChannels();}+ }- if ((size_t)pluginInstance->getMainBusNumInputChannels() !=- outputBlock.getNumChannels()) {- throw std::invalid_argument(- "Plugin '" + pluginInstance->getName().toStdString() +- "' was instantiated with " +- std::to_string(pluginInstance->getMainBusNumInputChannels()) +- "-channel input, but data provided was " +- std::to_string(outputBlock.getNumChannels()) + "-channel.");- }+ std::vector<float *> channelPointers(pluginBufferChannelCount);- if ((size_t)pluginInstance->getMainBusNumOutputChannels() <- outputBlock.getNumChannels()) {- throw std::invalid_argument(- "Plugin '" + pluginInstance->getName().toStdString() +- "' produces " +- std::to_string(pluginInstance->getMainBusNumOutputChannels()) +- "-channel output, but data provided was " +- std::to_string(outputBlock.getNumChannels()) +- "-channel. (The number of channels returned must match the "- "number of channels passed in.)");- }+ for (size_t i = 0; i < outputBlock.getNumChannels(); i++) {+ channelPointers[i] = outputBlock.getChannelPointer(i);+ }- // Create an audio buffer that doesn't actually allocate anything, but- // just points to the data in the ProcessContext.- juce::AudioBuffer<float> audioBuffer(channelPointers.data(),- pluginBufferChannelCount,- outputBlock.getNumSamples());- pluginInstance->processBlock(audioBuffer, emptyMidiBuffer);+ // Depending on the bus layout, we may have to pass extra buffers to the+ // plugin that we don't use. Use vector here to ensure the memory is+ // freed via RAII.+ std::vector<std::vector<float>> dummyChannels;+ for (size_t i = outputBlock.getNumChannels();+ i < pluginBufferChannelCount; i++) {+ std::vector<float> dummyChannel(outputBlock.getNumSamples());+ channelPointers[i] = dummyChannel.data();+ dummyChannels.push_back(dummyChannel);}++ // Create an audio buffer that doesn't actually allocate anything, but+ // just points to the data in the ProcessContext.+ juce::AudioBuffer<float> audioBuffer(channelPointers.data(),+ pluginBufferChannelCount,+ outputBlock.getNumSamples());+ pluginInstance->processBlock(audioBuffer, emptyMidiBuffer);}}@@ -415,6 +617,8 @@ private:juce::PluginDescription foundPluginDescription;juce::AudioPluginFormatManager pluginFormatManager;std::unique_ptr<juce::AudioPluginInstance> pluginInstance;++ ExternalPluginReloadType reloadType = ExternalPluginReloadType::Unknown;};inline void init_external_plugins(py::module &m) {diff --git a/tests/test_external_plugins.py b/tests/test_external_plugins.pyindex d308b38..0152122 100644--- a/tests/test_external_plugins.py+++ b/tests/test_external_plugins.py@@ -17,6 +17,7 @@import osimport math+import randomimport platformfrom glob import glob@@ -49,9 +50,10 @@ def get_parameters(plugin_filename: str):TEST_PLUGIN_CACHE = {}+TEST_PLUGIN_ORIGINAL_PARAMETER_CACHE = {}-def load_test_plugin(plugin_filename: str, *args, **kwargs):+def load_test_plugin(plugin_filename: str, disable_caching: bool = False, *args, **kwargs):"""Load a plugin file from disk, or use an existing instance to saveon test runtime if we already have one in memory.@@ -61,11 +63,40 @@ def load_test_plugin(plugin_filename: str, *args, **kwargs):"""key = repr((plugin_filename, args, tuple(kwargs.items())))- if key not in TEST_PLUGIN_CACHE:- TEST_PLUGIN_CACHE[key] = pedalboard.load_plugin(+ if key not in TEST_PLUGIN_CACHE or disable_caching:+ plugin = pedalboard.load_plugin(os.path.join(TEST_PLUGIN_BASE_PATH, platform.system(), plugin_filename), *args, **kwargs)- return TEST_PLUGIN_CACHE[key]+ if disable_caching:+ return plugin+ TEST_PLUGIN_CACHE[key] = plugin+ TEST_PLUGIN_ORIGINAL_PARAMETER_CACHE[key] = {+ key: getattr(plugin, key) for key in plugin.parameters.keys()+ }++ # Reset default parameters when loading:+ plugin = TEST_PLUGIN_CACHE[key]+ for name in plugin.parameters.keys():+ setattr(plugin, name, TEST_PLUGIN_ORIGINAL_PARAMETER_CACHE[key][name])++ # Throw some silence in and force a reset:+ plugin.process(np.zeros((44100, 2)), 44100, reset=True)+ return plugin+++# Allow testing with all of the plugins on the local machine:+if os.environ.get("ENABLE_TESTING_WITH_LOCAL_PLUGINS", False):+ for plugin_class in pedalboard.AVAILABLE_PLUGIN_CLASSES:+ for plugin_path in plugin_class.installed_plugins:+ try:+ load_test_plugin(plugin_path)+ AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT.append(plugin_path)+ except Exception:+ pass+++def max_volume_of(x: np.ndarray) -> float:+ return np.amax(np.abs(x))def test_at_least_one_plugin_is_available_for_testing():@@ -90,10 +121,13 @@ def test_initial_parameters(plugin_filename: str):}# Reload the plugin, but set the initial parameters in the load call.- plugin = load_test_plugin(plugin_filename, parameters)+ plugin = load_test_plugin(plugin_filename, parameter_values=parameters)- for name, value in parameters.items():- assert getattr(plugin, name) == value+ for name, expected in parameters.items():+ actual = getattr(plugin, name)+ if math.isnan(actual):+ continue+ assert actual == expected, f"Expected attribute {name} to be {expected}, but was {actual}"@pytest.mark.parametrize(@@ -108,14 +142,15 @@ def test_initial_parameter_validation(plugin_filename: str, parameter_name: str)plugin = load_test_plugin(plugin_filename)with pytest.raises(ValueError):load_test_plugin(- plugin_filename, {parameter_name: getattr(plugin, parameter_name).max_value + 100}+ plugin_filename,+ parameter_values={parameter_name: getattr(plugin, parameter_name).max_value + 100},)@pytest.mark.parametrize("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)def test_initial_parameter_validation_missing(plugin_filename: str):with pytest.raises(AttributeError):- load_test_plugin(plugin_filename, {"missing_parameter": 123})+ load_test_plugin(plugin_filename, parameter_values={"missing_parameter": 123})@pytest.mark.parametrize("loader", [pedalboard.load_plugin] + pedalboard.AVAILABLE_PLUGIN_CLASSES)@@ -134,8 +169,32 @@ def test_plugin_accepts_variable_channel_count():plugin = load_test_plugin(plugin_filename)noise = np.random.rand(num_channels, sample_rate)- effected = plugin(noise, sample_rate)- assert effected.shape == noise.shape+ try:+ effected = plugin(noise, sample_rate)+ assert effected.shape == noise.shape+ except ValueError as e:+ if "does not support" not in str(e):+ raise++[email protected]("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)+def test_plugin_accepts_variable_channel_count_without_reloading(plugin_filename: str):+ plugin = load_test_plugin(plugin_filename)+ for num_channels, sample_rate in [+ (1, 48000),+ (2, 48000),+ (1, 44100),+ (2, 44100),+ (1, 22050),+ (2, 22050),+ ]:+ noise = np.random.rand(num_channels, sample_rate)+ try:+ effected = plugin(noise, sample_rate)+ assert effected.shape == noise.shape+ except ValueError as e:+ if "does not support" not in str(e):+ raise@pytest.mark.parametrize("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)@@ -229,6 +288,8 @@ def test_float_parameters(plugin_filename: str, parameter_name: str):step_size = parameter_value.step_size or parameter_value.approximate_step_sizefor new_value in np.arange(_min, _max, step_size):setattr(plugin, parameter_name, new_value)+ if math.isnan(getattr(plugin, parameter_name)):+ continueassert math.isclose(new_value, getattr(plugin, parameter_name), abs_tol=step_size * 2)# Ensure that if we access an attribute that we're not adding to the value,@@ -308,41 +369,79 @@ def test_string_parameter_valdation(plugin_filename: str, parameter_name: str):@pytest.mark.parametrize("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)-def test_plugin_state_cleared_between_invocations(plugin_filename: str):+def test_plugin_parameters_persist_between_calls(plugin_filename: str):plugin = load_test_plugin(plugin_filename)sr = 44100- noise = np.random.rand(sr)- silence = np.zeros_like(noise)+ noise = np.random.rand(2, sr)++ # Set random parameter values on the plugin:+ for name, parameter in plugin.parameters.items():+ if name == "program":+ continue+ if parameter.type == float:+ low, high, step = parameter.range+ if not step:+ step = 0.1+ if low is None:+ low = 0.0+ if high is None:+ high = 1.0+ values = [+ x * step for x in list(range(int(low / step), int(high / step), 1)) + [high / step]+ ]+ random_value = random.choice(values)+ elif parameter.type == bool:+ random_value = bool(random.random())+ elif parameter.type == str:+ if parameter.valid_values:+ random_value = random.choice(parameter.valid_values)+ else:+ random_value = None+ if random_value is not None:+ setattr(plugin, name, random_value)++ expected_values = {}+ for name, parameter in plugin.parameters.items():+ expected_values[name] = getattr(plugin, name)++ plugin.process(noise, sr)++ for name, parameter in plugin.parameters.items():+ assert (+ getattr(plugin, name) == expected_values[name]+ ), f"Expected {name} to match saved value"- # Passing zero inputs should return silence- effected_silence = plugin(silence, sr)- plugin_noise_floor = np.amax(np.abs(effected_silence))- effected = plugin(noise, sr)- assert np.amax(np.abs(effected)) > plugin_noise_floor * 10[email protected]("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)+def test_plugin_state_cleared_between_invocations_by_default(plugin_filename: str):+ plugin = load_test_plugin(plugin_filename, disable_caching=True)++ sr = 44100+ noise = np.random.rand(sr, 2)+ assert max_volume_of(noise) > 0.95+ silence = np.zeros_like(noise)+ assert max_volume_of(silence) == 0.0- # Calling plugin again shouldn't allow any audio tails- # to carry over from previous calls.- assert np.allclose(plugin(silence, sr), effected_silence)+ assert max_volume_of(plugin(silence, sr)) < 0.00001+ assert max_volume_of(plugin(noise, sr)) > 0.00001+ for _ in range(10):+ assert max_volume_of(silence) == 0.0+ assert max_volume_of(plugin(silence, sr)) < 0.00001@pytest.mark.parametrize("plugin_filename", AVAILABLE_PLUGINS_IN_TEST_ENVIRONMENT)-def test_plugin_state_not_cleared_between_invocations(plugin_filename: str):- plugin = load_test_plugin(plugin_filename)+def test_plugin_state_not_cleared_between_invocations_if_reset_is_false(plugin_filename: str):+ plugin = load_test_plugin(plugin_filename, disable_caching=True)+sr = 44100- noise = np.random.rand(sr)+ noise = np.random.rand(sr, 2)+ assert max_volume_of(noise) > 0.95silence = np.zeros_like(noise)+ assert max_volume_of(silence) == 0.0- # 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)+ assert max_volume_of(plugin(silence, sr, reset=False)) < 0.00001+ assert max_volume_of(plugin(noise, sr, reset=False)) > 0.00001+ assert max_volume_of(plugin(silence, sr, reset=False)) > 0.00001@pytest.mark.parametrize("value", (True, False))