37#ifndef __UTILS_MATH_H__
38#define __UTILS_MATH_H__
57#define MATH_RMS_FRAMES 1
61#define MATH_TINY_NUMBER (0.0000001)
63#define MATH_MINUS_INFINITY (-HUGE_VAL)
70#define math_floats_equal_epsilon(a, b, e) \
71 ((a) > (b) ? (a) - (b) < e : (b) - (a) < e)
70#define math_floats_equal_epsilon(a, b, e) \ …
73#define math_doubles_equal_epsilon math_floats_equal_epsilon
78#define math_floats_equal(a, b) \
79 ((a) > (b) ? (a) - (b) < FLT_EPSILON : (b) - (a) < FLT_EPSILON)
78#define math_floats_equal(a, b) \ …
81#define math_doubles_equal(a, b) \
82 ((a) > (b) ? (a) - (b) < DBL_EPSILON : (b) - (a) < DBL_EPSILON)
88#define math_round_double_to_signed_32(x) (lround (x))
94#define math_round_double_to_signed_64(x) (llround (x))
96#define math_round_double_to_signed_frame_t(x) \
97 math_round_double_to_signed_64 (x)
103#define math_round_float_to_signed_32(x) (lroundf (x))
109#define math_round_float_to_signed_64(x) (llroundf (x))
111#define math_round_float_to_signed_frame_t(x) math_round_float_to_signed_64 (x)
121math_fast_log2 (
float val)
129 int *
const exp_ptr = &t.i;
131 const float 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);
145math_fast_log (
const float val)
147 return (math_fast_log2 (val) * 0.69314718f);
152math_fast_log10 (
const float val)
154 return math_fast_log2 (val) / 3.312500f;
163math_get_fader_val_from_amp (
sample_t amp)
165 const float fader_coefficient1 =
167 133.084258667509499408f;
168 const float fader_coefficient2 =
170 1.25870863180257576e17f;
188 6.f * logf (amp) + fader_coefficient1, 8.f)
189 / fader_coefficient2;
200math_get_amp_val_from_fader (
sample_t fader)
202 static const float val1 = 1.f / 6.f;
203 return powf (2.f, (val1) * (-192.f + 198.f * powf (fader, 1.f / 8.f)));
213 return 20.f * log10f (amp);
235 return powf (10.f, (dbfs / 20.f));
243math_dbfs_to_fader_val (
sample_t dbfs)
245 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.