diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/audioanalyser.h | 4 | ||||
-rw-r--r-- | libs/ardour/ardour/audioregion.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/transient_detector.h | 2 | ||||
-rw-r--r-- | libs/ardour/audioanalyser.cc | 3 | ||||
-rw-r--r-- | libs/ardour/audioregion.cc | 63 | ||||
-rw-r--r-- | libs/ardour/transient_detector.cc | 6 |
6 files changed, 73 insertions, 7 deletions
diff --git a/libs/ardour/ardour/audioanalyser.h b/libs/ardour/ardour/audioanalyser.h index aac2600ba6..dbd8a52d5a 100644 --- a/libs/ardour/ardour/audioanalyser.h +++ b/libs/ardour/ardour/audioanalyser.h @@ -43,7 +43,7 @@ class AudioAnalyser { /* analysis object should provide a run method that accepts a path to write the results to (optionally empty) - a boost::shared_ptr<Readable> to read data from + a Readable* to read data from and a reference to a type-specific container to return the results. */ @@ -59,7 +59,7 @@ class AudioAnalyser { nframes64_t stepsize; int initialize_plugin (AnalysisPluginKey name, float sample_rate); - int analyse (const std::string& path, boost::shared_ptr<Readable>, uint32_t channel); + int analyse (const std::string& path, Readable*, uint32_t channel); /* instances of an analysis object will have this method called whenever there are results to process. if out is non-null, diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index e35b041a08..5bc59a715a 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -148,6 +148,8 @@ class AudioRegion : public Region void set_playlist (boost::weak_ptr<Playlist>); + int get_transients (std::vector<nframes64_t>&); + private: friend class RegionFactory; diff --git a/libs/ardour/ardour/transient_detector.h b/libs/ardour/ardour/transient_detector.h index 45172d8f54..c65bae3ed5 100644 --- a/libs/ardour/ardour/transient_detector.h +++ b/libs/ardour/ardour/transient_detector.h @@ -40,7 +40,7 @@ class TransientDetector : public AudioAnalyser float get_threshold () const; float get_sensitivity () const; - int run (const std::string& path, boost::shared_ptr<Readable>, uint32_t channel, std::vector<nframes64_t>& results); + int run (const std::string& path, Readable*, uint32_t channel, std::vector<nframes64_t>& results); protected: std::vector<nframes64_t>* current_results; diff --git a/libs/ardour/audioanalyser.cc b/libs/ardour/audioanalyser.cc index 86bf1c51be..4cc99a5d5e 100644 --- a/libs/ardour/audioanalyser.cc +++ b/libs/ardour/audioanalyser.cc @@ -37,6 +37,7 @@ AudioAnalyser::initialize_plugin (AnalysisPluginKey key, float sr) plugin = loader->loadPlugin (key, sr, PluginLoader::ADAPT_ALL); if (!plugin) { + error << string_compose (_("VAMP Plugin \"%1\" could not be loaded"), key) << endmsg; return -1; } @@ -69,7 +70,7 @@ AudioAnalyser::reset () } int -AudioAnalyser::analyse (const string& path, boost::shared_ptr<Readable> src, uint32_t channel) +AudioAnalyser::analyse (const string& path, Readable* src, uint32_t channel) { ofstream ofile; Plugin::FeatureSet onsets; diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index ebf42255cc..01728a8c01 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -43,6 +43,7 @@ #include <ardour/audiofilter.h> #include <ardour/audiofilesource.h> #include <ardour/region_factory.h> +#include <ardour/transient_detector.h> #include "i18n.h" #include <locale.h> @@ -1502,6 +1503,68 @@ AudioRegion::set_playlist (boost::weak_ptr<Playlist> wpl) } } +int +AudioRegion::get_transients (vector<nframes64_t>& results) +{ + if (!playlist()) { + return -1; + } + + TransientDetector t (playlist()->session().frame_rate()); + bool existing_results = !results.empty(); + + for (uint32_t i = 0; i < n_channels(); ++i) { + + vector<nframes64_t> these_results; + + t.reset (); + + if (t.run ("", this, i, these_results)) { + return -1; + } + + /* translate all transients to give absolute position */ + + for (vector<nframes64_t>::iterator i = these_results.begin(); i != these_results.end(); ++i) { + (*i) += _position; + } + + /* merge */ + + results.insert (results.end(), these_results.begin(), these_results.end()); + } + + if (!results.empty() && (existing_results || n_channels() > 1)) { + + /* now resort to bring transients from different channels together */ + + sort (results.begin(), results.end()); + + /* remove duplicates or other things that are too close */ + + vector<nframes64_t>::iterator i = results.begin(); + nframes64_t curr = (*i); + + /* XXX force a 3msec gap - use a config variable */ + + nframes64_t gap_frames = (nframes64_t) floor (3.0 * (playlist()->session().frame_rate() / 1000.0)); + + ++i; + + while (i != results.end()) { + if (((*i) == curr) || (((*i) - curr) < gap_frames)) { + i = results.erase (i); + } else { + ++i; + curr = *i; + } + } + } + + return 0; +} + + extern "C" { int region_read_peaks_from_c (void *arg, uint32_t npeaks, uint32_t start, uint32_t cnt, intptr_t data, uint32_t n_chan, double samples_per_unit) diff --git a/libs/ardour/transient_detector.cc b/libs/ardour/transient_detector.cc index cc554ee544..b85700dd90 100644 --- a/libs/ardour/transient_detector.cc +++ b/libs/ardour/transient_detector.cc @@ -7,7 +7,7 @@ using namespace ARDOUR; using namespace std; TransientDetector::TransientDetector (float sr) - : AudioAnalyser (sr, X_("ardour-vamp-plugins:percussiononsets")) + : AudioAnalyser (sr, X_("libardourvampplugins:percussiononsets")) { } @@ -16,7 +16,7 @@ TransientDetector::~TransientDetector() } int -TransientDetector::run (const std::string& path, boost::shared_ptr<Readable> src, uint32_t channel, vector<nframes64_t>& results) +TransientDetector::run (const std::string& path, Readable* src, uint32_t channel, vector<nframes64_t>& results) { current_results = &results; int ret = analyse (path, src, channel); @@ -37,7 +37,7 @@ TransientDetector::use_features (Plugin::FeatureSet& features, ostream* out) (*out) << (*f).timestamp.toString() << endl; } - current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, sample_rate)); + current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, (nframes_t) floor(sample_rate))); } } |