comparison data/fft/FFTMemoryCache.h @ 936:0c1d6de8f44b

Merge from branch warnfix_no_size_t
author Chris Cannam
date Wed, 18 Jun 2014 13:51:16 +0100
parents 59e7fe1b1003
children cc27f35aa75c
comparison
equal deleted inserted replaced
917:49618f39ff09 936:0c1d6de8f44b
45 45
46 class FFTMemoryCache : public FFTCacheReader, public FFTCacheWriter 46 class FFTMemoryCache : public FFTCacheReader, public FFTCacheWriter
47 { 47 {
48 public: 48 public:
49 FFTMemoryCache(FFTCache::StorageType storageType, 49 FFTMemoryCache(FFTCache::StorageType storageType,
50 size_t width, size_t height); 50 int width, int height);
51 ~FFTMemoryCache(); 51 ~FFTMemoryCache();
52 52
53 size_t getWidth() const { return m_width; } 53 int getWidth() const { return m_width; }
54 size_t getHeight() const { return m_height; } 54 int getHeight() const { return m_height; }
55 55
56 float getMagnitudeAt(size_t x, size_t y) const { 56 float getMagnitudeAt(int x, int y) const {
57 if (m_storageType == FFTCache::Rectangular) { 57 if (m_storageType == FFTCache::Rectangular) {
58 Profiler profiler("FFTMemoryCache::getMagnitudeAt: cart to polar"); 58 Profiler profiler("FFTMemoryCache::getMagnitudeAt: cart to polar");
59 return sqrtf(m_freal[x][y] * m_freal[x][y] + 59 return sqrtf(m_freal[x][y] * m_freal[x][y] +
60 m_fimag[x][y] * m_fimag[x][y]); 60 m_fimag[x][y] * m_fimag[x][y]);
61 } else { 61 } else {
62 return getNormalizedMagnitudeAt(x, y) * m_factor[x]; 62 return getNormalizedMagnitudeAt(x, y) * m_factor[x];
63 } 63 }
64 } 64 }
65 65
66 float getNormalizedMagnitudeAt(size_t x, size_t y) const { 66 float getNormalizedMagnitudeAt(int x, int y) const {
67 if (m_storageType == FFTCache::Rectangular) return getMagnitudeAt(x, y) / m_factor[x]; 67 if (m_storageType == FFTCache::Rectangular) return getMagnitudeAt(x, y) / m_factor[x];
68 else if (m_storageType == FFTCache::Polar) return m_fmagnitude[x][y]; 68 else if (m_storageType == FFTCache::Polar) return m_fmagnitude[x][y];
69 else return float(m_magnitude[x][y]) / 65535.0; 69 else return float(m_magnitude[x][y]) / 65535.0;
70 } 70 }
71 71
72 float getMaximumMagnitudeAt(size_t x) const { 72 float getMaximumMagnitudeAt(int x) const {
73 return m_factor[x]; 73 return m_factor[x];
74 } 74 }
75 75
76 float getPhaseAt(size_t x, size_t y) const { 76 float getPhaseAt(int x, int y) const {
77 if (m_storageType == FFTCache::Rectangular) { 77 if (m_storageType == FFTCache::Rectangular) {
78 Profiler profiler("FFTMemoryCache::getValuesAt: cart to polar"); 78 Profiler profiler("FFTMemoryCache::getValuesAt: cart to polar");
79 return atan2f(m_fimag[x][y], m_freal[x][y]); 79 return atan2f(m_fimag[x][y], m_freal[x][y]);
80 } else if (m_storageType == FFTCache::Polar) { 80 } else if (m_storageType == FFTCache::Polar) {
81 return m_fphase[x][y]; 81 return m_fphase[x][y];
83 int16_t i = (int16_t)m_phase[x][y]; 83 int16_t i = (int16_t)m_phase[x][y];
84 return (float(i) / 32767.0) * M_PI; 84 return (float(i) / 32767.0) * M_PI;
85 } 85 }
86 } 86 }
87 87
88 void getValuesAt(size_t x, size_t y, float &real, float &imag) const { 88 void getValuesAt(int x, int y, float &real, float &imag) const {
89 if (m_storageType == FFTCache::Rectangular) { 89 if (m_storageType == FFTCache::Rectangular) {
90 real = m_freal[x][y]; 90 real = m_freal[x][y];
91 imag = m_fimag[x][y]; 91 imag = m_fimag[x][y];
92 } else { 92 } else {
93 Profiler profiler("FFTMemoryCache::getValuesAt: polar to cart"); 93 Profiler profiler("FFTMemoryCache::getValuesAt: polar to cart");
96 real = mag * cosf(phase); 96 real = mag * cosf(phase);
97 imag = mag * sinf(phase); 97 imag = mag * sinf(phase);
98 } 98 }
99 } 99 }
100 100
101 void getMagnitudesAt(size_t x, float *values, size_t minbin, size_t count, size_t step) const 101 void getMagnitudesAt(int x, float *values, int minbin, int count, int step) const
102 { 102 {
103 if (m_storageType == FFTCache::Rectangular) { 103 if (m_storageType == FFTCache::Rectangular) {
104 for (size_t i = 0; i < count; ++i) { 104 for (int i = 0; i < count; ++i) {
105 size_t y = i * step + minbin; 105 int y = i * step + minbin;
106 values[i] = sqrtf(m_freal[x][y] * m_freal[x][y] + 106 values[i] = sqrtf(m_freal[x][y] * m_freal[x][y] +
107 m_fimag[x][y] * m_fimag[x][y]); 107 m_fimag[x][y] * m_fimag[x][y]);
108 } 108 }
109 } else if (m_storageType == FFTCache::Polar) { 109 } else if (m_storageType == FFTCache::Polar) {
110 for (size_t i = 0; i < count; ++i) { 110 for (int i = 0; i < count; ++i) {
111 size_t y = i * step + minbin; 111 int y = i * step + minbin;
112 values[i] = m_fmagnitude[x][y] * m_factor[x]; 112 values[i] = m_fmagnitude[x][y] * m_factor[x];
113 } 113 }
114 } else { 114 } else {
115 for (size_t i = 0; i < count; ++i) { 115 for (int i = 0; i < count; ++i) {
116 size_t y = i * step + minbin; 116 int y = i * step + minbin;
117 values[i] = (float(m_magnitude[x][y]) * m_factor[x]) / 65535.0; 117 values[i] = (float(m_magnitude[x][y]) * m_factor[x]) / 65535.0;
118 } 118 }
119 } 119 }
120 } 120 }
121 121
122 bool haveSetColumnAt(size_t x) const { 122 bool haveSetColumnAt(int x) const {
123 m_colsetLock.lockForRead(); 123 m_colsetLock.lockForRead();
124 bool have = m_colset.get(x); 124 bool have = m_colset.get(x);
125 m_colsetLock.unlock(); 125 m_colsetLock.unlock();
126 return have; 126 return have;
127 } 127 }
128 128
129 void setColumnAt(size_t x, float *mags, float *phases, float factor); 129 void setColumnAt(int x, float *mags, float *phases, float factor);
130 130
131 void setColumnAt(size_t x, float *reals, float *imags); 131 void setColumnAt(int x, float *reals, float *imags);
132 132
133 void allColumnsWritten() { } 133 void allColumnsWritten() { }
134 134
135 static size_t getCacheSize(size_t width, size_t height, 135 static int getCacheSize(int width, int height,
136 FFTCache::StorageType type); 136 FFTCache::StorageType type);
137 137
138 FFTCache::StorageType getStorageType() const { return m_storageType; } 138 FFTCache::StorageType getStorageType() const { return m_storageType; }
139 139
140 private: 140 private:
141 size_t m_width; 141 int m_width;
142 size_t m_height; 142 int m_height;
143 uint16_t **m_magnitude; 143 uint16_t **m_magnitude;
144 uint16_t **m_phase; 144 uint16_t **m_phase;
145 float **m_fmagnitude; 145 float **m_fmagnitude;
146 float **m_fphase; 146 float **m_fphase;
147 float **m_freal; 147 float **m_freal;
151 ResizeableBitset m_colset; 151 ResizeableBitset m_colset;
152 mutable QReadWriteLock m_colsetLock; 152 mutable QReadWriteLock m_colsetLock;
153 153
154 void initialise(); 154 void initialise();
155 155
156 void setNormalizationFactor(size_t x, float factor) { 156 void setNormalizationFactor(int x, float factor) {
157 if (x < m_width) m_factor[x] = factor; 157 if (x < m_width) m_factor[x] = factor;
158 } 158 }
159 159
160 void setMagnitudeAt(size_t x, size_t y, float mag) { 160 void setMagnitudeAt(int x, int y, float mag) {
161 // norm factor must already be set 161 // norm factor must already be set
162 setNormalizedMagnitudeAt(x, y, mag / m_factor[x]); 162 setNormalizedMagnitudeAt(x, y, mag / m_factor[x]);
163 } 163 }
164 164
165 void setNormalizedMagnitudeAt(size_t x, size_t y, float norm) { 165 void setNormalizedMagnitudeAt(int x, int y, float norm) {
166 if (x < m_width && y < m_height) { 166 if (x < m_width && y < m_height) {
167 if (m_storageType == FFTCache::Polar) m_fmagnitude[x][y] = norm; 167 if (m_storageType == FFTCache::Polar) m_fmagnitude[x][y] = norm;
168 else m_magnitude[x][y] = uint16_t(norm * 65535.0); 168 else m_magnitude[x][y] = uint16_t(norm * 65535.0);
169 } 169 }
170 } 170 }
171 171
172 void setPhaseAt(size_t x, size_t y, float phase) { 172 void setPhaseAt(int x, int y, float phase) {
173 // phase in range -pi -> pi 173 // phase in range -pi -> pi
174 if (x < m_width && y < m_height) { 174 if (x < m_width && y < m_height) {
175 if (m_storageType == FFTCache::Polar) m_fphase[x][y] = phase; 175 if (m_storageType == FFTCache::Polar) m_fphase[x][y] = phase;
176 else m_phase[x][y] = uint16_t(int16_t((phase * 32767) / M_PI)); 176 else m_phase[x][y] = uint16_t(int16_t((phase * 32767) / M_PI));
177 } 177 }