-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoftClipDistortion.cpp
More file actions
37 lines (29 loc) · 1.44 KB
/
SoftClipDistortion.cpp
File metadata and controls
37 lines (29 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) 2024 JDSherbert. All rights reserved.
#include "SoftClipDistortion.h"
#include <cmath>
// ======================================================================= //
Sherbert::SoftClipDistortion::SoftClipDistortion(float distortionAmount)
: Distortion(distortionAmount)
{
}
// ======================================================================= //
float Sherbert::SoftClipDistortion::ProcessSample(float input) const
{
// ==== HOW SOFT CLIPPING WORKS ==========================================
//
// tanh (hyperbolic tangent) maps any input value to the range (-1, 1).
// Its curve is gentle near zero and flattens gradually toward the limits,
// so loud parts of the signal are compressed rather than cut abruptly.
//
// Multiplying input by distortionAmount before passing it to tanh
// increases the drive — it pushes the signal further up the curve,
// introducing more harmonic content and compression.
//
// At low drive: the signal sits near the linear centre of the curve
// and passes through almost unchanged.
// At high drive: the signal is pushed to the flat extremes of the curve,
// approaching a square wave with rounded edges.
// =======================================================================
return std::tanh(distortionAmount * input);
}
// ======================================================================= //