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) {
for (uint32_t i = 0; i < frames; ++i) {
if (outLeft[i] > 0) {
outLeft[i] = inLeft[i] > clip_ ? clip_ : inLeft[i];
} else {
outLeft[i] = inLeft[i] < -clip_ ? -clip_ : inLeft[i];
}
if (outRight[i] > 0) {
outRight[i] = inRight[i] > clip_ ? clip_ : inRight[i];
} else {
outRight[i] = inRight[i] < -clip_ ? -clip_ : inRight[i];
}
outLeft[i] = 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 {
out = in < -clip_ ? -clip_ : in;
}
return out;
}