X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fstrip_silence.cc;h=8aa703740bdc707705a807134e2c4b9c1f2c9b61;hb=69b9ad6bccf95dbff9bf32f0f362c75d90918275;hp=d04612f6044ec1c38a51711fc40ce9d1858fb028;hpb=2d3c640fee5530fdf68c631feccbc22828583e98;p=ardour.git diff --git a/libs/ardour/strip_silence.cc b/libs/ardour/strip_silence.cc index d04612f604..8aa703740b 100644 --- a/libs/ardour/strip_silence.cc +++ b/libs/ardour/strip_silence.cc @@ -22,20 +22,17 @@ #include "ardour/strip_silence.h" #include "ardour/audioregion.h" #include "ardour/region_factory.h" -#include "ardour/session.h" -#include "ardour/dB.h" #include "ardour/progress.h" using namespace ARDOUR; /** Construct a StripSilence filter. * @param s Session. - * @param threshold Threshold below which audio is considered silence, in dBFS. - * @param minimum_length Minimum length of silence period to recognise, in samples. + * @param sm Silences to remove. * @param fade_length Length of fade in/out to apply to trimmed regions, in samples. */ -StripSilence::StripSilence (Session & s, const AudioIntervalMap& sm, framecnt_t fade_length) +StripSilence::StripSilence (Session & s, const AudioIntervalMap& sm, samplecnt_t fade_length) : Filter (s) , _smap (sm) , _fade_length (fade_length) @@ -49,7 +46,7 @@ StripSilence::run (boost::shared_ptr r, Progress* progress) results.clear (); /* we only operate on AudioRegions, for now, though this could be adapted to MIDI - as well I guess + as well I guess */ boost::shared_ptr region = boost::dynamic_pointer_cast (r); InterThreadInfo itt; @@ -101,33 +98,42 @@ StripSilence::run (boost::shared_ptr r, Progress* progress) AudioIntervalResult::const_iterator last_silence = silence.end (); --last_silence; - frameoffset_t const end_of_region = r->start() + r->length(); - - if (last_silence->second != end_of_region - 1) { + sampleoffset_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) { + + for (AudioIntervalResult::const_iterator i = audible.begin(); i != audible.end(); ++i, ++n) { 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) + RegionFactory::create (region, MusicSample (i->first - r->start(), 0), plist) ); - + copy->set_name (RegionFactory::new_region_name (region->name ())); - - copy->set_fade_in_active (true); - copy->set_fade_in (FadeLinear, _fade_length); + + samplecnt_t const f = std::min (_fade_length, (i->second - i->first) / 2); + + if (f > 0) { + copy->set_fade_in_active (true); + copy->set_fade_out_active (true); + copy->set_fade_in (FadeLinear, f); + copy->set_fade_out (FadeLinear, f); + } else { + copy->set_fade_in_active (false); + copy->set_fade_out_active (false); + } results.push_back (copy); - + if (progress && (n <= N)) { progress->set_progress (float (n) / N); }