comparison data/fft/FFTFileCacheWriter.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 cc27f35aa75c
comparison
equal deleted inserted replaced
928:6a94bb528e9d 929:59e7fe1b1003
31 // etc, and then store the normalization factor (maximum magnitude) at 31 // etc, and then store the normalization factor (maximum magnitude) at
32 // [m_height * 2]. In compact mode, the factor takes two cells. 32 // [m_height * 2]. In compact mode, the factor takes two cells.
33 33
34 FFTFileCacheWriter::FFTFileCacheWriter(QString fileBase, 34 FFTFileCacheWriter::FFTFileCacheWriter(QString fileBase,
35 FFTCache::StorageType storageType, 35 FFTCache::StorageType storageType,
36 size_t width, size_t height) : 36 int width, int height) :
37 m_writebuf(0), 37 m_writebuf(0),
38 m_fileBase(fileBase), 38 m_fileBase(fileBase),
39 m_storageType(storageType), 39 m_storageType(storageType),
40 m_factorSize(storageType == FFTCache::Compact ? 2 : 1), 40 m_factorSize(storageType == FFTCache::Compact ? 2 : 1),
41 m_mfc(new MatrixFile 41 m_mfc(new MatrixFile
60 FFTFileCacheWriter::getFileBase() const 60 FFTFileCacheWriter::getFileBase() const
61 { 61 {
62 return m_fileBase; 62 return m_fileBase;
63 } 63 }
64 64
65 size_t 65 int
66 FFTFileCacheWriter::getWidth() const 66 FFTFileCacheWriter::getWidth() const
67 { 67 {
68 return m_mfc->getWidth(); 68 return m_mfc->getWidth();
69 } 69 }
70 70
71 size_t 71 int
72 FFTFileCacheWriter::getHeight() const 72 FFTFileCacheWriter::getHeight() const
73 { 73 {
74 size_t mh = m_mfc->getHeight(); 74 int mh = m_mfc->getHeight();
75 if (mh > m_factorSize) return (mh - m_factorSize) / 2; 75 if (mh > m_factorSize) return (mh - m_factorSize) / 2;
76 else return 0; 76 else return 0;
77 } 77 }
78 78
79 bool 79 bool
80 FFTFileCacheWriter::haveSetColumnAt(size_t x) const 80 FFTFileCacheWriter::haveSetColumnAt(int x) const
81 { 81 {
82 return m_mfc->haveSetColumnAt(x); 82 return m_mfc->haveSetColumnAt(x);
83 } 83 }
84 84
85 void 85 void
86 FFTFileCacheWriter::setColumnAt(size_t x, float *mags, float *phases, float factor) 86 FFTFileCacheWriter::setColumnAt(int x, float *mags, float *phases, float factor)
87 { 87 {
88 size_t h = getHeight(); 88 int h = getHeight();
89 89
90 switch (m_storageType) { 90 switch (m_storageType) {
91 91
92 case FFTCache::Compact: 92 case FFTCache::Compact:
93 for (size_t y = 0; y < h; ++y) { 93 for (int y = 0; y < h; ++y) {
94 ((uint16_t *)m_writebuf)[y * 2] = uint16_t((mags[y] / factor) * 65535.0); 94 ((uint16_t *)m_writebuf)[y * 2] = uint16_t((mags[y] / factor) * 65535.0);
95 ((uint16_t *)m_writebuf)[y * 2 + 1] = uint16_t(int16_t((phases[y] * 32767) / M_PI)); 95 ((uint16_t *)m_writebuf)[y * 2 + 1] = uint16_t(int16_t((phases[y] * 32767) / M_PI));
96 } 96 }
97 break; 97 break;
98 98
99 case FFTCache::Rectangular: 99 case FFTCache::Rectangular:
100 for (size_t y = 0; y < h; ++y) { 100 for (int y = 0; y < h; ++y) {
101 ((float *)m_writebuf)[y * 2] = mags[y] * cosf(phases[y]); 101 ((float *)m_writebuf)[y * 2] = mags[y] * cosf(phases[y]);
102 ((float *)m_writebuf)[y * 2 + 1] = mags[y] * sinf(phases[y]); 102 ((float *)m_writebuf)[y * 2 + 1] = mags[y] * sinf(phases[y]);
103 } 103 }
104 break; 104 break;
105 105
106 case FFTCache::Polar: 106 case FFTCache::Polar:
107 for (size_t y = 0; y < h; ++y) { 107 for (int y = 0; y < h; ++y) {
108 ((float *)m_writebuf)[y * 2] = mags[y]; 108 ((float *)m_writebuf)[y * 2] = mags[y];
109 ((float *)m_writebuf)[y * 2 + 1] = phases[y]; 109 ((float *)m_writebuf)[y * 2 + 1] = phases[y];
110 } 110 }
111 break; 111 break;
112 } 112 }
121 121
122 m_mfc->setColumnAt(x, m_writebuf); 122 m_mfc->setColumnAt(x, m_writebuf);
123 } 123 }
124 124
125 void 125 void
126 FFTFileCacheWriter::setColumnAt(size_t x, float *real, float *imag) 126 FFTFileCacheWriter::setColumnAt(int x, float *real, float *imag)
127 { 127 {
128 size_t h = getHeight(); 128 int h = getHeight();
129 129
130 float factor = 0.0f; 130 float factor = 0.0f;
131 131
132 switch (m_storageType) { 132 switch (m_storageType) {
133 133
134 case FFTCache::Compact: 134 case FFTCache::Compact:
135 for (size_t y = 0; y < h; ++y) { 135 for (int y = 0; y < h; ++y) {
136 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]); 136 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]);
137 if (mag > factor) factor = mag; 137 if (mag > factor) factor = mag;
138 } 138 }
139 for (size_t y = 0; y < h; ++y) { 139 for (int y = 0; y < h; ++y) {
140 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]); 140 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]);
141 float phase = atan2f(imag[y], real[y]); 141 float phase = atan2f(imag[y], real[y]);
142 ((uint16_t *)m_writebuf)[y * 2] = uint16_t((mag / factor) * 65535.0); 142 ((uint16_t *)m_writebuf)[y * 2] = uint16_t((mag / factor) * 65535.0);
143 ((uint16_t *)m_writebuf)[y * 2 + 1] = uint16_t(int16_t((phase * 32767) / M_PI)); 143 ((uint16_t *)m_writebuf)[y * 2 + 1] = uint16_t(int16_t((phase * 32767) / M_PI));
144 } 144 }
145 break; 145 break;
146 146
147 case FFTCache::Rectangular: 147 case FFTCache::Rectangular:
148 for (size_t y = 0; y < h; ++y) { 148 for (int y = 0; y < h; ++y) {
149 ((float *)m_writebuf)[y * 2] = real[y]; 149 ((float *)m_writebuf)[y * 2] = real[y];
150 ((float *)m_writebuf)[y * 2 + 1] = imag[y]; 150 ((float *)m_writebuf)[y * 2 + 1] = imag[y];
151 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]); 151 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]);
152 if (mag > factor) factor = mag; 152 if (mag > factor) factor = mag;
153 } 153 }
154 break; 154 break;
155 155
156 case FFTCache::Polar: 156 case FFTCache::Polar:
157 for (size_t y = 0; y < h; ++y) { 157 for (int y = 0; y < h; ++y) {
158 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]); 158 float mag = sqrtf(real[y] * real[y] + imag[y] * imag[y]);
159 if (mag > factor) factor = mag; 159 if (mag > factor) factor = mag;
160 ((float *)m_writebuf)[y * 2] = mag; 160 ((float *)m_writebuf)[y * 2] = mag;
161 float phase = atan2f(imag[y], real[y]); 161 float phase = atan2f(imag[y], real[y]);
162 ((float *)m_writebuf)[y * 2 + 1] = phase; 162 ((float *)m_writebuf)[y * 2 + 1] = phase;
173 setNormalizationFactorToWritebuf(factor); 173 setNormalizationFactorToWritebuf(factor);
174 174
175 m_mfc->setColumnAt(x, m_writebuf); 175 m_mfc->setColumnAt(x, m_writebuf);
176 } 176 }
177 177
178 size_t 178 int
179 FFTFileCacheWriter::getCacheSize(size_t width, size_t height, 179 FFTFileCacheWriter::getCacheSize(int width, int height,
180 FFTCache::StorageType type) 180 FFTCache::StorageType type)
181 { 181 {
182 return (height * 2 + (type == FFTCache::Compact ? 2 : 1)) * width * 182 return (height * 2 + (type == FFTCache::Compact ? 2 : 1)) * width *
183 (type == FFTCache::Compact ? sizeof(uint16_t) : sizeof(float)) + 183 (type == FFTCache::Compact ? sizeof(uint16_t) : sizeof(float)) +
184 2 * sizeof(size_t); // matrix file header size 184 2 * sizeof(int); // matrix file header size
185 } 185 }
186 186
187 void 187 void
188 FFTFileCacheWriter::allColumnsWritten() 188 FFTFileCacheWriter::allColumnsWritten()
189 { 189 {