Mercurial > hg > vamp-test-plugin
comparison VampTestPlugin.cpp @ 19:534b001d8e8f
Switch to a feature that permits drawing some conclusions about the input data having arrived in the right order
author | Chris Cannam |
---|---|
date | Wed, 03 Dec 2014 10:40:07 +0000 |
parents | 014cce47e998 |
children | cfff2b6ff0fd |
comparison
equal
deleted
inserted
replaced
18:014cce47e998 | 19:534b001d8e8f |
---|---|
1 | 1 |
2 | 2 |
3 #include "VampTestPlugin.h" | 3 #include "VampTestPlugin.h" |
4 | 4 |
5 #include <iostream> | |
5 #include <sstream> | 6 #include <sstream> |
6 #include <cmath> | 7 #include <cmath> |
7 | 8 |
8 using std::stringstream; | 9 using namespace std; |
9 | 10 |
10 using Vamp::RealTime; | 11 using Vamp::RealTime; |
11 | 12 |
12 VampTestPlugin::VampTestPlugin(float inputSampleRate) : | 13 VampTestPlugin::VampTestPlugin(float inputSampleRate) : |
13 Plugin(inputSampleRate), | 14 Plugin(inputSampleRate), |
266 d.sampleRate = 0; | 267 d.sampleRate = 0; |
267 d.hasDuration = true; | 268 d.hasDuration = true; |
268 m_outputNumbers[d.identifier] = n++; | 269 m_outputNumbers[d.identifier] = n++; |
269 list.push_back(d); | 270 list.push_back(d); |
270 | 271 |
271 d.identifier = "rmss"; | 272 d.identifier = "input-summary"; |
272 d.name = "RMS of Input Channels"; | 273 d.name = "Data derived from inputs"; |
273 d.description = "RMS levels of each input channel"; | 274 d.description = "One-sample-per-step features with n values, where n is the number of input channels. Each feature contains, for each input channel, the first sample value on that channel plus the total number of non-zero samples on that channel"; |
274 d.unit = ""; | 275 d.unit = ""; |
275 d.hasFixedBinCount = true; | 276 d.hasFixedBinCount = true; |
276 d.binCount = m_channels; | 277 d.binCount = m_channels; |
277 d.hasKnownExtents = false; | 278 d.hasKnownExtents = false; |
278 d.isQuantized = false; | 279 d.isQuantized = false; |
304 } | 305 } |
305 | 306 |
306 static Vamp::Plugin::Feature | 307 static Vamp::Plugin::Feature |
307 instant(RealTime r, int i, int n) | 308 instant(RealTime r, int i, int n) |
308 { | 309 { |
309 std::stringstream s; | 310 stringstream s; |
310 Vamp::Plugin::Feature f; | 311 Vamp::Plugin::Feature f; |
311 f.hasTimestamp = true; | 312 f.hasTimestamp = true; |
312 f.timestamp = r; | 313 f.timestamp = r; |
313 f.hasDuration = false; | 314 f.hasDuration = false; |
314 s << i+1 << " of " << n << " at " << r.toText(); | 315 s << i+1 << " of " << n << " at " << r.toText(); |
317 } | 318 } |
318 | 319 |
319 static Vamp::Plugin::Feature | 320 static Vamp::Plugin::Feature |
320 untimedCurveValue(RealTime r, int i, int n) | 321 untimedCurveValue(RealTime r, int i, int n) |
321 { | 322 { |
322 std::stringstream s; | 323 stringstream s; |
323 Vamp::Plugin::Feature f; | 324 Vamp::Plugin::Feature f; |
324 f.hasTimestamp = false; | 325 f.hasTimestamp = false; |
325 f.hasDuration = false; | 326 f.hasDuration = false; |
326 float v = float(i) / float(n); | 327 float v = float(i) / float(n); |
327 f.values.push_back(v); | 328 f.values.push_back(v); |
331 } | 332 } |
332 | 333 |
333 static Vamp::Plugin::Feature | 334 static Vamp::Plugin::Feature |
334 timedCurveValue(RealTime r, int i, int n) | 335 timedCurveValue(RealTime r, int i, int n) |
335 { | 336 { |
336 std::stringstream s; | 337 stringstream s; |
337 Vamp::Plugin::Feature f; | 338 Vamp::Plugin::Feature f; |
338 f.hasTimestamp = true; | 339 f.hasTimestamp = true; |
339 f.timestamp = r; | 340 f.timestamp = r; |
340 f.hasDuration = false; | 341 f.hasDuration = false; |
341 float v = float(i) / float(n); | 342 float v = float(i) / float(n); |
346 } | 347 } |
347 | 348 |
348 static Vamp::Plugin::Feature | 349 static Vamp::Plugin::Feature |
349 snappedCurveValue(RealTime r, RealTime sn, int i, int n) | 350 snappedCurveValue(RealTime r, RealTime sn, int i, int n) |
350 { | 351 { |
351 std::stringstream s; | 352 stringstream s; |
352 Vamp::Plugin::Feature f; | 353 Vamp::Plugin::Feature f; |
353 f.hasTimestamp = true; | 354 f.hasTimestamp = true; |
354 f.timestamp = r; | 355 f.timestamp = r; |
355 f.hasDuration = false; | 356 f.hasDuration = false; |
356 float v = float(i) / float(n); | 357 float v = float(i) / float(n); |
361 } | 362 } |
362 | 363 |
363 static Vamp::Plugin::Feature | 364 static Vamp::Plugin::Feature |
364 gridColumn(RealTime r, int i, int n) | 365 gridColumn(RealTime r, int i, int n) |
365 { | 366 { |
366 std::stringstream s; | 367 stringstream s; |
367 Vamp::Plugin::Feature f; | 368 Vamp::Plugin::Feature f; |
368 f.hasTimestamp = false; | 369 f.hasTimestamp = false; |
369 f.hasDuration = false; | 370 f.hasDuration = false; |
370 for (int j = 0; j < 10; ++j) { | 371 for (int j = 0; j < 10; ++j) { |
371 float v = float(j + i + 2) / float(n + 10); | 372 float v = float(j + i + 2) / float(n + 10); |
377 } | 378 } |
378 | 379 |
379 static Vamp::Plugin::Feature | 380 static Vamp::Plugin::Feature |
380 noteOrRegion(RealTime r, RealTime d, int i, int n) | 381 noteOrRegion(RealTime r, RealTime d, int i, int n) |
381 { | 382 { |
382 std::stringstream s; | 383 stringstream s; |
383 Vamp::Plugin::Feature f; | 384 Vamp::Plugin::Feature f; |
384 f.hasTimestamp = true; | 385 f.hasTimestamp = true; |
385 f.timestamp = r; | 386 f.timestamp = r; |
386 f.hasDuration = true; | 387 f.hasDuration = true; |
387 f.duration = d; | 388 f.duration = d; |
488 if (!m_produceOutput) return FeatureSet(); | 489 if (!m_produceOutput) return FeatureSet(); |
489 FeatureSet fs = featuresFrom(timestamp, false); | 490 FeatureSet fs = featuresFrom(timestamp, false); |
490 | 491 |
491 Feature f; | 492 Feature f; |
492 for (int c = 0; c < m_channels; ++c) { | 493 for (int c = 0; c < m_channels; ++c) { |
493 float sum = 0.f; | 494 // first value plus number of non-zero values |
495 float sum = inputBuffers[c][0]; | |
494 for (int i = 0; i < m_blockSize; ++i) { | 496 for (int i = 0; i < m_blockSize; ++i) { |
495 sum += inputBuffers[c][i] * inputBuffers[c][i]; | 497 if (inputBuffers[c][i] != 0.f) sum += 1; |
496 } | 498 } |
497 float rms = sqrtf(sum / m_blockSize); | 499 f.values.push_back(sum); |
498 f.values.push_back(rms); | 500 } |
499 } | 501 fs[m_outputNumbers["input-summary"]].push_back(f); |
500 fs[m_outputNumbers["rmss"]].push_back(f); | |
501 | 502 |
502 return fs; | 503 return fs; |
503 } | 504 } |
504 | 505 |
505 VampTestPlugin::FeatureSet | 506 VampTestPlugin::FeatureSet |