Mercurial > hg > svcore
changeset 509:6066bde1c126
* Cut back on the locking and general workload in
FFTDataServer::getMagnitudes(). This stuff is far too complicated!
author | Chris Cannam |
---|---|
date | Mon, 08 Dec 2008 11:15:13 +0000 |
parents | 1b8c748fd7ea |
children | af7b6e55895b |
files | data/fft/FFTCache.h data/fft/FFTDataServer.cpp data/fft/FFTFileCache.cpp data/fft/FFTFileCache.h data/fft/FFTMemoryCache.h data/model/FFTModel.cpp |
diffstat | 6 files changed, 108 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fft/FFTCache.h Fri Dec 05 16:18:04 2008 +0000 +++ b/data/fft/FFTCache.h Mon Dec 08 11:15:13 2008 +0000 @@ -38,6 +38,7 @@ virtual float getPhaseAt(size_t x, size_t y) const = 0; virtual void getValuesAt(size_t x, size_t y, float &real, float &imaginary) const = 0; + virtual void getMagnitudesAt(size_t x, float *values, size_t minbin, size_t count, size_t step) const = 0; virtual bool haveSetColumnAt(size_t x) const = 0;
--- a/data/fft/FFTDataServer.cpp Fri Dec 05 16:18:04 2008 +0000 +++ b/data/fft/FFTDataServer.cpp Mon Dec 08 11:15:13 2008 +0000 @@ -916,9 +916,8 @@ fillColumn(x, true); } - for (size_t i = 0; i < count; ++i) { - values[i] = cache->getMagnitudeAt(col, i * step + minbin); - } + cache->getMagnitudesAt(col, values, minbin, count, step); + return true; }
--- a/data/fft/FFTFileCache.cpp Fri Dec 05 16:18:04 2008 +0000 +++ b/data/fft/FFTFileCache.cpp Mon Dec 08 11:15:13 2008 +0000 @@ -103,8 +103,8 @@ switch (m_storageType) { case Compact: - value = (getFromReadBufCompactUnsigned(x, y * 2) / 65535.0) - * getNormalizationFactor(x); + value = (getFromReadBufCompactUnsigned(x, y * 2, true) / 65535.0) + * getNormalizationFactor(x, true); break; case Rectangular: @@ -116,7 +116,7 @@ } case Polar: - value = getFromReadBufStandard(x, y * 2); + value = getFromReadBufStandard(x, y * 2, true); break; } @@ -131,13 +131,13 @@ switch (m_storageType) { case Compact: - value = getFromReadBufCompactUnsigned(x, y * 2) / 65535.0; + value = getFromReadBufCompactUnsigned(x, y * 2, true) / 65535.0; break; default: { float mag = getMagnitudeAt(x, y); - float factor = getNormalizationFactor(x); + float factor = getNormalizationFactor(x, true); if (factor != 0) value = mag / factor; else value = 0.f; break; @@ -150,7 +150,7 @@ float FFTFileCache::getMaximumMagnitudeAt(size_t x) const { - return getNormalizationFactor(x); + return getNormalizationFactor(x, true); } float @@ -161,7 +161,7 @@ switch (m_storageType) { case Compact: - value = (getFromReadBufCompactSigned(x, y * 2 + 1) / 32767.0) * M_PI; + value = (getFromReadBufCompactSigned(x, y * 2 + 1, true) / 32767.0) * M_PI; break; case Rectangular: @@ -173,7 +173,7 @@ } case Polar: - value = getFromReadBufStandard(x, y * 2 + 1); + value = getFromReadBufStandard(x, y * 2 + 1, true); break; } @@ -186,8 +186,10 @@ switch (m_storageType) { case Rectangular: - real = getFromReadBufStandard(x, y * 2); - imag = getFromReadBufStandard(x, y * 2 + 1); + m_readbufMutex.lock(); + real = getFromReadBufStandard(x, y * 2, false); + imag = getFromReadBufStandard(x, y * 2 + 1, false); + m_readbufMutex.unlock(); return; default: @@ -199,6 +201,46 @@ } } +void +FFTFileCache::getMagnitudesAt(size_t x, float *values, size_t minbin, size_t count, size_t step) const +{ + Profiler profiler("FFTFileCache::getMagnitudesAt"); + + m_readbufMutex.lock(); + + switch (m_storageType) { + + case Compact: + for (size_t i = 0; i < count; ++i) { + size_t y = minbin + i * step; + values[i] = (getFromReadBufCompactUnsigned(x, y * 2, false) / 65535.0) + * getNormalizationFactor(x, false); + } + break; + + case Rectangular: + { + float real, imag; + for (size_t i = 0; i < count; ++i) { + size_t y = minbin + i * step; + real = getFromReadBufStandard(x, y * 2, false); + imag = getFromReadBufStandard(x, y * 2 + 1, false); + values[i] = sqrtf(real * real + imag * imag); + } + break; + } + + case Polar: + for (size_t i = 0; i < count; ++i) { + size_t y = minbin + i * step; + values[i] = getFromReadBufStandard(x, y * 2, false); + } + break; + } + + m_readbufMutex.unlock(); +} + bool FFTFileCache::haveSetColumnAt(size_t x) const {
--- a/data/fft/FFTFileCache.h Fri Dec 05 16:18:04 2008 +0000 +++ b/data/fft/FFTFileCache.h Mon Dec 08 11:15:13 2008 +0000 @@ -42,6 +42,7 @@ virtual float getPhaseAt(size_t x, size_t y) const; virtual void getValuesAt(size_t x, size_t y, float &real, float &imag) const; + virtual void getMagnitudesAt(size_t x, float *values, size_t minbin, size_t count, size_t step) const; virtual bool haveSetColumnAt(size_t x) const; @@ -61,57 +62,63 @@ mutable size_t m_readbufCol; mutable size_t m_readbufWidth; - float getFromReadBufStandard(size_t x, size_t y) const { - m_readbufMutex.lock(); + float getFromReadBufStandard(size_t x, size_t y, bool lock) const { + if (lock) m_readbufMutex.lock(); + float v; if (m_readbuf && (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { - float v = ((float *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; - m_readbufMutex.unlock(); + v = ((float *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; + if (lock) m_readbufMutex.unlock(); return v; } else { populateReadBuf(x); - m_readbufMutex.unlock(); - return getFromReadBufStandard(x, y); + v = getFromReadBufStandard(x, y, false); + if (lock) m_readbufMutex.unlock(); + return v; } } - float getFromReadBufCompactUnsigned(size_t x, size_t y) const { - m_readbufMutex.lock(); + float getFromReadBufCompactUnsigned(size_t x, size_t y, bool lock) const { + if (lock) m_readbufMutex.lock(); + float v; if (m_readbuf && (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { - float v = ((uint16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; - m_readbufMutex.unlock(); + v = ((uint16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; + if (lock) m_readbufMutex.unlock(); return v; } else { populateReadBuf(x); - m_readbufMutex.unlock(); - return getFromReadBufCompactUnsigned(x, y); + v = getFromReadBufCompactUnsigned(x, y, false); + if (lock) m_readbufMutex.unlock(); + return v; } } - float getFromReadBufCompactSigned(size_t x, size_t y) const { - m_readbufMutex.lock(); + float getFromReadBufCompactSigned(size_t x, size_t y, bool lock) const { + if (lock) m_readbufMutex.lock(); + float v; if (m_readbuf && (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { - float v = ((int16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; - m_readbufMutex.unlock(); + v = ((int16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; + if (lock) m_readbufMutex.unlock(); return v; } else { populateReadBuf(x); - m_readbufMutex.unlock(); - return getFromReadBufCompactSigned(x, y); + v = getFromReadBufCompactSigned(x, y, false); + if (lock) m_readbufMutex.unlock(); + return v; } } void populateReadBuf(size_t x) const; - float getNormalizationFactor(size_t col) const { + float getNormalizationFactor(size_t col, bool lock) const { size_t h = m_mfc->getHeight(); if (h < m_factorSize) return 0; if (m_storageType != Compact) { - return getFromReadBufStandard(col, h - 1); + return getFromReadBufStandard(col, h - 1, lock); } else { - m_readbufMutex.lock(); + if (lock) m_readbufMutex.lock(); union { float f; uint16_t u[2]; @@ -124,7 +131,7 @@ size_t ix = (col - m_readbufCol) * m_mfc->getHeight() + h; factor.u[0] = ((uint16_t *)m_readbuf)[ix - 2]; factor.u[1] = ((uint16_t *)m_readbuf)[ix - 1]; - m_readbufMutex.unlock(); + if (lock) m_readbufMutex.unlock(); return factor.f; } }
--- a/data/fft/FFTMemoryCache.h Fri Dec 05 16:18:04 2008 +0000 +++ b/data/fft/FFTMemoryCache.h Mon Dec 08 11:15:13 2008 +0000 @@ -55,8 +55,8 @@ virtual float getMagnitudeAt(size_t x, size_t y) const { if (m_storageType == Rectangular) { Profiler profiler("FFTMemoryCache::getMagnitudeAt: cart to polar"); - return sqrt(m_freal[x][y] * m_freal[x][y] + - m_fimag[x][y] * m_fimag[x][y]); + return sqrtf(m_freal[x][y] * m_freal[x][y] + + m_fimag[x][y] * m_fimag[x][y]); } else { return getNormalizedMagnitudeAt(x, y) * m_factor[x]; } @@ -97,6 +97,27 @@ } } + virtual void getMagnitudesAt(size_t x, float *values, size_t minbin, size_t count, size_t step) const + { + if (m_storageType == Rectangular) { + for (size_t i = 0; i < count; ++i) { + size_t y = i * step + minbin; + values[i] = sqrtf(m_freal[x][y] * m_freal[x][y] + + m_fimag[x][y] * m_fimag[x][y]); + } + } else if (m_storageType == Polar) { + for (size_t i = 0; i < count; ++i) { + size_t y = i * step + minbin; + values[i] = m_fmagnitude[x][y] * m_factor[x]; + } + } else { + for (size_t i = 0; i < count; ++i) { + size_t y = i * step + minbin; + values[i] = (float(m_magnitude[x][y]) * m_factor[x]) / 65535.0; + } + } + } + virtual bool haveSetColumnAt(size_t x) const { return m_colset.get(x); }