Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Generators::Fast Namespace Reference

Performance-optimised oscillators.

Classes

struct  Increment
 Phase increment (optimised) More...
 
struct  Noise
 White noise generator (optimised) More...
 
struct  OSM
 Oscillator State Machine. More...
 
struct  Phase
 Oscillator phase (optimised) More...
 
struct  Pulse
 Pulse wave oscillator (band-limited, optimised) More...
 
struct  Saw
 Saw wave oscillator (band-limited, optimised) More...
 
struct  Sine
 Sine wave oscillator (band-limited, optimised) More...
 
struct  Square
 Square wave oscillator (band-limited, optimised) More...
 
struct  Triangle
 Triangle wave oscillator (band-limited, optimised) More...
 

Functions

static float polysin (float x)
 sin approximation [-pi/2, pi/2] using odd minimax polynomial (Robin Green)
 
static float fastsin (float x)
 fast sine (based on V2/Farbrausch; using polysin)
 
static float fastsinp (unsigned int p)
 fast sine (using polysin and integer math)
 

Variables

constexpr float twoPi = float(2.0 * 3.1415926535897932384626433832795)
 
constexpr float twoPiInv = float(1.0 / twoPi)
 

Function Documentation

◆ fastsin()

static float klang::Generators::Fast::fastsin ( float x)
inlinestatic

Definition at line 3830 of file klang.h.

3831 {
3832 // Range reduction to [0, 2pi]
3833 //x = fmodf(x, twoPi);
3834 //if (x < 0) // support -ve phase (e.g. for FM)
3835 // x += twoPi; //
3836 x = fast_mod2pi(x);
3837
3838 // Range reduction to [-pi/2, pi/2]
3839 if (x > 3/2.f * pi) // 3/2pi ... 2pi
3840 x -= twoPi; // (= translated)
3841 else if (x > pi/2) // pi/2 ... 3pi/2
3842 x = pi - x; // (= mirrored)
3843
3844 return polysin(x);
3845 }
constexpr float twoPi
Definition klang.h:3687
static float polysin(float x)
sin approximation [-pi/2, pi/2] using odd minimax polynomial (Robin Green)
Definition klang.h:3824
float fast_mod2pi(float x)
Definition klang.h:717
constexpr constant pi
The mathematical constant, pi (and it's inverse).
Definition klang.h:218

References klang::fast_mod2pi(), klang::pi, polysin(), and twoPi.

◆ fastsinp()

static float klang::Generators::Fast::fastsinp ( unsigned int p)
inlinestatic

Definition at line 3848 of file klang.h.

3849 {
3850 // Range reduction to [0, 2pi]
3851 //x = fmodf(x, twoPi);
3852 //if (x < 0) // support -ve phase (e.g. for FM)
3853 // x += twoPi; //
3854 float x = fast_modp(p);
3855
3856 // Range reduction to [-pi/2, pi/2]
3857 if (x > 3.f/2.f * pi) // 3/2pi ... 2pi
3858 x -= twoPi; // (= translated)
3859 else if (x > pi/2.f) // pi/2 ... 3pi/2
3860 x = pi - x; // (= mirrored)
3861
3862 return polysin(x);
3863 }
float fast_modp(unsigned int x)
Definition klang.h:723

References klang::fast_modp(), klang::pi, polysin(), and twoPi.

Referenced by klang::Generators::Fast::Sine::process().

◆ polysin()

static float klang::Generators::Fast::polysin ( float x)
inlinestatic

Definition at line 3824 of file klang.h.

3824 {
3825 const float x2 = x * x;
3826 return (((-0.00018542f * x2 + 0.0083143f) * x2 - 0.16666f) * x2 + 1.0f) * x;
3827 }

Referenced by fastsin(), and fastsinp().

Variable Documentation

◆ twoPi

float klang::Generators::Fast::twoPi = float(2.0 * 3.1415926535897932384626433832795)
constexpr

Definition at line 3687 of file klang.h.

Referenced by fastsin(), fastsinp(), and klang::Generators::Fast::Sine::set().

◆ twoPiInv

float klang::Generators::Fast::twoPiInv = float(1.0 / twoPi)
constexpr

Definition at line 3688 of file klang.h.