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.
template<std::floating_point T>
constexpr signed_frame_t round_to_signed_frame_t (T x)
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)
audio_sample_type_t calculate_rms_amp (const audio_sample_type_t *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 154 of file math.h.

◆ fast_log10()

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

Definition at line 161 of file math.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 130 of file math.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 76 of file math.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 66 of file math.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 86 of file math.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 103 of file math.h.

◆ round_to_signed_frame_t()

template<std::floating_point T>
signed_frame_t zrythm::utils::math::round_to_signed_frame_t ( T x)
constexpr

Definition at line 117 of file math.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 55 of file math.h.

◆ MINUS_INFINITY

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

Definition at line 57 of file math.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 51 of file math.h.