comparison plugins/Notes.cpp @ 20:8c939fff7ee1

* First bit of Vamp v2 work -- add an optional duration to features in a backward compatible way. Warning: this code is unstable and experimental and may change significantly in the coming weeks.
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 17 Jul 2008 08:51:13 +0000
parents 30153569c1a6
children 58619878e0e9
comparison
equal deleted inserted replaced
19:713c8b6fbf81 20:8c939fff7ee1
2 2
3 /* 3 /*
4 Vamp feature extraction plugins using Paul Brossier's Aubio library. 4 Vamp feature extraction plugins using Paul Brossier's Aubio library.
5 5
6 Centre for Digital Music, Queen Mary, University of London. 6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam. 7 This file copyright 2006-2008 Chris Cannam and QMUL.
8 8
9 This program is free software; you can redistribute it and/or 9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as 10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
20 using std::string; 20 using std::string;
21 using std::vector; 21 using std::vector;
22 using std::cerr; 22 using std::cerr;
23 using std::endl; 23 using std::endl;
24 24
25 Notes::Notes(float inputSampleRate) : 25 Notes::Notes(float inputSampleRate, unsigned int apiVersion) :
26 Plugin(inputSampleRate), 26 Plugin(inputSampleRate),
27 m_apiVersion(apiVersion),
27 m_ibuf(0), 28 m_ibuf(0),
28 m_fftgrain(0), 29 m_fftgrain(0),
29 m_onset(0), 30 m_onset(0),
30 m_pv(0), 31 m_pv(0),
31 m_peakpick(0), 32 m_peakpick(0),
41 m_maxpitch(95), 42 m_maxpitch(95),
42 m_wrapRange(false), 43 m_wrapRange(false),
43 m_avoidLeaps(false), 44 m_avoidLeaps(false),
44 m_prevPitch(-1) 45 m_prevPitch(-1)
45 { 46 {
47 if (apiVersion == 1) {
48 cerr << "vamp-aubio: WARNING: using compatibility version 1 of the Vamp API for note\n"
49 << "tracker plugin: upgrade your host to v2 for proper duration support" << endl;
50 }
46 } 51 }
47 52
48 Notes::~Notes() 53 Notes::~Notes()
49 { 54 {
50 if (m_onsetdet) aubio_onsetdetection_free(m_onsetdet); 55 if (m_onsetdet) aubio_onsetdetection_free(m_onsetdet);
81 } 86 }
82 87
83 int 88 int
84 Notes::getPluginVersion() const 89 Notes::getPluginVersion() const
85 { 90 {
86 return 1; 91 if (m_apiVersion == 1) return 2;
92 return 3;
87 } 93 }
88 94
89 string 95 string
90 Notes::getCopyright() const 96 Notes::getCopyright() const
91 { 97 {
318 OutputDescriptor d; 324 OutputDescriptor d;
319 d.identifier = "notes"; 325 d.identifier = "notes";
320 d.name = "Notes"; 326 d.name = "Notes";
321 d.unit = "Hz"; 327 d.unit = "Hz";
322 d.hasFixedBinCount = true; 328 d.hasFixedBinCount = true;
323 d.binCount = 2; 329
324 d.binNames.push_back("Frequency"); 330 if (m_apiVersion == 1) {
325 d.binNames.push_back("Duration"); 331 d.binCount = 3;
326 d.binNames.push_back("Velocity"); 332 d.binNames.push_back("Frequency");
333 d.binNames.push_back("Duration");
334 d.binNames.push_back("Velocity");
335 } else {
336 d.binCount = 2;
337 d.binNames.push_back("Frequency");
338 d.binNames.push_back("Velocity");
339 }
340
327 d.hasKnownExtents = false; 341 d.hasKnownExtents = false;
328 d.isQuantized = false; 342 d.isQuantized = false;
329 d.sampleType = OutputDescriptor::VariableSampleRate; 343 d.sampleType = OutputDescriptor::VariableSampleRate;
330 d.sampleRate = 0; 344 d.sampleRate = 0;
331 list.push_back(d); 345 list.push_back(d);
427 Feature feature; 441 Feature feature;
428 feature.hasTimestamp = true; 442 feature.hasTimestamp = true;
429 if (m_currentOnset < m_delay) m_currentOnset = m_delay; 443 if (m_currentOnset < m_delay) m_currentOnset = m_delay;
430 feature.timestamp = m_currentOnset - m_delay; 444 feature.timestamp = m_currentOnset - m_delay;
431 feature.values.push_back(freq); 445 feature.values.push_back(freq);
432 feature.values.push_back 446
433 (Vamp::RealTime::realTime2Frame(offTime, lrintf(m_inputSampleRate)) - 447 if (m_apiVersion == 1) {
434 Vamp::RealTime::realTime2Frame(m_currentOnset, lrintf(m_inputSampleRate))); 448 feature.values.push_back
449 (Vamp::RealTime::realTime2Frame
450 (offTime, lrintf(m_inputSampleRate)) -
451 Vamp::RealTime::realTime2Frame
452 (m_currentOnset, lrintf(m_inputSampleRate)));
453 feature.hasDuration = false;
454 } else {
455 feature.hasDuration = true;
456 feature.duration = offTime - m_currentOnset;
457 }
458
435 feature.values.push_back(m_currentLevel); 459 feature.values.push_back(m_currentLevel);
436 fs[0].push_back(feature); 460 fs[0].push_back(feature);
437 } 461 }
438 462