2 #include "ardour/onset_detector.h"
7 using namespace ARDOUR
;
10 /* need a static initializer function for this */
12 string
OnsetDetector::_op_id
= X_("libardourvampplugins:aubioonset:2");
14 OnsetDetector::OnsetDetector (float sr
)
15 : AudioAnalyser (sr
, X_("libardourvampplugins:aubioonset"))
18 /* update the op_id */
20 _op_id
= X_("libardourvampplugins:aubioonset");
22 // XXX this should load the above-named plugin and get the current version
27 OnsetDetector::~OnsetDetector()
32 OnsetDetector::operational_identifier()
38 OnsetDetector::run (const std::string
& path
, Readable
* src
, uint32_t channel
, AnalysisFeatureList
& results
)
40 current_results
= &results
;
41 int ret
= analyse (path
, src
, channel
);
48 OnsetDetector::use_features (Plugin::FeatureSet
& features
, ostream
* out
)
50 const Plugin::FeatureList
& fl (features
[0]);
52 for (Plugin::FeatureList::const_iterator f
= fl
.begin(); f
!= fl
.end(); ++f
) {
54 if ((*f
).hasTimestamp
) {
57 (*out
) << (*f
).timestamp
.toString() << endl
;
60 current_results
->push_back (RealTime::realTime2Frame ((*f
).timestamp
, (framecnt_t
) floor(sample_rate
)));
68 OnsetDetector::set_silence_threshold (float val
)
71 plugin
->setParameter ("silencethreshold", val
);
76 OnsetDetector::set_peak_threshold (float val
)
79 plugin
->setParameter ("peakpickthreshold", val
);
84 OnsetDetector::set_function (int val
)
87 plugin
->setParameter ("onsettype", (float) val
);
92 OnsetDetector::cleanup_onsets (AnalysisFeatureList
& t
, float sr
, float gap_msecs
)
100 /* remove duplicates or other things that are too close */
102 AnalysisFeatureList::iterator i
= t
.begin();
103 AnalysisFeatureList::iterator f
, b
;
104 const framecnt_t gap_frames
= (framecnt_t
) floor (gap_msecs
* (sr
/ 1000.0));
106 while (i
!= t
.end()) {
108 // move front iterator to just past i, and back iterator the same place
114 // move f until we find a new value that is far enough away
116 while ((f
!= t
.end()) && (((*f
) - (*i
)) < gap_frames
)) {
122 // if f moved forward from b, we had duplicates/too-close points: get rid of them