1 #include "ardour/transient_detector.h"
6 using namespace ARDOUR;
9 /* need a static initializer function for this */
11 string TransientDetector::_op_id = X_("libardourvampplugins:percussiononsets:2");
13 TransientDetector::TransientDetector (float sr)
14 : AudioAnalyser (sr, X_("libardourvampplugins:percussiononsets"))
16 /* update the op_id */
18 _op_id = X_("libardourvampplugins:percussiononsets");
20 // XXX this should load the above-named plugin and get the current version
25 TransientDetector::~TransientDetector()
30 TransientDetector::operational_identifier()
36 TransientDetector::run (const std::string& path, Readable* src, uint32_t channel, AnalysisFeatureList& results)
38 current_results = &results;
39 int ret = analyse (path, src, channel);
46 TransientDetector::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 TransientDetector::set_threshold (float val)
69 plugin->setParameter ("threshold", val);
74 TransientDetector::set_sensitivity (float val)
77 plugin->setParameter ("sensitivity", val);
82 TransientDetector::cleanup_transients (AnalysisFeatureList& t, float sr, float gap_msecs)
90 /* remove duplicates or other things that are too close */
92 AnalysisFeatureList::iterator i = t.begin();
93 AnalysisFeatureList::iterator f, b;
94 const nframes64_t gap_frames = (nframes64_t) floor (gap_msecs * (sr / 1000.0));
96 while (i != t.end()) {
98 // move front iterator to just past i, and back iterator the same place
104 // move f until we find a new value that is far enough away
106 while ((f != t.end()) && (((*f) - (*i)) < gap_frames)) {
112 // if f moved forward from b, we had duplicates/too-close points: get rid of them