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
warp.hpp
Go to the documentation of this file.
1// sbl/dsp/warp.hpp — Float warp engines for envelope/parameter shaping
2//
3// Float-domain warp engines for the Audio stack (SegmentGenerator).
4// Phase and curve are both float; no LUT or fixed-point math required.
5//
6// Phase: [0.0, 1.0] — linear ramp through the segment
7// Curve: [-1.0, 1.0] where:
8// -1.0 = full concave (fast start, slow approach to target)
9// 0.0 = linear (no shaping)
10// 1.0 = full convex (slow start, fast snap to target)
11//
12// See FDP-016 for design rationale.
13
14#ifndef SBL_DSP_PRIMITIVES_WARP_HPP_
15#define SBL_DSP_PRIMITIVES_WARP_HPP_
16
17namespace sbl::dsp::primitives {
18
19/// Rational function warp (float). Zero flash, zero RAM.
20/// f(t) = (1+a)*t / (1+a*t), with a = K * curve^2.
21/// Inspired by MI Stages WarpPhase (MIT).
23 static constexpr float K = 128.0f;
24
25 /// @note ISR-safe — bounded computation, no I/O.
26 static float warp(float phase, float curve) {
27 if (curve > -0.001f && curve < 0.001f) return phase;
28
29 bool flip = curve > 0.0f;
30 float t = flip ? (1.0f - phase) : phase;
31 float dc = flip ? curve : -curve;
32
33 float a = K * dc * dc;
34 float num = (1.0f + a) * t;
35 float den = 1.0f + a * t;
36 float result = num / den;
37
38 if (result > 1.0f) result = 1.0f;
39 return flip ? (1.0f - result) : result;
40 }
41};
42
43/// Default float warp engine for SegmentGenerator.
44/// FloatRationalWarp: zero flash, analytical, good character.
46
47} // namespace sbl::dsp::primitives
48
49#endif // SBL_DSP_PRIMITIVES_WARP_HPP_
Stateful, single-concern building blocks.
static float warp(float phase, float curve)
Definition warp.hpp:26