Mercurial > hg > vamp-plugin-sdk
comparison examples/ZeroCrossing.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 |
comparison
equal
deleted
inserted
replaced
189:5ce2c3f79a45 | 190:1982246a3902 |
---|---|
39 using std::string; | 39 using std::string; |
40 using std::vector; | 40 using std::vector; |
41 using std::cerr; | 41 using std::cerr; |
42 using std::endl; | 42 using std::endl; |
43 | 43 |
44 #include <cmath> | |
44 | 45 |
45 ZeroCrossing::ZeroCrossing(float inputSampleRate) : | 46 ZeroCrossing::ZeroCrossing(float inputSampleRate) : |
46 Plugin(inputSampleRate), | 47 Plugin(inputSampleRate), |
47 m_stepSize(0), | 48 m_stepSize(0), |
48 m_previousSample(0.0f) | 49 m_previousSample(0.0f) |
135 list.push_back(zc); | 136 list.push_back(zc); |
136 | 137 |
137 return list; | 138 return list; |
138 } | 139 } |
139 | 140 |
141 //static int scount = 0; | |
142 | |
140 ZeroCrossing::FeatureSet | 143 ZeroCrossing::FeatureSet |
141 ZeroCrossing::process(const float *const *inputBuffers, | 144 ZeroCrossing::process(const float *const *inputBuffers, |
142 Vamp::RealTime timestamp) | 145 Vamp::RealTime timestamp) |
143 { | 146 { |
144 if (m_stepSize == 0) { | 147 if (m_stepSize == 0) { |
146 << "ZeroCrossing has not been initialised" | 149 << "ZeroCrossing has not been initialised" |
147 << endl; | 150 << endl; |
148 return FeatureSet(); | 151 return FeatureSet(); |
149 } | 152 } |
150 | 153 |
154 // std::cerr << "ZeroCrossing::process: count = " << scount++ << ", timestamp = " << timestamp << ", rms = "; | |
155 | |
151 float prev = m_previousSample; | 156 float prev = m_previousSample; |
152 size_t count = 0; | 157 size_t count = 0; |
153 | 158 |
154 FeatureSet returnFeatures; | 159 FeatureSet returnFeatures; |
160 | |
161 // double acc = 0.0; | |
155 | 162 |
156 for (size_t i = 0; i < m_stepSize; ++i) { | 163 for (size_t i = 0; i < m_stepSize; ++i) { |
157 | 164 |
158 float sample = inputBuffers[0][i]; | 165 float sample = inputBuffers[0][i]; |
159 bool crossing = false; | 166 bool crossing = false; |
171 feature.timestamp = timestamp + | 178 feature.timestamp = timestamp + |
172 Vamp::RealTime::frame2RealTime(i, (size_t)m_inputSampleRate); | 179 Vamp::RealTime::frame2RealTime(i, (size_t)m_inputSampleRate); |
173 returnFeatures[1].push_back(feature); | 180 returnFeatures[1].push_back(feature); |
174 } | 181 } |
175 | 182 |
183 // acc += sample * sample; | |
184 | |
176 prev = sample; | 185 prev = sample; |
177 } | 186 } |
187 | |
188 // acc /= m_stepSize; | |
189 // std::cerr << sqrt(acc) << std::endl; | |
178 | 190 |
179 m_previousSample = prev; | 191 m_previousSample = prev; |
180 | 192 |
181 Feature feature; | 193 Feature feature; |
182 feature.hasTimestamp = false; | 194 feature.hasTimestamp = false; |