1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Optimization for new Truncate Silence code.

This commit is contained in:
BusinessmanProgrammerSteve 2010-03-23 21:49:48 +00:00
parent 3ee3c168e6
commit eac019b68a

View File

@ -456,7 +456,7 @@ bool EffectTruncSilence::Process()
bool EffectTruncSilence::Process() bool EffectTruncSilence::Process()
{ {
// Typical fraction of total time taken by detection (better to guess low) // Typical fraction of total time taken by detection (better to guess low)
const double detectFrac = .6; const double detectFrac = .4;
// Copy tracks // Copy tracks
this->CopyInputTracks(Track::All); this->CopyInputTracks(Track::All);
@ -504,15 +504,49 @@ bool EffectTruncSilence::Process()
sampleCount index = start; sampleCount index = start;
sampleCount silentFrames = 0; sampleCount silentFrames = 0;
bool cancelled = false; bool cancelled = false;
// Keep position in overall silences list for optimization
RegionList::iterator rit(silences.begin());
while (index < end) { while (index < end) {
// Show progress dialog, test for cancellation; we figure detection // Show progress dialog, test for cancellation
// takes a little more than half the total time
cancelled = TotalProgress( cancelled = TotalProgress(
detectFrac * (whichTrack + index / (double)end) / detectFrac * (whichTrack + index / (double)end) /
(double)GetNumWaveTracks()); (double)GetNumWaveTracks());
if (cancelled) if (cancelled)
break; break;
//
// Optimization: if not in a silent region skip ahead to the next one
//
double curTime = wt->LongSamplesToTime(index);
for ( ; rit != silences.end(); ++rit)
{
// Find the first silent region ending after current time
if ((*rit)->end >= curTime)
break;
}
if (rit == silences.end()) {
// No more regions -- no need to process the rest of the track
break;
}
else if ((*rit)->start > curTime) {
// End current silent region, skip ahead
if (silentFrames >= minSilenceFrames) {
Region *r = new Region;
r->start = wt->LongSamplesToTime(index - silentFrames);
r->end = wt->LongSamplesToTime(index);
trackSilences.push_back(r);
}
silentFrames = 0;
index = wt->TimeToLongSamples((*rit)->start);
}
//
// End of optimization
//
// Limit size of current block if we've reached the end // Limit size of current block if we've reached the end
sampleCount count = blockLen; sampleCount count = blockLen;
if ((index + count) > end) { if ((index + count) > end) {