mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-08 14:13:57 +01:00
Simplify Normalize by removing needless member variables
This commit is contained in:
@@ -163,7 +163,7 @@ bool EffectNormalize::Process()
|
|||||||
WaveTrack *track = (WaveTrack *) iter.First();
|
WaveTrack *track = (WaveTrack *) iter.First();
|
||||||
WaveTrack *prevTrack;
|
WaveTrack *prevTrack;
|
||||||
prevTrack = track;
|
prevTrack = track;
|
||||||
mCurTrackNum = 0;
|
int curTrackNum = 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");
|
||||||
@@ -193,9 +193,11 @@ bool EffectNormalize::Process()
|
|||||||
msg = topMsg + _("Analyzing: ") + trackName;
|
msg = topMsg + _("Analyzing: ") + trackName;
|
||||||
else
|
else
|
||||||
msg = topMsg + _("Analyzing first track of stereo pair: ") + trackName;
|
msg = topMsg + _("Analyzing first track of stereo pair: ") + trackName;
|
||||||
AnalyseTrack(track, msg); // sets mOffset and offset-adjusted mMin and mMax
|
float offset, min, max;
|
||||||
if(!track->GetLinked() || mStereoInd) { // mono or 'stereo tracks independently'
|
AnalyseTrack(track, msg, curTrackNum, offset, min, max);
|
||||||
float extent = wxMax(fabs(mMax), fabs(mMin));
|
if(!track->GetLinked() || mStereoInd) {
|
||||||
|
// 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
|
||||||
@@ -204,7 +206,7 @@ bool EffectNormalize::Process()
|
|||||||
if(track->GetLinked() || prevTrack->GetLinked()) // only get here if there is a linked track but we are processing independently
|
if(track->GetLinked() || prevTrack->GetLinked()) // only get here if there is a linked track but we are processing independently
|
||||||
msg = topMsg + _("Processing stereo channels independently: ") + trackName;
|
msg = topMsg + _("Processing stereo channels independently: ") + trackName;
|
||||||
|
|
||||||
if (!ProcessOne(track, msg))
|
if (!ProcessOne(track, msg, curTrackNum, offset))
|
||||||
{
|
{
|
||||||
bGoodResult = false;
|
bGoodResult = false;
|
||||||
break;
|
break;
|
||||||
@@ -215,37 +217,27 @@ bool EffectNormalize::Process()
|
|||||||
// we have a linked stereo track
|
// we have a linked stereo track
|
||||||
// so we need to find it's min, max and offset
|
// so we need to find it's min, max and offset
|
||||||
// as they are needed to calc the multiplier for both tracks
|
// as they are needed to calc the multiplier for both tracks
|
||||||
float offset1 = mOffset; // remember ones from first track
|
|
||||||
float min1 = mMin;
|
|
||||||
float max1 = mMax;
|
|
||||||
track = (WaveTrack *) iter.Next(); // get the next one
|
track = (WaveTrack *) iter.Next(); // get the next one
|
||||||
mCurTrackNum++; // keeps progress bar correct
|
|
||||||
msg = topMsg + _("Analyzing second track of stereo pair: ") + trackName;
|
msg = topMsg + _("Analyzing second track of stereo pair: ") + trackName;
|
||||||
AnalyseTrack(track, msg); // sets mOffset and offset-adjusted mMin and mMax
|
float offset2, min2, max2;
|
||||||
float offset2 = mOffset; // ones for second track
|
AnalyseTrack(track, msg, curTrackNum + 1, offset2, min2, max2);
|
||||||
float min2 = mMin;
|
float extent = wxMax(fabs(min), fabs(max));
|
||||||
float max2 = mMax;
|
|
||||||
float extent = wxMax(fabs(min1), fabs(max1));
|
|
||||||
extent = wxMax(extent, fabs(min2));
|
extent = wxMax(extent, fabs(min2));
|
||||||
extent = wxMax(extent, fabs(max2));
|
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
|
||||||
mMult = 1.0;
|
mMult = 1.0;
|
||||||
mOffset = offset1;
|
|
||||||
track = (WaveTrack *) iter.Prev(); // go back to the first linked one
|
track = (WaveTrack *) iter.Prev(); // go back to the first linked one
|
||||||
mCurTrackNum--; // keeps progress bar correct
|
|
||||||
msg = topMsg + _("Processing first track of stereo pair: ") + trackName;
|
msg = topMsg + _("Processing first track of stereo pair: ") + trackName;
|
||||||
if (!ProcessOne(track, msg))
|
if (!ProcessOne(track, msg, curTrackNum, offset))
|
||||||
{
|
{
|
||||||
bGoodResult = false;
|
bGoodResult = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mOffset = offset2;
|
|
||||||
track = (WaveTrack *) iter.Next(); // go to the second linked one
|
track = (WaveTrack *) iter.Next(); // go to the second linked one
|
||||||
mCurTrackNum++; // keeps progress bar correct
|
|
||||||
msg = topMsg + _("Processing second track of stereo pair: ") + trackName;
|
msg = topMsg + _("Processing second track of stereo pair: ") + trackName;
|
||||||
if (!ProcessOne(track, msg))
|
if (!ProcessOne(track, msg, curTrackNum, offset2))
|
||||||
{
|
{
|
||||||
bGoodResult = false;
|
bGoodResult = false;
|
||||||
break;
|
break;
|
||||||
@@ -256,7 +248,7 @@ 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();
|
||||||
mCurTrackNum++;
|
curTrackNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->ReplaceProcessedTracks(bGoodResult);
|
this->ReplaceProcessedTracks(bGoodResult);
|
||||||
@@ -333,7 +325,9 @@ bool EffectNormalize::TransferDataFromWindow()
|
|||||||
|
|
||||||
// EffectNormalize implementation
|
// EffectNormalize implementation
|
||||||
|
|
||||||
void EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg)
|
void EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg,
|
||||||
|
int curTrackNum,
|
||||||
|
float &offset, float &min, float &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
|
||||||
@@ -344,28 +338,29 @@ void EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg)
|
|||||||
wxMilliSleep(100);
|
wxMilliSleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
track->GetMinMax(&mMin, &mMax, mCurT0, mCurT1); // set mMin, mMax. No progress bar here as it's fast.
|
track->GetMinMax(&min, &max, mCurT0, mCurT1);
|
||||||
} else {
|
} else {
|
||||||
mMin = -1.0, mMax = 1.0; // sensible defaults?
|
min = -1.0, max = 1.0; // sensible defaults?
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mDC) {
|
if(mDC) {
|
||||||
AnalyseDC(track, msg); // sets mOffset
|
AnalyseDC(track, msg, curTrackNum, offset);
|
||||||
mMin += mOffset;
|
min += offset;
|
||||||
mMax += mOffset;
|
max += offset;
|
||||||
} else {
|
} else {
|
||||||
mOffset = 0.0;
|
offset = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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...
|
||||||
// sets mOffset
|
bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg,
|
||||||
bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg)
|
int curTrackNum,
|
||||||
|
float &offset)
|
||||||
{
|
{
|
||||||
bool rc = true;
|
bool rc = true;
|
||||||
|
|
||||||
mOffset = 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
|
||||||
return(rc);
|
return(rc);
|
||||||
@@ -407,7 +402,7 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg)
|
|||||||
s += block;
|
s += block;
|
||||||
|
|
||||||
//Update the Progress meter
|
//Update the Progress meter
|
||||||
if (TrackProgress(mCurTrackNum,
|
if (TrackProgress(curTrackNum,
|
||||||
((s - start).as_double() / len)/2.0, msg)) {
|
((s - start).as_double() / len)/2.0, 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;
|
||||||
@@ -417,7 +412,7 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg)
|
|||||||
//Clean up the buffer
|
//Clean up the buffer
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
|
||||||
mOffset = -mSum / mCount.as_double(); // calculate actual offset (amount that needs to be added on)
|
offset = -mSum / mCount.as_double(); // calculate actual offset (amount that needs to be added on)
|
||||||
|
|
||||||
//Return true because the effect processing succeeded ... unless cancelled
|
//Return true because the effect processing succeeded ... unless cancelled
|
||||||
return rc;
|
return rc;
|
||||||
@@ -425,8 +420,10 @@ bool EffectNormalize::AnalyseDC(const WaveTrack * track, const wxString &msg)
|
|||||||
|
|
||||||
//ProcessOne() takes a track, transforms it to bunch of buffer-blocks,
|
//ProcessOne() takes a track, transforms it to bunch of buffer-blocks,
|
||||||
//and executes ProcessData, on it...
|
//and executes ProcessData, on it...
|
||||||
// uses mMult and mOffset to normalize a track. Needs to have them set before being called
|
// uses mMult and offset to normalize a track.
|
||||||
bool EffectNormalize::ProcessOne(WaveTrack * track, const wxString &msg)
|
// mMult must be set before this is called
|
||||||
|
bool EffectNormalize::ProcessOne(
|
||||||
|
WaveTrack * track, const wxString &msg, int curTrackNum, float offset)
|
||||||
{
|
{
|
||||||
bool rc = true;
|
bool rc = true;
|
||||||
|
|
||||||
@@ -458,7 +455,7 @@ bool EffectNormalize::ProcessOne(WaveTrack * track, const wxString &msg)
|
|||||||
track->Get((samplePtr) buffer, floatSample, s, block);
|
track->Get((samplePtr) buffer, floatSample, s, block);
|
||||||
|
|
||||||
//Process the buffer.
|
//Process the buffer.
|
||||||
ProcessData(buffer, block);
|
ProcessData(buffer, block, offset);
|
||||||
|
|
||||||
//Copy the newly-changed samples back onto the track.
|
//Copy the newly-changed samples back onto the track.
|
||||||
track->Set((samplePtr) buffer, floatSample, s, block);
|
track->Set((samplePtr) buffer, floatSample, s, block);
|
||||||
@@ -467,7 +464,7 @@ bool EffectNormalize::ProcessOne(WaveTrack * track, const wxString &msg)
|
|||||||
s += block;
|
s += block;
|
||||||
|
|
||||||
//Update the Progress meter
|
//Update the Progress meter
|
||||||
if (TrackProgress(mCurTrackNum,
|
if (TrackProgress(curTrackNum,
|
||||||
0.5+((s - start).as_double() / len)/2.0, msg)) {
|
0.5+((s - start).as_double() / len)/2.0, 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;
|
||||||
@@ -487,10 +484,10 @@ void EffectNormalize::AnalyzeData(float *buffer, size_t len)
|
|||||||
mCount += len;
|
mCount += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EffectNormalize::ProcessData(float *buffer, size_t len)
|
void EffectNormalize::ProcessData(float *buffer, size_t len, float offset)
|
||||||
{
|
{
|
||||||
for(decltype(len) i = 0; i < len; i++) {
|
for(decltype(len) i = 0; i < len; i++) {
|
||||||
float adjFrame = (buffer[i] + mOffset) * mMult;
|
float adjFrame = (buffer[i] + offset) * mMult;
|
||||||
buffer[i] = adjFrame;
|
buffer[i] = adjFrame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,11 +56,15 @@ public:
|
|||||||
private:
|
private:
|
||||||
// EffectNormalize implementation
|
// EffectNormalize implementation
|
||||||
|
|
||||||
bool ProcessOne(WaveTrack * t, const wxString &msg);
|
bool ProcessOne(
|
||||||
void AnalyseTrack(const WaveTrack * track, const wxString &msg);
|
WaveTrack * t, const wxString &msg, int curTrackNum, float offset);
|
||||||
|
void AnalyseTrack(const WaveTrack * track, const wxString &msg,
|
||||||
|
int curTrackNum,
|
||||||
|
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);
|
bool AnalyseDC(const WaveTrack * track, const wxString &msg, int curTrackNum,
|
||||||
void ProcessData(float *buffer, size_t len);
|
float &offset);
|
||||||
|
void ProcessData(float *buffer, size_t len, float offset);
|
||||||
|
|
||||||
void OnUpdateUI(wxCommandEvent & evt);
|
void OnUpdateUI(wxCommandEvent & evt);
|
||||||
void UpdateUI();
|
void UpdateUI();
|
||||||
@@ -71,13 +75,9 @@ private:
|
|||||||
bool mDC;
|
bool mDC;
|
||||||
bool mStereoInd;
|
bool mStereoInd;
|
||||||
|
|
||||||
int mCurTrackNum;
|
|
||||||
double mCurT0;
|
double mCurT0;
|
||||||
double mCurT1;
|
double mCurT1;
|
||||||
float mMult;
|
float mMult;
|
||||||
float mOffset;
|
|
||||||
float mMin;
|
|
||||||
float mMax;
|
|
||||||
double mSum;
|
double mSum;
|
||||||
sampleCount mCount;
|
sampleCount mCount;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user