refactor: optimize Clipper class with extracted clip helper method for cleaner stereo processing logic
This commit is contained in:
parent
ce7844d7af
commit
3a11f43fdc
2 changed files with 13 additions and 10 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ public:
|
|||
|
||||
private:
|
||||
float clip_;
|
||||
float clip(const float in);
|
||||
|
||||
public:
|
||||
void setGain(float c) { clip_ = c; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue