36#include "utils/types.h"
57constexpr auto MINUS_INFINITY = -HUGE_VAL;
64template <std::
floating_po
int T>
68 return std::abs (a - b) < e;
74template <std::
floating_po
int T>
78 return floats_near (a, b, std::numeric_limits<T>::epsilon ());
84template <std::
floating_po
int T>
88 if constexpr (std::is_same_v<T, float>)
101template <std::
floating_po
int T>
105 if constexpr (std::is_same_v<T, float>)
115template <std::
floating_po
int T>
117round_to_signed_frame_t (T x)
138 int *
const exp_ptr = &t.i;
140 const auto log_2 = (float) (((x >> 23) & 255) - 128);
147 val = ((-1.0f / 3) * t.f + 2) * t.f - 2.0f / 3;
149 return (val + log_2);
154fast_log (
const float val)
156 return (
fast_log2 (val) * std::numbers::ln2_v<float>);
161fast_log10 (
const float val)
174 constexpr float fader_coefficient1 =
176 133.084258667509499408f;
177 constexpr float fader_coefficient2 =
179 1.25870863180257576e17f;
195 (6.f * std::logf (amp)) + fader_coefficient1, 8.f)
196 / fader_coefficient2;
207 constexpr float val1 = 1.f / 6.f;
209 2.f, (val1) * (-192.f + 198.f * std::powf (fader, 1.f / 8.f)));
219 return 20.f * std::log10f (amp);
248 return std::powf (10.f, (dbfs / 20.f));
258 return get_fader_val_from_amp (dbfs_to_amp (dbfs));
uint32_t nframes_t
Frame count.
float audio_sample_type_t
The sample type.
int_fast64_t signed_frame_t
Signed type for frame index.
constexpr bool floats_equal(T a, T b)
Checks if 2 floating point numbers are equal.
constexpr float fast_log2(float val)
Fast log calculation to be used where precision is not required (like log curves).
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).
constexpr long round_to_signed_32(T x)
Rounds a double to a (minimum) signed 32-bit integer.
constexpr bool floats_near(T a, T b, T e)
Returns whether 2 floating point numbers are equal.
constexpr long long round_to_signed_64(T x)
Rounds a double to a (minimum) signed 64-bit integer.
bool is_string_valid_float(const std::string &str, float *ret)
Returns whether the given string is a valid float.
constexpr float ALMOST_SILENCE
Tiny number to be used for denormaml prevention (-140dB).
constexpr unsigned RMS_FRAMES
Frames to skip when calculating the RMS.
bool assert_nonnann(float x)
Asserts that the value is non-nan.