55constexpr auto MINUS_INFINITY = -HUGE_VAL;
62template <std::
floating_po
int T>
66 return std::abs (a - b) < e;
72template <std::
floating_po
int T>
76 return floats_near (a, b, std::numeric_limits<T>::epsilon ());
82template <std::
floating_po
int T>
86 if constexpr (std::is_same_v<T, float>)
99template <std::
floating_po
int T>
103 if constexpr (std::is_same_v<T, float>)
129 int *
const exp_ptr = &t.i;
131 const auto log_2 = (float) (((x >> 23) & 255) - 128);
138 val = ((-1.0f / 3) * t.f + 2) * t.f - 2.0f / 3;
140 return (val + log_2);
145fast_log (
const float val)
147 return (
fast_log2 (val) * std::numbers::ln2_v<float>);
152fast_log10 (
const float val)
161template <std::
floating_po
int T>
164get_fader_val_from_amp (T amp)
166 constexpr T fader_coefficient1 =
168 133.084258667509499408f;
169 constexpr T fader_coefficient2 =
171 1.25870863180257576e17f;
187 (6.f * std::logf (amp)) + fader_coefficient1, 8.f)
188 / fader_coefficient2;
195template <std::
floating_po
int T>
198get_amp_val_from_fader (T fader)
200 constexpr float val1 = 1.f / 6.f;
202 2.f, (val1) * (-192.f + 198.f * std::powf (fader, 1.f / 8.f)));
208template <std::
floating_po
int T>
213 return 20.f * std::log10f (amp);
229template <std::
floating_po
int T>
231calculate_rms_db (
const T * buf, uint32_t nframes)
239template <std::
floating_po
int T>
244 return std::powf (10.f, (dbfs / 20.f));
250template <std::
floating_po
int T>
253dbfs_to_fader_val (T dbfs)
255 return get_fader_val_from_amp (dbfs_to_amp (dbfs));
float calculate_rms_amp(const float *buf, uint32_t nframes)
Gets the RMS of the given signal as amplitude (0-2).
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).
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.