37#ifndef __UTILS_MATH_H__
38#define __UTILS_MATH_H__
59#define MATH_RMS_FRAMES 1
63#define MATH_TINY_NUMBER (0.0000001)
65#define MATH_MINUS_INFINITY (-HUGE_VAL)
72#define math_floats_equal_epsilon(a, b, e) \
73 ((a) > (b) ? (a) - (b) < e : (b) - (a) < e)
75#define math_doubles_equal_epsilon math_floats_equal_epsilon
80#define math_floats_equal(a, b) \
81 ((a) > (b) ? (a) - (b) < FLT_EPSILON : (b) - (a) < FLT_EPSILON)
83#define math_doubles_equal(a, b) \
84 ((a) > (b) ? (a) - (b) < DBL_EPSILON : (b) - (a) < DBL_EPSILON)
90#define math_round_double_to_signed_32(x) (lround (x))
96#define math_round_double_to_signed_64(x) (llround (x))
98#define math_round_double_to_signed_frame_t(x) \
99 math_round_double_to_signed_64 (x)
105#define math_round_float_to_signed_32(x) (lroundf (x))
111#define math_round_float_to_signed_64(x) (llroundf (x))
113#define math_round_float_to_signed_frame_t(x) math_round_float_to_signed_64 (x)
123math_fast_log2 (
float val)
131 int *
const exp_ptr = &t.i;
133 const float log_2 = (float) (((x >> 23) & 255) - 128);
140 val = ((-1.0f / 3) * t.f + 2) * t.f - 2.0f / 3;
142 return (val + log_2);
147math_fast_log (
const float val)
149 return (math_fast_log2 (val) * 0.69314718f);
154math_fast_log10 (
const float val)
156 return math_fast_log2 (val) / 3.312500f;
165math_get_fader_val_from_amp (
sample_t amp)
167 const float fader_coefficient1 =
169 133.084258667509499408f;
170 const float fader_coefficient2 =
172 1.25870863180257576e17f;
190 6.f * logf (amp) + fader_coefficient1, 8.f)
191 / fader_coefficient2;
202math_get_amp_val_from_fader (
sample_t fader)
204 static const float val1 = 1.f / 6.f;
205 return powf (2.f, (val1) * (-192.f + 198.f * powf (fader, 1.f / 8.f)));
215 return 20.f * log10f (amp);
237 return powf (10.f, (dbfs / 20.f));
245math_dbfs_to_fader_val (
sample_t dbfs)
247 return math_get_fader_val_from_amp (math_dbfs_to_amp (dbfs));
NONNULL_ARGS(1) int undo_manager_undo(UndoManager *self
Undo last action.
#define math_floats_equal(a, b)
Checks if 2 doubles are equal.
bool math_is_string_valid_float(const char *str, float *ret)
Returns whether the given string is a valid float.
uint32_t nframes_t
Frame count.
bool math_assert_nonnann(float x)
Asserts that the value is non-nan.
sample_t math_calculate_rms_db(sample_t *buf, const nframes_t nframes)
Calculate db using RMS method.
float sample_t
The sample type.