1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-23 07:58:05 +02:00

Bug 499 - Normalize includes white space in offset calculation

This commit is contained in:
James Crook 2018-03-25 15:42:14 +01:00
parent 14577d878b
commit de53f64757
3 changed files with 16 additions and 6 deletions

View File

@ -1993,13 +1993,14 @@ float WaveTrack::GetRMS(double t0, double t1, bool mayThrow) const
bool WaveTrack::Get(samplePtr buffer, sampleFormat format,
sampleCount start, size_t len, fillFormat fill,
bool mayThrow) const
bool mayThrow, sampleCount * pNumCopied) const
{
// Simple optimization: When this buffer is completely contained within one clip,
// don't clear anything (because we won't have to). Otherwise, just clear
// everything to be on the safe side.
bool doClear = true;
bool result = true;
sampleCount samplesCopied = 0;
for (const auto &clip: mClips)
{
if (start >= clip->GetStartSample() && start+len <= clip->GetEndSample())
@ -2062,9 +2063,12 @@ bool WaveTrack::Get(samplePtr buffer, sampleFormat format,
SAMPLE_SIZE(format)),
format, inclipDelta, samplesToCopy.as_size_t(), mayThrow ))
result = false;
else
samplesCopied += samplesToCopy;
}
}
if( pNumCopied )
*pNumCopied = samplesCopied;
return result;
}

View File

@ -253,7 +253,7 @@ private:
///
bool Get(samplePtr buffer, sampleFormat format,
sampleCount start, size_t len,
fillFormat fill = fillZero, bool mayThrow = true) const;
fillFormat fill = fillZero, bool mayThrow = true, sampleCount * pNumCopied = nullptr) const;
void Set(samplePtr buffer, sampleFormat format,
sampleCount start, size_t len);

View File

@ -412,6 +412,9 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
mSum = 0.0; // dc offset inits
mCount = 0;
sampleCount blockSamples;
sampleCount totalSamples = 0;
//Go through the track one buffer at a time. s counts which
//sample the current buffer starts at.
auto s = start;
@ -424,7 +427,8 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
);
//Get the samples from the track and put them in the buffer
track->Get((samplePtr) buffer.get(), floatSample, s, block);
track->Get((samplePtr) buffer.get(), floatSample, s, block, fillZero, true, &blockSamples);
totalSamples += blockSamples;
//Process the buffer.
AnalyzeData(buffer.get(), block);
@ -439,8 +443,10 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
break;
}
}
offset = -mSum / mCount.as_double(); // calculate actual offset (amount that needs to be added on)
if( totalSamples > 0 )
offset = -mSum / totalSamples.as_double(); // calculate actual offset (amount that needs to be added on)
else
offset = 0.0;
//Return true because the effect processing succeeded ... unless cancelled
return rc;