Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::utils::math Namespace Reference

Math utils. More...

Functions

template<std::floating_point T>
constexpr bool floats_near (T a, T b, T e)
 Returns whether 2 floating point numbers are equal.
template<std::floating_point T>
constexpr bool floats_equal (T a, T b)
 Checks if 2 floating point numbers are equal.
template<std::floating_point T>
constexpr long round_to_signed_32 (T x)
 Rounds a double to a (minimum) signed 32-bit integer.
template<std::floating_point T>
constexpr long long round_to_signed_64 (T x)
 Rounds a double to a (minimum) signed 64-bit integer.
constexpr float fast_log2 (float val)
 Fast log calculation to be used where precision is not required (like log curves).
constexpr auto fast_log (const float val)
constexpr auto fast_log10 (const float val)
float calculate_rms_amp (const float *buf, nframes_t nframes)
 Gets the RMS of the given signal as amplitude (0-2).
bool assert_nonnann (float x)
 Asserts that the value is non-nan.
bool is_string_valid_float (const std::string &str, float *ret)
 Returns whether the given string is a valid float.

Variables

constexpr unsigned RMS_FRAMES = 1
 Frames to skip when calculating the RMS.
constexpr float ALMOST_SILENCE = 0.0000001f
 Tiny number to be used for denormaml prevention (-140dB).
constexpr auto MINUS_INFINITY = -HUGE_VAL

Detailed Description

Math utils.

For more, look at libs/pbd/pbd/control_math.h in ardour.

Function Documentation

◆ assert_nonnann()

bool zrythm::utils::math::assert_nonnann ( float x)

Asserts that the value is non-nan.

Not real-time safe.

Returns
Whether the value is valid (nonnan).

◆ fast_log()

auto zrythm::utils::math::fast_log ( const float val)
constexpr

Definition at line 146 of file math_utils.h.

◆ fast_log10()

auto zrythm::utils::math::fast_log10 ( const float val)
constexpr

Definition at line 153 of file math_utils.h.

◆ fast_log2()

float zrythm::utils::math::fast_log2 ( float val)
constexpr

Fast log calculation to be used where precision is not required (like log curves).

Taken from ardour from code in the public domain.

Definition at line 122 of file math_utils.h.

◆ floats_equal()

template<std::floating_point T>
bool zrythm::utils::math::floats_equal ( T a,
T b )
constexpr

Checks if 2 floating point numbers are equal.

Definition at line 75 of file math_utils.h.

◆ floats_near()

template<std::floating_point T>
bool zrythm::utils::math::floats_near ( T a,
T b,
T e )
constexpr

Returns whether 2 floating point numbers are equal.

Parameters
eThe allowed difference (epsilon).

Definition at line 65 of file math_utils.h.

◆ is_string_valid_float()

bool zrythm::utils::math::is_string_valid_float ( const std::string & str,
float * ret )

Returns whether the given string is a valid float.

Parameters
retIf non-nullptr, the result will be placed here.

◆ round_to_signed_32()

template<std::floating_point T>
long zrythm::utils::math::round_to_signed_32 ( T x)
constexpr

Rounds a double to a (minimum) signed 32-bit integer.

Definition at line 85 of file math_utils.h.

◆ round_to_signed_64()

template<std::floating_point T>
long long zrythm::utils::math::round_to_signed_64 ( T x)
constexpr

Rounds a double to a (minimum) signed 64-bit integer.

Definition at line 102 of file math_utils.h.

Variable Documentation

◆ ALMOST_SILENCE

float zrythm::utils::math::ALMOST_SILENCE = 0.0000001f
constexpr

Tiny number to be used for denormaml prevention (-140dB).

Definition at line 54 of file math_utils.h.

◆ MINUS_INFINITY

auto zrythm::utils::math::MINUS_INFINITY = -HUGE_VAL
constexpr

Definition at line 56 of file math_utils.h.

◆ RMS_FRAMES

unsigned zrythm::utils::math::RMS_FRAMES = 1
constexpr

Frames to skip when calculating the RMS.

The lower the more CPU intensive.

Definition at line 50 of file math_utils.h.