From c2c224727eee4c16bd64ca4a5b5bb2d276f5afe3 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 3 Mar 2010 23:39:26 +0000 Subject: [PATCH] changes to help strp silence git-svn-id: svn://localhost/ardour2/branches/3.0@6725 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/audioregion.h | 2 +- libs/ardour/audioregion.cc | 7 +++++-- libs/ardour/strip_silence.cc | 13 ++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index ec9a64002f..59876d6e56 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -178,7 +178,7 @@ class AudioRegion : public Region void resume_fade_out (); int get_transients (AnalysisFeatureList&, bool force_new = false); - std::list > find_silence (Sample, framecnt_t) const; + std::list > find_silence (Sample, framecnt_t, InterThreadInfo&) const; private: friend class RegionFactory; diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index abddffc12e..2cdb0dfbd1 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -1458,7 +1458,7 @@ then quit ardour and restart.")); */ std::list > -AudioRegion::find_silence (Sample threshold, framecnt_t min_length) const +AudioRegion::find_silence (Sample threshold, framecnt_t min_length, InterThreadInfo& itt) const { framecnt_t const block_size = 64 * 1024; Sample loudest[block_size]; @@ -1473,7 +1473,7 @@ AudioRegion::find_silence (Sample threshold, framecnt_t min_length) const frameoffset_t silence_start = 0; bool silence; - while (pos < end) { + 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); @@ -1502,6 +1502,7 @@ AudioRegion::find_silence (Sample threshold, framecnt_t min_length) const } pos += block_size; + itt.progress = (end-pos)/(double)_length; } if (in_silence && end - 1 - silence_start >= min_length) { @@ -1509,6 +1510,8 @@ AudioRegion::find_silence (Sample threshold, framecnt_t min_length) const silent_periods.push_back (std::make_pair (silence_start, end)); } + itt.done = true; + return silent_periods; } diff --git a/libs/ardour/strip_silence.cc b/libs/ardour/strip_silence.cc index 0f58ccf9a3..ae35eebd8f 100644 --- a/libs/ardour/strip_silence.cc +++ b/libs/ardour/strip_silence.cc @@ -46,14 +46,25 @@ StripSilence::run (boost::shared_ptr r) /* we only operate on AudioRegions, for now, though this could be adapted to MIDI as well I guess */ boost::shared_ptr region = boost::dynamic_pointer_cast (r); + InterThreadInfo itt; + if (!region) { results.push_back (r); return -1; } + /* we don't care about this but we need to fill out the fields + anyway. XXX should really be a default constructor for ITT + */ + + itt.done = false; + itt.cancel = false; + itt.progress = 0.0; + itt.thread = 0; + /* find periods of silence in the region */ std::list > const silence = - region->find_silence (dB_to_coefficient (_threshold), _minimum_length); + region->find_silence (dB_to_coefficient (_threshold), _minimum_length, itt); if (silence.size () == 1 && silence.front().first == 0 && silence.front().second == region->length() - 1) { /* the region is all silence, so just return with nothing */