diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-12-09 16:31:05 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-12-09 16:31:05 +0000 |
commit | 0a62044c2c51b38c900ed75d4037e6093901f387 (patch) | |
tree | 280b47be28b61f79e8988619ca7026962bd3f457 /libs | |
parent | d28ecb2b93540e64a7c8dc820dcb6dcedc17a550 (diff) |
make strip silence work (again?)
git-svn-id: svn://localhost/ardour2/branches/3.0@8226 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/strip_silence.h | 11 | ||||
-rw-r--r-- | libs/ardour/ardour/types.h | 4 | ||||
-rw-r--r-- | libs/ardour/audioregion.cc | 11 | ||||
-rw-r--r-- | libs/ardour/audiosource.cc | 2 | ||||
-rw-r--r-- | libs/ardour/strip_silence.cc | 58 |
5 files changed, 50 insertions, 36 deletions
diff --git a/libs/ardour/ardour/strip_silence.h b/libs/ardour/ardour/strip_silence.h index 91374be88a..ff1d1b7f17 100644 --- a/libs/ardour/ardour/strip_silence.h +++ b/libs/ardour/ardour/strip_silence.h @@ -22,16 +22,15 @@ namespace ARDOUR { /// A filter to strip silence from regions -class StripSilence : public Filter { - -public: - StripSilence (Session &, double, framecnt_t, framecnt_t); +class StripSilence : public Filter +{ + public: + StripSilence (Session &, const AudioIntervalMap&, framecnt_t fade_length); int run (boost::shared_ptr<ARDOUR::Region>, Progress* progress = 0); private: - double _threshold; ///< silence threshold, in dBFS - framecnt_t _minimum_length; ///< minimum length to be considered silence, in samples + AudioIntervalMap _smap; framecnt_t _fade_length; ///< fade in/out to use on trimmed regions, in samples }; diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index cae2d5bcf7..92739c3cd6 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -22,6 +22,7 @@ #include <istream> #include <vector> +#include <map> #include <boost/shared_ptr.hpp> #include <sys/types.h> #include <stdint.h> @@ -46,6 +47,7 @@ namespace ARDOUR { class Source; class AudioSource; class Route; + class Region; typedef jack_default_audio_sample_t Sample; typedef float pan_t; @@ -74,6 +76,8 @@ namespace ARDOUR { // a set of (time) intervals: first of pair is the offset within the region, second is the length of the interval typedef std::list<std::pair<frameoffset_t,framecnt_t> > AudioIntervalResult; + // associate a set of intervals with regions (e.g. for silence detection) + typedef std::map<boost::shared_ptr<ARDOUR::Region>,AudioIntervalResult> AudioIntervalMap; struct IOChange { diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 84709d7bb2..5c213bfb7c 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -24,6 +24,7 @@ #include <set> +#include <boost/scoped_array.hpp> #include <glibmm/thread.h> @@ -1498,15 +1499,15 @@ in this and future transient-detection operations.\n\ * * @param threshold Threshold below which signal is considered silence (as a sample value) * @param min_length Minimum length of silent period to be reported. - * @return Silent intervals + * @return Silent intervals, measured relative to the region start in the source */ AudioIntervalResult AudioRegion::find_silence (Sample threshold, framecnt_t min_length, InterThreadInfo& itt) const { framecnt_t const block_size = 64 * 1024; - Sample loudest[block_size]; - Sample buf[block_size]; + boost::scoped_array<Sample> loudest (new Sample[block_size]); + boost::scoped_array<Sample> buf (new Sample[block_size]); framepos_t pos = _start; framepos_t const end = _start + _length - 1; @@ -1520,10 +1521,10 @@ AudioRegion::find_silence (Sample threshold, framecnt_t min_length, InterThreadI while (pos < end && !itt.cancel) { /* fill `loudest' with the loudest absolute sample at each instant, across all channels */ - memset (loudest, 0, sizeof (Sample) * block_size); + memset (loudest.get(), 0, sizeof (Sample) * block_size); for (uint32_t n = 0; n < n_channels(); ++n) { - read_raw_internal (buf, pos, block_size, n); + read_raw_internal (buf.get(), pos, block_size, n); for (framecnt_t i = 0; i < block_size; ++i) { loudest[i] = max (loudest[i], abs (buf[i])); } diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc index 38261f3cbb..b993a093b5 100644 --- a/libs/ardour/audiosource.cc +++ b/libs/ardour/audiosource.cc @@ -238,7 +238,7 @@ AudioSource::initialize_peakfile (bool newfile, string audio_path) /* we found it in the peaks dir, so check it out */ - if (statbuf.st_size == 0 || ((framecnt_t) statbuf.st_size < ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) { + if (statbuf.st_size == 0 || (statbuf.st_size < (off_t) ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) { // empty _peaks_built = false; } else { diff --git a/libs/ardour/strip_silence.cc b/libs/ardour/strip_silence.cc index cf03c2df8b..cd7ab879e7 100644 --- a/libs/ardour/strip_silence.cc +++ b/libs/ardour/strip_silence.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2009 Paul Davis + Copyright (C) 2009-2010 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,8 +35,10 @@ using namespace ARDOUR; * @param fade_length Length of fade in/out to apply to trimmed regions, in samples. */ -StripSilence::StripSilence (Session & s, double threshold, framecnt_t minimum_length, framecnt_t fade_length) - : Filter (s), _threshold (threshold), _minimum_length (minimum_length), _fade_length (fade_length) +StripSilence::StripSilence (Session & s, const AudioIntervalMap& sm, framecnt_t fade_length) + : Filter (s) + , _smap (sm) + , _fade_length (fade_length) { } @@ -51,15 +53,19 @@ StripSilence::run (boost::shared_ptr<Region> r, Progress* progress) */ boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (r); InterThreadInfo itt; - + AudioIntervalMap::const_iterator sm; + if (!region) { results.push_back (r); return -1; } - /* find periods of silence in the region */ - std::list<std::pair<frameoffset_t, framecnt_t> > const silence = - region->find_silence (dB_to_coefficient (_threshold), _minimum_length, itt); + if ((sm = _smap.find (r)) == _smap.end()) { + results.push_back (r); + return -1; + } + + const AudioIntervalResult& silence = sm->second; if (silence.size () == 1 && silence.front().first == 0 && silence.front().second == region->length() - 1) { /* the region is all silence, so just return with nothing */ @@ -72,19 +78,21 @@ StripSilence::run (boost::shared_ptr<Region> r, Progress* progress) return 0; } - std::list<std::pair<framepos_t, framecnt_t > >::const_iterator s = silence.begin (); + AudioIntervalResult::const_iterator s = silence.begin (); PBD::PropertyList plist; - framepos_t start = 0; + framepos_t start; framepos_t end; bool in_silence; boost::shared_ptr<AudioRegion> copy; - if (s->first == 0) { - /* initial segment, starting at zero, is silent */ + start = r->start(); + + if (s->first == start) { + /* segment starting at zero is silent */ end = s->second; in_silence = true; } else { - /* initial segment, starting at zero, is audible */ + /* segment starting at zero is audible, and begins at the start of the region in the source */ end = s->first; in_silence = false; } @@ -92,42 +100,44 @@ StripSilence::run (boost::shared_ptr<Region> r, Progress* progress) int n = 0; int const N = silence.size (); - while (s != silence.end()) { + while (start < r->start() + r->length()) { framecnt_t interval_duration; interval_duration = end - start; - if (!in_silence && interval_duration > 0) { plist.clear (); plist.add (Properties::length, interval_duration); - plist.add (Properties::position, region->position() + start); + plist.add (Properties::position, r->position() + (start - r->start())); copy = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create - (region, start, plist)); + (region, (start - r->start()), plist)); copy->set_name (RegionFactory::new_region_name (region->name ())); - std::cerr << "New silent delineated region called " << copy->name() - << " @ " << copy->start() << " length = " << copy->length() << " pos = " << - copy->position() << std::endl; - copy->set_fade_in_active (true); copy->set_fade_in (FadeLinear, _fade_length); results.push_back (copy); } start = end; - ++s; - end = s->first; in_silence = !in_silence; + ++s; + + if (s == silence.end()) { + end = r->start() + r->length(); + } else { + end = s->first; + } - if (progress) { + ++n; + + if (progress && (n <= N)) { progress->set_progress (float (n) / N); } - ++n; + } return 0; |