1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 16:49:41 +02:00

Move minus sign to text box.

Allow stereo normalising.
Default to stereo normalising.
Speedup (maybe 20%) by use of track->GetMinMax instead of an expensive conditional in a tight loop.
This commit is contained in:
martynshaw99 2011-06-09 23:22:10 +00:00
parent 9bd2da0284
commit 40f82c962c
2 changed files with 49 additions and 21 deletions

View File

@ -58,6 +58,8 @@ bool EffectNormalize::Init()
boolProxy = gPrefs->Read(wxT("/CsPresets/Norm_RemoveDcOffset"), 1);
mDC = (boolProxy == 1);
gPrefs->Read(wxT("/CsPresets/Norm_Level"), &mLevel, 0.0);
boolProxy = gPrefs->Read(wxT("/CsPresets/Norm_StereoIndependent"), 0L);
mStereoInd = (boolProxy == 1);
return true;
}
@ -67,14 +69,15 @@ wxString EffectNormalize::GetEffectDescription() // useful only after parameter
wxString strResult =
/* i18n-hint: First %s is the effect name, 2nd and 3rd are either true or
* false (translated below) if those options were selected */
wxString::Format(_("Applied effect: %s remove dc offset = %s, normalize amplitude = %s"),
wxString::Format(_("Applied effect: %s remove dc offset = %s, normalize amplitude = %s, stereo independent %s"),
this->GetEffectName().c_str(),
/* i18n-hint: true here means that the option was
* selected. Opposite false if not selected */
mDC ? _("true") : _("false"),
mGain ? _("true") : _("false"));
mGain ? _("true") : _("false"),
mStereoInd ? _("true") : _("false"));
if (mGain)
strResult += wxString::Format(_(", maximum amplitude = %.1f dB"), -mLevel);
strResult += wxString::Format(_(", maximum amplitude = %.1f dB"), mLevel);
return strResult;
}
@ -84,6 +87,7 @@ bool EffectNormalize::TransferParameters( Shuttle & shuttle )
shuttle.TransferBool( wxT("ApplyGain"), mGain, true );
shuttle.TransferBool( wxT("RemoveDcOffset"), mDC, true );
shuttle.TransferDouble( wxT("Level"), mLevel, 0.0);
shuttle.TransferBool( wxT("StereoIndependent"), mStereoInd, false );
return true;
}
@ -114,6 +118,7 @@ bool EffectNormalize::PromptUser()
dlog.mGain = mGain;
dlog.mDC = mDC;
dlog.mLevel = mLevel;
dlog.mStereoInd = mStereoInd;
dlog.TransferDataToWindow();
dlog.CentreOnParent();
@ -125,15 +130,19 @@ bool EffectNormalize::PromptUser()
mGain = dlog.mGain;
mDC = dlog.mDC;
mLevel = dlog.mLevel;
mStereoInd = dlog.mStereoInd;
gPrefs->Write(wxT("/CsPresets/Norm_AmpDbGain"), mGain);
gPrefs->Write(wxT("/CsPresets/Norm_RemoveDcOffset"), mDC);
gPrefs->Write(wxT("/CsPresets/Norm_Level"), mLevel);
gPrefs->Write(wxT("/CsPresets/Norm_StereoIndependent"), mStereoInd);
return true;
}
bool EffectNormalize::Process()
{
bool wasLinked = false; // set when a track has a linked (stereo) track
if (mGain == false &&
mDC == false)
return true;
@ -166,6 +175,28 @@ bool EffectNormalize::Process()
mCurRate = track->GetRate();
mCurChannel = track->GetChannel();
if(mStereoInd) // do stereo tracks independently (the easy way)
track->GetMinMax(&mMin, &mMax, mCurT0, mCurT1);
else
{
if(!wasLinked) // new mono track or first of a stereo pair
{
track->GetMinMax(&mMin, &mMax, mCurT0, mCurT1);
if(track->GetLinked())
{
wasLinked = true; // so we use these values for the next (linked) track
track = (WaveTrack *) iter.Next(); // get the next one for the max/min
float min, max;
track->GetMinMax(&min, &max, mCurT0, mCurT1);
mMin = min < mMin ? min : mMin;
mMax = max > mMax ? max : mMax;
track = (WaveTrack *) iter.Prev(); // back to the one we are on
}
}
else
wasLinked = false; // second of the stereo pair, next one is mono or first
}
//ProcessOne() (implemented below) processes a single track
if (!ProcessOne(track, start, end))
{
@ -205,7 +236,7 @@ bool EffectNormalize::ProcessOne(WaveTrack * track,
for(pass=0; pass<2; pass++) {
if (pass==0)
StartAnalysis();
StartAnalysis(); // dc offset only. Max/min done in Process().
if (pass==1)
StartProcessing();
@ -256,8 +287,6 @@ bool EffectNormalize::ProcessOne(WaveTrack * track,
void EffectNormalize::StartAnalysis()
{
mMin = 1.0;
mMax = -1.0;
mSum = 0.0;
mCount = 0;
}
@ -266,14 +295,8 @@ void EffectNormalize::AnalyzeData(float *buffer, sampleCount len)
{
int i;
for(i=0; i<len; i++) {
if (buffer[i] < mMin)
mMin = buffer[i];
if (buffer[i] > mMax)
mMax = buffer[i];
for(i=0; i<len; i++)
mSum += (double)buffer[i];
}
mCount += len;
}
@ -282,7 +305,7 @@ void EffectNormalize::StartProcessing()
mMult = 1.0;
mOffset = 0.0;
float ratio = pow(10.0,TrapDouble(-mLevel,
float ratio = pow(10.0,TrapDouble(mLevel,
NORMALIZE_DB_MIN,
NORMALIZE_DB_MAX)/20.0);
@ -330,6 +353,7 @@ NormalizeDialog::NormalizeDialog(EffectNormalize *effect,
mDC = false;
mGain = false;
mLevel = 0;
mStereoInd = false;
Init();
}
@ -360,11 +384,6 @@ void NormalizeDialog::PopulateOrExchange(ShuttleGui & S)
S.StartHorizontalLay(wxALIGN_LEFT, false);
{
wxCheckBox *c = S.AddCheckBox(wxT(""), wxT("false"));
S.AddSpace(c->GetSize().GetWidth() + (S.GetBorder() * 2));
c->Hide();
mLevelMinux = S.AddVariableText(_("-"), false,
wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT);
mLevelTextCtrl = S.AddTextBox(wxT(""),
Internat::ToString(mLevel, 1),
10);
@ -373,6 +392,8 @@ void NormalizeDialog::PopulateOrExchange(ShuttleGui & S)
wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
}
S.EndHorizontalLay();
mStereoIndCheckBox = S.AddCheckBox(_("Normalize stereo channels independently"),
mStereoInd ? wxT("true") : wxT("false"));
}
S.EndVerticalLay();
}
@ -384,6 +405,7 @@ bool NormalizeDialog::TransferDataToWindow()
mGainCheckBox->SetValue(mGain);
mDCCheckBox->SetValue(mDC);
mLevelTextCtrl->SetValue(Internat::ToString(mLevel, 1));
mStereoIndCheckBox->SetValue(mStereoInd);
UpdateUI();
@ -397,6 +419,7 @@ bool NormalizeDialog::TransferDataFromWindow()
mGain = mGainCheckBox->GetValue();
mDC = mDCCheckBox->GetValue();
mLevel = Internat::CompatibleToDouble(mLevelTextCtrl->GetValue());
mStereoInd = mStereoIndCheckBox->GetValue();
return true;
}
@ -409,9 +432,9 @@ void NormalizeDialog::OnUpdateUI(wxCommandEvent& evt)
void NormalizeDialog::UpdateUI()
{
bool enable = mGainCheckBox->GetValue();
mLevelMinux->Enable(enable);
mLevelTextCtrl->Enable(enable);
mLeveldB->Enable(enable);
mStereoIndCheckBox->Enable(enable);
}
void NormalizeDialog::OnPreview(wxCommandEvent &event)
@ -422,16 +445,19 @@ void NormalizeDialog::OnPreview(wxCommandEvent &event)
bool oldGain = mEffect->mGain;
bool oldDC = mEffect->mDC;
double oldLevel = mEffect->mLevel;
bool oldStereoInd = mEffect->mStereoInd;
mEffect->mGain = mGain;
mEffect->mDC = mDC;
mEffect->mLevel = mLevel;
mEffect->mStereoInd = mStereoInd;
mEffect->Preview();
mEffect->mGain = oldGain;
mEffect->mDC = oldDC;
mEffect->mLevel = oldLevel;
mEffect->mStereoInd = oldStereoInd;
}
// Indentation settings for Vim and Emacs and unique identifier for Arch, a

View File

@ -72,6 +72,7 @@ class EffectNormalize: public Effect
bool mGain;
bool mDC;
double mLevel;
bool mStereoInd;
int mCurTrackNum;
double mCurRate;
@ -112,9 +113,9 @@ class NormalizeDialog: public EffectDialog
EffectNormalize *mEffect;
wxCheckBox *mGainCheckBox;
wxCheckBox *mDCCheckBox;
wxStaticText *mLevelMinux;
wxTextCtrl *mLevelTextCtrl;
wxStaticText *mLeveldB;
wxCheckBox *mStereoIndCheckBox;
DECLARE_EVENT_TABLE()
@ -122,6 +123,7 @@ class NormalizeDialog: public EffectDialog
bool mGain;
bool mDC;
double mLevel;
bool mStereoInd;
};
#endif