feat: add clipper node

This commit is contained in:
Liam Kerr 2026-08-02 20:03:04 +01:00
parent 229b3eb1e2
commit 77c4851119
3 changed files with 39 additions and 1 deletions

16
core/Clipper.cpp Normal file
View file

@ -0,0 +1,16 @@
#include "Clipper.hpp"
Clipper::Clipper(float init_clip) : clip_(init_clip) {}
void Clipper::process(const float *in, float *out, uint32_t frames) {
for (uint32_t i = 0; i < frames; ++i) {
out[i] = in[i] > clip_ ? clip_ : in[i];
}
}
void Clipper::processStereo(const float *inLeft, const float *inRight,
float *outLeft, float *outRight, uint32_t frames) {
for (uint32_t i = 0; i < frames; ++i) {
outLeft[i] = inLeft[i] > clip_ ? clip_ : inLeft[i];
outRight[i] = inRight[i] > clip_ ? clip_ : inRight[i];
}
}

22
core/Clipper.hpp Normal file
View file

@ -0,0 +1,22 @@
#ifndef CLIPPER_HPP_INCLUDED
#define CLIPPER_HPP_INCLUDED
#include <cstdint>
class Clipper {
public:
Clipper(float init_clip = 1.0f);
void process(const float *in, float *out, uint32_t frames);
void processStereo(const float *inLeft, const float *inRight, float *outLeft,
float *outRight, uint32_t frames);
private:
float clip_;
public:
void setGain(float c) { clip_ = c; }
float getGain() const { return clip_; }
};
#endif // CLIPPER_HPP_INCLUDED