π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Add Invert plugin.
Peter Sobot58bd2ea10bd6
diff --git a/pedalboard/plugins/Invert.h b/pedalboard/plugins/Invert.hnew file mode 100644index 0000000..b48c9f3--- /dev/null+++ b/pedalboard/plugins/Invert.h@@ -0,0 +1,49 @@+/*+ * pedalboard+ * Copyright 2021 Spotify AB+ *+ * Licensed under the GNU Public License, Version 3.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * https://www.gnu.org/licenses/gpl-3.0.html+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++#include <pybind11/pybind11.h>+#include <pybind11/stl.h>++namespace py = pybind11;++#include "../JucePlugin.h"++namespace Pedalboard {+template <typename SampleType> class Invert : public Plugin {+ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {}+ int process(const juce::dsp::ProcessContextReplacing<SampleType> &context)+ override final {+ context.getOutputBlock().negate();+ return context.getOutputBlock().getNumSamples();+ }+ void reset() noexcept override {}+};++inline void init_invert(py::module &m) {+ py::class_<Invert<float>, Plugin>(+ m, "Invert",+ "Flip the polarity of the signal. This effect is not audible on its own.")+ .def(py::init([]() { return new Invert<float>(); }))+ .def("__repr__", [](const Invert<float> &plugin) {+ std::ostringstream ss;+ ss << "<pedalboard.Invert";+ ss << " at " << &plugin;+ ss << ">";+ return ss.str();+ });+}+}; // namespace Pedalboard\ No newline at end of filediff --git a/pedalboard/python_bindings.cpp b/pedalboard/python_bindings.cppindex f9b6e41..45f342d 100644--- a/pedalboard/python_bindings.cpp+++ b/pedalboard/python_bindings.cpp@@ -39,6 +39,7 @@ namespace py = pybind11;#include "plugins/Distortion.h"#include "plugins/Gain.h"#include "plugins/HighpassFilter.h"+#include "plugins/Invert.h"#include "plugins/LadderFilter.h"#include "plugins/Limiter.h"#include "plugins/LowpassFilter.h"@@ -139,6 +140,7 @@ PYBIND11_MODULE(pedalboard_native, m) {init_distortion(m);init_gain(m);init_highpass(m);+ init_invert(m);init_ladderfilter(m);init_limiter(m);init_lowpass(m);diff --git a/tests/test_native_module.py b/tests/test_native_module.pyindex 4df3863..bdc841f 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, Reverb+from pedalboard import process, Distortion, Invert, Gain, Compressor, Convolution, ReverbIMPULSE_RESPONSE_PATH = os.path.join(os.path.dirname(__file__), "impulse_response.wav")@@ -91,6 +91,13 @@ def test_distortion(gain_db, shape, sr=44100):np.testing.assert_allclose(np.tanh(full_scale_noise * gain_scale), result, rtol=4e-7, atol=2e-7)[email protected]("shape", [(44100,), (44100, 1), (44100, 2), (1, 44100), (2, 44100)])+def test_invert(shape, sr=44100):+ full_scale_noise = np.random.rand(*shape).astype(np.float32)+ result = Invert()(full_scale_noise, sr)+ np.testing.assert_allclose(full_scale_noise * -1, result, rtol=4e-7, atol=2e-7)++@pytest.mark.parametrize("reset", (True, False))def test_plugin_state_not_cleared_between_invocations(reset: bool):"""