Mercurial > hg > svcore
comparison data/fft/FFTFileCache.h @ 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 | f60360209e5c |
children |
comparison
equal
deleted
inserted
replaced
508:1b8c748fd7ea | 509:6066bde1c126 |
---|---|
40 virtual float getNormalizedMagnitudeAt(size_t x, size_t y) const; | 40 virtual float getNormalizedMagnitudeAt(size_t x, size_t y) const; |
41 virtual float getMaximumMagnitudeAt(size_t x) const; | 41 virtual float getMaximumMagnitudeAt(size_t x) const; |
42 virtual float getPhaseAt(size_t x, size_t y) const; | 42 virtual float getPhaseAt(size_t x, size_t y) const; |
43 | 43 |
44 virtual void getValuesAt(size_t x, size_t y, float &real, float &imag) const; | 44 virtual void getValuesAt(size_t x, size_t y, float &real, float &imag) const; |
45 virtual void getMagnitudesAt(size_t x, float *values, size_t minbin, size_t count, size_t step) const; | |
45 | 46 |
46 virtual bool haveSetColumnAt(size_t x) const; | 47 virtual bool haveSetColumnAt(size_t x) const; |
47 | 48 |
48 virtual void setColumnAt(size_t x, float *mags, float *phases, float factor); | 49 virtual void setColumnAt(size_t x, float *mags, float *phases, float factor); |
49 virtual void setColumnAt(size_t x, float *reals, float *imags); | 50 virtual void setColumnAt(size_t x, float *reals, float *imags); |
59 char *m_writebuf; | 60 char *m_writebuf; |
60 mutable char *m_readbuf; | 61 mutable char *m_readbuf; |
61 mutable size_t m_readbufCol; | 62 mutable size_t m_readbufCol; |
62 mutable size_t m_readbufWidth; | 63 mutable size_t m_readbufWidth; |
63 | 64 |
64 float getFromReadBufStandard(size_t x, size_t y) const { | 65 float getFromReadBufStandard(size_t x, size_t y, bool lock) const { |
65 m_readbufMutex.lock(); | 66 if (lock) m_readbufMutex.lock(); |
67 float v; | |
66 if (m_readbuf && | 68 if (m_readbuf && |
67 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { | 69 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { |
68 float v = ((float *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; | 70 v = ((float *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; |
69 m_readbufMutex.unlock(); | 71 if (lock) m_readbufMutex.unlock(); |
70 return v; | 72 return v; |
71 } else { | 73 } else { |
72 populateReadBuf(x); | 74 populateReadBuf(x); |
73 m_readbufMutex.unlock(); | 75 v = getFromReadBufStandard(x, y, false); |
74 return getFromReadBufStandard(x, y); | 76 if (lock) m_readbufMutex.unlock(); |
77 return v; | |
75 } | 78 } |
76 } | 79 } |
77 | 80 |
78 float getFromReadBufCompactUnsigned(size_t x, size_t y) const { | 81 float getFromReadBufCompactUnsigned(size_t x, size_t y, bool lock) const { |
79 m_readbufMutex.lock(); | 82 if (lock) m_readbufMutex.lock(); |
83 float v; | |
80 if (m_readbuf && | 84 if (m_readbuf && |
81 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { | 85 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { |
82 float v = ((uint16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; | 86 v = ((uint16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; |
83 m_readbufMutex.unlock(); | 87 if (lock) m_readbufMutex.unlock(); |
84 return v; | 88 return v; |
85 } else { | 89 } else { |
86 populateReadBuf(x); | 90 populateReadBuf(x); |
87 m_readbufMutex.unlock(); | 91 v = getFromReadBufCompactUnsigned(x, y, false); |
88 return getFromReadBufCompactUnsigned(x, y); | 92 if (lock) m_readbufMutex.unlock(); |
93 return v; | |
89 } | 94 } |
90 } | 95 } |
91 | 96 |
92 float getFromReadBufCompactSigned(size_t x, size_t y) const { | 97 float getFromReadBufCompactSigned(size_t x, size_t y, bool lock) const { |
93 m_readbufMutex.lock(); | 98 if (lock) m_readbufMutex.lock(); |
99 float v; | |
94 if (m_readbuf && | 100 if (m_readbuf && |
95 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { | 101 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { |
96 float v = ((int16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; | 102 v = ((int16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y]; |
97 m_readbufMutex.unlock(); | 103 if (lock) m_readbufMutex.unlock(); |
98 return v; | 104 return v; |
99 } else { | 105 } else { |
100 populateReadBuf(x); | 106 populateReadBuf(x); |
101 m_readbufMutex.unlock(); | 107 v = getFromReadBufCompactSigned(x, y, false); |
102 return getFromReadBufCompactSigned(x, y); | 108 if (lock) m_readbufMutex.unlock(); |
109 return v; | |
103 } | 110 } |
104 } | 111 } |
105 | 112 |
106 void populateReadBuf(size_t x) const; | 113 void populateReadBuf(size_t x) const; |
107 | 114 |
108 float getNormalizationFactor(size_t col) const { | 115 float getNormalizationFactor(size_t col, bool lock) const { |
109 size_t h = m_mfc->getHeight(); | 116 size_t h = m_mfc->getHeight(); |
110 if (h < m_factorSize) return 0; | 117 if (h < m_factorSize) return 0; |
111 if (m_storageType != Compact) { | 118 if (m_storageType != Compact) { |
112 return getFromReadBufStandard(col, h - 1); | 119 return getFromReadBufStandard(col, h - 1, lock); |
113 } else { | 120 } else { |
114 m_readbufMutex.lock(); | 121 if (lock) m_readbufMutex.lock(); |
115 union { | 122 union { |
116 float f; | 123 float f; |
117 uint16_t u[2]; | 124 uint16_t u[2]; |
118 } factor; | 125 } factor; |
119 if (!m_readbuf || | 126 if (!m_readbuf || |
122 populateReadBuf(col); | 129 populateReadBuf(col); |
123 } | 130 } |
124 size_t ix = (col - m_readbufCol) * m_mfc->getHeight() + h; | 131 size_t ix = (col - m_readbufCol) * m_mfc->getHeight() + h; |
125 factor.u[0] = ((uint16_t *)m_readbuf)[ix - 2]; | 132 factor.u[0] = ((uint16_t *)m_readbuf)[ix - 2]; |
126 factor.u[1] = ((uint16_t *)m_readbuf)[ix - 1]; | 133 factor.u[1] = ((uint16_t *)m_readbuf)[ix - 1]; |
127 m_readbufMutex.unlock(); | 134 if (lock) m_readbufMutex.unlock(); |
128 return factor.f; | 135 return factor.f; |
129 } | 136 } |
130 } | 137 } |
131 | 138 |
132 void setNormalizationFactorToWritebuf(float newfactor) { | 139 void setNormalizationFactorToWritebuf(float newfactor) { |