-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistortion.h
More file actions
73 lines (56 loc) · 2.55 KB
/
Distortion.h
File metadata and controls
73 lines (56 loc) · 2.55 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
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2024 JDSherbert. All rights reserved.
#pragma once
// ======================================================================= //
// Distortion (Base Class)
//
// A family of distortion effects implemented as a base class with separate
// subclasses for each algorithm. Each subclass overrides ProcessSample()
// with its own waveshaping function.
//
// Distortion works by intentionally deforming the shape of an audio
// waveform. The nature of that deformation determines the character of
// the effect — soft and musical, harsh and aggressive, or complex and
// metallic.
//
// All algorithms share a single parameter: distortionAmount, which
// controls the intensity of the effect. The valid range and behaviour
// of this parameter varies per algorithm and is documented on each subclass.
//
// Do not instantiate this class directly — use one of the subclasses:
// - SoftClipDistortion (SoftClipDistortion.h)
// - HardClipDistortion (HardClipDistortion.h)
// - FoldbackDistortion (FoldbackDistortion.h)
//
// ======================================================================= //
namespace Sherbert
{
class Distortion
{
public:
// ------------------------------------------------------------------
// Constructor
//
// distortionAmount - Controls the intensity of the effect.
// See each subclass for its specific range and behaviour.
// Must be greater than 0.
// ------------------------------------------------------------------
explicit Distortion(float distortionAmount);
virtual ~Distortion() = default;
// ------------------------------------------------------------------
// ProcessSample
//
// Apply the distortion effect to a single input sample.
// Call this once per sample in your audio callback loop.
// Input is expected to be in the range [-1.0, 1.0].
// ------------------------------------------------------------------
[[nodiscard]] virtual float ProcessSample(float input) const = 0;
// ------------------------------------------------------------------
// Getters / Setters
// ------------------------------------------------------------------
float getDistortionAmount() const noexcept { return distortionAmount; }
void setDistortionAmount(float newAmount);
protected:
float distortionAmount;
};
}
// ======================================================================= //