Mercurial > hg > svcore
comparison base/Window.h @ 928:6a94bb528e9d warnfix_no_size_t
Remove size_t's, fix compiler warnings
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2014 13:52:07 +0100 |
parents | 97741fe16205 |
children | cc27f35aa75c |
comparison
equal
deleted
inserted
replaced
917:49618f39ff09 | 928:6a94bb528e9d |
---|---|
45 * | 45 * |
46 * Note that the cosine windows are periodic by design, rather | 46 * Note that the cosine windows are periodic by design, rather |
47 * than symmetrical. (A window of size N is equivalent to a | 47 * than symmetrical. (A window of size N is equivalent to a |
48 * symmetrical window of size N+1 with the final element missing.) | 48 * symmetrical window of size N+1 with the final element missing.) |
49 */ | 49 */ |
50 Window(WindowType type, size_t size) : m_type(type), m_size(size) { encache(); } | 50 Window(WindowType type, int size) : m_type(type), m_size(size) { encache(); } |
51 Window(const Window &w) : m_type(w.m_type), m_size(w.m_size) { encache(); } | 51 Window(const Window &w) : m_type(w.m_type), m_size(w.m_size) { encache(); } |
52 Window &operator=(const Window &w) { | 52 Window &operator=(const Window &w) { |
53 if (&w == this) return *this; | 53 if (&w == this) return *this; |
54 m_type = w.m_type; | 54 m_type = w.m_type; |
55 m_size = w.m_size; | 55 m_size = w.m_size; |
58 } | 58 } |
59 virtual ~Window() { delete[] m_cache; } | 59 virtual ~Window() { delete[] m_cache; } |
60 | 60 |
61 void cut(T *src) const { cut(src, src); } | 61 void cut(T *src) const { cut(src, src); } |
62 void cut(T *src, T *dst) const { | 62 void cut(T *src, T *dst) const { |
63 for (size_t i = 0; i < m_size; ++i) dst[i] = src[i] * m_cache[i]; | 63 for (int i = 0; i < m_size; ++i) dst[i] = src[i] * m_cache[i]; |
64 } | 64 } |
65 | 65 |
66 T getArea() { return m_area; } | 66 T getArea() { return m_area; } |
67 T getValue(size_t i) { return m_cache[i]; } | 67 T getValue(int i) { return m_cache[i]; } |
68 | 68 |
69 WindowType getType() const { return m_type; } | 69 WindowType getType() const { return m_type; } |
70 size_t getSize() const { return m_size; } | 70 int getSize() const { return m_size; } |
71 | 71 |
72 // The names used by these functions are un-translated, for use in | 72 // The names used by these functions are un-translated, for use in |
73 // e.g. XML I/O. Use Preferences::getPropertyValueLabel if you | 73 // e.g. XML I/O. Use Preferences::getPropertyValueLabel if you |
74 // want translated names for use in the user interface. | 74 // want translated names for use in the user interface. |
75 static std::string getNameForType(WindowType type); | 75 static std::string getNameForType(WindowType type); |
76 static WindowType getTypeForName(std::string name); | 76 static WindowType getTypeForName(std::string name); |
77 | 77 |
78 protected: | 78 protected: |
79 WindowType m_type; | 79 WindowType m_type; |
80 size_t m_size; | 80 int m_size; |
81 T *m_cache; | 81 T *m_cache; |
82 T m_area; | 82 T m_area; |
83 | 83 |
84 void encache(); | 84 void encache(); |
85 void cosinewin(T *, T, T, T, T); | 85 void cosinewin(T *, T, T, T, T); |
86 }; | 86 }; |
87 | 87 |
88 template <typename T> | 88 template <typename T> |
89 void Window<T>::encache() | 89 void Window<T>::encache() |
90 { | 90 { |
91 int n = int(m_size); | 91 const int n = m_size; |
92 T *mult = new T[n]; | 92 T *mult = new T[n]; |
93 int i; | 93 int i; |
94 for (i = 0; i < n; ++i) mult[i] = 1.0; | 94 for (i = 0; i < n; ++i) mult[i] = 1.0; |
95 | 95 |
96 switch (m_type) { | 96 switch (m_type) { |
162 } | 162 } |
163 | 163 |
164 template <typename T> | 164 template <typename T> |
165 void Window<T>::cosinewin(T *mult, T a0, T a1, T a2, T a3) | 165 void Window<T>::cosinewin(T *mult, T a0, T a1, T a2, T a3) |
166 { | 166 { |
167 int n = int(m_size); | 167 const int n = m_size; |
168 for (int i = 0; i < n; ++i) { | 168 for (int i = 0; i < n; ++i) { |
169 mult[i] *= (a0 | 169 mult[i] *= (a0 |
170 - a1 * cos((2 * M_PI * i) / n) | 170 - a1 * cos((2 * M_PI * i) / n) |
171 + a2 * cos((4 * M_PI * i) / n) | 171 + a2 * cos((4 * M_PI * i) / n) |
172 - a3 * cos((6 * M_PI * i) / n)); | 172 - a3 * cos((6 * M_PI * i) / n)); |