summaryrefslogtreecommitdiff
path: root/libs/ardour/strip_silence.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2011-02-28 18:57:25 +0000
committerCarl Hetherington <carl@carlh.net>2011-02-28 18:57:25 +0000
commit2d3c640fee5530fdf68c631feccbc22828583e98 (patch)
tree2e7076e410d4ecbfd97fe99a0c25beffaa420e53 /libs/ardour/strip_silence.cc
parent3af81e63bfae3b7a3203de28fc8ae466a54212f0 (diff)
Fix up strip silence.
git-svn-id: svn://localhost/ardour2/branches/3.0@8991 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/strip_silence.cc')
-rw-r--r--libs/ardour/strip_silence.cc95
1 files changed, 44 insertions, 51 deletions
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<Region> 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<AudioRegion> 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<AudioRegion> (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<AudioRegion> copy;
+
+ plist.add (Properties::length, i->second - i->first);
+ plist.add (Properties::position, r->position() + (i->first - r->start()));
+
+ copy = boost::dynamic_pointer_cast<AudioRegion> (
+ 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;