Skip to content

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

On branch add-dsp-filters Changes to be committed: new file: pedalboard/plugins/HighShelfFilter.h new file: pedalboard/plugins/LowShelfFilter.h new file: pedalboard/plugins/NotchFilter.h new file: pedalboard/plugins/PeakingFilter.h modified: pedalboard/python_bindings.cpp

Paul Mayer627f04b091b8
diff --git a/pedalboard/plugins/HighShelfFilter.h b/pedalboard/plugins/HighShelfFilter.h
new file mode 100644
index 0000000..b79caff
--- /dev/null
+++ b/pedalboard/plugins/HighShelfFilter.h
@@ -0,0 +1,88 @@
+/*
+ * 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 HighShelfFilter : public JucePlugin<juce::dsp::IIR::Filter<SampleType>> {
+public:
+ void setCutoffFrequencyHz(float f) noexcept { cutoffFrequencyHz = f; }
+ float getCutoffFrequencyHz() const noexcept { return cutoffFrequencyHz; }
+ void setQ(float f) noexcept { Q = f; }
+ float getQ() const noexcept { return Q; }
+ void setGainFactor(float f) noexcept { gainFactor = f; }
+ float getGainFactor() const noexcept { return gainFactor; }
+
+
+ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {
+ JucePlugin<juce::dsp::IIR::Filter<SampleType>>::prepare(spec);
+ this->getDSP().coefficients =
+ juce::dsp::IIR::Coefficients<SampleType>::makeHighShelf(
+ spec.sampleRate, cutoffFrequencyHz, Q, gainFactor);
+ }
+
+private:
+ float cutoffFrequencyHz;
+ float Q;
+ float gainFactor;
+};
+
+inline void init_highshelf(py::module &m) {
+ py::class_<HighShelfFilter<float>, Plugin>(
+ m, "HighShelfFilter",
+ "Apply a High Shelf filter with"
+ "The gain is a scale factor that the high frequencies are multiplied by, so values"
+ "greater than 1.0 will boost the high frequencies, values less than 1.0 will"
+ "attenuate them.")
+ .def(py::init([](float cutoff_frequency_hz, float Q_val, float gainFactorBoost) {
+ auto plugin = new HighShelfFilter<float>();
+ plugin->setCutoffFrequencyHz(cutoff_frequency_hz);
+ plugin->setQ(Q_val);
+ plugin->setGainFactor(gainFactorBoost);
+ return plugin;
+ }),
+ py::arg("cutoff_frequency_hz") = 50,
+ py::arg("Q") = 0.707,
+ py::arg("gain_factor") = 1.0)
+ .def("__repr__",
+ [](const HighShelfFilter<float> &plugin) {
+ std::ostringstream ss;
+ ss << "<pedalboard.HighShelf";
+ ss << " cutoff_frequency_hz=" << plugin.getCutoffFrequencyHz();
+ ss << " Q=" << plugin.getQ();
+ ss << " gain_factor=" << plugin.getGainFactor();
+ ss << " at " << &plugin;
+ ss << ">";
+ return ss.str();
+ })
+ .def_property("cutoff_frequency_hz",
+ &HighShelfFilter<float>::getCutoffFrequencyHz,
+ &HighShelfFilter<float>::setCutoffFrequencyHz)
+ .def_property("Q",
+ &HighShelfFilter<float>::getQ,
+ &HighShelfFilter<float>::setQ)
+ .def_property("gain_factor",
+ &HighShelfFilter<float>::getGainFactor,
+ &HighShelfFilter<float>::setGainFactor);
+}
+}; // namespace Pedalboard
diff --git a/pedalboard/plugins/LowShelfFilter.h b/pedalboard/plugins/LowShelfFilter.h
new file mode 100644
index 0000000..40aeb5a
--- /dev/null
+++ b/pedalboard/plugins/LowShelfFilter.h
@@ -0,0 +1,90 @@
+/*
+ * 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 LowShelfFilter : public JucePlugin<juce::dsp::IIR::Filter<SampleType>> {
+public:
+ void setCutoffFrequencyHz(float f) noexcept { cutoffFrequencyHz = f; }
+ float getCutoffFrequencyHz() const noexcept { return cutoffFrequencyHz; }
+ void setQ(float f) noexcept { Q = f; }
+ float getQ() const noexcept { return Q; }
+ void setGainFactor(float f) noexcept { gainFactor = f; }
+ float getGainFactor() const noexcept { return gainFactor; }
+
+
+ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {
+ JucePlugin<juce::dsp::IIR::Filter<SampleType>>::prepare(spec);
+ this->getDSP().coefficients =
+ juce::dsp::IIR::Coefficients<SampleType>::makeLowShelf(
+ spec.sampleRate, cutoffFrequencyHz, Q, gainFactor);
+ }
+
+private:
+ float cutoffFrequencyHz;
+ float Q;
+ float gainFactor;
+};
+
+inline void init_lowshelf(py::module &m) {
+ py::class_<LowShelfFilter<float>, Plugin>(
+ m, "LowShelfFilter",
+ "Apply a Low Shelf filter with"
+ "The gain is a scale factor that the high frequencies are multiplied by, so values"
+ "greater than 1.0 will boost the high frequencies, values less than 1.0 will"
+ "attenuate them."
+ "The cutoff frequency will be attenuated by -3dB (i.e.: 0.707x as "
+ "loud).")
+ .def(py::init([](float cutoff_frequency_hz, float Q_val, float gainFactorBoost) {
+ auto plugin = new LowShelfFilter<float>();
+ plugin->setCutoffFrequencyHz(cutoff_frequency_hz);
+ plugin->setQ(Q_val);
+ plugin->setGainFactor(gainFactorBoost);
+ return plugin;
+ }),
+ py::arg("cutoff_frequency_hz") = 50,
+ py::arg("Q_val") = 0.707,
+ py::arg("gain_factor") = 1.0)
+ .def("__repr__",
+ [](const LowShelfFilter<float> &plugin) {
+ std::ostringstream ss;
+ ss << "<pedalboard.LowShelf";
+ ss << " cutoff_frequency_hz=" << plugin.getCutoffFrequencyHz();
+ ss << " Q=" << plugin.getQ();
+ ss << " gain_factor=" << plugin.getGainFactor();
+ ss << " at " << &plugin;
+ ss << ">";
+ return ss.str();
+ })
+ .def_property("cutoff_frequency_hz",
+ &LowShelfFilter<float>::getCutoffFrequencyHz,
+ &LowShelfFilter<float>::setCutoffFrequencyHz)
+ .def_property("Q_val",
+ &LowShelfFilter<float>::getQ,
+ &LowShelfFilter<float>::setQ)
+ .def_property("gain_factor",
+ &LowShelfFilter<float>::getGainFactor,
+ &LowShelfFilter<float>::setGainFactor);
+}
+}; // namespace Pedalboard
diff --git a/pedalboard/plugins/NotchFilter.h b/pedalboard/plugins/NotchFilter.h
new file mode 100644
index 0000000..1ab8e86
--- /dev/null
+++ b/pedalboard/plugins/NotchFilter.h
@@ -0,0 +1,75 @@
+/*
+ * 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 NotchFilter : public JucePlugin<juce::dsp::IIR::Filter<SampleType>> {
+public:
+ void setCutoffFrequencyHz(float f) noexcept { cutoffFrequencyHz = f; }
+ float getCutoffFrequencyHz() const noexcept { return cutoffFrequencyHz; }
+ void setQ(float f) noexcept { Q = f; }
+ float getQ() const noexcept { return Q; }
+
+ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {
+ JucePlugin<juce::dsp::IIR::Filter<SampleType>>::prepare(spec);
+ this->getDSP().coefficients =
+ juce::dsp::IIR::Coefficients<SampleType>::makeNotch(
+ spec.sampleRate, cutoffFrequencyHz, Q);
+ }
+
+private:
+ float cutoffFrequencyHz;
+ float Q;
+};
+
+inline void init_notch(py::module &m) {
+ py::class_<NotchFilter<float>, Plugin>(
+ m, "NotchFilter",
+ "Create a notch filter with a variable Q, set around cutoffFrequencyHz")
+ .def(py::init([](float cutoff_frequency_hz, float Q_val) {
+ auto plugin = new NotchFilter<float>();
+ plugin->setCutoffFrequencyHz(cutoff_frequency_hz);
+ plugin->setQ(Q_val);
+ return plugin;
+ }),
+ py::arg("cutoff_frequency_hz") = 50,
+ py::arg("Q") = 0.707)
+ .def("__repr__",
+ [](const NotchFilter<float> &plugin) {
+ std::ostringstream ss;
+ ss << "<pedalboard.NotchFilter";
+ ss << " cutoff_frequency_hz=" << plugin.getCutoffFrequencyHz();
+ ss << " Q=" << plugin.getQ();
+ ss << " at " << &plugin;
+ ss << ">";
+ return ss.str();
+ })
+ .def_property("cutoff_frequency_hz",
+ &NotchFilter<float>::getCutoffFrequencyHz,
+ &NotchFilter<float>::setCutoffFrequencyHz)
+ .def_property("Q",
+ &NotchFilter<float>::getQ,
+ &NotchFilter<float>::setQ);
+}
+}; // namespace Pedalboard
diff --git a/pedalboard/plugins/PeakingFilter.h b/pedalboard/plugins/PeakingFilter.h
new file mode 100644
index 0000000..8f1220f
--- /dev/null
+++ b/pedalboard/plugins/PeakingFilter.h
@@ -0,0 +1,88 @@
+/*
+ * 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 PeakingFilter : public JucePlugin<juce::dsp::IIR::Filter<SampleType>> {
+public:
+ void setCentreFrequencyHz(float f) noexcept { centreFrequencyHz = f; }
+ float getCentreFrequencyHz() const noexcept { return centreFrequencyHz; }
+ void setQ(float f) noexcept { Q = f; }
+ float getQ() const noexcept { return Q; }
+ void setGainFactor(float f) noexcept { gainFactor = f; }
+ float getGainFactor() const noexcept { return gainFactor; }
+
+
+ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {
+ JucePlugin<juce::dsp::IIR::Filter<SampleType>>::prepare(spec);
+ this->getDSP().coefficients =
+ juce::dsp::IIR::Coefficients<SampleType>::makePeakFilter(
+ spec.sampleRate, centreFrequencyHz, Q, gainFactor);
+ }
+
+private:
+ float centreFrequencyHz;
+ float Q;
+ float gainFactor;
+};
+
+inline void init_peaking(py::module &m) {
+ py::class_<PeakingFilter<float>, Plugin>(
+ m, "PeakingFilter",
+ "Apply a Peaking filter."
+ "The gain is a scale factor that the high frequencies are multiplied by, so values"
+ "greater than 1.0 will boost the high frequencies, values less than 1.0 will"
+ "attenuate them. Centers the band around centreFrequencyHz")
+ .def(py::init([](float centre_frequency_hz, float Q_val, float gainFactorBoost) {
+ auto plugin = new PeakingFilter<float>();
+ plugin->setCentreFrequencyHz(centre_frequency_hz);
+ plugin->setQ(Q_val);
+ plugin->setGainFactor(gainFactorBoost);
+ return plugin;
+ }),
+ py::arg("centre_frequency_hz") = 50,
+ py::arg("Q") = 0.0,
+ py::arg("gain_factor") = .707)
+ .def("__repr__",
+ [](const PeakingFilter<float> &plugin) {
+ std::ostringstream ss;
+ ss << "<pedalboard.PeakingFilter";
+ ss << " centre_frequency_hz=" << plugin.getCentreFrequencyHz();
+ ss << " Q=" << plugin.getQ();
+ ss << " gain_factor=" << plugin.getGainFactor();
+ ss << " at " << &plugin;
+ ss << ">";
+ return ss.str();
+ })
+ .def_property("centre_frequency_hz",
+ &PeakingFilter<float>::getCentreFrequencyHz,
+ &PeakingFilter<float>::setCentreFrequencyHz)
+ .def_property("Q",
+ &PeakingFilter<float>::getQ,
+ &PeakingFilter<float>::setQ)
+ .def_property("gain_factor",
+ &PeakingFilter<float>::getGainFactor,
+ &PeakingFilter<float>::setGainFactor);
+}
+}; // namespace Pedalboard
diff --git a/pedalboard/python_bindings.cpp b/pedalboard/python_bindings.cpp
index d3a0bc0..3d7d935 100644
--- a/pedalboard/python_bindings.cpp
+++ b/pedalboard/python_bindings.cpp
@@ -49,13 +49,23 @@ namespace py = pybind11;
#include "plugins/GSMFullRateCompressor.h"
#include "plugins/Gain.h"
#include "plugins/HighpassFilter.h"
+<<<<<<< HEAD
#include "plugins/Invert.h"
#include "plugins/LadderFilter.h"
#include "plugins/Limiter.h"
#include "plugins/LowpassFilter.h"
#include "plugins/MP3Compressor.h"
#include "plugins/Mix.h"
+=======
+#include "plugins/HighShelfFilter.h"
+#include "plugins/LadderFilter.h"
+#include "plugins/Limiter.h"
+#include "plugins/LowpassFilter.h"
+#include "plugins/LowShelfFilter.h"
+>>>>>>> On branch add-dsp-filters
#include "plugins/NoiseGate.h"
+#include "plugins/NotchFilter.h"
+#include "plugins/PeakingFilter.h"
#include "plugins/Phaser.h"
#include "plugins/PitchShift.h"
#include "plugins/Reverb.h"
@@ -160,12 +170,16 @@ PYBIND11_MODULE(pedalboard_native, m) {
init_gsm_full_rate_compressor(m);
init_highpass(m);
+ init_highshelf(m);
init_invert(m);
init_ladderfilter(m);
init_limiter(m);
init_lowpass(m);
+ init_lowshelf(m);
init_mp3_compressor(m);
init_noisegate(m);
+ init_notch(m);
+ init_peaking(m);
init_phaser(m);
init_pitch_shift(m);
init_reverb(m);