-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoftClipDistortion.h
More file actions
48 lines (38 loc) · 1.48 KB
/
SoftClipDistortion.h
File metadata and controls
48 lines (38 loc) · 1.48 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
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2024 JDSherbert. All rights reserved.
#pragma once
#include "Distortion.h"
// ======================================================================= //
// SoftClipDistortion
//
// Uses a tanh (hyperbolic tangent) function to smoothly compress the
// waveform as it approaches the clipping threshold. This produces warm,
// musical overdrive — the same principle used in valve/tube amplifiers.
//
// Because tanh is a smooth curve, harmonics are introduced gradually,
// resulting in a natural, rounded sound. At low amounts it acts like
// gentle saturation; at high amounts it approaches hard clipping.
//
// Waveform shape:
// input: /\ /\
// output: ⌒ ⌒ (peaks rounded off smoothly)
//
// distortionAmount: Drive applied before the tanh function.
// Range: > 0.0 (typical range: 1.0 - 10.0)
// At 1.0 the effect is subtle; at 10.0 it is very driven.
//
// Usage:
// Sherbert::SoftClipDistortion distortion(2.0f);
// float output = distortion.ProcessSample(input);
//
// ======================================================================= //
namespace Sherbert
{
class SoftClipDistortion : public Distortion
{
public:
explicit SoftClipDistortion(float distortionAmount);
// Applies: output = tanh(distortionAmount * input)
[[nodiscard]] float ProcessSample(float input) const override;
};
}
// ======================================================================= //