Vital
Loading...
Searching...
No Matches
vital::futils Namespace Reference

Provides fast approximation functions for exponentials, logarithms, trigonometric operations, and saturation curves. More...

Functions

force_inline poly_float exp2 (poly_float exponent)
 Approximates 2^exponent for poly_float values using a polynomial approximation.
 
force_inline poly_float log2 (poly_float value)
 Approximates log2(value) for poly_float values using a polynomial approximation.
 
force_inline poly_float cheapExp2 (poly_float exponent)
 A cheaper but less accurate version of exp2 approximation.
 
force_inline poly_float cheapLog2 (poly_float value)
 A cheaper but less accurate version of log2 approximation.
 
force_inline mono_float exp2 (mono_float value)
 
force_inline mono_float log2 (mono_float value)
 
force_inline mono_float exp (mono_float exponent)
 
force_inline mono_float log (mono_float value)
 
force_inline mono_float exp_half (mono_float exponent)
 
force_inline mono_float pow (mono_float base, mono_float exponent)
 
template<mono_float(*)(mono_float) func>
force_inline poly_float map (poly_float value)
 Applies a scalar function to each element of a poly_float.
 
force_inline poly_float exp (poly_float exponent)
 
force_inline poly_float log (poly_float value)
 
force_inline poly_float exp_half (poly_float exponent)
 
force_inline poly_float pow (poly_float base, poly_float exponent)
 
force_inline poly_float cheapPow (poly_float base, poly_float exponent)
 
force_inline poly_float midiOffsetToRatio (poly_float note_offset)
 Converts a MIDI note offset to a frequency ratio.
 
force_inline poly_float midiNoteToFrequency (poly_float note)
 Converts a MIDI note number to frequency (in Hz).
 
force_inline mono_float magnitudeToDb (mono_float magnitude)
 Converts a magnitude (linear) to decibels (dB).
 
force_inline poly_float magnitudeToDb (poly_float magnitude)
 
force_inline mono_float dbToMagnitude (mono_float decibels)
 Converts decibels (dB) to magnitude (linear).
 
force_inline poly_float dbToMagnitude (poly_float decibels)
 
force_inline poly_float mulAdd (poly_float a, poly_float b, poly_float c)
 A fused multiply-add function: result = a * b + c.
 
force_inline mono_float quickTanh (mono_float value)
 A quick approximation of the tanh function.
 
force_inline poly_float quickTanh (poly_float value)
 
force_inline poly_float quickTanhDerivative (poly_float value)
 Derivative of the quick tanh approximation.
 
force_inline mono_float quickTanhDerivative (mono_float value)
 
force_inline mono_float reciprocalSat (mono_float value)
 Saturation approximation using 1/x function.
 
force_inline mono_float algebraicSat (mono_float value)
 Algebraic saturation approximation.
 
force_inline poly_float algebraicSat (poly_float value)
 
force_inline poly_float quadraticInvSat (poly_float value)
 Quadratic inverse saturation approximation.
 
force_inline poly_float bumpSat (poly_float value)
 Bump saturation approximations.
 
force_inline poly_float bumpSat2 (poly_float value)
 
force_inline mono_float algebraicSatDerivative (mono_float value)
 Derivative of algebraic saturation approximation.
 
force_inline poly_float algebraicSatDerivative (poly_float value)
 
force_inline poly_float tanh (poly_float value)
 Approximates tanh function using a complex polynomial.
 
force_inline mono_float tanh (mono_float value)
 
force_inline poly_float hardTanh (poly_float value)
 Another saturation function using half-range tanh.
 
force_inline poly_float tanhDerivativeFast (poly_float value)
 A fast approximation for the derivative of tanh.
 
force_inline mono_float quickSin (mono_float phase)
 Quick approximations of sine functions assuming limited phase input ranges.
 
force_inline poly_float quickSin (poly_float phase)
 
force_inline mono_float sin (mono_float phase)
 
force_inline poly_float sin (poly_float phase)
 
force_inline poly_float sinInterpolate (poly_float from, poly_float to, poly_float t)
 
force_inline mono_float quickSin1 (mono_float phase)
 
force_inline poly_float quickSin1 (poly_float phase)
 
force_inline mono_float sin1 (mono_float phase)
 
force_inline poly_float sin1 (poly_float phase)
 
force_inline poly_float equalPowerFade (poly_float t)
 Produces an equal-power crossfade (sin-based) between 0.0 and 1.0.
 
force_inline poly_float panAmplitude (poly_float pan)
 
force_inline poly_float equalPowerFadeInverse (poly_float t)
 The inverse equal-power fade from t to t+1.0.
 
force_inline mono_float powerScale (mono_float value, mono_float power)
 A power-scaling function to map a linear range to a curved response.
 
force_inline poly_float powerScale (poly_float value, poly_float power)
 

Detailed Description

Provides fast approximation functions for exponentials, logarithms, trigonometric operations, and saturation curves.

The approximations in futils are designed to be efficient and are often "good enough" for audio DSP tasks where slight deviations from exact mathematical results are acceptable.

Function Documentation

◆ algebraicSat() [1/2]

force_inline mono_float vital::futils::algebraicSat ( mono_float value)

Algebraic saturation approximation.

Parameters
valueInput value.
Returns
Saturated output.

◆ algebraicSat() [2/2]

force_inline poly_float vital::futils::algebraicSat ( poly_float value)

◆ algebraicSatDerivative() [1/2]

force_inline mono_float vital::futils::algebraicSatDerivative ( mono_float value)

Derivative of algebraic saturation approximation.

◆ algebraicSatDerivative() [2/2]

force_inline poly_float vital::futils::algebraicSatDerivative ( poly_float value)

◆ bumpSat()

force_inline poly_float vital::futils::bumpSat ( poly_float value)

Bump saturation approximations.

◆ bumpSat2()

force_inline poly_float vital::futils::bumpSat2 ( poly_float value)

◆ cheapExp2()

force_inline poly_float vital::futils::cheapExp2 ( poly_float exponent)

A cheaper but less accurate version of exp2 approximation.

Parameters
exponentThe exponent to raise 2 to.
Returns
Approximate 2^exponent as poly_float with lower accuracy.

◆ cheapLog2()

force_inline poly_float vital::futils::cheapLog2 ( poly_float value)

A cheaper but less accurate version of log2 approximation.

Parameters
valueThe input value for log base 2.
Returns
Approximate log2(value) as poly_float with lower accuracy.

◆ cheapPow()

force_inline poly_float vital::futils::cheapPow ( poly_float base,
poly_float exponent )

◆ dbToMagnitude() [1/2]

force_inline mono_float vital::futils::dbToMagnitude ( mono_float decibels)

Converts decibels (dB) to magnitude (linear).

Parameters
decibelsValue in decibels.
Returns
Linear magnitude.

◆ dbToMagnitude() [2/2]

force_inline poly_float vital::futils::dbToMagnitude ( poly_float decibels)

◆ equalPowerFade()

force_inline poly_float vital::futils::equalPowerFade ( poly_float t)

Produces an equal-power crossfade (sin-based) between 0.0 and 1.0.

◆ equalPowerFadeInverse()

force_inline poly_float vital::futils::equalPowerFadeInverse ( poly_float t)

The inverse equal-power fade from t to t+1.0.

◆ exp() [1/2]

force_inline mono_float vital::futils::exp ( mono_float exponent)

◆ exp() [2/2]

force_inline poly_float vital::futils::exp ( poly_float exponent)

◆ exp2() [1/2]

force_inline mono_float vital::futils::exp2 ( mono_float value)

◆ exp2() [2/2]

force_inline poly_float vital::futils::exp2 ( poly_float exponent)

Approximates 2^exponent for poly_float values using a polynomial approximation.

This is a more accurate approximation but still faster than a standard library exp2 function.

Parameters
exponentThe exponent to raise 2 to.
Returns
Approximate 2^exponent as poly_float.

◆ exp_half() [1/2]

force_inline mono_float vital::futils::exp_half ( mono_float exponent)

◆ exp_half() [2/2]

force_inline poly_float vital::futils::exp_half ( poly_float exponent)

◆ hardTanh()

force_inline poly_float vital::futils::hardTanh ( poly_float value)

Another saturation function using half-range tanh.

◆ log() [1/2]

force_inline mono_float vital::futils::log ( mono_float value)

◆ log() [2/2]

force_inline poly_float vital::futils::log ( poly_float value)

◆ log2() [1/2]

force_inline mono_float vital::futils::log2 ( mono_float value)

◆ log2() [2/2]

force_inline poly_float vital::futils::log2 ( poly_float value)

Approximates log2(value) for poly_float values using a polynomial approximation.

Parameters
valueThe input value to take the log base 2 of.
Returns
Approximate log2(value) as poly_float.

◆ magnitudeToDb() [1/2]

force_inline mono_float vital::futils::magnitudeToDb ( mono_float magnitude)

Converts a magnitude (linear) to decibels (dB).

Parameters
magnitudeLinear magnitude value.
Returns
Value in decibels.

◆ magnitudeToDb() [2/2]

force_inline poly_float vital::futils::magnitudeToDb ( poly_float magnitude)

◆ map()

template<mono_float(*)(mono_float) func>
force_inline poly_float vital::futils::map ( poly_float value)

Applies a scalar function to each element of a poly_float.

Template Parameters
funcA function pointer taking a mono_float and returning mono_float.
Parameters
valueThe input poly_float.
Returns
A poly_float with func applied to each element.

◆ midiNoteToFrequency()

force_inline poly_float vital::futils::midiNoteToFrequency ( poly_float note)

Converts a MIDI note number to frequency (in Hz).

Parameters
noteThe MIDI note number (as poly_float).
Returns
The frequency corresponding to that MIDI note.

◆ midiOffsetToRatio()

force_inline poly_float vital::futils::midiOffsetToRatio ( poly_float note_offset)

Converts a MIDI note offset to a frequency ratio.

Parameters
note_offsetThe note offset in semitones.
Returns
The corresponding frequency ratio.

◆ mulAdd()

force_inline poly_float vital::futils::mulAdd ( poly_float a,
poly_float b,
poly_float c )

A fused multiply-add function: result = a * b + c.

Parameters
a,b,cpoly_float inputs for the operation.
Returns
a * b + c as poly_float.

◆ panAmplitude()

force_inline poly_float vital::futils::panAmplitude ( poly_float pan)

◆ pow() [1/2]

force_inline mono_float vital::futils::pow ( mono_float base,
mono_float exponent )

◆ pow() [2/2]

force_inline poly_float vital::futils::pow ( poly_float base,
poly_float exponent )

◆ powerScale() [1/2]

force_inline mono_float vital::futils::powerScale ( mono_float value,
mono_float power )

A power-scaling function to map a linear range to a curved response.

◆ powerScale() [2/2]

force_inline poly_float vital::futils::powerScale ( poly_float value,
poly_float power )

◆ quadraticInvSat()

force_inline poly_float vital::futils::quadraticInvSat ( poly_float value)

Quadratic inverse saturation approximation.

◆ quickSin() [1/2]

force_inline mono_float vital::futils::quickSin ( mono_float phase)

Quick approximations of sine functions assuming limited phase input ranges.

◆ quickSin() [2/2]

force_inline poly_float vital::futils::quickSin ( poly_float phase)

◆ quickSin1() [1/2]

force_inline mono_float vital::futils::quickSin1 ( mono_float phase)

◆ quickSin1() [2/2]

force_inline poly_float vital::futils::quickSin1 ( poly_float phase)

◆ quickTanh() [1/2]

force_inline mono_float vital::futils::quickTanh ( mono_float value)

A quick approximation of the tanh function.

Parameters
valueThe input value.
Returns
Approximate tanh(value).

◆ quickTanh() [2/2]

force_inline poly_float vital::futils::quickTanh ( poly_float value)

◆ quickTanhDerivative() [1/2]

force_inline mono_float vital::futils::quickTanhDerivative ( mono_float value)

◆ quickTanhDerivative() [2/2]

force_inline poly_float vital::futils::quickTanhDerivative ( poly_float value)

Derivative of the quick tanh approximation.

Parameters
valueThe input value.
Returns
Derivative of quick tanh at value.

◆ reciprocalSat()

force_inline mono_float vital::futils::reciprocalSat ( mono_float value)

Saturation approximation using 1/x function.

Parameters
valueInput value.
Returns
Saturated output.

◆ sin() [1/2]

force_inline mono_float vital::futils::sin ( mono_float phase)

◆ sin() [2/2]

force_inline poly_float vital::futils::sin ( poly_float phase)

◆ sin1() [1/2]

force_inline mono_float vital::futils::sin1 ( mono_float phase)

◆ sin1() [2/2]

force_inline poly_float vital::futils::sin1 ( poly_float phase)

◆ sinInterpolate()

force_inline poly_float vital::futils::sinInterpolate ( poly_float from,
poly_float to,
poly_float t )

◆ tanh() [1/2]

force_inline mono_float vital::futils::tanh ( mono_float value)

◆ tanh() [2/2]

force_inline poly_float vital::futils::tanh ( poly_float value)

Approximates tanh function using a complex polynomial.

◆ tanhDerivativeFast()

force_inline poly_float vital::futils::tanhDerivativeFast ( poly_float value)

A fast approximation for the derivative of tanh.