Sound Byte Libs
0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
asymmetric_shaper.hpp
Go to the documentation of this file.
1
// sbl/dsp/asymmetric_shaper.hpp — Asymmetric distortion primitive
2
//
3
// Adds even-order harmonics via a quadratic term: y = x + k * x²
4
//
5
// k controls the asymmetry:
6
// k = 0.0: linear (no distortion)
7
// k = 0.1: mild warmth (subtle 2nd harmonic)
8
// k = 0.3+: obvious asymmetric character
9
//
10
// Asymmetric saturation is what gives tube and transformer coloration
11
// its "warm" quality — the positive and negative half-cycles are shaped
12
// differently, introducing even-order harmonics (2nd, 4th) that the ear
13
// perceives as warmth rather than harshness.
14
//
15
// This primitive exposes the asymmetry amount as a configurable parameter
16
// rather than hardcoding it. Pair with SoftLimiter to bound the output.
17
//
18
// Usage:
19
// sbl::dsp::AsymmetricShaper shaper;
20
// shaper.set_asymmetry(0.1f);
21
// float out = shaper.process(signal);
22
23
#ifndef SBL_DSP_PRIMITIVES_ASYMMETRIC_SHAPER_HPP_
24
#define SBL_DSP_PRIMITIVES_ASYMMETRIC_SHAPER_HPP_
25
26
#include <cstdint>
27
28
namespace
sbl::dsp::primitives
{
29
30
class
AsymmetricShaper
{
31
public
:
32
/// Set asymmetry depth (not a signal — structural character parameter)
33
void
set_asymmetry
(
float
k) { k_ = k; }
34
35
/// Current asymmetry depth
36
float
asymmetry
()
const
{
return
k_; }
37
38
/// Process a single sample
39
float
process
(
float
x) {
40
return
x + k_ * x * x;
41
}
42
43
/// Process a block in-place
44
void
process
(
float
* buf, uint16_t frames) {
45
for
(uint16_t i = 0; i < frames; ++i) {
46
buf[i] =
process
(buf[i]);
47
}
48
}
49
50
private
:
51
float
k_ = 0.0f;
52
};
53
54
}
// namespace sbl::dsp::primitives
55
56
#endif
// SBL_DSP_PRIMITIVES_ASYMMETRIC_SHAPER_HPP_
sbl::dsp::primitives::AsymmetricShaper
Definition
asymmetric_shaper.hpp:30
sbl::dsp::primitives::AsymmetricShaper::process
float process(float x)
Process a single sample.
Definition
asymmetric_shaper.hpp:39
sbl::dsp::primitives::AsymmetricShaper::process
void process(float *buf, uint16_t frames)
Process a block in-place.
Definition
asymmetric_shaper.hpp:44
sbl::dsp::primitives::AsymmetricShaper::set_asymmetry
void set_asymmetry(float k)
Set asymmetry depth (not a signal — structural character parameter)
Definition
asymmetric_shaper.hpp:33
sbl::dsp::primitives::AsymmetricShaper::asymmetry
float asymmetry() const
Current asymmetry depth.
Definition
asymmetric_shaper.hpp:36
sbl::dsp::primitives
Stateful, single-concern building blocks.
Definition
allpass_filter.hpp:23
src
sbl
dsp
primitives
asymmetric_shaper.hpp
Generated by
1.9.8