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"))
16 /* update the op_id */
18 _op_id = X_("libardourvampplugins:aubioonset");
20 // XXX this should load the above-named plugin and get the current version
25 OnsetDetector::~OnsetDetector()
30 OnsetDetector::operational_identifier()
36 OnsetDetector::run (const std::string& path, Readable* src, uint32_t channel, AnalysisFeatureList& results)
38 current_results = &results;
39 int ret = analyse (path, src, channel);
46 OnsetDetector::use_features (Plugin::FeatureSet& features, ostream* out)
48 const Plugin::FeatureList& fl (features[0]);
50 for (Plugin::FeatureList::const_iterator f = fl.begin(); f != fl.end(); ++f) {
52 if ((*f).hasTimestamp) {
55 (*out) << (*f).timestamp.toString() << endl;
58 current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, (nframes_t) floor(sample_rate)));
66 OnsetDetector::set_silence_threshold (float val)
69 plugin->setParameter ("silencethreshold", val);
74 OnsetDetector::set_peak_threshold (float val)
77 plugin->setParameter ("peakpickthreshold", val);
82 OnsetDetector::set_function (int val)
85 plugin->setParameter ("onsettype", (float) val);
90 OnsetDetector::cleanup_onsets (AnalysisFeatureList& t, float sr, float gap_msecs)
98 /* remove duplicates or other things that are too close */
100 AnalysisFeatureList::iterator i = t.begin();
101 AnalysisFeatureList::iterator f, b;
102 const nframes64_t gap_frames = (nframes64_t) floor (gap_msecs * (sr / 1000.0));
104 while (i != t.end()) {
106 // move front iterator to just past i, and back iterator the same place
112 // move f until we find a new value that is far enough away
114 while ((f != t.end()) && (((*f) - (*i)) < gap_frames)) {
120 // if f moved forward from b, we had duplicates/too-close points: get rid of them