Chirp SonicLib  2.1.0
ch_math_utils.h
Go to the documentation of this file.
1 
11 #ifndef CH_MATH_UTILS_H_
12 #define CH_MATH_UTILS_H_
13 
14 #include <stdio.h>
15 #include <math.h>
16 #include <stdint.h>
17 
18 #define FRACT_BITS 16
19 
20 #define INT2FIXED(x) ((x) << FRACT_BITS)
21 #define FLOAT2FIXED(x) ((fixed_t)((x) * (1 << FRACT_BITS)))
22 
23 #define FIXED2INT(x) ((x) >> FRACT_BITS)
24 #define FIXED2FLOAT(x) (((float)(x)) / (1 << FRACT_BITS))
25 
26 #define FIXEDDIV(x,y) ((fixed_t)(((uint64_t)(x) << FRACT_BITS) / (y)))
27 #define FIXEDMUL(x,y) ((fixed_t)(((x) >> (FRACT_BITS/2)) * ((y) >> (FRACT_BITS/2))))
28 
29 #define FIXED_PI 0x3243FU
30 
31 #define INV_LOG2_E_Q1DOT31 0x58b90bfcU // Inverse log base 2 of e
32 
33 typedef uint32_t fixed_t;
34 
35 fixed_t FP_sqrt(fixed_t x);
36 
37 fixed_t FP_log2(fixed_t x);
38 
39 fixed_t FP_log(fixed_t x);
40 
41 int32_t sqrt_int32( int32_t v );
42 
43 #endif /* CH_MATH_UTILS_H_ */