-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHardClipDistortion.h
More file actions
60 lines (46 loc) · 1.84 KB
/
HardClipDistortion.h
File metadata and controls
60 lines (46 loc) · 1.84 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
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2024 JDSherbert. All rights reserved.
#pragma once
#include "Distortion.h"
// ======================================================================= //
// HardClipDistortion
//
// Clamps the waveform to a fixed threshold, cutting off any part of the
// signal that exceeds it. This produces a harsh, aggressive distortion
// with strong odd harmonics — characteristic of fuzz pedals and
// transistor clipping circuits.
//
// Unlike soft clipping, the transition from clean to clipped is abrupt,
// which introduces more high-frequency content and a more abrasive tone.
//
// Waveform shape:
// input: /\ /\
// output: ⌐¬ ⌐¬ (peaks cut flat)
//
// distortionAmount: Gain applied before clipping.
// Range: > 0.0 (typical range: 1.0 - 10.0)
// Higher values push more of the signal into clipping.
//
// threshold: The absolute value at which the signal is clamped.
// Range: (0.0, 1.0] — defaults to 1.0.
// Lower values produce earlier, more aggressive clipping.
//
// Usage:
// Sherbert::HardClipDistortion distortion(3.0f, 0.8f);
// float output = distortion.ProcessSample(input);
//
// ======================================================================= //
namespace Sherbert
{
class HardClipDistortion : public Distortion
{
public:
explicit HardClipDistortion(float distortionAmount, float threshold = 1.0f);
// Applies: output = clamp(distortionAmount * input, -threshold, +threshold)
[[nodiscard]] float ProcessSample(float input) const override;
float getThreshold() const noexcept { return threshold; }
void setThreshold(float newThreshold);
private:
float threshold;
};
}
// ======================================================================= //