2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "ardour/onset_detector.h"
26 using namespace ARDOUR;
29 /* need a static initializer function for this */
31 string OnsetDetector::_op_id = X_("libardourvampplugins:aubioonset:2");
33 OnsetDetector::OnsetDetector (float sr)
34 : AudioAnalyser (sr, X_("libardourvampplugins:aubioonset"))
37 /* update the op_id */
39 _op_id = X_("libardourvampplugins:aubioonset");
41 // XXX this should load the above-named plugin and get the current version
46 OnsetDetector::~OnsetDetector()
51 OnsetDetector::operational_identifier()
57 OnsetDetector::run (const std::string& path, Readable* src, uint32_t channel, AnalysisFeatureList& results)
59 current_results = &results;
60 int ret = analyse (path, src, channel);
67 OnsetDetector::use_features (Plugin::FeatureSet& features, ostream* out)
69 const Plugin::FeatureList& fl (features[0]);
71 for (Plugin::FeatureList::const_iterator f = fl.begin(); f != fl.end(); ++f) {
73 if ((*f).hasTimestamp) {
76 (*out) << (*f).timestamp.toString() << endl;
79 current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, (framecnt_t) floor(sample_rate)));
87 OnsetDetector::set_silence_threshold (float val)
90 plugin->setParameter ("silencethreshold", val);
95 OnsetDetector::set_peak_threshold (float val)
98 plugin->setParameter ("peakpickthreshold", val);
103 OnsetDetector::set_function (int val)
106 plugin->setParameter ("onsettype", (float) val);
111 OnsetDetector::cleanup_onsets (AnalysisFeatureList& t, float sr, float gap_msecs)
119 /* remove duplicates or other things that are too close */
121 AnalysisFeatureList::iterator i = t.begin();
122 AnalysisFeatureList::iterator f, b;
123 const framecnt_t gap_frames = (framecnt_t) floor (gap_msecs * (sr / 1000.0));
125 while (i != t.end()) {
127 // move front iterator to just past i, and back iterator the same place
133 // move f until we find a new value that is far enough away
135 while ((f != t.end()) && (((*f) - (*i)) < gap_frames)) {
141 // if f moved forward from b, we had duplicates/too-close points: get rid of them