refactor: optimize Clipper class with extracted clip helper method for cleaner stereo processing logic

This commit is contained in:
Liam Kerr 2026-08-02 20:26:06 +01:00
parent ce7844d7af
commit 3a11f43fdc
2 changed files with 13 additions and 10 deletions

View file

@ -11,15 +11,17 @@ void Clipper::processStereo(const float *inLeft, const float *inRight,
float *outLeft, float *outRight, uint32_t frames) { float *outLeft, float *outRight, uint32_t frames) {
for (uint32_t i = 0; i < frames; ++i) { for (uint32_t i = 0; i < frames; ++i) {
if (outLeft[i] > 0) { outLeft[i] = clip(inLeft[i]);
outLeft[i] = inLeft[i] > clip_ ? clip_ : inLeft[i]; outRight[i] = clip(inRight[i]);
}
}
float Clipper::clip(const float in) {
float out = in;
if (in > 0) {
out = in > clip_ ? clip_ : in;
} else { } else {
outLeft[i] = inLeft[i] < -clip_ ? -clip_ : inLeft[i]; out = in < -clip_ ? -clip_ : in;
}
if (outRight[i] > 0) {
outRight[i] = inRight[i] > clip_ ? clip_ : inRight[i];
} else {
outRight[i] = inRight[i] < -clip_ ? -clip_ : inRight[i];
}
} }
return out;
} }

View file

@ -13,6 +13,7 @@ public:
private: private:
float clip_; float clip_;
float clip(const float in);
public: public:
void setGain(float c) { clip_ = c; } void setGain(float c) { clip_ = c; }