-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add distortion effect. * Bump version. * Add tests for distortion. * Reduce memory usage in tests to avoid failures. * Update pedalboard/plugins/Distortion.h Co-authored-by: David Rubinstein <[email protected]> * Update tests/test_native_module.py Co-authored-by: David Rubinstein <[email protected]> * Add more tests for distortion. Co-authored-by: David Rubinstein <[email protected]>
- Loading branch information
1 parent
8f0fa90
commit 009d7f3
Showing
6 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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 Distortion | ||
: public JucePlugin<juce::dsp::ProcessorChain< | ||
juce::dsp::Gain<SampleType>, juce::dsp::WaveShaper<SampleType>>> { | ||
public: | ||
void setDriveDecibels(const float f) noexcept { driveDecibels = f; } | ||
float getDriveDecibels() const noexcept { return driveDecibels; } | ||
|
||
virtual void prepare(const juce::dsp::ProcessSpec &spec) override { | ||
JucePlugin<juce::dsp::ProcessorChain<juce::dsp::Gain<SampleType>, | ||
juce::dsp::WaveShaper<SampleType>>>:: | ||
prepare(spec); | ||
this->getDSP().template get<gainIndex>().setGainDecibels( | ||
getDriveDecibels()); | ||
this->getDSP().template get<waveshaperIndex>().functionToUse = | ||
[](SampleType x) { return std::tanh(x); }; | ||
} | ||
|
||
private: | ||
SampleType driveDecibels; | ||
|
||
enum { gainIndex, waveshaperIndex }; | ||
}; | ||
|
||
inline void init_distortion(py::module &m) { | ||
py::class_<Distortion<float>, Plugin>( | ||
m, "Distortion", "Apply soft distortion with a tanh waveshaper.") | ||
.def(py::init([](float drive_db) { | ||
auto plugin = new Distortion<float>(); | ||
plugin->setDriveDecibels(drive_db); | ||
return plugin; | ||
}), | ||
py::arg("drive_db") = 25) | ||
.def("__repr__", | ||
[](const Distortion<float> &plugin) { | ||
std::ostringstream ss; | ||
ss << "<pedalboard.Distortion"; | ||
ss << " drive_db=" << plugin.getDriveDecibels(); | ||
ss << " at " << &plugin; | ||
ss << ">"; | ||
return ss.str(); | ||
}) | ||
.def_property("drive_db", &Distortion<float>::getDriveDecibels, | ||
&Distortion<float>::setDriveDecibels); | ||
} | ||
}; // namespace Pedalboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,7 +200,7 @@ | |
|
||
setup( | ||
name='pedalboard', | ||
version='0.3.3', | ||
version='0.3.4', | ||
author='Peter Sobot', | ||
author_email='[email protected]', | ||
description='A Python library for adding effects to audio.', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters