bugfix: clipper now uses threshold consistently
This commit is contained in:
parent
34efab4d8e
commit
e1274e7be7
2 changed files with 12 additions and 12 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
Clipper::Clipper(float init_clip, ClipperMode init_mode)
|
Clipper::Clipper(float init_clip, ClipperMode init_mode)
|
||||||
: clip_(init_clip), mode_(init_mode) {}
|
: threshold_(init_clip), mode_(init_mode) {}
|
||||||
|
|
||||||
void Clipper::process(const float *in, float *out, uint32_t frames) {
|
void Clipper::process(const float *in, float *out, uint32_t frames) {
|
||||||
for (uint32_t i = 0; i < frames; ++i) {
|
for (uint32_t i = 0; i < frames; ++i) {
|
||||||
|
|
@ -21,19 +21,19 @@ float Clipper::clip(const float in) {
|
||||||
switch (mode_) {
|
switch (mode_) {
|
||||||
default:
|
default:
|
||||||
case kClipperModeHard: {
|
case kClipperModeHard: {
|
||||||
return std::fmin(std::fmax(in, -clip_), clip_);
|
return std::fmin(std::fmax(in, -threshold_), threshold_);
|
||||||
}
|
}
|
||||||
case kClipperModeSoft: {
|
case kClipperModeSoft: {
|
||||||
float normalized = (in / clip_) * 0.75f;
|
float normalized = (in / threshold_) * 0.75f;
|
||||||
return std::tanh(normalized) * clip_;
|
return std::tanh(normalized) * threshold_;
|
||||||
}
|
}
|
||||||
case kClipperModeFold: {
|
case kClipperModeFold: {
|
||||||
float x = in;
|
float x = in;
|
||||||
while (x > clip_ || x < -clip_) {
|
while (x > threshold_ || x < -threshold_) {
|
||||||
if (x > clip_) {
|
if (x > threshold_) {
|
||||||
x = 2.0f * clip_ - x;
|
x = 2.0f * threshold_ - x;
|
||||||
} else if (x < -clip_) {
|
} else if (x < -threshold_) {
|
||||||
x = -2.0f * clip_ - x;
|
x = -2.0f * threshold_ - x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@ public:
|
||||||
float *outRight, uint32_t frames);
|
float *outRight, uint32_t frames);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float clip_;
|
float threshold_;
|
||||||
float clip(const float in);
|
float clip(const float in);
|
||||||
ClipperMode mode_;
|
ClipperMode mode_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setGain(float c) { clip_ = c; }
|
void setThreshold(float c) { threshold_ = c; }
|
||||||
float getGain() const { return clip_; }
|
float getThreshold() const { return threshold_; }
|
||||||
void setMode(ClipperMode m) { mode_ = m; }
|
void setMode(ClipperMode m) { mode_ = m; }
|
||||||
ClipperMode getMode() const { return mode_; }
|
ClipperMode getMode() const { return mode_; }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue