1 #include "ardour/onset_detector.h"
6 using namespace ARDOUR;
9 /* need a static initializer function for this */
11 string OnsetDetector::_op_id = X_("libardourvampplugins:aubioonset:2");
13 OnsetDetector::OnsetDetector (float sr)
14 : AudioAnalyser (sr, X_("libardourvampplugins:aubioonset"))
17 /* update the op_id */
19 _op_id = X_("libardourvampplugins:aubioonset");
21 // XXX this should load the above-named plugin and get the current version
26 OnsetDetector::~OnsetDetector()
31 OnsetDetector::operational_identifier()
37 OnsetDetector::run (const std::string& path, Readable* src, uint32_t channel, AnalysisFeatureList& results)
39 current_results = &results;
40 int ret = analyse (path, src, channel);
47 OnsetDetector::use_features (Plugin::FeatureSet& features, ostream* out)
49 const Plugin::FeatureList& fl (features[0]);
51 for (Plugin::FeatureList::const_iterator f = fl.begin(); f != fl.end(); ++f) {
53 if ((*f).hasTimestamp) {
56 (*out) << (*f).timestamp.toString() << endl;
59 current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, (nframes_t) floor(sample_rate)));
67 OnsetDetector::set_silence_threshold (float val)
70 plugin->setParameter ("silencethreshold", val);
75 OnsetDetector::set_peak_threshold (float val)
78 plugin->setParameter ("peakpickthreshold", val);
83 OnsetDetector::set_function (int val)
86 plugin->setParameter ("onsettype", (float) val);
91 OnsetDetector::cleanup_onsets (AnalysisFeatureList& t, float sr, float gap_msecs)
99 /* remove duplicates or other things that are too close */
101 AnalysisFeatureList::iterator i = t.begin();
102 AnalysisFeatureList::iterator f, b;
103 const nframes64_t gap_frames = (nframes64_t) floor (gap_msecs * (sr / 1000.0));
105 while (i != t.end()) {
107 // move front iterator to just past i, and back iterator the same place
113 // move f until we find a new value that is far enough away
115 while ((f != t.end()) && (((*f) - (*i)) < gap_frames)) {
121 // if f moved forward from b, we had duplicates/too-close points: get rid of them