1 #include <ardour/transient_detector.h>
6 using namespace ARDOUR;
9 string TransientDetector::_op_id;
11 TransientDetector::TransientDetector (float sr)
12 : AudioAnalyser (sr, X_("libardourvampplugins:percussiononsets"))
15 _op_id = X_("libardourvampplugins:percussiononsets");
17 // XXX this should load the above-named plugin and get the current version
23 TransientDetector::~TransientDetector()
28 TransientDetector::operational_identifier()
34 TransientDetector::run (const std::string& path, Readable* src, uint32_t channel, AnalysisFeatureList& results)
36 current_results = &results;
37 int ret = analyse (path, src, channel);
44 TransientDetector::use_features (Plugin::FeatureSet& features, ostream* out)
46 const Plugin::FeatureList& fl (features[0]);
48 for (Plugin::FeatureList::const_iterator f = fl.begin(); f != fl.end(); ++f) {
50 if ((*f).hasTimestamp) {
53 (*out) << (*f).timestamp.toString() << endl;
56 current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, (nframes_t) floor(sample_rate)));
64 TransientDetector::set_threshold (float val)
67 plugin->setParameter ("threshold", val);
72 TransientDetector::set_sensitivity (float val)
75 plugin->setParameter ("sensitivity", val);
80 TransientDetector::cleanup_transients (AnalysisFeatureList& t, float sr, float gap_msecs)
88 /* remove duplicates or other things that are too close */
90 AnalysisFeatureList::iterator i = t.begin();
91 AnalysisFeatureList::iterator f, b;
92 const nframes64_t gap_frames = (nframes64_t) floor (gap_msecs * (sr / 1000.0));
94 while (i != t.end()) {
96 // move front iterator to just past i, and back iterator the same place
102 // move f until we find a new value that is far enough away
104 while ((f != t.end()) && (((*f) - (*i)) < gap_frames)) {
110 // if f moved forward from b, we had duplicates/too-close points: get rid of them