comparison data/fft/FFTDataServer.h @ 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 948271d124ac
children cc27f35aa75c
comparison
equal deleted inserted replaced
928:6a94bb528e9d 929:59e7fe1b1003
41 { 41 {
42 public: 42 public:
43 static FFTDataServer *getInstance(const DenseTimeValueModel *model, 43 static FFTDataServer *getInstance(const DenseTimeValueModel *model,
44 int channel, 44 int channel,
45 WindowType windowType, 45 WindowType windowType,
46 size_t windowSize, 46 int windowSize,
47 size_t windowIncrement, 47 int windowIncrement,
48 size_t fftSize, 48 int fftSize,
49 bool polar, 49 bool polar,
50 StorageAdviser::Criteria criteria = 50 StorageAdviser::Criteria criteria =
51 StorageAdviser::NoCriteria, 51 StorageAdviser::NoCriteria,
52 size_t fillFromColumn = 0); 52 int fillFromColumn = 0);
53 53
54 static FFTDataServer *getFuzzyInstance(const DenseTimeValueModel *model, 54 static FFTDataServer *getFuzzyInstance(const DenseTimeValueModel *model,
55 int channel, 55 int channel,
56 WindowType windowType, 56 WindowType windowType,
57 size_t windowSize, 57 int windowSize,
58 size_t windowIncrement, 58 int windowIncrement,
59 size_t fftSize, 59 int fftSize,
60 bool polar, 60 bool polar,
61 StorageAdviser::Criteria criteria = 61 StorageAdviser::Criteria criteria =
62 StorageAdviser::NoCriteria, 62 StorageAdviser::NoCriteria,
63 size_t fillFromColumn = 0); 63 int fillFromColumn = 0);
64 64
65 static void claimInstance(FFTDataServer *); 65 static void claimInstance(FFTDataServer *);
66 static void releaseInstance(FFTDataServer *); 66 static void releaseInstance(FFTDataServer *);
67 67
68 static void modelAboutToBeDeleted(Model *); 68 static void modelAboutToBeDeleted(Model *);
69 69
70 const DenseTimeValueModel *getModel() const { return m_model; } 70 const DenseTimeValueModel *getModel() const { return m_model; }
71 int getChannel() const { return m_channel; } 71 int getChannel() const { return m_channel; }
72 WindowType getWindowType() const { return m_windower.getType(); } 72 WindowType getWindowType() const { return m_windower.getType(); }
73 size_t getWindowSize() const { return m_windowSize; } 73 int getWindowSize() const { return m_windowSize; }
74 size_t getWindowIncrement() const { return m_windowIncrement; } 74 int getWindowIncrement() const { return m_windowIncrement; }
75 size_t getFFTSize() const { return m_fftSize; } 75 int getFFTSize() const { return m_fftSize; }
76 bool getPolar() const { return m_polar; } 76 bool getPolar() const { return m_polar; }
77 77
78 size_t getWidth() const { return m_width; } 78 int getWidth() const { return m_width; }
79 size_t getHeight() const { return m_height; } 79 int getHeight() const { return m_height; }
80 80
81 float getMagnitudeAt(size_t x, size_t y); 81 float getMagnitudeAt(int x, int y);
82 float getNormalizedMagnitudeAt(size_t x, size_t y); 82 float getNormalizedMagnitudeAt(int x, int y);
83 float getMaximumMagnitudeAt(size_t x); 83 float getMaximumMagnitudeAt(int x);
84 float getPhaseAt(size_t x, size_t y); 84 float getPhaseAt(int x, int y);
85 void getValuesAt(size_t x, size_t y, float &real, float &imaginary); 85 void getValuesAt(int x, int y, float &real, float &imaginary);
86 bool isColumnReady(size_t x); 86 bool isColumnReady(int x);
87 87
88 bool getMagnitudesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0, size_t step = 1); 88 bool getMagnitudesAt(int x, float *values, int minbin = 0, int count = 0, int step = 1);
89 bool getNormalizedMagnitudesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0, size_t step = 1); 89 bool getNormalizedMagnitudesAt(int x, float *values, int minbin = 0, int count = 0, int step = 1);
90 bool getPhasesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0, size_t step = 1); 90 bool getPhasesAt(int x, float *values, int minbin = 0, int count = 0, int step = 1);
91 bool getValuesAt(size_t x, float *reals, float *imaginaries, size_t minbin = 0, size_t count = 0, size_t step = 1); 91 bool getValuesAt(int x, float *reals, float *imaginaries, int minbin = 0, int count = 0, int step = 1);
92 92
93 void suspend(); 93 void suspend();
94 void suspendWrites(); 94 void suspendWrites();
95 void resume(); // also happens automatically if new data needed 95 void resume(); // also happens automatically if new data needed
96 96
97 // Convenience functions: 97 // Convenience functions:
98 98
99 bool isLocalPeak(size_t x, size_t y) { 99 bool isLocalPeak(int x, int y) {
100 float mag = getMagnitudeAt(x, y); 100 float mag = getMagnitudeAt(x, y);
101 if (y > 0 && mag < getMagnitudeAt(x, y - 1)) return false; 101 if (y > 0 && mag < getMagnitudeAt(x, y - 1)) return false;
102 if (y < getHeight()-1 && mag < getMagnitudeAt(x, y + 1)) return false; 102 if (y < getHeight()-1 && mag < getMagnitudeAt(x, y + 1)) return false;
103 return true; 103 return true;
104 } 104 }
105 bool isOverThreshold(size_t x, size_t y, float threshold) { 105 bool isOverThreshold(int x, int y, float threshold) {
106 return getMagnitudeAt(x, y) > threshold; 106 return getMagnitudeAt(x, y) > threshold;
107 } 107 }
108 108
109 QString getError() const; 109 QString getError() const;
110 size_t getFillCompletion() const; 110 int getFillCompletion() const;
111 size_t getFillExtent() const; 111 int getFillExtent() const;
112 112
113 private: 113 private:
114 FFTDataServer(QString fileBaseName, 114 FFTDataServer(QString fileBaseName,
115 const DenseTimeValueModel *model, 115 const DenseTimeValueModel *model,
116 int channel, 116 int channel,
117 WindowType windowType, 117 WindowType windowType,
118 size_t windowSize, 118 int windowSize,
119 size_t windowIncrement, 119 int windowIncrement,
120 size_t fftSize, 120 int fftSize,
121 bool polar, 121 bool polar,
122 StorageAdviser::Criteria criteria, 122 StorageAdviser::Criteria criteria,
123 size_t fillFromColumn = 0); 123 int fillFromColumn = 0);
124 124
125 virtual ~FFTDataServer(); 125 virtual ~FFTDataServer();
126 126
127 FFTDataServer(const FFTDataServer &); // not implemented 127 FFTDataServer(const FFTDataServer &); // not implemented
128 FFTDataServer &operator=(const FFTDataServer &); // not implemented 128 FFTDataServer &operator=(const FFTDataServer &); // not implemented
133 const DenseTimeValueModel *m_model; 133 const DenseTimeValueModel *m_model;
134 int m_channel; 134 int m_channel;
135 135
136 Window<fftsample> m_windower; 136 Window<fftsample> m_windower;
137 137
138 size_t m_windowSize; 138 int m_windowSize;
139 size_t m_windowIncrement; 139 int m_windowIncrement;
140 size_t m_fftSize; 140 int m_fftSize;
141 bool m_polar; 141 bool m_polar;
142 142
143 size_t m_width; 143 int m_width;
144 size_t m_height; 144 int m_height;
145 size_t m_cacheWidth; 145 int m_cacheWidth;
146 size_t m_cacheWidthPower; 146 int m_cacheWidthPower;
147 size_t m_cacheWidthMask; 147 int m_cacheWidthMask;
148 148
149 struct CacheBlock { 149 struct CacheBlock {
150 FFTMemoryCache *memoryCache; 150 FFTMemoryCache *memoryCache;
151 typedef std::map<QThread *, FFTFileCacheReader *> ThreadReaderMap; 151 typedef std::map<QThread *, FFTFileCacheReader *> ThreadReaderMap;
152 ThreadReaderMap fileCacheReader; 152 ThreadReaderMap fileCacheReader;
165 typedef std::vector<CacheBlock *> CacheVector; 165 typedef std::vector<CacheBlock *> CacheVector;
166 CacheVector m_caches; 166 CacheVector m_caches;
167 QReadWriteLock m_cacheVectorLock; // locks cache lookup, not use 167 QReadWriteLock m_cacheVectorLock; // locks cache lookup, not use
168 QMutex m_cacheCreationMutex; // solely to serialise makeCache() calls 168 QMutex m_cacheCreationMutex; // solely to serialise makeCache() calls
169 169
170 FFTCacheReader *getCacheReader(size_t x, size_t &col) { 170 FFTCacheReader *getCacheReader(int x, int &col) {
171 Profiler profiler("FFTDataServer::getCacheReader"); 171 Profiler profiler("FFTDataServer::getCacheReader");
172 col = x & m_cacheWidthMask; 172 col = x & m_cacheWidthMask;
173 int c = x >> m_cacheWidthPower; 173 int c = x >> m_cacheWidthPower;
174 m_cacheVectorLock.lockForRead(); 174 m_cacheVectorLock.lockForRead();
175 CacheBlock *cb(m_caches.at(c)); 175 CacheBlock *cb(m_caches.at(c));
198 m_cacheVectorLock.unlock(); 198 m_cacheVectorLock.unlock();
199 if (!makeCache(c)) return 0; 199 if (!makeCache(c)) return 0;
200 return getCacheReader(x, col); 200 return getCacheReader(x, col);
201 } 201 }
202 202
203 FFTCacheWriter *getCacheWriter(size_t x, size_t &col) { 203 FFTCacheWriter *getCacheWriter(int x, int &col) {
204 Profiler profiler("FFTDataServer::getCacheWriter"); 204 Profiler profiler("FFTDataServer::getCacheWriter");
205 col = x & m_cacheWidthMask; 205 col = x & m_cacheWidthMask;
206 int c = x >> m_cacheWidthPower; 206 int c = x >> m_cacheWidthPower;
207 { 207 {
208 QReadLocker locker(&m_cacheVectorLock); 208 QReadLocker locker(&m_cacheVectorLock);
216 } 216 }
217 if (!makeCache(c)) return 0; 217 if (!makeCache(c)) return 0;
218 return getCacheWriter(x, col); 218 return getCacheWriter(x, col);
219 } 219 }
220 220
221 bool haveCache(size_t x) { 221 bool haveCache(int x) {
222 int c = x >> m_cacheWidthPower; 222 int c = x >> m_cacheWidthPower;
223 return (m_caches.at(c) != 0); 223 return (m_caches.at(c) != 0);
224 } 224 }
225 225
226 bool makeCache(int c); 226 bool makeCache(int c);
227 bool makeCacheReader(int c); 227 bool makeCacheReader(int c);
228 228
229 StorageAdviser::Criteria m_criteria; 229 StorageAdviser::Criteria m_criteria;
230 230
231 void getStorageAdvice(size_t w, size_t h, bool &memory, bool &compact); 231 void getStorageAdvice(int w, int h, bool &memory, bool &compact);
232 232
233 QMutex m_fftBuffersLock; 233 QMutex m_fftBuffersLock;
234 QWaitCondition m_condition; 234 QWaitCondition m_condition;
235 235
236 fftsample *m_fftInput; 236 fftsample *m_fftInput;
239 fftf_plan m_fftPlan; 239 fftf_plan m_fftPlan;
240 240
241 class FillThread : public Thread 241 class FillThread : public Thread
242 { 242 {
243 public: 243 public:
244 FillThread(FFTDataServer &server, size_t fillFromColumn) : 244 FillThread(FFTDataServer &server, int fillFromColumn) :
245 m_server(server), m_extent(0), m_completion(0), 245 m_server(server), m_extent(0), m_completion(0),
246 m_fillFrom(fillFromColumn) { } 246 m_fillFrom(fillFromColumn) { }
247 247
248 size_t getExtent() const { return m_extent; } 248 int getExtent() const { return m_extent; }
249 size_t getCompletion() const { return m_completion ? m_completion : 1; } 249 int getCompletion() const { return m_completion ? m_completion : 1; }
250 QString getError() const { return m_error; } 250 QString getError() const { return m_error; }
251 virtual void run(); 251 virtual void run();
252 252
253 protected: 253 protected:
254 FFTDataServer &m_server; 254 FFTDataServer &m_server;
255 size_t m_extent; 255 int m_extent;
256 size_t m_completion; 256 int m_completion;
257 size_t m_fillFrom; 257 int m_fillFrom;
258 QString m_error; 258 QString m_error;
259 }; 259 };
260 260
261 bool m_exiting; 261 bool m_exiting;
262 bool m_suspended; 262 bool m_suspended;
263 FillThread *m_fillThread; 263 FillThread *m_fillThread;
264 QString m_error; 264 QString m_error;
265 265
266 void deleteProcessingData(); 266 void deleteProcessingData();
267 void fillColumn(size_t x); 267 void fillColumn(int x);
268 void fillComplete(); 268 void fillComplete();
269 269
270 QString generateFileBasename() const; 270 QString generateFileBasename() const;
271 static QString generateFileBasename(const DenseTimeValueModel *model, 271 static QString generateFileBasename(const DenseTimeValueModel *model,
272 int channel, 272 int channel,
273 WindowType windowType, 273 WindowType windowType,
274 size_t windowSize, 274 int windowSize,
275 size_t windowIncrement, 275 int windowIncrement,
276 size_t fftSize, 276 int fftSize,
277 bool polar); 277 bool polar);
278 278
279 typedef std::pair<FFTDataServer *, int> ServerCountPair; 279 typedef std::pair<FFTDataServer *, int> ServerCountPair;
280 typedef std::map<QString, ServerCountPair> ServerMap; 280 typedef std::map<QString, ServerCountPair> ServerMap;
281 typedef std::deque<FFTDataServer *> ServerQueue; 281 typedef std::deque<FFTDataServer *> ServerQueue;