DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
DspMath.h File Reference

Core mathematical utilities for digital signal processing. More...

#include <algorithm>
#include <cmath>
#include <concepts>
#include <numbers>
Include dependency graph for DspMath.h:

Go to the source code of this file.

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Concepts

concept  dspark::FloatType
 Constrains a type to IEEE floating-point (float or double).
 

Functions

template<FloatType T>
dspark::decibelsToGain (T dB, T minusInfinityDb=T(-100)) noexcept
 Converts a value in decibels to linear gain.
 
template<FloatType T>
dspark::gainToDecibels (T gain, T minusInfinityDb=T(-100)) noexcept
 Converts a linear gain value to decibels.
 
template<FloatType T>
dspark::mapRange (T value, T inMin, T inMax, T outMin, T outMax) noexcept
 Maps a value from one range to another (linear interpolation).
 
template<FloatType T>
dspark::fastTanh (T x) noexcept
 Fast tanh approximation using Pade rational function.
 
template<FloatType T>
dspark::fastPow10 (T x) noexcept
 Fast approximation of 10^x using exp2.
 
template<FloatType T>
dspark::fastExp (T x) noexcept
 Fast approximation of e^x via std::exp2 (~2x faster than std::exp on MSVC).
 
template<FloatType T>
dspark::fastTan (T x) noexcept
 Fast approximation of tan(x) using a Pade [5,4] rational approximant.
 
template<FloatType T>
dspark::fastSin (T x) noexcept
 Fast sine approximation (degree-9 odd minimax polynomial).
 
template<FloatType T>
dspark::fastCos (T x) noexcept
 Fast cosine approximation. See fastSin() for accuracy notes (float error is ~7e-6 here: half an ulp more from the pi/2 offset).
 
template<FloatType T>
dspark::fastLog (T x) noexcept
 Fast natural logarithm approximation.
 
template<FloatType T>
dspark::wrapPhase (T phase) noexcept
 Normalises a phase value to the range [0, 2*pi).
 

Variables

template<FloatType T>
constexpr T dspark::pi = std::numbers::pi_v<T>
 Pi (3.14159...) for the given floating-point type.
 
template<FloatType T>
constexpr T dspark::twoPi = T(2) * std::numbers::pi_v<T>
 2 * Pi (6.28318...).
 
template<FloatType T>
constexpr T dspark::invTwoPi = T(1) / twoPi<T>
 1 / (2 * Pi) (0.15915...). Useful for fast phase divisions.
 
template<FloatType T>
constexpr T dspark::halfPi = std::numbers::pi_v<T> / T(2)
 Pi / 2 (1.57079...). Quarter period; sin/cos phase offset.
 
template<FloatType T>
constexpr T dspark::sqrt2 = std::numbers::sqrt2_v<T>
 Square root of 2 (1.41421...).
 
template<FloatType T>
constexpr T dspark::invSqrt2 = T(1) / std::numbers::sqrt2_v<T>
 1 / square root of 2 (0.70710...). Butterworth Q factor.
 

Detailed Description

Core mathematical utilities for digital signal processing.

Provides constants, unit conversions, and fast approximations commonly needed in audio DSP code. All functions are noexcept and suitable for real-time use.

Dependencies: C++20 standard library only.

Definition in file DspMath.h.