New plugin: FFT, A frequency analyzer plugin
[kugel-rb.git] / apps / plugins / fft / math.h
blob450b9aafcbd15c5fe06bfc0fbae53f7a0c47db51
1 #ifndef __MATH_H_
2 #define __MATH_H_
4 #include <inttypes.h>
5 #include <math.h>
6 #include "lib/fixedpoint.h"
8 #define Q_MUL(a, b, bits) (( (int64_t) (a) * (int64_t) (b) ) >> (bits))
9 #define Q15_MUL(a, b) Q_MUL(a,b,15)
10 #define Q16_MUL(a, b) Q_MUL(a,b,16)
12 #define Q_DIV(a, b, bits) ( (((int64_t) (a)) << (bits)) / (b) )
13 #define Q15_DIV(a, b) Q_DIV(a,b,15)
14 #define Q16_DIV(a, b) Q_DIV(a,b,16)
16 #define float_q(a, bits) (int32_t)( ((float)(a)) *(1<<(bits)))
17 #define float_q15(a) float_q(a, 15)
18 #define float_q16(a) float_q(a, 16)
20 /**
21 * Fixed point square root via Newton-Raphson.
22 * @param a square root argument.
23 * @param fracbits specifies number of fractional bits in argument.
24 * @return Square root of argument in same fixed point format as input.
26 int64_t fsqrt64(int64_t a, unsigned int fracbits);
28 #endif