beeping-core 2.0.0
C++20 library for encoding and decoding data over sound
Loading...
Searching...
No Matches
defines_ooura.h
1#ifndef _defines_ooura_
2#define _defines_ooura_
3
4#include <math.h>
5
6typedef int INT32;
7typedef float DATA;
8typedef int BOOL;
9
10#define SOMAX(a, b) ((a >= b) ? a : b)
11#define SOMIN(a, b) ((a < b) ? a : b)
12#define _TWO_PI 6.28318530717958647692f
13#define invTWO_PI 0.15915494309189533576901767873386f
14#define _PI 3.141592653589793238462643f
15#define PI_2 1.57079632679489661923f
16#define INSIGNIFICANT 0.000001f
17
18__inline DATA SOabs(DATA a) {
19 if (a >= 0)
20 return a;
21 else
22 return -a;
23}
24// #define SOabs(a) ((a>=0) ? a : -a)
25
26__inline DATA wrapPh(DATA ph) {
27 if ((ph < 0) || (ph >= _TWO_PI)) ph -= floorf(ph * invTWO_PI) * _TWO_PI;
28 if (ph > _PI) ph -= _TWO_PI;
29 return ph;
30}
31
32__inline DATA getPhDiff(DATA toPhase, DATA fromPhase) {
33 if (toPhase >= fromPhase + _PI)
34 return toPhase - _TWO_PI - fromPhase;
35 else if (toPhase < fromPhase - _PI)
36 return toPhase + _TWO_PI - fromPhase;
37 else
38 return toPhase - fromPhase;
39}
40
41__inline DATA getPh(DATA* pReal, DATA* pImag, DATA bin) {
42 INT32 iBin = (INT32)bin;
43 DATA intp = bin - iBin;
44 DATA lPh = atan2f(pImag[iBin], pReal[iBin]);
45 DATA rPh = atan2f(pImag[iBin + 1], pReal[iBin + 1]);
46 return lPh + intp * getPhDiff(rPh, lPh);
47}
48
49__inline void SOSwap(DATA** a, DATA** b) {
50 DATA* tmp = *a;
51 *a = *b;
52 *b = tmp;
53}
54
55#endif