Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
soft_limiter.hpp
Go to the documentation of this file.
1// sbl/dsp/soft_limiter.hpp — Soft limiter primitive
2//
3// Bounded rational sigmoid: x * (27 + x²) / (27 + 9x²)
4// Same [3,2] Padé approximant as fast_tanhf, without clamping or NaN guard.
5//
6// Monotonic, odd-symmetric, unity gain at origin. NOT bounded — approaches
7// x/9 for large x. For bounded [-1,1] output, clamp input to [-3,3] first.
8//
9// Key values: process(1.0) ≈ 0.78, process(3.0) = 1.0
10//
11// Usage:
12// sbl::dsp::SoftLimiter limiter;
13// float out = limiter.process(signal);
14
15#ifndef SBL_DSP_PRIMITIVES_SOFT_LIMITER_HPP_
16#define SBL_DSP_PRIMITIVES_SOFT_LIMITER_HPP_
17
18#include <cstdint>
19
20namespace sbl::dsp::primitives {
21
23public:
24 /// Process a single sample
25 float process(float x) { return limit(x); }
26
27 /// Process a block in-place
28 void process(float* buf, uint16_t frames) {
29 for (uint16_t i = 0; i < frames; ++i) {
30 buf[i] = limit(buf[i]);
31 }
32 }
33
34 /// The rational sigmoid, available for composition use
35 static float limit(float x) {
36 float x2 = x * x;
37 return x * (27.0f + x2) / (27.0f + 9.0f * x2);
38 }
39};
40
41} // namespace sbl::dsp::primitives
42
43#endif // SBL_DSP_PRIMITIVES_SOFT_LIMITER_HPP_
float process(float x)
Process a single sample.
void process(float *buf, uint16_t frames)
Process a block in-place.
static float limit(float x)
The rational sigmoid, available for composition use.
Stateful, single-concern building blocks.