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

Fix normalize progress bar in case of stereo tracks.

Before this commit, progress jumped from 0.25 to 0.5,
then from 0.75 to 0.25 and finally from 0.5 to 0.75 when
normalizing a dependent stereo track.
This commit is contained in:
Max Maisel 2018-07-24 17:20:52 +02:00
parent d707f68189
commit 6655f6e38a
2 changed files with 22 additions and 19 deletions

View File

@ -175,7 +175,7 @@ bool EffectNormalize::Process()
WaveTrack *track = (WaveTrack *) iter.First(); WaveTrack *track = (WaveTrack *) iter.First();
WaveTrack *prevTrack; WaveTrack *prevTrack;
prevTrack = track; prevTrack = track;
int curTrackNum = 0; double progress = 0;
wxString topMsg; wxString topMsg;
if(mDC && mGain) if(mDC && mGain)
topMsg = _("Removing DC offset and Normalizing...\n"); topMsg = _("Removing DC offset and Normalizing...\n");
@ -208,7 +208,7 @@ bool EffectNormalize::Process()
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, min, max;
bGoodResult = AnalyseTrack(track, msg, curTrackNum, offset, min, max); bGoodResult = AnalyseTrack(track, msg, progress, offset, min, max);
if (!bGoodResult ) if (!bGoodResult )
break; break;
if(!track->GetLinked() || mStereoInd) { if(!track->GetLinked() || mStereoInd) {
@ -224,7 +224,7 @@ bool EffectNormalize::Process()
msg = msg =
topMsg + wxString::Format( _("Processing stereo channels independently: %s"), trackName ); topMsg + wxString::Format( _("Processing stereo channels independently: %s"), trackName );
if (!ProcessOne(track, msg, curTrackNum, offset)) if (!ProcessOne(track, msg, progress, offset))
{ {
bGoodResult = false; bGoodResult = false;
break; break;
@ -239,7 +239,7 @@ bool EffectNormalize::Process()
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, min2, max2;
bGoodResult = AnalyseTrack(track, msg, curTrackNum + 1, offset2, min2, max2); bGoodResult = AnalyseTrack(track, msg, progress, offset2, min2, max2);
if ( !bGoodResult ) if ( !bGoodResult )
break; break;
float extent = wxMax(fabs(min), fabs(max)); float extent = wxMax(fabs(min), fabs(max));
@ -252,16 +252,15 @@ bool EffectNormalize::Process()
track = (WaveTrack *) iter.Prev(); // go back to the first linked one track = (WaveTrack *) iter.Prev(); // go back to the first linked one
msg = msg =
topMsg + wxString::Format( _("Processing first track of stereo pair: %s"), trackName ); topMsg + wxString::Format( _("Processing first track of stereo pair: %s"), trackName );
if (!ProcessOne(track, msg, curTrackNum, offset)) if (!ProcessOne(track, msg, progress, offset))
{ {
bGoodResult = false; bGoodResult = false;
break; break;
} }
track = (WaveTrack *) iter.Next(); // go to the second linked one track = (WaveTrack *) iter.Next(); // go to the second linked one
curTrackNum++; // keeps progress bar correct
msg = msg =
topMsg + wxString::Format( _("Processing second track of stereo pair: %s"), trackName ); topMsg + wxString::Format( _("Processing second track of stereo pair: %s"), trackName );
if (!ProcessOne(track, msg, curTrackNum, offset2)) if (!ProcessOne(track, msg, progress, offset2))
{ {
bGoodResult = false; bGoodResult = false;
break; break;
@ -272,7 +271,6 @@ bool EffectNormalize::Process()
//Iterate to the next track //Iterate to the next track
prevTrack = track; prevTrack = track;
track = (WaveTrack *) iter.Next(); track = (WaveTrack *) iter.Next();
curTrackNum++;
} }
this->ReplaceProcessedTracks(bGoodResult); this->ReplaceProcessedTracks(bGoodResult);
@ -350,7 +348,7 @@ 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,
int curTrackNum, double &progress,
float &offset, float &min, float &max) float &offset, float &min, float &max)
{ {
if(mGain) { if(mGain) {
@ -373,7 +371,7 @@ bool EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg,
} }
if(mDC) { if(mDC) {
auto rc = AnalyseDC(track, msg, curTrackNum, offset); auto rc = AnalyseDC(track, msg, progress, offset);
min += offset; min += offset;
max += offset; max += offset;
return rc; return rc;
@ -386,7 +384,7 @@ bool EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg,
//AnalyseDC() takes a track, transforms it to bunch of buffer-blocks, //AnalyseDC() takes a track, transforms it to bunch of buffer-blocks,
//and executes AnalyzeData on it... //and executes AnalyzeData on it...
bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg, bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
int curTrackNum, double &progress,
float &offset) float &offset)
{ {
bool rc = true; bool rc = true;
@ -394,7 +392,10 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
offset = 0.0; // we might just return offset = 0.0; // we might just return
if(!mDC) // don't do analysis if not doing dc removal if(!mDC) // don't do analysis if not doing dc removal
{
progress += 1.0/double(2*GetNumWaveTracks());
return(rc); return(rc);
}
//Transform the marker timepoints to samples //Transform the marker timepoints to samples
auto start = track->TimeToLongSamples(mCurT0); auto start = track->TimeToLongSamples(mCurT0);
@ -437,8 +438,8 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
s += block; s += block;
//Update the Progress meter //Update the Progress meter
if (TrackProgress(curTrackNum, if (TotalProgress(progress +
((s - start).as_double() / len)/2.0, msg)) { ((s - start).as_double() / len)/double(2*GetNumWaveTracks()), msg)) {
rc = false; //lda .. break, not return, so that buffer is deleted rc = false; //lda .. break, not return, so that buffer is deleted
break; break;
} }
@ -448,6 +449,7 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
else else
offset = 0.0; offset = 0.0;
progress += 1.0/double(2*GetNumWaveTracks());
//Return true because the effect processing succeeded ... unless cancelled //Return true because the effect processing succeeded ... unless cancelled
return rc; return rc;
} }
@ -457,7 +459,7 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
// uses mMult and offset to normalize a track. // uses mMult and offset to normalize a track.
// mMult must be set before this is called // mMult must be set before this is called
bool EffectNormalize::ProcessOne( bool EffectNormalize::ProcessOne(
WaveTrack * track, const wxString &msg, int curTrackNum, float offset) WaveTrack * track, const wxString &msg, double &progress, float offset)
{ {
bool rc = true; bool rc = true;
@ -498,12 +500,13 @@ bool EffectNormalize::ProcessOne(
s += block; s += block;
//Update the Progress meter //Update the Progress meter
if (TrackProgress(curTrackNum, if (TotalProgress(progress +
0.5+((s - start).as_double() / len)/2.0, msg)) { ((s - start).as_double() / len)/double(2*GetNumWaveTracks()), msg)) {
rc = false; //lda .. break, not return, so that buffer is deleted rc = false; //lda .. break, not return, so that buffer is deleted
break; break;
} }
} }
progress += 1.0/double(2*GetNumWaveTracks());
//Return true because the effect processing succeeded ... unless cancelled //Return true because the effect processing succeeded ... unless cancelled
return rc; return rc;

View File

@ -59,12 +59,12 @@ private:
// EffectNormalize implementation // EffectNormalize implementation
bool ProcessOne( bool ProcessOne(
WaveTrack * t, const wxString &msg, int curTrackNum, 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,
int curTrackNum, double &progress,
float &offset, float &min, float &max); 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, int curTrackNum, bool AnalyseDC(const WaveTrack * track, const wxString &msg, double &progress,
float &offset); float &offset);
void ProcessData(float *buffer, size_t len, float offset); void ProcessData(float *buffer, size_t len, float offset);