Audio Processing Framework (APF) version 0.5.0
Classes | Functions
apf::math Namespace Reference

Mathematical constants and helper functions. More...

Classes

struct  identity
 Identity function object. Function call returns a const reference to input. More...
 
class  linear_interpolator
 Function object for linear interpolation. More...
 
class  raised_cosine
 Raised cosine (function object). More...
 

Functions

template<typename T >
constexpr T pi ()
 $\pi$. More...
 
template<>
constexpr float pi< float > ()
 $\pi$. More...
 
template<>
constexpr double pi< double > ()
 $\pi$. More...
 
template<>
constexpr long double pi< long double > ()
 $\pi$. More...
 
template<typename T >
pi_div_180 ()
 $\pi/180$ More...
 
template<typename T >
square (T x)
 Product of a number with itself. More...
 
template<typename T >
dB2linear (T L, bool power=false)
 Convert a level in decibel to a linear gain factor. More...
 
template<typename T >
linear2dB (T x, bool power=false)
 Convert a linear gain factor to a level in dB. More...
 
template<typename T >
deg2rad (T angle)
 Convert an angle in degrees to an angle in radians. More...
 
template<typename T >
rad2deg (T angle)
 Convert an angle in radians to an angle in degrees. More...
 
template<typename T >
fwrap (T x, T full)
 Wrap x into the interval [0, full). More...
 
template<typename T >
wrap (T x, T full)
 Wrap x into the interval [0, full). More...
 
template<>
float wrap (float x, float full)
 Wrap x into the interval [0, full). More...
 
template<>
double wrap (double x, double full)
 Wrap x into the interval [0, full). More...
 
template<>
long double wrap (long double x, long double full)
 Wrap x into the interval [0, full). More...
 
template<typename T >
wrap_two_pi (T x)
 
template<typename T >
next_power_of_2 (T number)
 Find a power of 2 which is >= a given number. More...
 
template<typename I >
std::iterator_traits< I >::value_type max_amplitude (I begin, I end)
 Return the absolute maximum of a series of numbers. More...
 
template<typename I >
std::iterator_traits< I >::value_type rms (I begin, I end)
 Root Mean Square (RMS) value of a series of numbers. More...
 
template<typename I >
bool has_only_zeros (I first, I last)
 Check if there are only zeros in a range. More...
 
template<typename T >
linear_interpolator< T > make_linear_interpolator (T first, T last)
 Helper function for automatic template type deduction. More...
 
template<typename T , typename U >
linear_interpolator< T, U > make_linear_interpolator (T first, T last, U length)
 Helper function for automatic template type deduction. More...
 

Detailed Description

Mathematical constants and helper functions.

Function Documentation

◆ pi()

template<typename T >
constexpr T apf::math::pi ( )
constexpr

$\pi$.

Undefined general case.

◆ pi< float >()

template<>
constexpr float apf::math::pi< float > ( )
constexpr

$\pi$.

Specialization for float.

Definition at line 51 of file math.h.

◆ pi< double >()

template<>
constexpr double apf::math::pi< double > ( )
constexpr

$\pi$.

Specialization for double.

Definition at line 61 of file math.h.

◆ pi< long double >()

template<>
constexpr long double apf::math::pi< long double > ( )
constexpr

$\pi$.

Specialization for long double.

Definition at line 69 of file math.h.

◆ pi_div_180()

template<typename T >
T apf::math::pi_div_180 ( )
inline

$\pi/180$

Definition at line 76 of file math.h.

◆ square()

template<typename T >
T apf::math::square ( x)
inline

Product of a number with itself.

Parameters
xnumber (any numeric type)
Returns
x squared.

Definition at line 87 of file math.h.

◆ dB2linear()

template<typename T >
T apf::math::dB2linear ( L,
bool  power = false 
)
inline

Convert a level in decibel to a linear gain factor.

Parameters
Llevel
powerif true, a factor of 10 is used, if false (default), the factor is 20.
Returns
the linear counterpart to L.

Definition at line 96 of file math.h.

◆ linear2dB()

template<typename T >
T apf::math::linear2dB ( x,
bool  power = false 
)
inline

Convert a linear gain factor to a level in dB.

Parameters
xgain factor
powerif true, a factor of 10 is used, if false (default), the factor is 20.
Returns
the logarithmic counterpart to x.
Attention
returns -Inf for x=0 and NaN for x<0.

Definition at line 111 of file math.h.

◆ deg2rad()

template<typename T >
T apf::math::deg2rad ( angle)
inline

Convert an angle in degrees to an angle in radians.

Parameters
angledito
Returns
angle in radians.

Definition at line 122 of file math.h.

◆ rad2deg()

template<typename T >
T apf::math::rad2deg ( angle)
inline

Convert an angle in radians to an angle in degrees.

Parameters
angledito
Returns
angle in degrees.

Definition at line 132 of file math.h.

◆ fwrap()

template<typename T >
T apf::math::fwrap ( x,
full 
)
inline

Wrap x into the interval [0, full).

Helper function for float, double and long double.

See also
wrap()

Definition at line 141 of file math.h.

Referenced by wrap().

◆ wrap() [1/4]

template<typename T >
T apf::math::wrap ( x,
full 
)
inline

Wrap x into the interval [0, full).

Unspecialized case, works only for integral types.

Definition at line 151 of file math.h.

Referenced by apf::circular_iterator< I >::operator+=().

◆ wrap() [2/4]

template<>
float apf::math::wrap ( float  x,
float  full 
)
inline

Wrap x into the interval [0, full).

Template specialization for float.

Definition at line 161 of file math.h.

References fwrap().

◆ wrap() [3/4]

template<>
double apf::math::wrap ( double  x,
double  full 
)
inline

Wrap x into the interval [0, full).

Template specialization for double.

Definition at line 169 of file math.h.

References fwrap().

◆ wrap() [4/4]

template<>
long double apf::math::wrap ( long double  x,
long double  full 
)
inline

Wrap x into the interval [0, full).

Template specialization for long double.

Definition at line 177 of file math.h.

References fwrap().

◆ wrap_two_pi()

template<typename T >
T apf::math::wrap_two_pi ( x)
inline

Definition at line 183 of file math.h.

◆ next_power_of_2()

template<typename T >
T apf::math::next_power_of_2 ( number)
inline

Find a power of 2 which is >= a given number.

Parameters
numbernumber for which to find next power of 2
Returns
power of 2 above (or equal to) number
Note
For all numbers <= 1 the result is 1;

Definition at line 196 of file math.h.

◆ max_amplitude()

template<typename I >
std::iterator_traits< I >::value_type apf::math::max_amplitude ( begin,
end 
)
inline

Return the absolute maximum of a series of numbers.

Parameters
beginbeginning of range
endend of range
Returns
maximum, this is always >= 0.

Definition at line 210 of file math.h.

◆ rms()

template<typename I >
std::iterator_traits< I >::value_type apf::math::rms ( begin,
end 
)
inline

Root Mean Square (RMS) value of a series of numbers.

Parameters
beginbeginning of range
endend of range
Returns
RMS value

Definition at line 223 of file math.h.

◆ has_only_zeros()

template<typename I >
bool apf::math::has_only_zeros ( first,
last 
)

Check if there are only zeros in a range.

Returns
false as soon as a non-zero value is encountered

Definition at line 238 of file math.h.

Referenced by apf::conv::Input::add_block(), and apf::conv::TransformBase::prepare_partition().

◆ make_linear_interpolator() [1/2]

template<typename T >
linear_interpolator< T > apf::math::make_linear_interpolator ( first,
last 
)

Helper function for automatic template type deduction.

Definition at line 318 of file math.h.

◆ make_linear_interpolator() [2/2]

template<typename T , typename U >
linear_interpolator< T, U > apf::math::make_linear_interpolator ( first,
last,
length 
)

Helper function for automatic template type deduction.

Definition at line 326 of file math.h.