diff --git a/Makefile b/Makefile index 9675111..06e9521 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ clean: echo "Cleaning $$plugin..."; \ $(MAKE) clean -C plugins/$$plugin || true; \ done - rm -rf bin build core/*.o core/*.obj + rm -rf bin/* build/* core/*.o core/*.obj # -------------------------------------------------------------- diff --git a/core/Clipper.cpp b/core/Clipper.cpp index 09fb3fa..de5b581 100644 --- a/core/Clipper.cpp +++ b/core/Clipper.cpp @@ -1,10 +1,12 @@ #include "Clipper.hpp" +#include -Clipper::Clipper(float init_clip) : clip_(init_clip) {} +Clipper::Clipper(float init_clip, ClipperMode init_mode) + : clip_(init_clip), mode_(init_mode) {} void Clipper::process(const float *in, float *out, uint32_t frames) { for (uint32_t i = 0; i < frames; ++i) { - out[i] = in[i] > clip_ ? clip_ : in[i]; + out[i] = clip(in[i]); } } void Clipper::processStereo(const float *inLeft, const float *inRight, @@ -16,11 +18,20 @@ void Clipper::processStereo(const float *inLeft, const float *inRight, } float Clipper::clip(const float in) { - float out = in; - if (in > 0) { - out = in > clip_ ? clip_ : in; - } else { - out = in < -clip_ ? -clip_ : in; + switch (mode_) { + default: + case kClipperModeHard: { + float out = in; + if (in > 0) { + out = in > clip_ ? clip_ : in; + } else { + out = in < -clip_ ? -clip_ : in; + } + return out; + } + case kClipperModeSoft: { + float normalized = (in / clip_) * 0.75f; + return std::tanh(normalized) * clip_; + } } - return out; } \ No newline at end of file diff --git a/core/Clipper.hpp b/core/Clipper.hpp index 91c7722..58500ec 100644 --- a/core/Clipper.hpp +++ b/core/Clipper.hpp @@ -5,7 +5,9 @@ class Clipper { public: - Clipper(float init_clip = 1.0f); + enum ClipperMode { kClipperModeSoft, kClipperModeHard, kClipperModeCount }; + + Clipper(float init_clip = 1.0f, ClipperMode mode = kClipperModeSoft); void process(const float *in, float *out, uint32_t frames); void processStereo(const float *inLeft, const float *inRight, float *outLeft, @@ -14,10 +16,13 @@ public: private: float clip_; float clip(const float in); + ClipperMode mode_; public: void setGain(float c) { clip_ = c; } float getGain() const { return clip_; } + void setMode(ClipperMode m) { mode_ = m; } + ClipperMode getMode() const { return mode_; } }; #endif // CLIPPER_HPP_INCLUDED \ No newline at end of file diff --git a/plugins/SquidgeDistortion/DistrhoPluginInfo.h b/plugins/SquidgeDistortion/DistrhoPluginInfo.h index 2f902eb..9631a1f 100644 --- a/plugins/SquidgeDistortion/DistrhoPluginInfo.h +++ b/plugins/SquidgeDistortion/DistrhoPluginInfo.h @@ -9,7 +9,7 @@ #define DISTRHO_PLUGIN_NUM_INPUTS 2 #define DISTRHO_PLUGIN_NUM_OUTPUTS 2 -#define DISTRHO_PLUGIN_NUM_PARAMETERS 1 +#define DISTRHO_PLUGIN_NUM_PARAMETERS 2 #define DISTRHO_PLUGIN_WANT_PROGRAMS 0 #define DISTRHO_PLUGIN_WANT_STATE 0 diff --git a/plugins/SquidgeDistortion/SquidgeDistortion.cpp b/plugins/SquidgeDistortion/SquidgeDistortion.cpp index b1505da..105e83c 100644 --- a/plugins/SquidgeDistortion/SquidgeDistortion.cpp +++ b/plugins/SquidgeDistortion/SquidgeDistortion.cpp @@ -11,6 +11,7 @@ class SquidgeDistortion : public Plugin { public: enum Parameters { kParamGain, + kParamClipMode, kParameterCount // must be last }; SquidgeDistortion() : Plugin(kParameterCount, 0, 0), gain_(2.0f) {} @@ -26,7 +27,6 @@ protected: int64_t getUniqueId() const override { return d_cconst('S', 'Q', 'D', 'T'); } void initParameter(uint32_t index, Parameter ¶meter) override { - parameter.unit = "!"; switch (index) { case kParamGain: parameter.name = "Gain"; @@ -35,7 +35,18 @@ protected: parameter.ranges.def = 2.0f; parameter.ranges.max = 10.0f; parameter.hints = kParameterIsAutomatable; - + break; + case kParamClipMode: + parameter.name = "Clip Mode"; + parameter.symbol = "clipmode"; + parameter.ranges.min = 0.0f; + parameter.ranges.def = 0.0f; + parameter.ranges.max = Clipper::kClipperModeCount - 1; + parameter.hints = kParameterIsAutomatable | kParameterIsInteger; + parameter.enumValues.count = Clipper::kClipperModeCount; + parameter.enumValues.restrictedMode = true; + parameter.enumValues.values = + new ParameterEnumerationValue[2]{{0.0f, "Soft"}, {1.0f, "Hard"}}; break; } } @@ -44,6 +55,8 @@ protected: switch (index) { case kParamGain: return gain_.getGain(); + case kParamClipMode: + return (float)clipper_.getMode(); } return 0.0f; } @@ -53,6 +66,9 @@ protected: case kParamGain: gain_.setGain(value); break; + case kParamClipMode: + clipper_.setMode((Clipper::ClipperMode)value); + break; } }