π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Consolidate IIR filters into one file to share code.
Peter Sobotbd171ff58009
diff --git a/pedalboard/plugins/HighShelfFilter.h b/pedalboard/plugins/HighShelfFilter.hdeleted file mode 100644index cdc63b7..0000000--- a/pedalboard/plugins/HighShelfFilter.h+++ /dev/null@@ -1,88 +0,0 @@-/*- * 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-pass shelf filter with variable Q and gain. "- "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") = (juce::MathConstants<double>::sqrt2 / 2.0),- py::arg("gain_factor") = 1.0)- .def("__repr__",- [](const HighShelfFilter<float> &plugin) {- std::ostringstream ss;- ss << "<pedalboard.HighShelfFilter";- 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 Pedalboarddiff --git a/pedalboard/plugins/IIRFilters.h b/pedalboard/plugins/IIRFilters.hnew file mode 100644index 0000000..f05162e--- /dev/null+++ b/pedalboard/plugins/IIRFilters.h@@ -0,0 +1,220 @@+/*+ * 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 {++/**+ * Given a cutoff frequency and sample rate, clamp the cutoff frequency to+ * [e, sr / 2 - e] for some small epsilon, to ensure that filter frequency+ * response is stable.+ */+inline float clampCutoffFrequency(float cutoffFrequencyHz, float sampleRate) {+ return juce::jlimit(1e-2f, (sampleRate / 2) - 1e2f, cutoffFrequencyHz);+}++/**+ * A base class for all IIR filter classes.+ */+template <typename SampleType>+class IIRFilter : public JucePlugin<juce::dsp::IIR::Filter<SampleType>> {+public:+ void setCutoffFrequencyHz(float f) {+ if (f <= 0)+ throw std::domain_error("Cutoff frequency must be greater than 0Hz.");+ cutoffFrequencyHz = f;+ }+ float getCutoffFrequencyHz() const noexcept { return cutoffFrequencyHz; }++ void setQ(float q) {+ if (q <= 0)+ throw std::domain_error("Q value must be greater than 0.");+ Q = q;+ }+ float getQ() const noexcept { return Q; }++ void setGainDecibels(float dB) {+ gainFactor = juce::Decibels::decibelsToGain<SampleType>(dB);+ }+ float getGainDecibels() const noexcept {+ return juce::Decibels::gainToDecibels<SampleType>(gainFactor);+ }++ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {+ if (this->lastSpec.sampleRate != spec.sampleRate ||+ this->lastSpec.maximumBlockSize < spec.maximumBlockSize ||+ spec.numChannels != this->lastSpec.numChannels) {+ JucePlugin<juce::dsp::IIR::Filter<SampleType>>::prepare(spec);+ this->lastSpec = spec;+ }+ }++protected:+ float cutoffFrequencyHz;+ float Q;+ float gainFactor;+};++template <typename SampleType>+class HighShelfFilter : public IIRFilter<SampleType> {+public:+ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {+ IIRFilter<SampleType>::prepare(spec);++ this->getDSP().coefficients =+ juce::dsp::IIR::Coefficients<SampleType>::makeHighShelf(+ spec.sampleRate,+ clampCutoffFrequency(this->cutoffFrequencyHz, spec.sampleRate), this->Q,+ this->gainFactor);+ }+};++template <typename SampleType>+class LowShelfFilter : public IIRFilter<SampleType> {+public:+ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {+ IIRFilter<SampleType>::prepare(spec);++ this->getDSP().coefficients =+ juce::dsp::IIR::Coefficients<SampleType>::makeLowShelf(+ spec.sampleRate,+ clampCutoffFrequency(this->cutoffFrequencyHz, spec.sampleRate), this->Q,+ this->gainFactor);+ }+};++template <typename SampleType> class PeakFilter : public IIRFilter<SampleType> {+public:+ virtual void prepare(const juce::dsp::ProcessSpec &spec) override {+ IIRFilter<SampleType>::prepare(spec);++ this->getDSP().coefficients =+ juce::dsp::IIR::Coefficients<SampleType>::makePeakFilter(+ spec.sampleRate,+ clampCutoffFrequency(this->cutoffFrequencyHz, spec.sampleRate), this->Q,+ this->gainFactor);+ }+};++inline void init_iir_filters(py::module &m) {+ py::class_<HighShelfFilter<float>, Plugin,+ std::shared_ptr<HighShelfFilter<float>>>(+ m, "HighShelfFilter",+ "Apply a high shelf filter with variable Q and gain. Frequencies above "+ "the cutoff frequency will be boosted (or cut) by the provided gain "+ "value.")+ .def(py::init([](float cutoffFrequencyHz, float gaindB, float Q) {+ auto plugin = std::make_unique<HighShelfFilter<float>>();+ plugin->setCutoffFrequencyHz(cutoffFrequencyHz);+ plugin->setQ(Q);+ plugin->setGainDecibels(gaindB);+ return plugin;+ }),+ py::arg("cutoff_frequency_hz") = 440, py::arg("gain_db") = 0.0,+ py::arg("q") = (juce::MathConstants<float>::sqrt2 / 2.0))+ .def("__repr__",+ [](const HighShelfFilter<float> &plugin) {+ std::ostringstream ss;+ ss << "<pedalboard.HighShelfFilter";+ ss << " cutoff_frequency_hz=" << plugin.getCutoffFrequencyHz();+ ss << " q=" << plugin.getQ();+ ss << " gain_db=" << plugin.getGainDecibels();+ 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_db", &HighShelfFilter<float>::getGainDecibels,+ &HighShelfFilter<float>::setGainDecibels);++ py::class_<LowShelfFilter<float>, Plugin,+ std::shared_ptr<LowShelfFilter<float>>>(+ m, "LowShelfFilter",+ "Apply a low shelf filter with variable Q and gain. Frequencies below "+ "the cutoff frequency will be boosted (or cut) by the provided gain "+ "value.")+ .def(py::init([](float cutoffFrequencyHz, float gaindB, float Q) {+ auto plugin = std::make_unique<LowShelfFilter<float>>();+ plugin->setCutoffFrequencyHz(cutoffFrequencyHz);+ plugin->setQ(Q);+ plugin->setGainDecibels(gaindB);+ return plugin;+ }),+ py::arg("cutoff_frequency_hz") = 440, py::arg("gain_db") = 0.0,+ py::arg("q") = (juce::MathConstants<float>::sqrt2 / 2.0))+ .def("__repr__",+ [](const LowShelfFilter<float> &plugin) {+ std::ostringstream ss;+ ss << "<pedalboard.LowShelfFilter";+ ss << " cutoff_frequency_hz=" << plugin.getCutoffFrequencyHz();+ ss << " q=" << plugin.getQ();+ ss << " gain_db=" << plugin.getGainDecibels();+ ss << " at " << &plugin;+ ss << ">";+ return ss.str();+ })+ .def_property("cutoff_frequency_hz",+ &LowShelfFilter<float>::getCutoffFrequencyHz,+ &LowShelfFilter<float>::setCutoffFrequencyHz)+ .def_property("q", &LowShelfFilter<float>::getQ,+ &LowShelfFilter<float>::setQ)+ .def_property("gain_db", &LowShelfFilter<float>::getGainDecibels,+ &LowShelfFilter<float>::setGainDecibels);++ py::class_<PeakFilter<float>, Plugin, std::shared_ptr<PeakFilter<float>>>(+ m, "PeakFilter",+ "Apply a peak (or notch) filter with variable Q and gain. Frequencies "+ "around the cutoff frequency will be boosted (or cut) by the provided "+ "gain value.")+ .def(py::init([](float cutoffFrequencyHz, float gaindB, float Q) {+ auto plugin = std::make_unique<PeakFilter<float>>();+ plugin->setCutoffFrequencyHz(cutoffFrequencyHz);+ plugin->setQ(Q);+ plugin->setGainDecibels(gaindB);+ return plugin;+ }),+ py::arg("cutoff_frequency_hz") = 440, py::arg("gain_db") = 0.0,+ py::arg("q") = (juce::MathConstants<float>::sqrt2 / 2.0))+ .def("__repr__",+ [](const PeakFilter<float> &plugin) {+ std::ostringstream ss;+ ss << "<pedalboard.PeakFilter";+ ss << " cutoff_frequency_hz=" << plugin.getCutoffFrequencyHz();+ ss << " q=" << plugin.getQ();+ ss << " gain_db=" << plugin.getGainDecibels();+ ss << " at " << &plugin;+ ss << ">";+ return ss.str();+ })+ .def_property("cutoff_frequency_hz",+ &PeakFilter<float>::getCutoffFrequencyHz,+ &PeakFilter<float>::setCutoffFrequencyHz)+ .def_property("q", &PeakFilter<float>::getQ, &PeakFilter<float>::setQ)+ .def_property("gain_db", &PeakFilter<float>::getGainDecibels,+ &PeakFilter<float>::setGainDecibels);+}+}; // namespace Pedalboarddiff --git a/pedalboard/plugins/LowShelfFilter.h b/pedalboard/plugins/LowShelfFilter.hdeleted file mode 100644index b553ec8..0000000--- a/pedalboard/plugins/LowShelfFilter.h+++ /dev/null@@ -1,88 +0,0 @@-/*- * 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-pass shelf filter with variable Q and gain. "- "The gain is a scale factor that the low frequencies are multiplied by, so values"- "greater than 1.0 will boost the low frequencies, values less than 1.0 will"- "attenuate them.")- .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") = (juce::MathConstants<double>::sqrt2 / 2.0),- py::arg("gain_factor") = 1.0)- .def("__repr__",- [](const LowShelfFilter<float> &plugin) {- std::ostringstream ss;- ss << "<pedalboard.LowShelfFilter";- 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",- &LowShelfFilter<float>::getQ,- &LowShelfFilter<float>::setQ)- .def_property("gain_factor",- &LowShelfFilter<float>::getGainFactor,- &LowShelfFilter<float>::setGainFactor);-}-}; // namespace Pedalboarddiff --git a/pedalboard/plugins/NotchFilter.h b/pedalboard/plugins/NotchFilter.hdeleted file mode 100644index 459184c..0000000--- a/pedalboard/plugins/NotchFilter.h+++ /dev/null@@ -1,75 +0,0 @@-/*- * 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 cutoff_frequency_hz.")- .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") = (juce::MathConstants<double>::sqrt2 / 2.0))- .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 Pedalboarddiff --git a/pedalboard/plugins/PeakingFilter.h b/pedalboard/plugins/PeakingFilter.hdeleted file mode 100644index 494b738..0000000--- a/pedalboard/plugins/PeakingFilter.h+++ /dev/null@@ -1,88 +0,0 @@-/*- * 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") = (juce::MathConstants<double>::sqrt2 / 2.0))- .def("__repr__",- [](const PeakFilter<float> &plugin) {- std::ostringstream ss;- ss << "<pedalboard.PeakFilter";- 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 Pedalboarddiff --git a/pedalboard/python_bindings.cpp b/pedalboard/python_bindings.cppindex ad8c7da..ddc1921 100644--- a/pedalboard/python_bindings.cpp+++ b/pedalboard/python_bindings.cpp@@ -50,10 +50,14 @@ namespace py = pybind11;#include "plugins/Gain.h"#include "plugins/HighpassFilter.h"<<<<<<< HEAD-#include "plugins/Invert.h"+<<<<<<< HEAD+=======#include "plugins/LadderFilter.h"#include "plugins/Limiter.h"#include "plugins/LowpassFilter.h"+#include "plugins/IIRFilters.h"+>>>>>>> Consolidate IIR filters into one file to share code.+#include "plugins/Invert.h"#include "plugins/MP3Compressor.h"#include "plugins/Mix.h"=======@@ -64,8 +68,6 @@ namespace py = pybind11;#include "plugins/LowShelfFilter.h">>>>>>> On branch add-dsp-filters#include "plugins/NoiseGate.h"-#include "plugins/NotchFilter.h"-#include "plugins/PeakFilter.h"#include "plugins/Phaser.h"#include "plugins/PitchShift.h"#include "plugins/Reverb.h"@@ -170,16 +172,13 @@ PYBIND11_MODULE(pedalboard_native, m) {init_gsm_full_rate_compressor(m);init_highpass(m);- init_highshelf(m);+ init_iir_filters(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_peak(m);init_phaser(m);init_pitch_shift(m);init_reverb(m);diff --git a/tests/test_filters.py b/tests/test_filters.pyindex 55627e4..7962afe 100644--- a/tests/test_filters.py+++ b/tests/test_filters.py@@ -17,11 +17,12 @@import pytestimport numpy as np-from pedalboard import HighpassFilter, LowpassFilter+from pedalboard import HighpassFilter, LowpassFilter, HighShelfFilter, LowShelfFilter, PeakFilter+from .utils import generate_sine_atdef rms(x: np.ndarray) -> float:- return np.sqrt(np.mean(x ** 2))+ return np.sqrt(np.mean(x**2))def normalized(x: np.ndarray) -> np.ndarray:@@ -69,3 +70,50 @@ def test_lowpass_slope(cutoff_frequency_hz, fundamental_hz, sample_rate):assert np.allclose(rms(filtered) / rms(sine_wave), db_to_gain((num_octaves + 1) * -3), rtol=0.1, atol=0.1)++[email protected]("filter_type", [HighShelfFilter, LowShelfFilter])[email protected]("fundamental_hz", [440, 880])[email protected]("sample_rate", [22050, 44100, 48000])[email protected]("gain_db", [-12, -6, 0, 6, 12])+def test_shelf_filters(filter_type, fundamental_hz, sample_rate, gain_db):+ sine_wave = generate_sine_at(sample_rate, fundamental_hz, num_seconds=2)+ filtered = filter_type(cutoff_frequency_hz=fundamental_hz, gain_db=gain_db)(+ sine_wave, sample_rate+ )+ np.testing.assert_allclose(+ rms(filtered) / rms(sine_wave), db_to_gain(gain_db / 2), rtol=0.01, atol=0.01+ )++[email protected]("fundamental_hz", [440, 880])[email protected]("sample_rate", [22050, 44100, 48000])[email protected]("gain_db", [-12, -6, 0, 6, 12])+def test_peak_filter(fundamental_hz, sample_rate, gain_db):+ sine_wave = generate_sine_at(sample_rate, fundamental_hz, num_seconds=2)+ filtered = PeakFilter(cutoff_frequency_hz=fundamental_hz, gain_db=gain_db)(+ sine_wave, sample_rate+ )+ np.testing.assert_allclose(+ rms(filtered) / rms(sine_wave), db_to_gain(gain_db), rtol=0.01, atol=0.01+ )++[email protected]("filter_type", [HighShelfFilter, LowShelfFilter])[email protected]("fundamental_hz", [440, 880])[email protected]("sample_rate", [22050, 44100, 48000])[email protected]("gain_db", [-12, -6, 0, 6, 12])[email protected]("q", [1 / np.sqrt(2), 1, 100])+def test_q_factor(filter_type, fundamental_hz, sample_rate, gain_db, q):+ sine_wave = generate_sine_at(sample_rate, fundamental_hz, num_seconds=2)++ cutoff_frequency_hz = (+ (fundamental_hz / 4) if filter_type == HighShelfFilter else (fundamental_hz * 4)+ )++ filtered = filter_type(cutoff_frequency_hz=cutoff_frequency_hz, gain_db=gain_db, q=q)(+ sine_wave, sample_rate+ )+ np.testing.assert_allclose(+ rms(filtered) / rms(sine_wave), db_to_gain(gain_db), rtol=0.1, atol=0.1+ )