bugfix: clipper now uses threshold consistently

This commit is contained in:
Liam Kerr 2026-08-03 15:43:02 +01:00
parent 34efab4d8e
commit e1274e7be7
2 changed files with 12 additions and 12 deletions

View file

@ -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;