This commit is contained in:
wan-may 2024-05-02 23:30:15 -03:00
parent d9c98c59b3
commit 3f779532ac
1 changed files with 18 additions and 9 deletions

View File

@ -21,12 +21,20 @@ protected:
void initParameter(uint32_t index, Parameter &parameter) override void initParameter(uint32_t index, Parameter &parameter) override
{ {
parameter.hints = kParameterIsAutomable; parameter.hints = kParameterIsAutomatable;
parameter.ranges.def = 0.0f; parameter.ranges.def = 0.5f;
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
parameter.name = "param"; if( index > 0 ) {
parameter.symbol = "param"; parameter.name = "limit";
parameter.symbol = "l";
parameter.ranges.max = 2.0f;
}
else {
parameter.name = "gain";
parameter.symbol = "g";
parameter.ranges.max = 20.0f;
}
} }
void sampleRateChanged(double newRate) override void sampleRateChanged(double newRate) override
@ -34,12 +42,13 @@ protected:
float getParameterValue(uint32_t index) const override float getParameterValue(uint32_t index) const override
{ {
return index ? gain : limit; if( index > 0 ) { return limit; }
else { return gain; }
} }
void setParameterValue(uint32_t idx, float val) override void setParameterValue(uint32_t idx, float val) override
{ {
if( idx ) { limit = val; } if( idx > 0 ) { limit = val; }
else { gain = val; } else { gain = val; }
} }
@ -49,14 +58,14 @@ protected:
{ {
for( uint32_t i = 0; i < frames; ++i) { for( uint32_t i = 0; i < frames; ++i) {
outputs[chn][i] = limit / ( 1.f + expf(-inputs[chn][i] * gain)); outputs[chn][i] = limit * (2.f / ( 1.f + expf(-inputs[chn][i] * gain)) - 1.f);
} }
} }
} }
private: private:
double limit = 0.0; float limit = 0.f;
double gain = 0.0; float gain = 0.f;
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Limiter) DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Limiter)
}; };