comparison base/Window.h @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents 6a94bb528e9d
children 7598a78cf915
comparison
equal deleted inserted replaced
1037:bf0e5944289b 1038:cc27f35aa75c
80 int 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 *, double, double, double, double);
86 }; 86 };
87 87
88 template <typename T> 88 template <typename T>
89 void Window<T>::encache() 89 void Window<T>::encache()
90 { 90 {
95 95
96 switch (m_type) { 96 switch (m_type) {
97 97
98 case RectangularWindow: 98 case RectangularWindow:
99 for (i = 0; i < n; ++i) { 99 for (i = 0; i < n; ++i) {
100 mult[i] *= 0.5; 100 mult[i] *= T(0.5);
101 } 101 }
102 break; 102 break;
103 103
104 case BartlettWindow: 104 case BartlettWindow:
105 for (i = 0; i < n/2; ++i) { 105 for (i = 0; i < n/2; ++i) {
106 mult[i] *= (i / T(n/2)); 106 mult[i] *= T(i) / T(n/2);
107 mult[i + n/2] *= (1.0 - (i / T(n/2))); 107 mult[i + n/2] *= T(1.0) - T(i) / T(n/2);
108 } 108 }
109 break; 109 break;
110 110
111 case HammingWindow: 111 case HammingWindow:
112 cosinewin(mult, 0.54, 0.46, 0.0, 0.0); 112 cosinewin(mult, 0.54, 0.46, 0.0, 0.0);
120 cosinewin(mult, 0.42, 0.50, 0.08, 0.0); 120 cosinewin(mult, 0.42, 0.50, 0.08, 0.0);
121 break; 121 break;
122 122
123 case GaussianWindow: 123 case GaussianWindow:
124 for (i = 0; i < n; ++i) { 124 for (i = 0; i < n; ++i) {
125 mult[i] *= pow(2, - pow((i - (n-1)/2.0) / ((n-1)/2.0 / 3), 2)); 125 mult[i] *= T(pow(2, - pow((i - (n-1)/2.0) / ((n-1)/2.0 / 3), 2)));
126 } 126 }
127 break; 127 break;
128 128
129 case ParzenWindow: 129 case ParzenWindow:
130 { 130 {
131 int N = n-1; 131 int N = n-1;
132 for (i = 0; i < N/4; ++i) { 132 for (i = 0; i < N/4; ++i) {
133 T m = 2 * pow(1.0 - (T(N)/2 - i) / (T(N)/2), 3); 133 T m = T(2 * pow(1.0 - (T(N)/2 - T(i)) / (T(N)/2), 3));
134 mult[i] *= m; 134 mult[i] *= m;
135 mult[N-i] *= m; 135 mult[N-i] *= m;
136 } 136 }
137 for (i = N/4; i <= N/2; ++i) { 137 for (i = N/4; i <= N/2; ++i) {
138 int wn = i - N/2; 138 int wn = i - N/2;
139 T m = 1.0 - 6 * pow(wn / (T(N)/2), 2) * (1.0 - abs(wn) / (T(N)/2)); 139 T m = T(1.0 - 6 * pow(T(wn) / (T(N)/2), 2) * (1.0 - T(abs(wn)) / (T(N)/2)));
140 mult[i] *= m; 140 mult[i] *= m;
141 mult[N-i] *= m; 141 mult[N-i] *= m;
142 } 142 }
143 break; 143 break;
144 } 144 }
156 156
157 m_area = 0; 157 m_area = 0;
158 for (int i = 0; i < n; ++i) { 158 for (int i = 0; i < n; ++i) {
159 m_area += m_cache[i]; 159 m_area += m_cache[i];
160 } 160 }
161 m_area /= n; 161 m_area /= T(n);
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, double a0, double a1, double a2, double a3)
166 { 166 {
167 const int n = 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] *= T(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));
173 } 173 }
174 } 174 }
175 175
176 template <typename T> 176 template <typename T>
177 std::string 177 std::string