mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-23 16:08:07 +02:00
Bug 499 - Normalize includes white space in offset calculation
This commit is contained in:
parent
14577d878b
commit
de53f64757
@ -1993,13 +1993,14 @@ float WaveTrack::GetRMS(double t0, double t1, bool mayThrow) const
|
|||||||
|
|
||||||
bool WaveTrack::Get(samplePtr buffer, sampleFormat format,
|
bool WaveTrack::Get(samplePtr buffer, sampleFormat format,
|
||||||
sampleCount start, size_t len, fillFormat fill,
|
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,
|
// Simple optimization: When this buffer is completely contained within one clip,
|
||||||
// don't clear anything (because we won't have to). Otherwise, just clear
|
// don't clear anything (because we won't have to). Otherwise, just clear
|
||||||
// everything to be on the safe side.
|
// everything to be on the safe side.
|
||||||
bool doClear = true;
|
bool doClear = true;
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
sampleCount samplesCopied = 0;
|
||||||
for (const auto &clip: mClips)
|
for (const auto &clip: mClips)
|
||||||
{
|
{
|
||||||
if (start >= clip->GetStartSample() && start+len <= clip->GetEndSample())
|
if (start >= clip->GetStartSample() && start+len <= clip->GetEndSample())
|
||||||
@ -2062,9 +2063,12 @@ bool WaveTrack::Get(samplePtr buffer, sampleFormat format,
|
|||||||
SAMPLE_SIZE(format)),
|
SAMPLE_SIZE(format)),
|
||||||
format, inclipDelta, samplesToCopy.as_size_t(), mayThrow ))
|
format, inclipDelta, samplesToCopy.as_size_t(), mayThrow ))
|
||||||
result = false;
|
result = false;
|
||||||
|
else
|
||||||
|
samplesCopied += samplesToCopy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( pNumCopied )
|
||||||
|
*pNumCopied = samplesCopied;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ private:
|
|||||||
///
|
///
|
||||||
bool Get(samplePtr buffer, sampleFormat format,
|
bool Get(samplePtr buffer, sampleFormat format,
|
||||||
sampleCount start, size_t len,
|
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,
|
void Set(samplePtr buffer, sampleFormat format,
|
||||||
sampleCount start, size_t len);
|
sampleCount start, size_t len);
|
||||||
|
|
||||||
|
@ -412,6 +412,9 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
|
|||||||
mSum = 0.0; // dc offset inits
|
mSum = 0.0; // dc offset inits
|
||||||
mCount = 0;
|
mCount = 0;
|
||||||
|
|
||||||
|
sampleCount blockSamples;
|
||||||
|
sampleCount totalSamples = 0;
|
||||||
|
|
||||||
//Go through the track one buffer at a time. s counts which
|
//Go through the track one buffer at a time. s counts which
|
||||||
//sample the current buffer starts at.
|
//sample the current buffer starts at.
|
||||||
auto s = start;
|
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
|
//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.
|
//Process the buffer.
|
||||||
AnalyzeData(buffer.get(), block);
|
AnalyzeData(buffer.get(), block);
|
||||||
@ -439,8 +443,10 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( totalSamples > 0 )
|
||||||
offset = -mSum / mCount.as_double(); // calculate actual offset (amount that needs to be added on)
|
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 true because the effect processing succeeded ... unless cancelled
|
||||||
return rc;
|
return rc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user