Mercurial > hg > vamp-aubio-plugins
comparison plugins/Silence.cpp @ 31:2e979622bd93
Update plugin version numbers, remove API version back compatibility (API v1 is now so long out of date)
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Mon, 09 Jul 2012 15:44:07 +0100 |
parents | eb246395f576 |
children | 8a20f3488d88 |
comparison
equal
deleted
inserted
replaced
30:7fd8f7a0b088 | 31:2e979622bd93 |
---|---|
19 using std::string; | 19 using std::string; |
20 using std::vector; | 20 using std::vector; |
21 using std::cerr; | 21 using std::cerr; |
22 using std::endl; | 22 using std::endl; |
23 | 23 |
24 Silence::Silence(float inputSampleRate, unsigned int apiVersion) : | 24 Silence::Silence(float inputSampleRate) : |
25 Plugin(inputSampleRate), | 25 Plugin(inputSampleRate), |
26 m_apiVersion(apiVersion), | |
27 m_ibuf(0), | 26 m_ibuf(0), |
28 m_pbuf(0), | 27 m_pbuf(0), |
29 m_tmpptrs(0), | 28 m_tmpptrs(0), |
30 m_threshold(-80), | 29 m_threshold(-80), |
31 m_prevSilent(false), | 30 m_prevSilent(false), |
32 m_first(true) | 31 m_first(true) |
33 { | 32 { |
34 if (m_apiVersion == 1) { | |
35 cerr << "vamp-aubio: WARNING: using compatibility version 1 of the Vamp API for silence\n" | |
36 << "detector plugin: upgrade your host to v2 for proper duration support" << endl; | |
37 } | |
38 } | 33 } |
39 | 34 |
40 Silence::~Silence() | 35 Silence::~Silence() |
41 { | 36 { |
42 if (m_ibuf) del_fvec(m_ibuf); | 37 if (m_ibuf) del_fvec(m_ibuf); |
69 } | 64 } |
70 | 65 |
71 int | 66 int |
72 Silence::getPluginVersion() const | 67 Silence::getPluginVersion() const |
73 { | 68 { |
74 if (m_apiVersion == 1) return 2; | 69 return 4; |
75 return 3; | |
76 } | 70 } |
77 | 71 |
78 string | 72 string |
79 Silence::getCopyright() const | 73 Silence::getCopyright() const |
80 { | 74 { |
155 { | 149 { |
156 OutputList list; | 150 OutputList list; |
157 | 151 |
158 OutputDescriptor d; | 152 OutputDescriptor d; |
159 | 153 |
160 if (m_apiVersion == 1) { | 154 d.identifier = "silent"; |
161 | 155 d.name = "Silent Regions"; |
162 d.identifier = "silencestart"; | 156 d.description = "Return an interval covering each silent region"; |
163 d.name = "Beginnings of Silent Regions"; | 157 d.hasFixedBinCount = true; |
164 d.description = "Return a single instant at the point where each silent region begins"; | 158 d.binCount = 0; |
165 d.hasFixedBinCount = true; | 159 d.hasKnownExtents = false; |
166 d.binCount = 0; | 160 d.sampleType = OutputDescriptor::VariableSampleRate; |
167 d.hasKnownExtents = false; | 161 d.sampleRate = 0; |
168 d.sampleType = OutputDescriptor::VariableSampleRate; | 162 d.hasDuration = true; |
169 d.sampleRate = 0; | 163 list.push_back(d); |
170 list.push_back(d); | 164 |
171 | 165 d.identifier = "noisy"; |
172 d.identifier = "silenceend"; | 166 d.name = "Non-Silent Regions"; |
173 d.name = "Ends of Silent Regions"; | 167 d.description = "Return an interval covering each non-silent region"; |
174 d.description = "Return a single instant at the point where each silent region ends"; | 168 d.hasFixedBinCount = true; |
175 d.hasFixedBinCount = true; | 169 d.binCount = 0; |
176 d.binCount = 0; | 170 d.hasKnownExtents = false; |
177 d.hasKnownExtents = false; | 171 d.sampleType = OutputDescriptor::VariableSampleRate; |
178 d.sampleType = OutputDescriptor::VariableSampleRate; | 172 d.sampleRate = 0; |
179 d.sampleRate = 0; | 173 d.hasDuration = true; |
180 list.push_back(d); | 174 list.push_back(d); |
181 | |
182 } else { | |
183 | |
184 d.identifier = "silent"; | |
185 d.name = "Silent Regions"; | |
186 d.description = "Return an interval covering each silent region"; | |
187 d.hasFixedBinCount = true; | |
188 d.binCount = 0; | |
189 d.hasKnownExtents = false; | |
190 d.sampleType = OutputDescriptor::VariableSampleRate; | |
191 d.sampleRate = 0; | |
192 d.hasDuration = true; | |
193 list.push_back(d); | |
194 | |
195 d.identifier = "noisy"; | |
196 d.name = "Non-Silent Regions"; | |
197 d.description = "Return an interval covering each non-silent region"; | |
198 d.hasFixedBinCount = true; | |
199 d.binCount = 0; | |
200 d.hasKnownExtents = false; | |
201 d.sampleType = OutputDescriptor::VariableSampleRate; | |
202 d.sampleRate = 0; | |
203 d.hasDuration = true; | |
204 list.push_back(d); | |
205 } | |
206 | 175 |
207 d.identifier = "silencelevel"; | 176 d.identifier = "silencelevel"; |
208 d.name = "Silence Test"; | 177 d.name = "Silence Test"; |
209 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends"; | 178 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends"; |
210 d.hasFixedBinCount = true; | 179 d.hasFixedBinCount = true; |
286 feature.values.push_back(silent ? 0 : 1); | 255 feature.values.push_back(silent ? 0 : 1); |
287 returnFeatures[2].push_back(feature); | 256 returnFeatures[2].push_back(feature); |
288 | 257 |
289 feature.values.clear(); | 258 feature.values.clear(); |
290 | 259 |
291 if (m_apiVersion == 1) { | 260 if (!m_first) { |
261 feature.timestamp = m_lastChange; | |
262 feature.hasDuration = true; | |
263 feature.duration = featureStamp - m_lastChange; | |
292 if (silent) { | 264 if (silent) { |
293 // silencestart feature | 265 // non-silent regions feature |
266 // (becoming silent, so this is a non-silent region) | |
267 returnFeatures[1].push_back(feature); | |
268 } else { | |
269 // silent regions feature | |
270 // (becoming non-silent, so this is a silent region) | |
294 returnFeatures[0].push_back(feature); | 271 returnFeatures[0].push_back(feature); |
295 } else { | 272 } |
296 // silenceend feature | 273 } |
297 returnFeatures[1].push_back(feature); | 274 m_lastChange = featureStamp; |
298 } | |
299 } else { | |
300 if (!m_first) { | |
301 feature.timestamp = m_lastChange; | |
302 feature.hasDuration = true; | |
303 feature.duration = featureStamp - m_lastChange; | |
304 if (silent) { | |
305 // non-silent regions feature | |
306 // (becoming silent, so this is a non-silent region) | |
307 returnFeatures[1].push_back(feature); | |
308 } else { | |
309 // silent regions feature | |
310 // (becoming non-silent, so this is a silent region) | |
311 returnFeatures[0].push_back(feature); | |
312 } | |
313 } | |
314 m_lastChange = featureStamp; | |
315 } | |
316 | 275 |
317 m_prevSilent = silent; | 276 m_prevSilent = silent; |
318 m_first = false; | 277 m_first = false; |
319 } | 278 } |
320 | 279 |
340 if (m_lastTimestamp > m_lastChange) { | 299 if (m_lastTimestamp > m_lastChange) { |
341 | 300 |
342 Feature feature; | 301 Feature feature; |
343 feature.hasTimestamp = true; | 302 feature.hasTimestamp = true; |
344 | 303 |
345 if (m_apiVersion == 1) { | 304 feature.timestamp = m_lastChange; |
346 if (m_prevSilent) { | 305 feature.hasDuration = true; |
347 // silenceend feature | 306 feature.duration = m_lastTimestamp - m_lastChange; |
348 feature.timestamp = m_lastTimestamp; | 307 if (m_prevSilent) { |
349 returnFeatures[1].push_back(feature); | 308 // silent regions feature |
350 } | 309 returnFeatures[0].push_back(feature); |
351 } else { | 310 } else { |
352 | 311 // non-silent regions feature |
353 feature.timestamp = m_lastChange; | 312 returnFeatures[1].push_back(feature); |
354 feature.hasDuration = true; | |
355 feature.duration = m_lastTimestamp - m_lastChange; | |
356 if (m_prevSilent) { | |
357 // silent regions feature | |
358 returnFeatures[0].push_back(feature); | |
359 } else { | |
360 // non-silent regions feature | |
361 returnFeatures[1].push_back(feature); | |
362 } | |
363 } | 313 } |
364 | 314 |
365 if (!m_prevSilent) { | 315 if (!m_prevSilent) { |
366 Feature silenceTestFeature; | 316 Feature silenceTestFeature; |
367 silenceTestFeature.hasTimestamp = true; | 317 silenceTestFeature.hasTimestamp = true; |