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>
|
||||
|
||||
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) {
|
||||
for (uint32_t i = 0; i < frames; ++i) {
|
||||
|
|
@ -21,19 +21,19 @@ float Clipper::clip(const float in) {
|
|||
switch (mode_) {
|
||||
default:
|
||||
case kClipperModeHard: {
|
||||
return std::fmin(std::fmax(in, -clip_), clip_);
|
||||
return std::fmin(std::fmax(in, -threshold_), threshold_);
|
||||
}
|
||||
case kClipperModeSoft: {
|
||||
float normalized = (in / clip_) * 0.75f;
|
||||
return std::tanh(normalized) * clip_;
|
||||
float normalized = (in / threshold_) * 0.75f;
|
||||
return std::tanh(normalized) * threshold_;
|
||||
}
|
||||
case kClipperModeFold: {
|
||||
float x = in;
|
||||
while (x > clip_ || x < -clip_) {
|
||||
if (x > clip_) {
|
||||
x = 2.0f * clip_ - x;
|
||||
} else if (x < -clip_) {
|
||||
x = -2.0f * clip_ - x;
|
||||
while (x > threshold_ || x < -threshold_) {
|
||||
if (x > threshold_) {
|
||||
x = 2.0f * threshold_ - x;
|
||||
} else if (x < -threshold_) {
|
||||
x = -2.0f * threshold_ - x;
|
||||
}
|
||||
}
|
||||
return x;
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ public:
|
|||
float *outRight, uint32_t frames);
|
||||
|
||||
private:
|
||||
float clip_;
|
||||
float threshold_;
|
||||
float clip(const float in);
|
||||
ClipperMode mode_;
|
||||
|
||||
public:
|
||||
void setGain(float c) { clip_ = c; }
|
||||
float getGain() const { return clip_; }
|
||||
void setThreshold(float c) { threshold_ = c; }
|
||||
float getThreshold() const { return threshold_; }
|
||||
void setMode(ClipperMode m) { mode_ = m; }
|
||||
ClipperMode getMode() const { return mode_; }
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue