comparison examples/SpectralCentroid.cpp @ 190:1982246a3902

* Provide PluginWrapper method for getting hold of a nested wrapper directly (a bit gross, but useful) * Use the above to enable the simple host to adjust timestamps appropriately when printing out results from input domain adapter wrapped plugins
author cannam
date Wed, 17 Sep 2008 13:16:09 +0000
parents aa64a46320d4
children a5187dad96cd
comparison
equal deleted inserted replaced
189:5ce2c3f79a45 190:1982246a3902
131 list.push_back(d); 131 list.push_back(d);
132 132
133 return list; 133 return list;
134 } 134 }
135 135
136 //static int scount = 0;
137
136 SpectralCentroid::FeatureSet 138 SpectralCentroid::FeatureSet
137 SpectralCentroid::process(const float *const *inputBuffers, Vamp::RealTime) 139 SpectralCentroid::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
138 { 140 {
139 if (m_stepSize == 0) { 141 if (m_stepSize == 0) {
140 cerr << "ERROR: SpectralCentroid::process: " 142 cerr << "ERROR: SpectralCentroid::process: "
141 << "SpectralCentroid has not been initialised" 143 << "SpectralCentroid has not been initialised"
142 << endl; 144 << endl;
143 return FeatureSet(); 145 return FeatureSet();
144 } 146 }
147
148 // std::cerr << "SpectralCentroid::process: count = " << scount++ << ", timestamp = " << timestamp << ", total power = ";
145 149
146 double numLin = 0.0, numLog = 0.0, denom = 0.0; 150 double numLin = 0.0, numLog = 0.0, denom = 0.0;
147 151
148 for (size_t i = 1; i <= m_blockSize/2; ++i) { 152 for (size_t i = 1; i <= m_blockSize/2; ++i) {
149 double freq = (double(i) * m_inputSampleRate) / m_blockSize; 153 double freq = (double(i) * m_inputSampleRate) / m_blockSize;
153 numLin += freq * power; 157 numLin += freq * power;
154 numLog += log10f(freq) * power; 158 numLog += log10f(freq) * power;
155 denom += power; 159 denom += power;
156 } 160 }
157 161
162 // std::cerr << denom << std::endl;
163
158 FeatureSet returnFeatures; 164 FeatureSet returnFeatures;
159
160 // std::cerr << "power " << denom << ", block size " << m_blockSize << std::endl;
161 165
162 if (denom != 0.0) { 166 if (denom != 0.0) {
163 float centroidLin = float(numLin / denom); 167 float centroidLin = float(numLin / denom);
164 float centroidLog = powf(10, float(numLog / denom)); 168 float centroidLog = powf(10, float(numLog / denom));
165 169