From eb1a82ac93343e86ef1c98caa512fcf2e52a546b Mon Sep 17 00:00:00 2001 From: wan-may Date: Mon, 20 Mar 2023 21:13:47 -0300 Subject: [PATCH] Back at it! Add limiter plugin. --- src/CMakeLists.txt | 3 +- src/yaw-brick/CMakeLists.txt | 9 ++++ src/yaw-brick/DistrhoPluginInfo.h | 17 ++++++++ src/yaw-brick/dsp.cpp | 68 +++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/yaw-brick/CMakeLists.txt create mode 100644 src/yaw-brick/DistrhoPluginInfo.h create mode 100644 src/yaw-brick/dsp.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df15ee5..e6fb382 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,4 +3,5 @@ add_subdirectory(yaw-tab) add_subdirectory(yaw-shepard) add_subdirectory(yaw-vowel) add_subdirectory(yaw-totune) -add_subdirectory(yaw-shep) \ No newline at end of file +add_subdirectory(yaw-shep) +add_subdirectory(yaw-brick) \ No newline at end of file diff --git a/src/yaw-brick/CMakeLists.txt b/src/yaw-brick/CMakeLists.txt new file mode 100644 index 0000000..5da3ae4 --- /dev/null +++ b/src/yaw-brick/CMakeLists.txt @@ -0,0 +1,9 @@ +dpf_add_plugin(yaw-brick + TARGETS vst2 + FILES_DSP + dsp.cpp) + + +target_include_directories(yaw-brick PUBLIC + "." + "../../lib") \ No newline at end of file diff --git a/src/yaw-brick/DistrhoPluginInfo.h b/src/yaw-brick/DistrhoPluginInfo.h new file mode 100644 index 0000000..f724ea8 --- /dev/null +++ b/src/yaw-brick/DistrhoPluginInfo.h @@ -0,0 +1,17 @@ +#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED +#define DISTRHO_PLUGIN_INFO_H_INCLUDED + +#define DISTRHO_PLUGIN_BRAND "yaw-audio" +#define DISTRHO_PLUGIN_NAME "yaw-brick" +#define DISTRHO_PLUGIN_URI "https://yaw.man/plugins/yaw-brick" + +#define DISTRHO_PLUGIN_IS_RT_SAFE 1 +#define DISTRHO_PLUGIN_NUM_INPUTS 2 +#define DISTRHO_PLUGIN_NUM_OUTPUTS 2 + +enum Parameters { + kParamLimit = 0, //Maximum gain. + kParamGain //Pre-amplification +}; + +#endif diff --git a/src/yaw-brick/dsp.cpp b/src/yaw-brick/dsp.cpp new file mode 100644 index 0000000..901975f --- /dev/null +++ b/src/yaw-brick/dsp.cpp @@ -0,0 +1,68 @@ +#include "DistrhoPlugin.hpp" + +START_NAMESPACE_DISTRHO + +class Limiter : public Plugin +{ +public: + Limiter() + : Plugin(2, 0, 0) + { + } + +protected: + const char *getLabel() const override { return "yaw-brick"; } + const char *getDescription() const override { return "Limiter"; } + const char *getMaker() const override { return "yaw-audio"; } + const char *getHomePage() const override { return "https://yaw.man/plugins/yaw-brick"; } + const char *getLicense() const override { return "Fuck you pay me"; } + uint32_t getVersion() const override { return d_version(1, 0, 0); } + int64_t getUniqueId() const override { return d_cconst('y', 'b', 'r', 'k'); } + + void initParameter(uint32_t index, Parameter ¶meter) override + { + parameter.hints = kParameterIsAutomable; + parameter.ranges.def = 0.0f; + parameter.ranges.min = 0.0f; + parameter.ranges.max = 1.0f; + parameter.name = "param"; + parameter.symbol = "param"; + } + + void sampleRateChanged(double newRate) override + {} + + float getParameterValue(uint32_t index) const override + { + return index ? gain : limit; + } + + void setParameterValue(uint32_t idx, float val) override + { + if( idx ) { limit = val; } + else { gain = val; } + } + + void run(const float **inputs, float **outputs, uint32_t frames) override + { + for (int chn = 0; chn < 2; ++chn) + { + for( uint32_t i = 0; i < frames; ++i){ + float x = inputs[chn][i]; + outputs[chn][i] = gain * limit * x / (1.f + gain * x); + } + } + } + +private: + double limit = 0.0; + double gain = 0.0; + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Limiter) +}; + +Plugin *createPlugin() +{ + return new Limiter(); +} + +END_NAMESPACE_DISTRHO