mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-19 09:30:52 +02:00
Refactor Normalize extent calculation in preparation of EBU R128 loudness normalization.
This commit is contained in:
parent
6655f6e38a
commit
d16b4526ce
@ -207,13 +207,12 @@ bool EffectNormalize::Process()
|
|||||||
else
|
else
|
||||||
msg =
|
msg =
|
||||||
topMsg + wxString::Format( _("Analyzing first track of stereo pair: %s"), trackName );
|
topMsg + wxString::Format( _("Analyzing first track of stereo pair: %s"), trackName );
|
||||||
float offset, min, max;
|
float offset, extent;
|
||||||
bGoodResult = AnalyseTrack(track, msg, progress, offset, min, max);
|
bGoodResult = AnalyseTrack(track, msg, progress, offset, extent);
|
||||||
if (!bGoodResult )
|
if (!bGoodResult )
|
||||||
break;
|
break;
|
||||||
if(!track->GetLinked() || mStereoInd) {
|
if(!track->GetLinked() || mStereoInd) {
|
||||||
// mono or 'stereo tracks independently'
|
// mono or 'stereo tracks independently'
|
||||||
float extent = wxMax(fabs(max), fabs(min));
|
|
||||||
if( (extent > 0) && mGain )
|
if( (extent > 0) && mGain )
|
||||||
mMult = ratio / extent;
|
mMult = ratio / extent;
|
||||||
else
|
else
|
||||||
@ -238,13 +237,11 @@ bool EffectNormalize::Process()
|
|||||||
track = (WaveTrack *) iter.Next(); // get the next one
|
track = (WaveTrack *) iter.Next(); // get the next one
|
||||||
msg =
|
msg =
|
||||||
topMsg + wxString::Format( _("Analyzing second track of stereo pair: %s"), trackName );
|
topMsg + wxString::Format( _("Analyzing second track of stereo pair: %s"), trackName );
|
||||||
float offset2, min2, max2;
|
float offset2, extent2;
|
||||||
bGoodResult = AnalyseTrack(track, msg, progress, offset2, min2, max2);
|
bGoodResult = AnalyseTrack(track, msg, progress, offset2, extent2);
|
||||||
if ( !bGoodResult )
|
if ( !bGoodResult )
|
||||||
break;
|
break;
|
||||||
float extent = wxMax(fabs(min), fabs(max));
|
extent = fmax(extent, extent2);
|
||||||
extent = wxMax(extent, fabs(min2));
|
|
||||||
extent = wxMax(extent, fabs(max2));
|
|
||||||
if( (extent > 0) && mGain )
|
if( (extent > 0) && mGain )
|
||||||
mMult = ratio / extent; // we need to use this for both linked tracks
|
mMult = ratio / extent; // we need to use this for both linked tracks
|
||||||
else
|
else
|
||||||
@ -348,9 +345,11 @@ bool EffectNormalize::TransferDataFromWindow()
|
|||||||
// EffectNormalize implementation
|
// EffectNormalize implementation
|
||||||
|
|
||||||
bool EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg,
|
bool EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg,
|
||||||
double &progress,
|
double &progress, float &offset, float &extent)
|
||||||
float &offset, float &min, float &max)
|
|
||||||
{
|
{
|
||||||
|
bool result = true;
|
||||||
|
float min, max;
|
||||||
|
|
||||||
if(mGain) {
|
if(mGain) {
|
||||||
// Since we need complete summary data, we need to block until the OD tasks are done for this track
|
// Since we need complete summary data, we need to block until the OD tasks are done for this track
|
||||||
// TODO: should we restrict the flags to just the relevant block files (for selections)
|
// TODO: should we restrict the flags to just the relevant block files (for selections)
|
||||||
@ -371,14 +370,15 @@ bool EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(mDC) {
|
if(mDC) {
|
||||||
auto rc = AnalyseDC(track, msg, progress, offset);
|
result = AnalyseDC(track, msg, progress, offset);
|
||||||
min += offset;
|
min += offset;
|
||||||
max += offset;
|
max += offset;
|
||||||
return rc;
|
|
||||||
} else {
|
} else {
|
||||||
offset = 0.0;
|
offset = 0.0;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extent = fmax(fabs(min), fabs(max));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//AnalyseDC() takes a track, transforms it to bunch of buffer-blocks,
|
//AnalyseDC() takes a track, transforms it to bunch of buffer-blocks,
|
||||||
|
@ -61,8 +61,7 @@ private:
|
|||||||
bool ProcessOne(
|
bool ProcessOne(
|
||||||
WaveTrack * t, const wxString &msg, double& progress, float offset);
|
WaveTrack * t, const wxString &msg, double& progress, float offset);
|
||||||
bool AnalyseTrack(const WaveTrack * track, const wxString &msg,
|
bool AnalyseTrack(const WaveTrack * track, const wxString &msg,
|
||||||
double &progress,
|
double &progress, float &offset, float &extent);
|
||||||
float &offset, float &min, float &max);
|
|
||||||
void AnalyzeData(float *buffer, size_t len);
|
void AnalyzeData(float *buffer, size_t len);
|
||||||
bool AnalyseDC(const WaveTrack * track, const wxString &msg, double &progress,
|
bool AnalyseDC(const WaveTrack * track, const wxString &msg, double &progress,
|
||||||
float &offset);
|
float &offset);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user