Mercurial > hg > svcore
diff data/fft/FFTMemoryCache.h @ 334:aa8dbac62024
* Pass StorageAdviser::Criteria into FFTModel constructor etc
author | Chris Cannam |
---|---|
date | Sun, 11 Nov 2007 20:31:12 +0000 (2007-11-11) |
parents | 260032c26c4f |
children | 02d2ad95ea52 |
line wrap: on
line diff
--- a/data/fft/FFTMemoryCache.h Fri Nov 09 17:46:58 2007 +0000 +++ b/data/fft/FFTMemoryCache.h Sun Nov 11 20:31:12 2007 +0000 @@ -44,7 +44,8 @@ public: enum StorageType { Compact, // 16 bits normalized polar - Polar, // floating point mag+phase + Rectangular, // floating point real+imag + Polar // floating point mag+phase }; FFTMemoryCache(StorageType storageType); // of size zero, call resize() before using @@ -57,11 +58,17 @@ virtual void reset(); // zero-fill or 1-fill as appropriate without changing size virtual float getMagnitudeAt(size_t x, size_t y) const { - return getNormalizedMagnitudeAt(x, y) * m_factor[x]; + if (m_storageType == Rectangular) { + return sqrt(m_freal[x][y] * m_freal[x][y] + + m_fimag[x][y] * m_fimag[x][y]); + } else { + return getNormalizedMagnitudeAt(x, y) * m_factor[x]; + } } virtual float getNormalizedMagnitudeAt(size_t x, size_t y) const { - if (m_storageType == Polar) return m_fmagnitude[x][y]; + if (m_storageType == Rectangular) return getMagnitudeAt(x, y) / m_factor[x]; + else if (m_storageType == Polar) return m_fmagnitude[x][y]; else return float(m_magnitude[x][y]) / 65535.0; } @@ -70,18 +77,51 @@ } virtual float getPhaseAt(size_t x, size_t y) const { - if (m_storageType == Polar) return m_fphase[x][y]; - int16_t i = (int16_t)m_phase[x][y]; - return (float(i) / 32767.0) * M_PI; + if (m_storageType == Rectangular) { + return atan2f(m_fimag[x][y], m_freal[x][y]); + } else if (m_storageType == Polar) { + return m_fphase[x][y]; + } else { + int16_t i = (int16_t)m_phase[x][y]; + return (float(i) / 32767.0) * M_PI; + } } virtual void getValuesAt(size_t x, size_t y, float &real, float &imag) const { - float mag = getMagnitudeAt(x, y); - float phase = getPhaseAt(x, y); - real = mag * cosf(phase); - imag = mag * sinf(phase); + if (m_storageType == Rectangular) { + real = m_freal[x][y]; + imag = m_fimag[x][y]; + } else { + float mag = getMagnitudeAt(x, y); + float phase = getPhaseAt(x, y); + real = mag * cosf(phase); + imag = mag * sinf(phase); + } } + virtual bool haveSetColumnAt(size_t x) const { + return m_colset.get(x); + } + + virtual void setColumnAt(size_t x, float *mags, float *phases, float factor); + + virtual void setColumnAt(size_t x, float *reals, float *imags); + + static size_t getCacheSize(size_t width, size_t height, StorageType type); + +private: + size_t m_width; + size_t m_height; + uint16_t **m_magnitude; + uint16_t **m_phase; + float **m_fmagnitude; + float **m_fphase; + float **m_freal; + float **m_fimag; + float *m_factor; + StorageType m_storageType; + ResizeableBitset m_colset; + virtual void setNormalizationFactor(size_t x, float factor) { if (x < m_width) m_factor[x] = factor; } @@ -105,34 +145,6 @@ else m_phase[x][y] = uint16_t(int16_t((phase * 32767) / M_PI)); } } - - virtual bool haveSetColumnAt(size_t x) const { - return m_colset.get(x); - } - - virtual void setColumnAt(size_t x, float *mags, float *phases, float factor) { - setNormalizationFactor(x, factor); - for (size_t y = 0; y < m_height; ++y) { - setMagnitudeAt(x, y, mags[y]); - setPhaseAt(x, y, phases[y]); - } - m_colset.set(x); - } - - virtual void setColumnAt(size_t x, float *reals, float *imags); - - static size_t getCacheSize(size_t width, size_t height, StorageType type); - -private: - size_t m_width; - size_t m_height; - uint16_t **m_magnitude; - uint16_t **m_phase; - float **m_fmagnitude; - float **m_fphase; - float *m_factor; - StorageType m_storageType; - ResizeableBitset m_colset; void resize(uint16_t **&, size_t, size_t); void resize(float **&, size_t, size_t);