Audacity  2.2.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
EffectNormalize Class Referencefinal

An Effect to bring the peak level up to a chosen level. More...

#include <Normalize.h>

Inheritance diagram for EffectNormalize:
Effect EffectClientInterface EffectUIClientInterface EffectHostInterface EffectDefinitionInterface ConfigClientInterface IdentInterface ParamsInterface

Public Member Functions

 EffectNormalize ()
 
virtual ~EffectNormalize ()
 
IdentInterfaceSymbol GetSymbol () override
 
wxString GetDescription () override
 
wxString ManualPage () override
 
EffectType GetType () override
 
bool DefineParams (ShuttleParams &S) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool CheckWhetherSkipEffect () override
 
bool Startup () override
 
bool Process () override
 
void PopulateOrExchange (ShuttleGui &S) override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
wxString GetPath () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () override
 
IdentInterfaceSymbol GetFamilyId () override
 
bool IsInteractive () override
 
bool IsDefault () override
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 
bool SupportsAutomation () override
 
bool SetHost (EffectHostInterface *host) override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
bool IsReady () override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 
bool ProcessFinalize () override
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () override
 
bool ShowInterface (wxWindow *parent, bool forceModal=false) override
 
bool LoadUserPreset (const wxString &name) override
 
bool SaveUserPreset (const wxString &name) override
 
wxArrayString GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (wxWindow *parent) override
 
bool IsGraphicalUI () override
 
bool ValidateUI () override
 
bool HideUI () override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets () override
 
void ImportPresets () override
 
bool HasOptions () override
 
void ShowOptions () override
 
double GetDefaultDuration () override
 
double GetDuration () override
 
NumericFormatId GetDurationFormat () override
 
virtual NumericFormatId GetSelectionFormat ()
 
void SetDuration (double duration) override
 
bool Apply () override
 
void Preview () override
 
wxDialog * CreateUI (wxWindow *parent, EffectUIClientInterface *client) override
 
wxString GetUserPresetsGroup (const wxString &name) override
 
wxString GetCurrentSettingsGroup () override
 
wxString GetFactoryDefaultsGroup () override
 
virtual wxString GetSavedStateGroup ()
 
bool HasSharedConfigGroup (const wxString &group) override
 
bool GetSharedConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const wxString &group) override
 
bool RemoveSharedConfig (const wxString &group, const wxString &key) override
 
bool HasPrivateConfigGroup (const wxString &group) override
 
bool GetPrivateConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const wxString &group) override
 
bool RemovePrivateConfig (const wxString &group, const wxString &key) override
 
virtual PluginID GetID ()
 
virtual bool Startup (EffectClientInterface *client)
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (const wxString &parms)
 
virtual wxArrayString GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual wxString GetPreset (wxWindow *parent, const wxString &parms)
 
virtual wxString HelpPage ()
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (wxWindow *parent, double projectRate, TrackList *list, TrackFactory *factory, SelectedRegion *selectedRegion, bool shouldPrompt=true)
 
bool Delegate (Effect &delegate, wxWindow *parent, bool shouldPrompt)
 
bool RealtimeAddProcessor (int group, unsigned chans, float rate)
 
size_t RealtimeProcess (int group, unsigned chans, float **inbuf, float **outbuf, size_t numSamples)
 
bool IsRealtimeActive ()
 
virtual bool IsHidden ()
 
int MessageBox (const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
- Public Member Functions inherited from IdentInterface
virtual ~IdentInterface ()
 
const wxString & GetTranslatedName ()
 
- Public Member Functions inherited from ParamsInterface
virtual ~ParamsInterface ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()
 
- Public Member Functions inherited from ConfigClientInterface
virtual ~ConfigClientInterface ()
 

Private Member Functions

bool ProcessOne (WaveTrack *t, const wxString &msg, int curTrackNum, float offset)
 
bool AnalyseTrack (const WaveTrack *track, const wxString &msg, int curTrackNum, float &offset, float &min, float &max)
 
void AnalyzeData (float *buffer, size_t len)
 
bool AnalyseDC (const WaveTrack *track, const wxString &msg, int curTrackNum, float &offset)
 
void ProcessData (float *buffer, size_t len, float offset)
 
void OnUpdateUI (wxCommandEvent &evt)
 
void UpdateUI ()
 

Private Attributes

double mLevel
 
bool mGain
 
bool mDC
 
bool mStereoInd
 
double mCurT0
 
double mCurT1
 
float mMult
 
double mSum
 
sampleCount mCount
 
wxCheckBox * mGainCheckBox
 
wxCheckBox * mDCCheckBox
 
wxTextCtrl * mLevelTextCtrl
 
wxStaticText * mLeveldB
 
wxStaticText * mWarning
 
wxCheckBox * mStereoIndCheckBox
 
bool mCreating
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Protected Member Functions inherited from Effect
virtual bool Init ()
 
virtual bool PromptUser (wxWindow *parent)
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual int GetPass ()
 
virtual void End ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
virtual void Preview (bool dryOnly)
 
virtual bool EnableApply (bool enable=true)
 
virtual bool EnablePreview (bool enable=true)
 
virtual void EnableDebug (bool enable=true)
 
bool TotalProgress (double frac)
 
bool TrackProgress (int whichTrack, double frac, const wxString &=wxEmptyString)
 
bool TrackGroupProgress (int whichGroup, double frac, const wxString &=wxEmptyString)
 
int GetNumWaveTracks ()
 
int GetNumWaveGroups ()
 
void GetSamples (const WaveTrack *track, sampleCount *start, sampleCount *len)
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing ()
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void CopyInputTracks ()
 
void CopyInputTracks (int trackType)
 
std::shared_ptr
< AddedAnalysisTrack
AddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
TrackAddToOutputTracks (std::unique_ptr< Track > &&t)
 
TrackListinputTracks () const
 
- Protected Attributes inherited from Effect
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
SelectedRegionmpSelectedRegion {}
 
TrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
double mF0
 
double mF1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
sampleCount mSampleCnt
 
int mOutputTracksType
 

Detailed Description

An Effect to bring the peak level up to a chosen level.

Definition at line 27 of file Normalize.h.

Constructor & Destructor Documentation

EffectNormalize::EffectNormalize ( )

Definition at line 45 of file Normalize.cpp.

46 {
47  mLevel = DEF_Level;
48  mDC = DEF_RemoveDC;
49  mGain = DEF_ApplyGain;
50  mStereoInd = DEF_StereoInd;
51 
52  SetLinearEffectFlag(false);
53 }
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1961
double mLevel
Definition: Normalize.h:75
EffectNormalize::~EffectNormalize ( )
virtual

Definition at line 55 of file Normalize.cpp.

56 {
57 }

Member Function Documentation

bool EffectNormalize::AnalyseDC ( const WaveTrack track,
const wxString &  msg,
int  curTrackNum,
float &  offset 
)
private

Definition at line 388 of file Normalize.cpp.

References AnalyzeData(), sampleCount::as_double(), fillZero, floatSample, WaveTrack::Get(), WaveTrack::GetBestBlockSize(), WaveTrack::GetMaxBlockSize(), limitSampleBufferSize(), mCount, mCurT0, mCurT1, mDC, mSum, WaveTrack::TimeToLongSamples(), and Effect::TrackProgress().

Referenced by AnalyseTrack().

391 {
392  bool rc = true;
393 
394  offset = 0.0; // we might just return
395 
396  if(!mDC) // don't do analysis if not doing dc removal
397  return(rc);
398 
399  //Transform the marker timepoints to samples
400  auto start = track->TimeToLongSamples(mCurT0);
401  auto end = track->TimeToLongSamples(mCurT1);
402 
403  //Get the length of the buffer (as double). len is
404  //used simply to calculate a progress meter, so it is easier
405  //to make it a double now than it is to do it later
406  auto len = (end - start).as_double();
407 
408  //Initiate a processing buffer. This buffer will (most likely)
409  //be shorter than the length of the track being processed.
410  Floats buffer{ track->GetMaxBlockSize() };
411 
412  mSum = 0.0; // dc offset inits
413  mCount = 0;
414 
415  sampleCount blockSamples;
416  sampleCount totalSamples = 0;
417 
418  //Go through the track one buffer at a time. s counts which
419  //sample the current buffer starts at.
420  auto s = start;
421  while (s < end) {
422  //Get a block of samples (smaller than the size of the buffer)
423  //Adjust the block size if it is the final block in the track
424  const auto block = limitSampleBufferSize(
425  track->GetBestBlockSize(s),
426  end - s
427  );
428 
429  //Get the samples from the track and put them in the buffer
430  track->Get((samplePtr) buffer.get(), floatSample, s, block, fillZero, true, &blockSamples);
431  totalSamples += blockSamples;
432 
433  //Process the buffer.
434  AnalyzeData(buffer.get(), block);
435 
436  //Increment s one blockfull of samples
437  s += block;
438 
439  //Update the Progress meter
440  if (TrackProgress(curTrackNum,
441  ((s - start).as_double() / len)/2.0, msg)) {
442  rc = false; //lda .. break, not return, so that buffer is deleted
443  break;
444  }
445  }
446  if( totalSamples > 0 )
447  offset = -mSum / totalSamples.as_double(); // calculate actual offset (amount that needs to be added on)
448  else
449  offset = 0.0;
450 
451  //Return true because the effect processing succeeded ... unless cancelled
452  return rc;
453 }
bool TrackProgress(int whichTrack, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1985
void AnalyzeData(float *buffer, size_t len)
Definition: Normalize.cpp:512
double as_double() const
Definition: Types.h:88
double mCurT0
Definition: Normalize.h:80
size_t GetBestBlockSize(sampleCount t) const
Definition: WaveTrack.cpp:1607
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
char * samplePtr
Definition: Types.h:203
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:1625
sampleCount mCount
Definition: Normalize.h:84
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
double mCurT1
Definition: Normalize.h:81
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumCopied=nullptr) const
Definition: WaveTrack.cpp:1971
bool EffectNormalize::AnalyseTrack ( const WaveTrack track,
const wxString &  msg,
int  curTrackNum,
float &  offset,
float &  min,
float &  max 
)
private

Definition at line 352 of file Normalize.cpp.

References _(), AnalyseDC(), Cancelled, WaveTrack::GetMinMax(), WaveTrack::GetODFlags(), mCurT0, mCurT1, mDC, mGain, Effect::mProgress, and ProgressDialog::Update().

Referenced by Process().

355 {
356  if(mGain) {
357  // Since we need complete summary data, we need to block until the OD tasks are done for this track
358  // TODO: should we restrict the flags to just the relevant block files (for selections)
359  while (track->GetODFlags()) {
360  // update the gui
362  0, _("Waiting for waveform to finish computing...")) )
363  return false;
364  wxMilliSleep(100);
365  }
366 
367  // set mMin, mMax. No progress bar here as it's fast.
368  auto pair = track->GetMinMax(mCurT0, mCurT1); // may throw
369  min = pair.first, max = pair.second;
370 
371  } else {
372  min = -1.0, max = 1.0; // sensible defaults?
373  }
374 
375  if(mDC) {
376  auto rc = AnalyseDC(track, msg, curTrackNum, offset);
377  min += offset;
378  max += offset;
379  return rc;
380  } else {
381  offset = 0.0;
382  return true;
383  }
384 }
ProgressDialog * mProgress
Definition: Effect.h:452
unsigned int GetODFlags() const
gets an int with OD flags so that we can determine which ODTasks should be run on this track after sa...
Definition: WaveTrack.cpp:1583
double mCurT0
Definition: Normalize.h:80
ProgressResult Update(int value, const wxString &message=wxEmptyString)
int min(int a, int b)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
double mCurT1
Definition: Normalize.h:81
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
Definition: WaveTrack.cpp:1898
bool AnalyseDC(const WaveTrack *track, const wxString &msg, int curTrackNum, float &offset)
Definition: Normalize.cpp:388
void EffectNormalize::AnalyzeData ( float *  buffer,
size_t  len 
)
private

Definition at line 512 of file Normalize.cpp.

References mCount, and mSum.

Referenced by AnalyseDC().

513 {
514  for(decltype(len) i = 0; i < len; i++)
515  mSum += (double)buffer[i];
516  mCount += len;
517 }
sampleCount mCount
Definition: Normalize.h:84
bool EffectNormalize::CheckWhetherSkipEffect ( )
overridevirtual

Reimplemented from Effect.

Definition at line 119 of file Normalize.cpp.

References mDC, and mGain.

120 {
121  return ((mGain == false) && (mDC == false));
122 }
bool EffectNormalize::DefineParams ( ShuttleParams S)
override

Definition at line 84 of file Normalize.cpp.

References mDC, mGain, mLevel, and mStereoInd.

84  {
85  S.SHUTTLE_PARAM( mLevel, Level );
86  S.SHUTTLE_PARAM( mGain, ApplyGain );
87  S.SHUTTLE_PARAM( mDC, RemoveDC );
88  S.SHUTTLE_PARAM( mStereoInd, StereoInd );
89  return true;
90 }
double mLevel
Definition: Normalize.h:75
bool EffectNormalize::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 92 of file Normalize.cpp.

References mDC, mGain, mLevel, and mStereoInd.

93 {
94  parms.Write(KEY_Level, mLevel);
95  parms.Write(KEY_ApplyGain, mGain);
96  parms.Write(KEY_RemoveDC, mDC);
97  parms.Write(KEY_StereoInd, mStereoInd);
98 
99  return true;
100 }
double mLevel
Definition: Normalize.h:75
wxString EffectNormalize::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 66 of file Normalize.cpp.

References _().

67 {
68  return _("Sets the peak amplitude of one or more tracks");
69 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
IdentInterfaceSymbol EffectNormalize::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 61 of file Normalize.cpp.

References NORMALIZE_PLUGIN_SYMBOL.

62 {
64 }
#define NORMALIZE_PLUGIN_SYMBOL
Definition: Normalize.h:25
EffectType EffectNormalize::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 78 of file Normalize.cpp.

References EffectTypeProcess.

79 {
80  return EffectTypeProcess;
81 }
wxString EffectNormalize::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 71 of file Normalize.cpp.

72 {
73  return wxT("Normalize");
74 }
void EffectNormalize::OnUpdateUI ( wxCommandEvent &  evt)
private

Definition at line 527 of file Normalize.cpp.

References UpdateUI().

528 {
529  UpdateUI();
530 }
void EffectNormalize::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 282 of file Normalize.cpp.

References _(), ShuttleGuiBase::AddCheckBox(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::AddVariableText(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndVerticalLay(), mCreating, mDC, mDCCheckBox, mGain, mGainCheckBox, mLevel, mLeveldB, mLevelTextCtrl, mStereoInd, mStereoIndCheckBox, mWarning, ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), and ShuttleGuiBase::StartVerticalLay().

283 {
284  mCreating = true;
285 
286  S.StartVerticalLay(0);
287  {
288  S.StartMultiColumn(2, wxALIGN_CENTER);
289  {
290  S.StartVerticalLay(false);
291  {
292  mDCCheckBox = S.AddCheckBox(_("Remove DC offset (center on 0.0 vertically)"),
293  mDC ? wxT("true") : wxT("false"));
294  mDCCheckBox->SetValidator(wxGenericValidator(&mDC));
295 
296  S.StartHorizontalLay(wxALIGN_CENTER, false);
297  {
298  mGainCheckBox = S.AddCheckBox(_("Normalize maximum amplitude to"),
299  mGain ? wxT("true") : wxT("false"));
300  mGainCheckBox->SetValidator(wxGenericValidator(&mGain));
301 
302  FloatingPointValidator<double> vldLevel(2, &mLevel, NumValidatorStyle::ONE_TRAILING_ZERO);
303  vldLevel.SetRange(MIN_Level, MAX_Level);
304  mLevelTextCtrl = S.AddTextBox( {}, wxT(""), 10);
305  mLevelTextCtrl->SetName(_("Maximum amplitude dB"));
306  mLevelTextCtrl->SetValidator(vldLevel);
307  mLeveldB = S.AddVariableText(_("dB"), false,
308  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
309  mWarning = S.AddVariableText( {}, false,
310  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
311  }
312  S.EndHorizontalLay();
313 
314 
315  mStereoIndCheckBox = S.AddCheckBox(_("Normalize stereo channels independently"),
316  mStereoInd ? wxT("true") : wxT("false"));
317  mStereoIndCheckBox->SetValidator(wxGenericValidator(&mStereoInd));
318  }
319  S.EndVerticalLay();
320  }
321  S.EndMultiColumn();
322  }
323  S.EndVerticalLay();
324 
325  mCreating = false;
326 }
wxCheckBox * mDCCheckBox
Definition: Normalize.h:87
void EndMultiColumn()
wxCheckBox * mGainCheckBox
Definition: Normalize.h:86
wxTextCtrl * mLevelTextCtrl
Definition: Normalize.h:88
void EndHorizontalLay()
void EndVerticalLay()
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
wxStaticText * mWarning
Definition: Normalize.h:90
wxCheckBox * AddCheckBox(const wxString &Prompt, const wxString &Selected)
Definition: ShuttleGui.cpp:298
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
double mLevel
Definition: Normalize.h:75
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxStaticText * mLeveldB
Definition: Normalize.h:89
wxStaticText * AddVariableText(const wxString &Str, bool bCenter=false, int PositionFlags=0)
Definition: ShuttleGui.cpp:414
wxCheckBox * mStereoIndCheckBox
Definition: Normalize.h:91
void StartVerticalLay(int iProp=1)
bool EffectNormalize::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 159 of file Normalize.cpp.

References _(), AnalyseTrack(), Effect::CopyInputTracks(), DB_TO_LINEAR(), Track::GetLinked(), mCurT0, mCurT1, mDC, mGain, min(), mLevel, mMult, Effect::mOutputTracks, mStereoInd, Effect::mT0, Effect::mT1, ProcessOne(), Effect::ReplaceProcessedTracks(), TrapDouble(), and Track::Wave.

160 {
161  if (mGain == false && mDC == false)
162  return true;
163 
164  float ratio;
165  if( mGain )
166  // same value used for all tracks
167  ratio = DB_TO_LINEAR(TrapDouble(mLevel, MIN_Level, MAX_Level));
168  else
169  ratio = 1.0;
170 
171  //Iterate over each track
172  this->CopyInputTracks(); // Set up mOutputTracks.
173  bool bGoodResult = true;
175  WaveTrack *track = (WaveTrack *) iter.First();
176  WaveTrack *prevTrack;
177  prevTrack = track;
178  int curTrackNum = 0;
179  wxString topMsg;
180  if(mDC && mGain)
181  topMsg = _("Removing DC offset and Normalizing...\n");
182  else if(mDC && !mGain)
183  topMsg = _("Removing DC offset...\n");
184  else if(!mDC && mGain)
185  topMsg = _("Normalizing without removing DC offset...\n");
186  else if(!mDC && !mGain)
187  topMsg = _("Not doing anything...\n"); // shouldn't get here
188 
189  while (track) {
190  //Get start and end times from track
191  double trackStart = track->GetStartTime();
192  double trackEnd = track->GetEndTime();
193 
194  //Set the current bounds to whichever left marker is
195  //greater and whichever right marker is less:
196  mCurT0 = mT0 < trackStart? trackStart: mT0;
197  mCurT1 = mT1 > trackEnd? trackEnd: mT1;
198 
199  // Process only if the right marker is to the right of the left marker
200  if (mCurT1 > mCurT0) {
201  wxString msg;
202  auto trackName = track->GetName();
203 
204  if(!track->GetLinked() || mStereoInd)
205  msg =
206  topMsg + wxString::Format( _("Analyzing: %s"), trackName );
207  else
208  msg =
209  topMsg + wxString::Format( _("Analyzing first track of stereo pair: %s"), trackName );
210  float offset, min, max;
211  bGoodResult = AnalyseTrack(track, msg, curTrackNum, offset, min, max);
212  if (!bGoodResult )
213  break;
214  if(!track->GetLinked() || mStereoInd) {
215  // mono or 'stereo tracks independently'
216  float extent = wxMax(fabs(max), fabs(min));
217  if( (extent > 0) && mGain )
218  mMult = ratio / extent;
219  else
220  mMult = 1.0;
221  msg =
222  topMsg + wxString::Format( _("Processing: %s"), trackName );
223  if(track->GetLinked() || prevTrack->GetLinked()) // only get here if there is a linked track but we are processing independently
224  msg =
225  topMsg + wxString::Format( _("Processing stereo channels independently: %s"), trackName );
226 
227  if (!ProcessOne(track, msg, curTrackNum, offset))
228  {
229  bGoodResult = false;
230  break;
231  }
232  }
233  else
234  {
235  // we have a linked stereo track
236  // so we need to find it's min, max and offset
237  // as they are needed to calc the multiplier for both tracks
238  track = (WaveTrack *) iter.Next(); // get the next one
239  msg =
240  topMsg + wxString::Format( _("Analyzing second track of stereo pair: %s"), trackName );
241  float offset2, min2, max2;
242  bGoodResult = AnalyseTrack(track, msg, curTrackNum + 1, offset2, min2, max2);
243  if ( !bGoodResult )
244  break;
245  float extent = wxMax(fabs(min), fabs(max));
246  extent = wxMax(extent, fabs(min2));
247  extent = wxMax(extent, fabs(max2));
248  if( (extent > 0) && mGain )
249  mMult = ratio / extent; // we need to use this for both linked tracks
250  else
251  mMult = 1.0;
252  track = (WaveTrack *) iter.Prev(); // go back to the first linked one
253  msg =
254  topMsg + wxString::Format( _("Processing first track of stereo pair: %s"), trackName );
255  if (!ProcessOne(track, msg, curTrackNum, offset))
256  {
257  bGoodResult = false;
258  break;
259  }
260  track = (WaveTrack *) iter.Next(); // go to the second linked one
261  curTrackNum++; // keeps progress bar correct
262  msg =
263  topMsg + wxString::Format( _("Processing second track of stereo pair: %s"), trackName );
264  if (!ProcessOne(track, msg, curTrackNum, offset2))
265  {
266  bGoodResult = false;
267  break;
268  }
269  }
270  }
271 
272  //Iterate to the next track
273  prevTrack = track;
274  track = (WaveTrack *) iter.Next();
275  curTrackNum++;
276  }
277 
278  this->ReplaceProcessedTracks(bGoodResult);
279  return bGoodResult;
280 }
double mT1
Definition: Effect.h:461
bool ProcessOne(WaveTrack *t, const wxString &msg, int curTrackNum, float offset)
Definition: Normalize.cpp:459
void CopyInputTracks()
Definition: Effect.cpp:2036
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
bool GetLinked() const
Definition: Track.h:279
double mCurT0
Definition: Normalize.h:80
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
double mLevel
Definition: Normalize.h:75
int min(int a, int b)
bool AnalyseTrack(const WaveTrack *track, const wxString &msg, int curTrackNum, float &offset, float &min, float &max)
Definition: Normalize.cpp:352
double TrapDouble(double x, double min, double max)
Definition: Effect.h:729
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
double mCurT1
Definition: Normalize.h:81
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
double mT0
Definition: Effect.h:460
void EffectNormalize::ProcessData ( float *  buffer,
size_t  len,
float  offset 
)
private

Definition at line 519 of file Normalize.cpp.

References mMult.

Referenced by ProcessOne().

520 {
521  for(decltype(len) i = 0; i < len; i++) {
522  float adjFrame = (buffer[i] + offset) * mMult;
523  buffer[i] = adjFrame;
524  }
525 }
bool EffectNormalize::ProcessOne ( WaveTrack t,
const wxString &  msg,
int  curTrackNum,
float  offset 
)
private

Definition at line 459 of file Normalize.cpp.

References floatSample, WaveTrack::Get(), WaveTrack::GetBestBlockSize(), WaveTrack::GetMaxBlockSize(), limitSampleBufferSize(), mCurT0, mCurT1, ProcessData(), WaveTrack::Set(), WaveTrack::TimeToLongSamples(), and Effect::TrackProgress().

Referenced by Process().

461 {
462  bool rc = true;
463 
464  //Transform the marker timepoints to samples
465  auto start = track->TimeToLongSamples(mCurT0);
466  auto end = track->TimeToLongSamples(mCurT1);
467 
468  //Get the length of the buffer (as double). len is
469  //used simply to calculate a progress meter, so it is easier
470  //to make it a double now than it is to do it later
471  auto len = (end - start).as_double();
472 
473  //Initiate a processing buffer. This buffer will (most likely)
474  //be shorter than the length of the track being processed.
475  Floats buffer{ track->GetMaxBlockSize() };
476 
477  //Go through the track one buffer at a time. s counts which
478  //sample the current buffer starts at.
479  auto s = start;
480  while (s < end) {
481  //Get a block of samples (smaller than the size of the buffer)
482  //Adjust the block size if it is the final block in the track
483  const auto block = limitSampleBufferSize(
484  track->GetBestBlockSize(s),
485  end - s
486  );
487 
488  //Get the samples from the track and put them in the buffer
489  track->Get((samplePtr) buffer.get(), floatSample, s, block);
490 
491  //Process the buffer.
492  ProcessData(buffer.get(), block, offset);
493 
494  //Copy the newly-changed samples back onto the track.
495  track->Set((samplePtr) buffer.get(), floatSample, s, block);
496 
497  //Increment s one blockfull of samples
498  s += block;
499 
500  //Update the Progress meter
501  if (TrackProgress(curTrackNum,
502  0.5+((s - start).as_double() / len)/2.0, msg)) {
503  rc = false; //lda .. break, not return, so that buffer is deleted
504  break;
505  }
506  }
507 
508  //Return true because the effect processing succeeded ... unless cancelled
509  return rc;
510 }
bool TrackProgress(int whichTrack, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1985
void ProcessData(float *buffer, size_t len, float offset)
Definition: Normalize.cpp:519
double mCurT0
Definition: Normalize.h:80
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
char * samplePtr
Definition: Types.h:203
double mCurT1
Definition: Normalize.h:81
bool EffectNormalize::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 102 of file Normalize.cpp.

References mDC, mGain, mLevel, mStereoInd, ReadAndVerifyBool, and ReadAndVerifyDouble.

103 {
104  ReadAndVerifyDouble(Level);
105  ReadAndVerifyBool(ApplyGain);
106  ReadAndVerifyBool(RemoveDC);
107  ReadAndVerifyBool(StereoInd);
108 
109  mLevel = Level;
110  mGain = ApplyGain;
111  mDC = RemoveDC;
112  mStereoInd = StereoInd;
113 
114  return true;
115 }
#define ReadAndVerifyDouble(name)
Definition: Effect.h:798
double mLevel
Definition: Normalize.h:75
#define ReadAndVerifyBool(name)
Definition: Effect.h:800
bool EffectNormalize::Startup ( )
overridevirtual

Reimplemented from Effect.

Definition at line 124 of file Normalize.cpp.

References Effect::GetCurrentSettingsGroup(), gPrefs, mDC, mGain, mLevel, mStereoInd, and Effect::SaveUserPreset().

125 {
126  wxString base = wxT("/Effects/Normalize/");
127 
128  // Migrate settings from 2.1.0 or before
129 
130  // Already migrated, so bail
131  if (gPrefs->Exists(base + wxT("Migrated")))
132  {
133  return true;
134  }
135 
136  // Load the old "current" settings
137  if (gPrefs->Exists(base))
138  {
139  int boolProxy = gPrefs->Read(base + wxT("RemoveDcOffset"), 1);
140  mDC = (boolProxy == 1);
141  boolProxy = gPrefs->Read(base + wxT("Normalize"), 1);
142  mGain = (boolProxy == 1);
143  gPrefs->Read(base + wxT("Level"), &mLevel, -1.0);
144  if(mLevel > 0.0) // this should never happen
145  mLevel = -mLevel;
146  boolProxy = gPrefs->Read(base + wxT("StereoIndependent"), 0L);
147  mStereoInd = (boolProxy == 1);
148 
150 
151  // Do not migrate again
152  gPrefs->Write(base + wxT("Migrated"), true);
153  gPrefs->Flush();
154  }
155 
156  return true;
157 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool SaveUserPreset(const wxString &name) override
Definition: Effect.cpp:600
wxString GetCurrentSettingsGroup() override
Definition: Effect.cpp:801
double mLevel
Definition: Normalize.h:75
bool EffectNormalize::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 340 of file Normalize.cpp.

References Effect::mUIParent.

341 {
342  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
343  {
344  return false;
345  }
346 
347  return true;
348 }
wxWindow * mUIParent
Definition: Effect.h:472
bool EffectNormalize::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 328 of file Normalize.cpp.

References Effect::mUIParent, and UpdateUI().

329 {
330  if (!mUIParent->TransferDataToWindow())
331  {
332  return false;
333  }
334 
335  UpdateUI();
336 
337  return true;
338 }
wxWindow * mUIParent
Definition: Effect.h:472
void EffectNormalize::UpdateUI ( void  )
private

Definition at line 532 of file Normalize.cpp.

References _(), Effect::EnableApply(), mDC, mGain, mLeveldB, mLevelTextCtrl, mStereoIndCheckBox, Effect::mUIParent, and mWarning.

Referenced by OnUpdateUI(), and TransferDataToWindow().

533 {
534  if (!mUIParent->TransferDataFromWindow())
535  {
536  mWarning->SetLabel(_(". Maximum 0dB."));
537  EnableApply(false);
538  return;
539  }
540  mWarning->SetLabel(wxT(""));
541 
542  // Disallow level stuff if not normalizing
543  mLevelTextCtrl->Enable(mGain);
544  mLeveldB->Enable(mGain);
545  mStereoIndCheckBox->Enable(mGain);
546 
547  // Disallow OK/Preview if doing nothing
548  EnableApply(mGain || mDC);
549 }
wxTextCtrl * mLevelTextCtrl
Definition: Normalize.h:88
wxStaticText * mWarning
Definition: Normalize.h:90
wxWindow * mUIParent
Definition: Effect.h:472
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxStaticText * mLeveldB
Definition: Normalize.h:89
wxCheckBox * mStereoIndCheckBox
Definition: Normalize.h:91
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1886

Member Data Documentation

sampleCount EffectNormalize::mCount
private

Definition at line 84 of file Normalize.h.

Referenced by AnalyseDC(), and AnalyzeData().

bool EffectNormalize::mCreating
private

Definition at line 93 of file Normalize.h.

Referenced by PopulateOrExchange().

double EffectNormalize::mCurT0
private

Definition at line 80 of file Normalize.h.

Referenced by AnalyseDC(), AnalyseTrack(), Process(), and ProcessOne().

double EffectNormalize::mCurT1
private

Definition at line 81 of file Normalize.h.

Referenced by AnalyseDC(), AnalyseTrack(), Process(), and ProcessOne().

bool EffectNormalize::mDC
private
wxCheckBox* EffectNormalize::mDCCheckBox
private

Definition at line 87 of file Normalize.h.

Referenced by PopulateOrExchange().

bool EffectNormalize::mGain
private
wxCheckBox* EffectNormalize::mGainCheckBox
private

Definition at line 86 of file Normalize.h.

Referenced by PopulateOrExchange().

double EffectNormalize::mLevel
private
wxStaticText* EffectNormalize::mLeveldB
private

Definition at line 89 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

wxTextCtrl* EffectNormalize::mLevelTextCtrl
private

Definition at line 88 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

float EffectNormalize::mMult
private

Definition at line 82 of file Normalize.h.

Referenced by Process(), and ProcessData().

bool EffectNormalize::mStereoInd
private
wxCheckBox* EffectNormalize::mStereoIndCheckBox
private

Definition at line 91 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

double EffectNormalize::mSum
private

Definition at line 83 of file Normalize.h.

Referenced by AnalyseDC(), and AnalyzeData().

wxStaticText* EffectNormalize::mWarning
private

Definition at line 90 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().


The documentation for this class was generated from the following files: