Audio Effects Framework
Util.h
Go to the documentation of this file.
1 #if !defined(__Util_hdr__)
2 #define __Util_hdr__
3 
4 #include <cassert>
5 #include <cstring>
6 #include <limits>
7 
10 class CUtil
11 {
12 public:
17  template<typename T>
18  static T float2int (float fInput)
19  {
20  if (fInput >= 0.F)
21  return static_cast<T>(fInput + .5F);
22  else
23  return static_cast<T>(fInput - .5F);
24  }
29  template<typename T>
30  static T double2int (double fInput)
31  {
32  if (fInput >= 0)
33  return static_cast<T>(fInput + .5);
34  else
35  return static_cast<T>(fInput - .5);
36  }
37 
42  static bool isPowOf2 (int n)
43  {
44  return !(n & (n-1));
45  }
46 
51  static int nextPowOf2(int n)
52  {
53  int iOrder = 0;
54 
55  if (n == 0)
56  return 0;
57 
58  while (n>>iOrder)
59  iOrder++;
60 
61  if (!(n%(1<<(iOrder-1))))
62  iOrder--;
63 
64  return (1<<(iOrder));
65  }
66 
67  template<typename T>
68  static void swap (T &tValue1, T &tValue2)
69  {
70  T tTmp = tValue1;
71 
72  tValue1 = tValue2;
73  tValue2 = tTmp;
74  }
75 };
76 #endif // __Util_hdr__
CUtil::nextPowOf2
static int nextPowOf2(int n)
Definition: Util.h:51
CUtil::swap
static void swap(T &tValue1, T &tValue2)
Definition: Util.h:68
CUtil::float2int
static T float2int(float fInput)
Definition: Util.h:18
CUtil::isPowOf2
static bool isPowOf2(int n)
Definition: Util.h:42
CUtil::double2int
static T double2int(double fInput)
Definition: Util.h:30
CUtil
class with static utility functions
Definition: Util.h:11