comparison data/fft/FFTMemoryCache.cpp @ 929:59e7fe1b1003 warnfix_no_size_t

Unsigned removals and warning fixes in data/
author Chris Cannam
date Tue, 17 Jun 2014 14:33:42 +0100
parents e802e550a1f2
children 5173e56e17f7
comparison
equal deleted inserted replaced
928:6a94bb528e9d 929:59e7fe1b1003
20 #include <cstdlib> 20 #include <cstdlib>
21 21
22 //#define DEBUG_FFT_MEMORY_CACHE 1 22 //#define DEBUG_FFT_MEMORY_CACHE 1
23 23
24 FFTMemoryCache::FFTMemoryCache(FFTCache::StorageType storageType, 24 FFTMemoryCache::FFTMemoryCache(FFTCache::StorageType storageType,
25 size_t width, size_t height) : 25 int width, int height) :
26 m_width(width), 26 m_width(width),
27 m_height(height), 27 m_height(height),
28 m_magnitude(0), 28 m_magnitude(0),
29 m_phase(0), 29 m_phase(0),
30 m_fmagnitude(0), 30 m_fmagnitude(0),
46 { 46 {
47 #ifdef DEBUG_FFT_MEMORY_CACHE 47 #ifdef DEBUG_FFT_MEMORY_CACHE
48 cerr << "FFTMemoryCache[" << this << "]::~FFTMemoryCache" << endl; 48 cerr << "FFTMemoryCache[" << this << "]::~FFTMemoryCache" << endl;
49 #endif 49 #endif
50 50
51 for (size_t i = 0; i < m_width; ++i) { 51 for (int i = 0; i < m_width; ++i) {
52 if (m_magnitude && m_magnitude[i]) free(m_magnitude[i]); 52 if (m_magnitude && m_magnitude[i]) free(m_magnitude[i]);
53 if (m_phase && m_phase[i]) free(m_phase[i]); 53 if (m_phase && m_phase[i]) free(m_phase[i]);
54 if (m_fmagnitude && m_fmagnitude[i]) free(m_fmagnitude[i]); 54 if (m_fmagnitude && m_fmagnitude[i]) free(m_fmagnitude[i]);
55 if (m_fphase && m_fphase[i]) free(m_fphase[i]); 55 if (m_fphase && m_fphase[i]) free(m_fphase[i]);
56 if (m_freal && m_freal[i]) free(m_freal[i]); 56 if (m_freal && m_freal[i]) free(m_freal[i]);
69 void 69 void
70 FFTMemoryCache::initialise() 70 FFTMemoryCache::initialise()
71 { 71 {
72 Profiler profiler("FFTMemoryCache::initialise"); 72 Profiler profiler("FFTMemoryCache::initialise");
73 73
74 size_t width = m_width, height = m_height; 74 int width = m_width, height = m_height;
75 75
76 #ifdef DEBUG_FFT_MEMORY_CACHE 76 #ifdef DEBUG_FFT_MEMORY_CACHE
77 cerr << "FFTMemoryCache[" << this << "]::initialise(" << width << "x" << height << " = " << width*height << ")" << endl; 77 cerr << "FFTMemoryCache[" << this << "]::initialise(" << width << "x" << height << " = " << width*height << ")" << endl;
78 #endif 78 #endif
79 79
105 { 105 {
106 array = (uint16_t **)malloc(m_width * sizeof(uint16_t *)); 106 array = (uint16_t **)malloc(m_width * sizeof(uint16_t *));
107 if (!array) throw std::bad_alloc(); 107 if (!array) throw std::bad_alloc();
108 MUNLOCK(array, m_width * sizeof(uint16_t *)); 108 MUNLOCK(array, m_width * sizeof(uint16_t *));
109 109
110 for (size_t i = 0; i < m_width; ++i) { 110 for (int i = 0; i < m_width; ++i) {
111 array[i] = (uint16_t *)malloc(m_height * sizeof(uint16_t)); 111 array[i] = (uint16_t *)malloc(m_height * sizeof(uint16_t));
112 if (!array[i]) throw std::bad_alloc(); 112 if (!array[i]) throw std::bad_alloc();
113 MUNLOCK(array[i], m_height * sizeof(uint16_t)); 113 MUNLOCK(array[i], m_height * sizeof(uint16_t));
114 } 114 }
115 } 115 }
119 { 119 {
120 array = (float **)malloc(m_width * sizeof(float *)); 120 array = (float **)malloc(m_width * sizeof(float *));
121 if (!array) throw std::bad_alloc(); 121 if (!array) throw std::bad_alloc();
122 MUNLOCK(array, m_width * sizeof(float *)); 122 MUNLOCK(array, m_width * sizeof(float *));
123 123
124 for (size_t i = 0; i < m_width; ++i) { 124 for (int i = 0; i < m_width; ++i) {
125 array[i] = (float *)malloc(m_height * sizeof(float)); 125 array[i] = (float *)malloc(m_height * sizeof(float));
126 if (!array[i]) throw std::bad_alloc(); 126 if (!array[i]) throw std::bad_alloc();
127 MUNLOCK(array[i], m_height * sizeof(float)); 127 MUNLOCK(array[i], m_height * sizeof(float));
128 } 128 }
129 } 129 }
130 130
131 void 131 void
132 FFTMemoryCache::setColumnAt(size_t x, float *mags, float *phases, float factor) 132 FFTMemoryCache::setColumnAt(int x, float *mags, float *phases, float factor)
133 { 133 {
134 Profiler profiler("FFTMemoryCache::setColumnAt: from polar"); 134 Profiler profiler("FFTMemoryCache::setColumnAt: from polar");
135 135
136 setNormalizationFactor(x, factor); 136 setNormalizationFactor(x, factor);
137 137
138 if (m_storageType == FFTCache::Rectangular) { 138 if (m_storageType == FFTCache::Rectangular) {
139 Profiler subprof("FFTMemoryCache::setColumnAt: polar to cart"); 139 Profiler subprof("FFTMemoryCache::setColumnAt: polar to cart");
140 for (size_t y = 0; y < m_height; ++y) { 140 for (int y = 0; y < m_height; ++y) {
141 m_freal[x][y] = mags[y] * cosf(phases[y]); 141 m_freal[x][y] = mags[y] * cosf(phases[y]);
142 m_fimag[x][y] = mags[y] * sinf(phases[y]); 142 m_fimag[x][y] = mags[y] * sinf(phases[y]);
143 } 143 }
144 } else { 144 } else {
145 for (size_t y = 0; y < m_height; ++y) { 145 for (int y = 0; y < m_height; ++y) {
146 setMagnitudeAt(x, y, mags[y]); 146 setMagnitudeAt(x, y, mags[y]);
147 setPhaseAt(x, y, phases[y]); 147 setPhaseAt(x, y, phases[y]);
148 } 148 }
149 } 149 }
150 150
152 m_colset.set(x); 152 m_colset.set(x);
153 m_colsetLock.unlock(); 153 m_colsetLock.unlock();
154 } 154 }
155 155
156 void 156 void
157 FFTMemoryCache::setColumnAt(size_t x, float *reals, float *imags) 157 FFTMemoryCache::setColumnAt(int x, float *reals, float *imags)
158 { 158 {
159 Profiler profiler("FFTMemoryCache::setColumnAt: from cart"); 159 Profiler profiler("FFTMemoryCache::setColumnAt: from cart");
160 160
161 float max = 0.0; 161 float max = 0.0;
162 162
163 switch (m_storageType) { 163 switch (m_storageType) {
164 164
165 case FFTCache::Rectangular: 165 case FFTCache::Rectangular:
166 for (size_t y = 0; y < m_height; ++y) { 166 for (int y = 0; y < m_height; ++y) {
167 m_freal[x][y] = reals[y]; 167 m_freal[x][y] = reals[y];
168 m_fimag[x][y] = imags[y]; 168 m_fimag[x][y] = imags[y];
169 float mag = sqrtf(reals[y] * reals[y] + imags[y] * imags[y]); 169 float mag = sqrtf(reals[y] * reals[y] + imags[y] * imags[y]);
170 if (mag > max) max = mag; 170 if (mag > max) max = mag;
171 } 171 }
173 173
174 case FFTCache::Compact: 174 case FFTCache::Compact:
175 case FFTCache::Polar: 175 case FFTCache::Polar:
176 { 176 {
177 Profiler subprof("FFTMemoryCache::setColumnAt: cart to polar"); 177 Profiler subprof("FFTMemoryCache::setColumnAt: cart to polar");
178 for (size_t y = 0; y < m_height; ++y) { 178 for (int y = 0; y < m_height; ++y) {
179 float mag = sqrtf(reals[y] * reals[y] + imags[y] * imags[y]); 179 float mag = sqrtf(reals[y] * reals[y] + imags[y] * imags[y]);
180 float phase = atan2f(imags[y], reals[y]); 180 float phase = atan2f(imags[y], reals[y]);
181 reals[y] = mag; 181 reals[y] = mag;
182 imags[y] = phase; 182 imags[y] = phase;
183 if (mag > max) max = mag; 183 if (mag > max) max = mag;
194 } else { 194 } else {
195 setColumnAt(x, reals, imags, max); 195 setColumnAt(x, reals, imags, max);
196 } 196 }
197 } 197 }
198 198
199 size_t 199 int
200 FFTMemoryCache::getCacheSize(size_t width, size_t height, FFTCache::StorageType type) 200 FFTMemoryCache::getCacheSize(int width, int height, FFTCache::StorageType type)
201 { 201 {
202 size_t sz = 0; 202 int sz = 0;
203 203
204 switch (type) { 204 switch (type) {
205 205
206 case FFTCache::Compact: 206 case FFTCache::Compact:
207 sz = (height * 2 + 1) * width * sizeof(uint16_t); 207 sz = (height * 2 + 1) * width * sizeof(uint16_t);