mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-08 08:01:19 +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:
parent
9bd2da0284
commit
40f82c962c
@ -58,6 +58,8 @@ bool EffectNormalize::Init()
|
|||||||
boolProxy = gPrefs->Read(wxT("/CsPresets/Norm_RemoveDcOffset"), 1);
|
boolProxy = gPrefs->Read(wxT("/CsPresets/Norm_RemoveDcOffset"), 1);
|
||||||
mDC = (boolProxy == 1);
|
mDC = (boolProxy == 1);
|
||||||
gPrefs->Read(wxT("/CsPresets/Norm_Level"), &mLevel, 0.0);
|
gPrefs->Read(wxT("/CsPresets/Norm_Level"), &mLevel, 0.0);
|
||||||
|
boolProxy = gPrefs->Read(wxT("/CsPresets/Norm_StereoIndependent"), 0L);
|
||||||
|
mStereoInd = (boolProxy == 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,14 +69,15 @@ wxString EffectNormalize::GetEffectDescription() // useful only after parameter
|
|||||||
wxString strResult =
|
wxString strResult =
|
||||||
/* i18n-hint: First %s is the effect name, 2nd and 3rd are either true or
|
/* i18n-hint: First %s is the effect name, 2nd and 3rd are either true or
|
||||||
* false (translated below) if those options were selected */
|
* 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(),
|
this->GetEffectName().c_str(),
|
||||||
/* i18n-hint: true here means that the option was
|
/* i18n-hint: true here means that the option was
|
||||||
* selected. Opposite false if not selected */
|
* selected. Opposite false if not selected */
|
||||||
mDC ? _("true") : _("false"),
|
mDC ? _("true") : _("false"),
|
||||||
mGain ? _("true") : _("false"));
|
mGain ? _("true") : _("false"),
|
||||||
|
mStereoInd ? _("true") : _("false"));
|
||||||
if (mGain)
|
if (mGain)
|
||||||
strResult += wxString::Format(_(", maximum amplitude = %.1f dB"), -mLevel);
|
strResult += wxString::Format(_(", maximum amplitude = %.1f dB"), mLevel);
|
||||||
|
|
||||||
return strResult;
|
return strResult;
|
||||||
}
|
}
|
||||||
@ -84,6 +87,7 @@ bool EffectNormalize::TransferParameters( Shuttle & shuttle )
|
|||||||
shuttle.TransferBool( wxT("ApplyGain"), mGain, true );
|
shuttle.TransferBool( wxT("ApplyGain"), mGain, true );
|
||||||
shuttle.TransferBool( wxT("RemoveDcOffset"), mDC, true );
|
shuttle.TransferBool( wxT("RemoveDcOffset"), mDC, true );
|
||||||
shuttle.TransferDouble( wxT("Level"), mLevel, 0.0);
|
shuttle.TransferDouble( wxT("Level"), mLevel, 0.0);
|
||||||
|
shuttle.TransferBool( wxT("StereoIndependent"), mStereoInd, false );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +118,7 @@ bool EffectNormalize::PromptUser()
|
|||||||
dlog.mGain = mGain;
|
dlog.mGain = mGain;
|
||||||
dlog.mDC = mDC;
|
dlog.mDC = mDC;
|
||||||
dlog.mLevel = mLevel;
|
dlog.mLevel = mLevel;
|
||||||
|
dlog.mStereoInd = mStereoInd;
|
||||||
dlog.TransferDataToWindow();
|
dlog.TransferDataToWindow();
|
||||||
|
|
||||||
dlog.CentreOnParent();
|
dlog.CentreOnParent();
|
||||||
@ -125,15 +130,19 @@ bool EffectNormalize::PromptUser()
|
|||||||
mGain = dlog.mGain;
|
mGain = dlog.mGain;
|
||||||
mDC = dlog.mDC;
|
mDC = dlog.mDC;
|
||||||
mLevel = dlog.mLevel;
|
mLevel = dlog.mLevel;
|
||||||
|
mStereoInd = dlog.mStereoInd;
|
||||||
gPrefs->Write(wxT("/CsPresets/Norm_AmpDbGain"), mGain);
|
gPrefs->Write(wxT("/CsPresets/Norm_AmpDbGain"), mGain);
|
||||||
gPrefs->Write(wxT("/CsPresets/Norm_RemoveDcOffset"), mDC);
|
gPrefs->Write(wxT("/CsPresets/Norm_RemoveDcOffset"), mDC);
|
||||||
gPrefs->Write(wxT("/CsPresets/Norm_Level"), mLevel);
|
gPrefs->Write(wxT("/CsPresets/Norm_Level"), mLevel);
|
||||||
|
gPrefs->Write(wxT("/CsPresets/Norm_StereoIndependent"), mStereoInd);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EffectNormalize::Process()
|
bool EffectNormalize::Process()
|
||||||
{
|
{
|
||||||
|
bool wasLinked = false; // set when a track has a linked (stereo) track
|
||||||
|
|
||||||
if (mGain == false &&
|
if (mGain == false &&
|
||||||
mDC == false)
|
mDC == false)
|
||||||
return true;
|
return true;
|
||||||
@ -166,6 +175,28 @@ bool EffectNormalize::Process()
|
|||||||
mCurRate = track->GetRate();
|
mCurRate = track->GetRate();
|
||||||
mCurChannel = track->GetChannel();
|
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
|
//ProcessOne() (implemented below) processes a single track
|
||||||
if (!ProcessOne(track, start, end))
|
if (!ProcessOne(track, start, end))
|
||||||
{
|
{
|
||||||
@ -205,7 +236,7 @@ bool EffectNormalize::ProcessOne(WaveTrack * track,
|
|||||||
for(pass=0; pass<2; pass++) {
|
for(pass=0; pass<2; pass++) {
|
||||||
|
|
||||||
if (pass==0)
|
if (pass==0)
|
||||||
StartAnalysis();
|
StartAnalysis(); // dc offset only. Max/min done in Process().
|
||||||
if (pass==1)
|
if (pass==1)
|
||||||
StartProcessing();
|
StartProcessing();
|
||||||
|
|
||||||
@ -256,8 +287,6 @@ bool EffectNormalize::ProcessOne(WaveTrack * track,
|
|||||||
|
|
||||||
void EffectNormalize::StartAnalysis()
|
void EffectNormalize::StartAnalysis()
|
||||||
{
|
{
|
||||||
mMin = 1.0;
|
|
||||||
mMax = -1.0;
|
|
||||||
mSum = 0.0;
|
mSum = 0.0;
|
||||||
mCount = 0;
|
mCount = 0;
|
||||||
}
|
}
|
||||||
@ -266,14 +295,8 @@ void EffectNormalize::AnalyzeData(float *buffer, sampleCount len)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i=0; i<len; i++) {
|
for(i=0; i<len; i++)
|
||||||
if (buffer[i] < mMin)
|
|
||||||
mMin = buffer[i];
|
|
||||||
if (buffer[i] > mMax)
|
|
||||||
mMax = buffer[i];
|
|
||||||
mSum += (double)buffer[i];
|
mSum += (double)buffer[i];
|
||||||
}
|
|
||||||
|
|
||||||
mCount += len;
|
mCount += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +305,7 @@ void EffectNormalize::StartProcessing()
|
|||||||
mMult = 1.0;
|
mMult = 1.0;
|
||||||
mOffset = 0.0;
|
mOffset = 0.0;
|
||||||
|
|
||||||
float ratio = pow(10.0,TrapDouble(-mLevel,
|
float ratio = pow(10.0,TrapDouble(mLevel,
|
||||||
NORMALIZE_DB_MIN,
|
NORMALIZE_DB_MIN,
|
||||||
NORMALIZE_DB_MAX)/20.0);
|
NORMALIZE_DB_MAX)/20.0);
|
||||||
|
|
||||||
@ -330,6 +353,7 @@ NormalizeDialog::NormalizeDialog(EffectNormalize *effect,
|
|||||||
mDC = false;
|
mDC = false;
|
||||||
mGain = false;
|
mGain = false;
|
||||||
mLevel = 0;
|
mLevel = 0;
|
||||||
|
mStereoInd = false;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
@ -360,11 +384,6 @@ void NormalizeDialog::PopulateOrExchange(ShuttleGui & S)
|
|||||||
|
|
||||||
S.StartHorizontalLay(wxALIGN_LEFT, false);
|
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(""),
|
mLevelTextCtrl = S.AddTextBox(wxT(""),
|
||||||
Internat::ToString(mLevel, 1),
|
Internat::ToString(mLevel, 1),
|
||||||
10);
|
10);
|
||||||
@ -373,6 +392,8 @@ void NormalizeDialog::PopulateOrExchange(ShuttleGui & S)
|
|||||||
wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
|
wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
|
||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
|
mStereoIndCheckBox = S.AddCheckBox(_("Normalize stereo channels independently"),
|
||||||
|
mStereoInd ? wxT("true") : wxT("false"));
|
||||||
}
|
}
|
||||||
S.EndVerticalLay();
|
S.EndVerticalLay();
|
||||||
}
|
}
|
||||||
@ -384,6 +405,7 @@ bool NormalizeDialog::TransferDataToWindow()
|
|||||||
mGainCheckBox->SetValue(mGain);
|
mGainCheckBox->SetValue(mGain);
|
||||||
mDCCheckBox->SetValue(mDC);
|
mDCCheckBox->SetValue(mDC);
|
||||||
mLevelTextCtrl->SetValue(Internat::ToString(mLevel, 1));
|
mLevelTextCtrl->SetValue(Internat::ToString(mLevel, 1));
|
||||||
|
mStereoIndCheckBox->SetValue(mStereoInd);
|
||||||
|
|
||||||
UpdateUI();
|
UpdateUI();
|
||||||
|
|
||||||
@ -397,6 +419,7 @@ bool NormalizeDialog::TransferDataFromWindow()
|
|||||||
mGain = mGainCheckBox->GetValue();
|
mGain = mGainCheckBox->GetValue();
|
||||||
mDC = mDCCheckBox->GetValue();
|
mDC = mDCCheckBox->GetValue();
|
||||||
mLevel = Internat::CompatibleToDouble(mLevelTextCtrl->GetValue());
|
mLevel = Internat::CompatibleToDouble(mLevelTextCtrl->GetValue());
|
||||||
|
mStereoInd = mStereoIndCheckBox->GetValue();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -409,9 +432,9 @@ void NormalizeDialog::OnUpdateUI(wxCommandEvent& evt)
|
|||||||
void NormalizeDialog::UpdateUI()
|
void NormalizeDialog::UpdateUI()
|
||||||
{
|
{
|
||||||
bool enable = mGainCheckBox->GetValue();
|
bool enable = mGainCheckBox->GetValue();
|
||||||
mLevelMinux->Enable(enable);
|
|
||||||
mLevelTextCtrl->Enable(enable);
|
mLevelTextCtrl->Enable(enable);
|
||||||
mLeveldB->Enable(enable);
|
mLeveldB->Enable(enable);
|
||||||
|
mStereoIndCheckBox->Enable(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NormalizeDialog::OnPreview(wxCommandEvent &event)
|
void NormalizeDialog::OnPreview(wxCommandEvent &event)
|
||||||
@ -422,16 +445,19 @@ void NormalizeDialog::OnPreview(wxCommandEvent &event)
|
|||||||
bool oldGain = mEffect->mGain;
|
bool oldGain = mEffect->mGain;
|
||||||
bool oldDC = mEffect->mDC;
|
bool oldDC = mEffect->mDC;
|
||||||
double oldLevel = mEffect->mLevel;
|
double oldLevel = mEffect->mLevel;
|
||||||
|
bool oldStereoInd = mEffect->mStereoInd;
|
||||||
|
|
||||||
mEffect->mGain = mGain;
|
mEffect->mGain = mGain;
|
||||||
mEffect->mDC = mDC;
|
mEffect->mDC = mDC;
|
||||||
mEffect->mLevel = mLevel;
|
mEffect->mLevel = mLevel;
|
||||||
|
mEffect->mStereoInd = mStereoInd;
|
||||||
|
|
||||||
mEffect->Preview();
|
mEffect->Preview();
|
||||||
|
|
||||||
mEffect->mGain = oldGain;
|
mEffect->mGain = oldGain;
|
||||||
mEffect->mDC = oldDC;
|
mEffect->mDC = oldDC;
|
||||||
mEffect->mLevel = oldLevel;
|
mEffect->mLevel = oldLevel;
|
||||||
|
mEffect->mStereoInd = oldStereoInd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
|
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
|
||||||
|
@ -72,6 +72,7 @@ class EffectNormalize: public Effect
|
|||||||
bool mGain;
|
bool mGain;
|
||||||
bool mDC;
|
bool mDC;
|
||||||
double mLevel;
|
double mLevel;
|
||||||
|
bool mStereoInd;
|
||||||
|
|
||||||
int mCurTrackNum;
|
int mCurTrackNum;
|
||||||
double mCurRate;
|
double mCurRate;
|
||||||
@ -112,9 +113,9 @@ class NormalizeDialog: public EffectDialog
|
|||||||
EffectNormalize *mEffect;
|
EffectNormalize *mEffect;
|
||||||
wxCheckBox *mGainCheckBox;
|
wxCheckBox *mGainCheckBox;
|
||||||
wxCheckBox *mDCCheckBox;
|
wxCheckBox *mDCCheckBox;
|
||||||
wxStaticText *mLevelMinux;
|
|
||||||
wxTextCtrl *mLevelTextCtrl;
|
wxTextCtrl *mLevelTextCtrl;
|
||||||
wxStaticText *mLeveldB;
|
wxStaticText *mLeveldB;
|
||||||
|
wxCheckBox *mStereoIndCheckBox;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
|
||||||
@ -122,6 +123,7 @@ class NormalizeDialog: public EffectDialog
|
|||||||
bool mGain;
|
bool mGain;
|
||||||
bool mDC;
|
bool mDC;
|
||||||
double mLevel;
|
double mLevel;
|
||||||
|
bool mStereoInd;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user