1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-01 08:29:27 +02:00

(bug 215)

Found some major memory leaks and fixed those, but they shouldn't have caused the crashes. 

No reason to DeleteContents on a RegionList immediately after it's declared (especially when not doing so when finished with the RegionList), so I removed those.

Corrected some comments. Improved readability.
This commit is contained in:
v.audacity 2010-09-03 01:42:02 +00:00
parent 00b4827dd5
commit ff93517312

View File

@ -10,7 +10,8 @@
*******************************************************************//** *******************************************************************//**
\class EffectTruncSilence \class EffectTruncSilence
\brief An Effect. \brief Truncate Silence automatically reduces the length of passages
where the volume is below a set threshold level.
\todo mBlendFrameCount only retrieved from prefs ... not using dialog \todo mBlendFrameCount only retrieved from prefs ... not using dialog
Only way to change (for windows) is thru registry Only way to change (for windows) is thru registry
@ -467,9 +468,10 @@ bool EffectTruncSilence::Process()
double truncDbSilenceThreshold = Enums::Db2Signal[mTruncDbChoiceIndex]; double truncDbSilenceThreshold = Enums::Db2Signal[mTruncDbChoiceIndex];
// Master list of silent regions; it is responsible for deleting them. // Master list of silent regions; it is responsible for deleting them.
// This list should always be kept in order // This list should always be kept in order.
RegionList silences; RegionList silences;
silences.DeleteContents(true);
RegionList trackSilences; // per track list of silent regions
// Start with the whole selection silent // Start with the whole selection silent
Region *sel = new Region; Region *sel = new Region;
@ -486,19 +488,15 @@ bool EffectTruncSilence::Process()
// Smallest silent region to detect in frames // Smallest silent region to detect in frames
sampleCount minSilenceFrames = sampleCount minSilenceFrames =
sampleCount((wxMax( mTruncInitialAllowedSilentMs, minTruncMs) * (sampleCount)((wxMax(mTruncInitialAllowedSilentMs, minTruncMs) * wt->GetRate()) / 1000.0);
wt->GetRate()) / 1000.0);
// //
// Scan the track for silences // Scan the track for silences
// //
RegionList trackSilences;
trackSilences.DeleteContents(true);
sampleCount blockLen = wt->GetMaxBlockSize(); sampleCount blockLen = wt->GetMaxBlockSize();
sampleCount start = wt->TimeToLongSamples(mT0); sampleCount start = wt->TimeToLongSamples(mT0);
sampleCount end = wt->TimeToLongSamples(mT1); sampleCount end = wt->TimeToLongSamples(mT1);
// Allocate buffer
float *buffer = new float[blockLen]; float *buffer = new float[blockLen];
sampleCount index = start; sampleCount index = start;
@ -509,10 +507,9 @@ bool EffectTruncSilence::Process()
RegionList::iterator rit(silences.begin()); RegionList::iterator rit(silences.begin());
while (index < end) { while (index < end) {
// Show progress dialog, test for cancellation // Show progress dialog, test for cancellation.
cancelled = TotalProgress( cancelled =
detectFrac * (whichTrack + index / (double)end) / TotalProgress(detectFrac * (whichTrack + index / (double)end) / (double)GetNumWaveTracks());
(double)GetNumWaveTracks());
if (cancelled) if (cancelled)
break; break;
@ -578,10 +575,12 @@ bool EffectTruncSilence::Process()
index += count; index += count;
} }
delete [] buffer; delete [] buffer; // Finished with buffer.
if (cancelled)
// Buffer has been freed, so we're OK to return if cancelled {
if (cancelled) { silences.DeleteContents(true);
trackSilences.DeleteContents(true);
ReplaceProcessedTracks(false);
return false; return false;
} }
@ -596,6 +595,8 @@ bool EffectTruncSilence::Process()
// Intersect with the overall silent region list // Intersect with the overall silent region list
Intersect(silences, trackSilences); Intersect(silences, trackSilences);
trackSilences.DeleteContents(true);
whichTrack++; whichTrack++;
} }
@ -611,10 +612,13 @@ bool EffectTruncSilence::Process()
for (rit = silences.rbegin(); rit != silences.rend(); ++rit) { for (rit = silences.rbegin(); rit != silences.rend(); ++rit) {
Region *r = *rit; Region *r = *rit;
// Progress dialog and cancellation; at this point it's safe to return // Progress dialog and cancellation.
if (TotalProgress(detectFrac + if (TotalProgress(detectFrac + (1 - detectFrac) * whichReg / (double)silences.size()))
(1 - detectFrac) * whichReg / (double)silences.size())) {
silences.DeleteContents(true);
ReplaceProcessedTracks(false);
return false; return false;
}
// Intersection may create regions smaller than allowed; ignore them // Intersection may create regions smaller than allowed; ignore them
if (r->end - r->start < mTruncInitialAllowedSilentMs / 1000.0) if (r->end - r->start < mTruncInitialAllowedSilentMs / 1000.0)
@ -688,6 +692,7 @@ bool EffectTruncSilence::Process()
mT1 -= totalCutLen; mT1 -= totalCutLen;
silences.DeleteContents(true);
ReplaceProcessedTracks(true); ReplaceProcessedTracks(true);
return true; return true;