MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::math Namespace Reference

Math helper functions and classes. More...

Namespaces

namespace  interpolators
 
namespace  vecops
 Collection of basic arithmetic operations on vectors, SIMD accelerated where possible.
 
namespace  windows
 Various windowing functions. An interactive graph with more intuition than the textual documentation can give can be found here
 

Classes

class  Hadamard
 A helper class to apply an NxN Hadamard matrix to a given input array-like. More...
 
class  Householder
 A helper class to apply an NxN Householder matrix to a given input array-like. More...
 
class  LeakyIntegrator
 An integrator of a continuous signal which leaks a small amount of said signal over time. More...
 
class  Reciprocal
 Class to handle mapping from one range to another (warped) range, based on the reciprocal function 1/x. More...
 
struct  ReciprocalRange
 Convenience POD struct for representing a range used by marvin::math::ReciprocalRange. More...
 

Functions

template<FloatType T>
lerp (T start, T end, T ratio) noexcept
 
template<FloatType T>
remap (T x, T newMin, T newMax)
 
template<FloatType T>
remap (T x, T srcMin, T srcMax, T newMin, T newMax)
 
template<FloatType T>
remap (T x, marvin::utils::Range< T > srcRange, marvin::utils::Range< T > newRange)
 
template<FloatType T>
remap (T x, marvin::utils::Range< T > newRange)
 
template<FloatType T>
std::span< std::complex< T > > interleavedToComplexView (std::span< T > data)
 
template<FloatType T>
std::span< T > complexViewToInterleaved (std::span< std::complex< T > > data)
 
template<FloatType T>
sinc (T x) noexcept
 
template<FloatType T>
msToSeconds (T ms) noexcept
 
template<FloatType T>
secondsToSamples (T seconds, double sampleRate) noexcept
 
template<FloatType T>
msToSamples (T ms, double sampleRate) noexcept
 
template<FloatType T>
dbToGain (T db, T referenceMinDb=static_cast< T >(-100.0))
 
template<FloatType T>
gainToDb (T gain, T minusInfDb=static_cast< T >(-100.0)) noexcept
 
template<FloatType T>
ReciprocalRange< T > operator+ (const ReciprocalRange< T > &other, T constant)
 
template<FloatType T>
ReciprocalRange< T > operator- (const ReciprocalRange< T > &other, T constant)
 
template<FloatType T>
ReciprocalRange< T > operator* (const ReciprocalRange< T > &other, T constant)
 
template<FloatType T>
ReciprocalRange< T > operator/ (const ReciprocalRange< T > &other, T constant)
 

Detailed Description

Math helper functions and classes.

Function Documentation

◆ complexViewToInterleaved()

template<FloatType T>
std::span< T > marvin::math::complexViewToInterleaved ( std::span< std::complex< T > > data)
nodiscard

Takes an array-like of std::complex<T>s of size N, and creates a non owning view treating the packed complex data as an interleaved stream of reals, represented as [re, im, re, im... im] of size N*2. Uses terrifying reinterpret-cast shennanigans to do so, and absolutely requires the caller to ensure that data.size() is even.

Parameters
dataThe data to create the view into.
Returns
A non owning view treating the data as an interleaved stream of reals data.size() * 2 points long.

◆ dbToGain()

template<FloatType T>
T marvin::math::dbToGain ( T db,
T referenceMinDb = static_cast<T>(-100.0) )
nodiscard

Converts from decibels to gain.

Parameters
dbThe level in decibels.
referenceMinDbThe level in decibels that should correspond to 0 gain. Optional, defaults to -100dB.
Returns
The level in decibels converted to a 0 to 1 gain.

◆ gainToDb()

template<FloatType T>
T marvin::math::gainToDb ( T gain,
T minusInfDb = static_cast<T>(-100.0) )
nodiscardnoexcept

Converts from gain to decibels.

Parameters
gainThe 0 to 1 gain to convert.
minusInfDbThe level in decibels that should correspond to 0 gain. Optional, defaults to -100dB.
Returns
The converted level in decibels.

◆ interleavedToComplexView()

template<FloatType T>
std::span< std::complex< T > > marvin::math::interleavedToComplexView ( std::span< T > data)
nodiscard

Takes an array-like of complexes represented as [re, im, re, im, ... im] of size N and creates a non-owning view treating the interleaved stream as an array-like of type std::complex<T> N/2 points long, with no copies or allocations.
Uses terrifying reinterpret-cast shennanigans to do so, and absolutely requires the caller to ensure that data.size() is even.

Parameters
dataThe data to create a view into.
Returns
A non owning view treating data as an array-like<std::complex<T>> data.size() / 2 points long.

◆ lerp()

template<FloatType T>
T marvin::math::lerp ( T start,
T end,
T ratio )
nodiscardnoexcept

Returns a point ratio of the way between start and end.

Parameters
startThe start value of the interpolation.
endThe end value of the interpolation.
ratioThe (0 to 1) position between start and end
Returns
A linear interpolation between start and end at position ratio.

◆ msToSamples()

template<FloatType T>
T marvin::math::msToSamples ( T ms,
double sampleRate )
nodiscardnoexcept

Converts a time in milliseconds to samples.

Parameters
msTime in milliseconds.
sampleRateThe currently used sample rate.
Returns
The number of samples for the given time in milliseconds.

◆ msToSeconds()

template<FloatType T>
T marvin::math::msToSeconds ( T ms)
nodiscardnoexcept

Converts a time in milliseconds to seconds

Parameters
msTime in milliseconds.
Returns
Time in seconds.

◆ operator*()

template<FloatType T>
ReciprocalRange< T > marvin::math::operator* ( const ReciprocalRange< T > & other,
T constant )

◆ operator+()

template<FloatType T>
ReciprocalRange< T > marvin::math::operator+ ( const ReciprocalRange< T > & other,
T constant )

◆ operator-()

template<FloatType T>
ReciprocalRange< T > marvin::math::operator- ( const ReciprocalRange< T > & other,
T constant )

◆ operator/()

template<FloatType T>
ReciprocalRange< T > marvin::math::operator/ ( const ReciprocalRange< T > & other,
T constant )

◆ remap() [1/4]

template<FloatType T>
T marvin::math::remap ( T x,
marvin::utils::Range< T > newRange )
nodiscard

Takes a value in range 0 to 1, and rescales it to be in range newRange.

Parameters
xThe value to remap.
newRangeThe range to map the value into.
Returns
The rescaled value.

◆ remap() [2/4]

template<FloatType T>
T marvin::math::remap ( T x,
marvin::utils::Range< T > srcRange,
marvin::utils::Range< T > newRange )
nodiscard

Takes a value in range srcRange, normalises it, and remaps it to be in range newRange.

Parameters
xThe value to remap.
srcRangeThe range the value is currently in.
newRangeThe range to map the value into.
Returns
The rescaled value.

◆ remap() [3/4]

template<FloatType T>
T marvin::math::remap ( T x,
T newMin,
T newMax )
nodiscard

Takes a value in range 0 to 1, and rescales it to be in range newMin to newMax.

Parameters
xThe value to remap.
newMinThe new range's min.
newMaxThe new range's max.
Returns
The rescaled value.

◆ remap() [4/4]

template<FloatType T>
T marvin::math::remap ( T x,
T srcMin,
T srcMax,
T newMin,
T newMax )
nodiscard

Takes a value in range srcMin to srcMax, normalises it, and rescales it to be in range newMin to newMax

Parameters
xThe value to remap.
srcMinThe min of the value's original range.
srcMaxThe max of the value's original range.
newMinThe new range's min.
newMaxThe new range's max.
Returns
The rescaled value.

◆ secondsToSamples()

template<FloatType T>
T marvin::math::secondsToSamples ( T seconds,
double sampleRate )
nodiscardnoexcept

Converts a time in seconds to samples.

Parameters
secondsTime in seconds.
sampleRateThe currently used sample rate.
Returns
The number of samples for the given time in seconds.

◆ sinc()

template<FloatType T>
T marvin::math::sinc ( T x)
nodiscardnoexcept