Mercurial > hg > vamp-plugin-sdk
comparison examples/SpectralCentroid.cpp @ 47:be8fdfe25693
* Change input buffers arg to process from float ** to const float *const *
to avoid plugins modifying their input data
* Some improvements to comments
* Fix stupidity in frequency-domain input passing (there are n/2+1 values,
not n/2)
author | cannam |
---|---|
date | Fri, 08 Dec 2006 17:39:32 +0000 |
parents | 3bbe244611bb |
children | f46bf5e0fa42 |
comparison
equal
deleted
inserted
replaced
46:2858c897d90f | 47:be8fdfe25693 |
---|---|
124 | 124 |
125 return list; | 125 return list; |
126 } | 126 } |
127 | 127 |
128 SpectralCentroid::FeatureSet | 128 SpectralCentroid::FeatureSet |
129 SpectralCentroid::process(float **inputBuffers, Vamp::RealTime) | 129 SpectralCentroid::process(const float *const *inputBuffers, Vamp::RealTime) |
130 { | 130 { |
131 if (m_stepSize == 0) { | 131 if (m_stepSize == 0) { |
132 cerr << "ERROR: SpectralCentroid::process: " | 132 cerr << "ERROR: SpectralCentroid::process: " |
133 << "SpectralCentroid has not been initialised" | 133 << "SpectralCentroid has not been initialised" |
134 << endl; | 134 << endl; |
135 return FeatureSet(); | 135 return FeatureSet(); |
136 } | 136 } |
137 | 137 |
138 double numLin = 0.0, numLog = 0.0, denom = 0.0; | 138 double numLin = 0.0, numLog = 0.0, denom = 0.0; |
139 | 139 |
140 for (size_t i = 1; i < m_blockSize/2; ++i) { | 140 for (size_t i = 1; i <= m_blockSize/2; ++i) { |
141 double freq = (double(i) * m_inputSampleRate) / m_blockSize; | 141 double freq = (double(i) * m_inputSampleRate) / m_blockSize; |
142 double real = inputBuffers[0][i*2]; | 142 double real = inputBuffers[0][i*2]; |
143 double imag = inputBuffers[0][i*2 + 1]; | 143 double imag = inputBuffers[0][i*2 + 1]; |
144 double power = sqrt(real * real + imag * imag) / (m_blockSize/2); | 144 double power = sqrt(real * real + imag * imag) / (m_blockSize/2); |
145 numLin += freq * power; | 145 numLin += freq * power; |
152 // std::cerr << "power " << denom << ", block size " << m_blockSize << std::endl; | 152 // std::cerr << "power " << denom << ", block size " << m_blockSize << std::endl; |
153 | 153 |
154 if (denom != 0.0) { | 154 if (denom != 0.0) { |
155 float centroidLin = float(numLin / denom); | 155 float centroidLin = float(numLin / denom); |
156 float centroidLog = powf(10, float(numLog / denom)); | 156 float centroidLog = powf(10, float(numLog / denom)); |
157 | |
157 Feature feature; | 158 Feature feature; |
158 feature.hasTimestamp = false; | 159 feature.hasTimestamp = false; |
159 feature.values.push_back(centroidLog); | 160 if (!isnan(centroidLog) && !isinf(centroidLog)) { |
161 feature.values.push_back(centroidLog); | |
162 } | |
160 returnFeatures[0].push_back(feature); | 163 returnFeatures[0].push_back(feature); |
164 | |
161 feature.values.clear(); | 165 feature.values.clear(); |
162 feature.values.push_back(centroidLin); | 166 if (!isnan(centroidLin) && !isinf(centroidLin)) { |
167 feature.values.push_back(centroidLin); | |
168 } | |
163 returnFeatures[1].push_back(feature); | 169 returnFeatures[1].push_back(feature); |
164 } | 170 } |
165 | 171 |
166 return returnFeatures; | 172 return returnFeatures; |
167 } | 173 } |