From 2d3c640fee5530fdf68c631feccbc22828583e98 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 28 Feb 2011 18:57:25 +0000 Subject: Fix up strip silence. git-svn-id: svn://localhost/ardour2/branches/3.0@8991 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/strip_silence.cc | 95 ++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 51 deletions(-) (limited to 'libs/ardour/strip_silence.cc') diff --git a/libs/ardour/strip_silence.cc b/libs/ardour/strip_silence.cc index cd7ab879e7..d04612f604 100644 --- a/libs/ardour/strip_silence.cc +++ b/libs/ardour/strip_silence.cc @@ -78,66 +78,59 @@ StripSilence::run (boost::shared_ptr r, Progress* progress) return 0; } - AudioIntervalResult::const_iterator s = silence.begin (); - PBD::PropertyList plist; - framepos_t start; - framepos_t end; - bool in_silence; - boost::shared_ptr copy; - - start = r->start(); - - if (s->first == start) { - /* segment starting at zero is silent */ - end = s->second; - in_silence = true; - } else { - /* segment starting at zero is audible, and begins at the start of the region in the source */ - end = s->first; - in_silence = false; - } - - int n = 0; - int const N = silence.size (); - - 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, r->position() + (start - r->start())); + /* Turn the silence list into an `audible' list */ + AudioIntervalResult audible; - copy = boost::dynamic_pointer_cast (RegionFactory::create - (region, (start - r->start()), plist)); - - copy->set_name (RegionFactory::new_region_name (region->name ())); + /* Add the possible audible section at the start of the region */ + AudioIntervalResult::const_iterator first_silence = silence.begin (); + if (first_silence->first != region->start()) { + audible.push_back (std::make_pair (r->start(), first_silence->first)); + } - copy->set_fade_in_active (true); - copy->set_fade_in (FadeLinear, _fade_length); - results.push_back (copy); - } + /* Add audible sections in the middle of the region */ + for (AudioIntervalResult::const_iterator i = silence.begin (); i != silence.end(); ++i) { + AudioIntervalResult::const_iterator j = i; + ++j; - start = end; - in_silence = !in_silence; - ++s; + if (j != silence.end ()) { + audible.push_back (std::make_pair (i->second, j->first)); + } + } - if (s == silence.end()) { - end = r->start() + r->length(); - } else { - end = s->first; - } + /* Add the possible audible section at the end of the region */ + AudioIntervalResult::const_iterator last_silence = silence.end (); + --last_silence; - ++n; + frameoffset_t const end_of_region = r->start() + r->length(); + + if (last_silence->second != end_of_region - 1) { + audible.push_back (std::make_pair (last_silence->second, end_of_region - 1)); + } + int n = 0; + int const N = audible.size (); + + for (AudioIntervalResult::const_iterator i = audible.begin(); i != audible.end(); ++i) { + + PBD::PropertyList plist; + boost::shared_ptr copy; + + plist.add (Properties::length, i->second - i->first); + plist.add (Properties::position, r->position() + (i->first - r->start())); + + copy = boost::dynamic_pointer_cast ( + RegionFactory::create (region, (i->first - r->start()), plist) + ); + + copy->set_name (RegionFactory::new_region_name (region->name ())); + + copy->set_fade_in_active (true); + copy->set_fade_in (FadeLinear, _fade_length); + results.push_back (copy); + if (progress && (n <= N)) { progress->set_progress (float (n) / N); } - } return 0; -- cgit v1.2.3