Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
fast_math.hpp File Reference

Fast analytical approximations of sin, tan, 2^x and tanh. More...

Detailed Description

Fast analytical approximations of sin, tan, 2^x and tanh.

Pure arithmetic, with no lookup tables, for hot audio paths where libm calls cost too much. Each function states its domain and accuracy.

float g = sbl::dsp::math::fast_tan_pif(fc / fs); // TPT integrator gain
// Exponential modulation (LFO -> filter cutoff):
float mod_cutoff = cutoff * sbl::dsp::math::fast_exp2f(lfo * depth_oct);
float fast_exp2f(float x)
Fast 2^x approximation for exponential modulation.
float fast_tan_pif(float f)
Fast tan(pi f) for normalized frequency f in [0, 0.497].
Definition fast_math.hpp:73

Definition in file fast_math.hpp.

#include <cstring>
#include <sbl/math/constants.hpp>

Go to the source code of this file.

Namespaces

namespace  sbl
 Root namespace for all Sound Byte Libs code.
 
namespace  sbl::dsp
 The audio stack.
 
namespace  sbl::dsp::math
 Math for the audio stack.
 

Functions

float sbl::dsp::math::fast_sinf (float x)
 Fast sine approximation for x in [0, pi/2].
 
float sbl::dsp::math::fast_tan_pif (float f)
 Fast tan(pi f) for normalized frequency f in [0, 0.497].
 
float sbl::dsp::math::fast_exp2f (float x)
 Fast 2^x approximation for exponential modulation.
 
float sbl::dsp::math::fast_tanhf (float x)
 Fast tanh approximation using a [3,2] Pade approximant.
 
constexpr float sbl::dsp::math::one_minus_exp_neg (float x)
 1 - e^(-x) by inverse Taylor, with no expf
 

Variables

constexpr float sbl::dsp::math::FAST_TAN_PIF_MAX_F = 0.497f
 
constexpr float sbl::dsp::math::EXP2_MAX_ARG = 16.0f
 
constexpr int32_t sbl::dsp::math::FLOAT_MANTISSA_BITS = 23
 
constexpr float sbl::dsp::math::TANH_SATURATE_X = 3.0f