update wavesaudio backend, now supports Windows (ASIO) as well as OS X (CoreAudio)
[ardour.git] / libs / backends / wavesaudio / wavesapi / miscutils / MinMaxUtilities.h
1 #ifndef __MinMaxUtilities_h__
2 #define __MinMaxUtilities_h__
3
4 /* copy to include
5 #include "MiscUtils/MinMaxUtilities.h"
6 */
7
8 #include "BasicTypes/WUDefines.h"
9 #include "BasicTypes/WUMathConsts.h"
10 #include "WavesPublicAPI/wstdint.h"
11
12 // New accelerated templates
13 #if defined ( __cplusplus ) && !defined (__WUMinMax)
14 #define __WUMinMax   // Also defined in Nativepr.h
15
16
17 template<class T> inline T WUMin(const T &a, const T &b) {return (a < b) ? a : b;} // requires only < to be defined for T
18 template<class T> inline T WUMax(const T &a,const T &b) {return (a < b) ? b : a;} // requires only < to be defined for T
19 template<class T> inline T WUMinMax(const T &Smallest, const T &Biggest, const T &Val)  // requires only < to be defined for T
20 {       
21         return ((Val < Smallest) ? Smallest : ((Biggest < Val) ? Biggest : Val));
22 }
23 /*      
24 // Min and Max
25         template<class T> inline T WUMin(T a,T b) {return (a < b) ? a : b;} // requires only < to be defined for T
26         template<class T> inline T WUMax(T a,T b) {return (a < b) ? b : a;} // requires only < to be defined for T
27         template<class T> inline T WUMinMax(T SMALLEST, T BIGGEST, T X)  // requires only < to be defined for T
28         {
29                 return ((X < SMALLEST) ? SMALLEST : ((BIGGEST < X) ? BIGGEST : X));
30         }
31  */     
32 // Absolute value
33 #ifdef _WINDOWS
34         #include <math.h>
35 #define __abs(x)        abs(x) 
36 #define __labs(x)       labs(x)
37 #define __fabs(x)       fabs(x)
38 #endif
39 #ifdef __GNUC__
40         #include <iostream> // why don't know makes it work need to check
41         #include <cstdlib>
42         #include <cmath>
43
44 #define __abs(x)        std::abs(x)
45 #define __labs(x)       std::labs(x)
46 #define __fabs(x)       std::fabs(x)
47 #endif
48         #ifdef __MACOS__
49         #ifdef __GNUC__
50             #include <iostream> // why don't know makes it work need to check
51             #include <cmath>
52 #define __abs(x)        std::abs(x)
53 #define __labs(x)       std::labs(x)
54 #define __fabs(x)       std::fabs(x)
55         #endif
56         #endif
57
58 // log2: on Windows there's no proper definition for log2, whereas on other platform there is.
59         #ifndef WUlog2
60     #if defined(_WINDOWS)
61         #define WUlog2(x)  (kdOneOverLog2 * log10((x))) 
62     #else    
63         #define WUlog2(x) log2(x)
64     #endif
65     #endif
66
67 template <class T> inline T WUAbs(const T &xA)
68 {
69         return (xA > T(0))? xA: -xA;
70 }
71
72 template <> inline int WUAbs(const int &xA)
73 {
74         return __abs(xA);
75 }
76
77 //template <> inline int32_t WUAbs(const int32_t &xA)// 64BitConversion
78 //{
79 //      return __labs(xA);
80 //}
81
82 template <> inline float WUAbs(const float &xA)
83 {
84         return (float) __fabs(xA);
85 }
86
87 template <> inline double WUAbs(const double &xA)
88 {
89         return __fabs(xA);
90 }
91
92 #endif
93
94 int32_t DllExport WURand(intptr_t in_Seed);
95 int32_t DllExport WURand();
96 int32_t DllExport rand_gen_formula(int32_t rndSeed);
97
98 template <class T> inline bool WUIsEqualWithTolerance(const T &xA, const T &xB, const T &xTolerance)
99 {
100         return (WUAbs(xA - xB) < xTolerance) ? true : false;
101 }
102
103
104 #endif