1pub struct Limiter;
4
5impl Limiter {
6 #[inline(always)]
8 pub fn tanh_soft_clip(sample: f32) -> f32 {
9 sample.tanh()
10 }
11
12 #[inline(always)]
14 pub fn cubic_soft_clip(sample: f32) -> f32 {
15 if sample > 1.0 {
16 2.0 / 3.0
17 } else if sample < -1.0 {
18 -2.0 / 3.0
19 } else {
20 sample - (sample.powi(3) / 3.0)
21 }
22 }
23
24 #[inline(always)]
26 pub fn hard_clamp(sample: f32) -> f32 {
27 sample.clamp(-1.0, 1.0)
28 }
29
30 pub fn process_tanh_buffer(buffer: &mut [f32]) {
32 for sample in buffer.iter_mut() {
33 *sample = Self::tanh_soft_clip(*sample);
34 }
35 }
36}