Audacity  3.0.3
Public Member Functions | Static Public Attributes | 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:
[legend]
Collaboration diagram for EffectNormalize:
[legend]

Public Member Functions

 EffectNormalize ()
 
virtual ~EffectNormalize ()
 
ComponentInterfaceSymbol GetSymbol () override
 
TranslatableString GetDescription () override
 
ManualPageID 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 ()
 
PluginPath GetPath () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
EffectFamilySymbol GetFamily () 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
 
size_t GetBlockSize () const 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, const EffectDialogFactory &factory, bool forceModal=false) override
 
bool LoadUserPreset (const RegistryPath &name) override
 
bool SaveUserPreset (const RegistryPath &name) override
 
RegistryPaths GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (ShuttleGui &S) final
 
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
 
NumericFormatSymbol GetDurationFormat () override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
void SetDuration (double duration) override
 
RegistryPath GetUserPresetsGroup (const RegistryPath &name) override
 
RegistryPath GetCurrentSettingsGroup () override
 
RegistryPath GetFactoryDefaultsGroup () override
 
virtual wxString GetSavedStateGroup ()
 
bool HasSharedConfigGroup (const RegistryPath &group) override
 
bool GetSharedConfigSubgroups (const RegistryPath &group, RegistryPaths &subgroups) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, wxString &value, const wxString &defval={}) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, int &value, int defval=0) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const wxString &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const int &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const bool &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const float &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const RegistryPath &group) override
 
bool RemoveSharedConfig (const RegistryPath &group, const RegistryPath &key) override
 
bool HasPrivateConfigGroup (const RegistryPath &group) override
 
bool GetPrivateConfigSubgroups (const RegistryPath &group, RegistryPaths &paths) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, wxString &value, const wxString &defval={}) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const wxString &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const int &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const bool &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const float &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const RegistryPath &group) override
 
bool RemovePrivateConfig (const RegistryPath &group, const RegistryPath &key) override
 
virtual PluginID GetID ()
 
virtual bool Startup (EffectClientInterface *client)
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (const wxString &parms)
 
virtual RegistryPaths GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual FilePath HelpPage ()
 
virtual void SetUIFlags (unsigned flags)
 
virtual unsigned TestUIFlags (unsigned mask)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={})
 
bool Delegate (Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory)
 
virtual bool IsHidden ()
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetClassification ()
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
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 ()
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Normalize") }
 
- Static Public Attributes inherited from Effect
static const wxString kUserPresetIdent = wxT("User Preset:")
 
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
 
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
 
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
 

Private Member Functions

bool ProcessOne (WaveTrack *t, const TranslatableString &msg, double &progress, float offset)
 
bool AnalyseTrack (const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset, float &extent)
 
bool AnalyseTrackData (const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset)
 
void AnalyseDataDC (float *buffer, size_t len)
 
void ProcessData (float *buffer, size_t len, float offset)
 
void OnUpdateUI (wxCommandEvent &evt)
 
void UpdateUI ()
 

Private Attributes

double mPeakLevel
 
bool mGain
 
bool mDC
 
bool mStereoInd
 
double mCurT0
 
double mCurT1
 
float mMult
 
double mSum
 
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 }
 
using VetoDialogHook = bool(*)(wxDialog *)
 
- Public Types inherited from EffectClientInterface
using EffectDialogFactory = std::function< wxDialog *(wxWindow &parent, EffectHostInterface *, EffectUIClientInterface *) >
 
- Static Public Member Functions inherited from Effect
static VetoDialogHook SetVetoDialogHook (VetoDialogHook hook)
 
static CommandID GetSquashedName (wxString name)
 
static void IncEffectCounter ()
 
- Protected Member Functions inherited from Effect
virtual bool Init ()
 
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, const TranslatableString &={})
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={})
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={})
 
int GetNumWaveTracks ()
 
int GetNumWaveGroups ()
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing ()
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from Effect
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
wxWeakRef< NotifyingSelectedRegionmpSelectedRegion {}
 
WaveTrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
unsigned mUIFlags
 
sampleCount mSampleCnt
 
- Static Protected Attributes inherited from Effect
static int nEffectsDone =0
 

Detailed Description

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

Definition at line 23 of file Normalize.h.

Constructor & Destructor Documentation

◆ EffectNormalize()

EffectNormalize::EffectNormalize ( )

Definition at line 55 of file Normalize.cpp.

56 {
57  mPeakLevel = DEF_PeakLevel;
58  mDC = DEF_RemoveDC;
59  mGain = DEF_ApplyGain;
60  mStereoInd = DEF_StereoInd;
61 
62  SetLinearEffectFlag(false);
63 }

◆ ~EffectNormalize()

EffectNormalize::~EffectNormalize ( )
virtual

Definition at line 65 of file Normalize.cpp.

66 {
67 }

Member Function Documentation

◆ AnalyseDataDC()

void EffectNormalize::AnalyseDataDC ( float *  buffer,
size_t  len 
)
private
See also
AnalyseDataLoudnessDC

Definition at line 523 of file Normalize.cpp.

524 {
525  for(decltype(len) i = 0; i < len; i++)
526  mSum += (double)buffer[i];
527 }

References mSum.

Referenced by AnalyseTrackData().

Here is the caller graph for this function:

◆ AnalyseTrack()

bool EffectNormalize::AnalyseTrack ( const WaveTrack track,
const TranslatableString msg,
double &  progress,
float &  offset,
float &  extent 
)
private

Definition at line 364 of file Normalize.cpp.

366 {
367  bool result = true;
368  float min, max;
369 
370  if(mGain)
371  {
372  // set mMin, mMax. No progress bar here as it's fast.
373  auto pair = track->GetMinMax(mCurT0, mCurT1); // may throw
374  min = pair.first, max = pair.second;
375 
376  if(mDC)
377  {
378  result = AnalyseTrackData(track, msg, progress, offset);
379  min += offset;
380  max += offset;
381  }
382  }
383  else if(mDC)
384  {
385  min = -1.0, max = 1.0; // sensible defaults?
386  result = AnalyseTrackData(track, msg, progress, offset);
387  min += offset;
388  max += offset;
389  }
390  else
391  {
392  wxFAIL_MSG("Analysing Track when nothing to do!");
393  min = -1.0, max = 1.0; // sensible defaults?
394  offset = 0.0;
395  }
396  extent = fmax(fabs(min), fabs(max));
397 
398  return result;
399 }

References AnalyseTrackData(), WaveTrack::GetMinMax(), mCurT0, mCurT1, mDC, mGain, and min().

Referenced by Process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AnalyseTrackData()

bool EffectNormalize::AnalyseTrackData ( const WaveTrack track,
const TranslatableString msg,
double &  progress,
float &  offset 
)
private

Definition at line 403 of file Normalize.cpp.

405 {
406  bool rc = true;
407 
408  //Transform the marker timepoints to samples
409  auto start = track->TimeToLongSamples(mCurT0);
410  auto end = track->TimeToLongSamples(mCurT1);
411 
412  //Get the length of the buffer (as double). len is
413  //used simply to calculate a progress meter, so it is easier
414  //to make it a double now than it is to do it later
415  auto len = (end - start).as_double();
416 
417  //Initiate a processing buffer. This buffer will (most likely)
418  //be shorter than the length of the track being processed.
419  Floats buffer{ track->GetMaxBlockSize() };
420 
421  mSum = 0.0; // dc offset inits
422 
423  sampleCount blockSamples;
424  sampleCount totalSamples = 0;
425 
426  //Go through the track one buffer at a time. s counts which
427  //sample the current buffer starts at.
428  auto s = start;
429  while (s < end) {
430  //Get a block of samples (smaller than the size of the buffer)
431  //Adjust the block size if it is the final block in the track
432  const auto block = limitSampleBufferSize(
433  track->GetBestBlockSize(s),
434  end - s
435  );
436 
437  //Get the samples from the track and put them in the buffer
438  track->GetFloats(buffer.get(), s, block, fillZero, true, &blockSamples);
439  totalSamples += blockSamples;
440 
441  //Process the buffer.
442  AnalyseDataDC(buffer.get(), block);
443 
444  //Increment s one blockfull of samples
445  s += block;
446 
447  //Update the Progress meter
448  if (TotalProgress(progress +
449  ((s - start).as_double() / len)/double(2*GetNumWaveTracks()), msg)) {
450  rc = false; //lda .. break, not return, so that buffer is deleted
451  break;
452  }
453  }
454  if( totalSamples > 0 )
455  offset = -mSum / totalSamples.as_double(); // calculate actual offset (amount that needs to be added on)
456  else
457  offset = 0.0;
458 
459  progress += 1.0/double(2*GetNumWaveTracks());
460  //Return true because the effect processing succeeded ... unless cancelled
461  return rc;
462 }

References AnalyseDataDC(), sampleCount::as_double(), fillZero, WaveTrack::GetBestBlockSize(), WaveTrack::GetFloats(), WaveTrack::GetMaxBlockSize(), Effect::GetNumWaveTracks(), limitSampleBufferSize(), mCurT0, mCurT1, mSum, WaveTrack::TimeToLongSamples(), and Effect::TotalProgress().

Referenced by AnalyseTrack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckWhetherSkipEffect()

bool EffectNormalize::CheckWhetherSkipEffect ( )
overridevirtual

Reimplemented from Effect.

Definition at line 129 of file Normalize.cpp.

130 {
131  return ((mGain == false) && (mDC == false));
132 }

References mDC, and mGain.

◆ DefineParams()

bool EffectNormalize::DefineParams ( ShuttleParams S)
override

Definition at line 94 of file Normalize.cpp.

94  {
95  S.SHUTTLE_PARAM( mPeakLevel, PeakLevel );
96  S.SHUTTLE_PARAM( mGain, ApplyGain );
97  S.SHUTTLE_PARAM( mDC, RemoveDC );
98  S.SHUTTLE_PARAM( mStereoInd, StereoInd );
99  return true;
100 }

References mDC, mGain, mPeakLevel, and mStereoInd.

◆ GetAutomationParameters()

bool EffectNormalize::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 102 of file Normalize.cpp.

103 {
104  parms.Write(KEY_PeakLevel, mPeakLevel);
105  parms.Write(KEY_ApplyGain, mGain);
106  parms.Write(KEY_RemoveDC, mDC);
107  parms.Write(KEY_StereoInd, mStereoInd);
108 
109  return true;
110 }

References mDC, mGain, mPeakLevel, and mStereoInd.

◆ GetDescription()

TranslatableString EffectNormalize::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 76 of file Normalize.cpp.

77 {
78  return XO("Sets the peak amplitude of one or more tracks");
79 }

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectNormalize::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 71 of file Normalize.cpp.

72 {
73  return Symbol;
74 }

References Symbol.

◆ GetType()

EffectType EffectNormalize::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 88 of file Normalize.cpp.

89 {
90  return EffectTypeProcess;
91 }

References EffectTypeProcess.

◆ ManualPage()

ManualPageID EffectNormalize::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 81 of file Normalize.cpp.

82 {
83  return L"Normalize";
84 }

◆ OnUpdateUI()

void EffectNormalize::OnUpdateUI ( wxCommandEvent &  evt)
private

Definition at line 537 of file Normalize.cpp.

538 {
539  UpdateUI();
540 }

References UpdateUI().

Here is the call graph for this function:

◆ PopulateOrExchange()

void EffectNormalize::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 288 of file Normalize.cpp.

289 {
290  mCreating = true;
291 
292  S.StartVerticalLay(0);
293  {
294  S.StartMultiColumn(2, wxALIGN_CENTER);
295  {
296  S.StartVerticalLay(false);
297  {
298  mDCCheckBox = S.Validator<wxGenericValidator>(&mDC)
299  .AddCheckBox(XXO("&Remove DC offset (center on 0.0 vertically)"),
300  mDC);
301 
302  S.StartHorizontalLay(wxALIGN_LEFT, false);
303  {
304  mGainCheckBox = S
305  .MinSize()
306  .Validator<wxGenericValidator>(&mGain)
307  .AddCheckBox(XXO("&Normalize peak amplitude to "),
308  mGain);
309 
310  mLevelTextCtrl = S
311  .Name(XO("Peak amplitude dB"))
312  .Validator<FloatingPointValidator<double>>(
313  2,
314  &mPeakLevel,
315  NumValidatorStyle::ONE_TRAILING_ZERO,
316  MIN_PeakLevel,
317  MAX_PeakLevel
318  )
319  .AddTextBox( {}, wxT(""), 10);
320  mLeveldB = S.AddVariableText(XO("dB"), false,
321  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
322  mWarning = S.AddVariableText( {}, false,
323  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
324  }
325  S.EndHorizontalLay();
326 
328  .Validator<wxGenericValidator>(&mStereoInd)
329  .AddCheckBox(XXO("N&ormalize stereo channels independently"),
330  mStereoInd);
331  }
332  S.EndVerticalLay();
333  }
334  S.EndMultiColumn();
335  }
336  S.EndVerticalLay();
337  mCreating = false;
338 }

References ShuttleGuiBase::AddVariableText(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndVerticalLay(), mCreating, mDC, mDCCheckBox, mGain, mGainCheckBox, ShuttleGui::MinSize(), mLeveldB, mLevelTextCtrl, mPeakLevel, mStereoInd, mStereoIndCheckBox, mWarning, ShuttleGui::Name(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), ShuttleGuiBase::StartVerticalLay(), ShuttleGui::Validator(), XO, and XXO.

Here is the call graph for this function:

◆ Process()

bool EffectNormalize::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 169 of file Normalize.cpp.

170 {
171  if (mGain == false && mDC == false)
172  return true;
173 
174  float ratio;
175  if( mGain )
176  {
177  // same value used for all tracks
178  ratio = DB_TO_LINEAR(TrapDouble(mPeakLevel, MIN_PeakLevel, MAX_PeakLevel));
179  }
180  else {
181  ratio = 1.0;
182  }
183 
184  //Iterate over each track
185  this->CopyInputTracks(); // Set up mOutputTracks.
186  bool bGoodResult = true;
187  double progress = 0;
188  TranslatableString topMsg;
189  if(mDC && mGain)
190  topMsg = XO("Removing DC offset and Normalizing...\n");
191  else if(mDC && !mGain)
192  topMsg = XO("Removing DC offset...\n");
193  else if(!mDC && mGain)
194  topMsg = XO("Normalizing without removing DC offset...\n");
195  else if(!mDC && !mGain)
196  topMsg = XO("Not doing anything...\n"); // shouldn't get here
197 
198  for ( auto track : mOutputTracks->Selected< WaveTrack >()
199  + ( mStereoInd ? &Track::Any : &Track::IsLeader ) ) {
200  //Get start and end times from track
201  // PRL: No accounting for multiple channels?
202  double trackStart = track->GetStartTime();
203  double trackEnd = track->GetEndTime();
204 
205  //Set the current bounds to whichever left marker is
206  //greater and whichever right marker is less:
207  mCurT0 = mT0 < trackStart? trackStart: mT0;
208  mCurT1 = mT1 > trackEnd? trackEnd: mT1;
209 
210  auto range = mStereoInd
212  : TrackList::Channels(track);
213 
214  // Process only if the right marker is to the right of the left marker
215  if (mCurT1 > mCurT0) {
216  wxString trackName = track->GetName();
217 
218  float extent;
219  // Will compute a maximum
220  extent = std::numeric_limits<float>::lowest();
221  std::vector<float> offsets;
222 
223  auto msg = (range.size() == 1)
224  // mono or 'stereo tracks independently'
225  ? topMsg +
226  XO("Analyzing: %s").Format( trackName )
227  : topMsg +
228  // TODO: more-than-two-channels-message
229  XO("Analyzing first track of stereo pair: %s").Format( trackName );
230 
231  // Analysis loop over channels collects offsets and extent
232  for (auto channel : range) {
233  float offset = 0;
234  float extent2 = 0;
235  bGoodResult =
236  AnalyseTrack( channel, msg, progress, offset, extent2 );
237  if ( ! bGoodResult )
238  goto break2;
239  extent = std::max( extent, extent2 );
240  offsets.push_back(offset);
241  // TODO: more-than-two-channels-message
242  msg = topMsg +
243  XO("Analyzing second track of stereo pair: %s").Format( trackName );
244  }
245 
246  // Compute the multiplier using extent
247  if( (extent > 0) && mGain ) {
248  mMult = ratio / extent;
249  }
250  else
251  mMult = 1.0;
252 
253  if (range.size() == 1) {
254  if (TrackList::Channels(track).size() == 1)
255  // really mono
256  msg = topMsg +
257  XO("Processing: %s").Format( trackName );
258  else
259  //'stereo tracks independently'
260  // TODO: more-than-two-channels-message
261  msg = topMsg +
262  XO("Processing stereo channels independently: %s").Format( trackName );
263  }
264  else
265  msg = topMsg +
266  // TODO: more-than-two-channels-message
267  XO("Processing first track of stereo pair: %s").Format( trackName );
268 
269  // Use multiplier in the second, processing loop over channels
270  auto pOffset = offsets.begin();
271  for (auto channel : range) {
272  if (false ==
273  (bGoodResult = ProcessOne(channel, msg, progress, *pOffset++)) )
274  goto break2;
275  // TODO: more-than-two-channels-message
276  msg = topMsg +
277  XO("Processing second track of stereo pair: %s").Format( trackName );
278  }
279  }
280  }
281 
282  break2:
283 
284  this->ReplaceProcessedTracks(bGoodResult);
285  return bGoodResult;
286 }

References AnalyseTrack(), Track::Any(), TrackList::Channels(), Effect::CopyInputTracks(), DB_TO_LINEAR(), Track::IsLeader(), mCurT0, mCurT1, mDC, mGain, mMult, Effect::mOutputTracks, mPeakLevel, mStereoInd, Effect::mT0, Effect::mT1, ProcessOne(), Effect::ReplaceProcessedTracks(), TrackList::SingletonRange(), size, TrapDouble(), and XO.

Here is the call graph for this function:

◆ ProcessData()

void EffectNormalize::ProcessData ( float *  buffer,
size_t  len,
float  offset 
)
private

Definition at line 529 of file Normalize.cpp.

530 {
531  for(decltype(len) i = 0; i < len; i++) {
532  float adjFrame = (buffer[i] + offset) * mMult;
533  buffer[i] = adjFrame;
534  }
535 }

References mMult.

Referenced by ProcessOne().

Here is the caller graph for this function:

◆ ProcessOne()

bool EffectNormalize::ProcessOne ( WaveTrack t,
const TranslatableString msg,
double &  progress,
float  offset 
)
private

Definition at line 468 of file Normalize.cpp.

470 {
471  bool rc = true;
472 
473  //Transform the marker timepoints to samples
474  auto start = track->TimeToLongSamples(mCurT0);
475  auto end = track->TimeToLongSamples(mCurT1);
476 
477  //Get the length of the buffer (as double). len is
478  //used simply to calculate a progress meter, so it is easier
479  //to make it a double now than it is to do it later
480  auto len = (end - start).as_double();
481 
482  //Initiate a processing buffer. This buffer will (most likely)
483  //be shorter than the length of the track being processed.
484  Floats buffer{ track->GetMaxBlockSize() };
485 
486  //Go through the track one buffer at a time. s counts which
487  //sample the current buffer starts at.
488  auto s = start;
489  while (s < end) {
490  //Get a block of samples (smaller than the size of the buffer)
491  //Adjust the block size if it is the final block in the track
492  const auto block = limitSampleBufferSize(
493  track->GetBestBlockSize(s),
494  end - s
495  );
496 
497  //Get the samples from the track and put them in the buffer
498  track->GetFloats(buffer.get(), s, block);
499 
500  //Process the buffer.
501  ProcessData(buffer.get(), block, offset);
502 
503  //Copy the newly-changed samples back onto the track.
504  track->Set((samplePtr) buffer.get(), floatSample, s, block);
505 
506  //Increment s one blockfull of samples
507  s += block;
508 
509  //Update the Progress meter
510  if (TotalProgress(progress +
511  ((s - start).as_double() / len)/double(2*GetNumWaveTracks()), msg)) {
512  rc = false; //lda .. break, not return, so that buffer is deleted
513  break;
514  }
515  }
516  progress += 1.0/double(2*GetNumWaveTracks());
517 
518  //Return true because the effect processing succeeded ... unless cancelled
519  return rc;
520 }

References floatSample, WaveTrack::GetBestBlockSize(), WaveTrack::GetFloats(), WaveTrack::GetMaxBlockSize(), Effect::GetNumWaveTracks(), limitSampleBufferSize(), mCurT0, mCurT1, ProcessData(), WaveTrack::Set(), WaveTrack::TimeToLongSamples(), and Effect::TotalProgress().

Referenced by Process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAutomationParameters()

bool EffectNormalize::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 112 of file Normalize.cpp.

113 {
114  ReadAndVerifyDouble(PeakLevel);
115  ReadAndVerifyBool(ApplyGain);
116  ReadAndVerifyBool(RemoveDC);
117  ReadAndVerifyBool(StereoInd);
118 
119  mPeakLevel = PeakLevel;
120  mGain = ApplyGain;
121  mDC = RemoveDC;
122  mStereoInd = StereoInd;
123 
124  return true;
125 }

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

◆ Startup()

bool EffectNormalize::Startup ( )
overridevirtual

Reimplemented from Effect.

Definition at line 134 of file Normalize.cpp.

135 {
136  wxString base = wxT("/Effects/Normalize/");
137 
138  // Migrate settings from 2.1.0 or before
139 
140  // Already migrated, so bail
141  if (gPrefs->Exists(base + wxT("Migrated")))
142  {
143  return true;
144  }
145 
146  // Load the old "current" settings
147  if (gPrefs->Exists(base))
148  {
149  int boolProxy = gPrefs->Read(base + wxT("RemoveDcOffset"), 1);
150  mDC = (boolProxy == 1);
151  boolProxy = gPrefs->Read(base + wxT("Normalize"), 1);
152  mGain = (boolProxy == 1);
153  gPrefs->Read(base + wxT("Level"), &mPeakLevel, -1.0);
154  if(mPeakLevel > 0.0) // this should never happen
156  boolProxy = gPrefs->Read(base + wxT("StereoIndependent"), 0L);
157  mStereoInd = (boolProxy == 1);
158 
160 
161  // Do not migrate again
162  gPrefs->Write(base + wxT("Migrated"), true);
163  gPrefs->Flush();
164  }
165 
166  return true;
167 }

References FileConfig::Flush(), Effect::GetCurrentSettingsGroup(), gPrefs, mDC, mGain, mPeakLevel, mStereoInd, and Effect::SaveUserPreset().

Here is the call graph for this function:

◆ TransferDataFromWindow()

bool EffectNormalize::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 352 of file Normalize.cpp.

353 {
354  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
355  {
356  return false;
357  }
358 
359  return true;
360 }

References Effect::mUIParent.

◆ TransferDataToWindow()

bool EffectNormalize::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 340 of file Normalize.cpp.

341 {
342  if (!mUIParent->TransferDataToWindow())
343  {
344  return false;
345  }
346 
347  UpdateUI();
348 
349  return true;
350 }

References Effect::mUIParent, and UpdateUI().

Here is the call graph for this function:

◆ UpdateUI()

void EffectNormalize::UpdateUI ( void  )
private

Definition at line 542 of file Normalize.cpp.

543 {
544 
545  if (!mUIParent->TransferDataFromWindow())
546  {
547  mWarning->SetLabel(_("(Maximum 0dB)"));
548  EnableApply(false);
549  return;
550  }
551  mWarning->SetLabel(wxT(""));
552 
553  // Disallow level stuff if not normalizing
554  mLevelTextCtrl->Enable(mGain);
555  mLeveldB->Enable(mGain);
556  mStereoIndCheckBox->Enable(mGain);
557 
558  // Disallow OK/Preview if doing nothing
559  EnableApply(mGain || mDC);
560 }

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

Referenced by OnUpdateUI(), and TransferDataToWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mCreating

bool EffectNormalize::mCreating
private

Definition at line 88 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mCurT0

double EffectNormalize::mCurT0
private

Definition at line 77 of file Normalize.h.

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

◆ mCurT1

double EffectNormalize::mCurT1
private

Definition at line 78 of file Normalize.h.

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

◆ mDC

bool EffectNormalize::mDC
private

◆ mDCCheckBox

wxCheckBox* EffectNormalize::mDCCheckBox
private

Definition at line 83 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mGain

bool EffectNormalize::mGain
private

◆ mGainCheckBox

wxCheckBox* EffectNormalize::mGainCheckBox
private

Definition at line 82 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mLeveldB

wxStaticText* EffectNormalize::mLeveldB
private

Definition at line 85 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mLevelTextCtrl

wxTextCtrl* EffectNormalize::mLevelTextCtrl
private

Definition at line 84 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mMult

float EffectNormalize::mMult
private

Definition at line 79 of file Normalize.h.

Referenced by Process(), and ProcessData().

◆ mPeakLevel

double EffectNormalize::mPeakLevel
private

◆ mStereoInd

bool EffectNormalize::mStereoInd
private

◆ mStereoIndCheckBox

wxCheckBox* EffectNormalize::mStereoIndCheckBox
private

Definition at line 87 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mSum

double EffectNormalize::mSum
private

Definition at line 80 of file Normalize.h.

Referenced by AnalyseDataDC(), and AnalyseTrackData().

◆ mWarning

wxStaticText* EffectNormalize::mWarning
private

Definition at line 86 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ Symbol

const ComponentInterfaceSymbol EffectNormalize::Symbol { XO("Normalize") }
static

Definition at line 26 of file Normalize.h.

Referenced by GetSymbol().


The documentation for this class was generated from the following files:
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
EffectNormalize::mStereoInd
bool mStereoInd
Definition: Normalize.h:75
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
EffectNormalize::UpdateUI
void UpdateUI()
Definition: Normalize.cpp:542
EffectNormalize::ProcessOne
bool ProcessOne(WaveTrack *t, const TranslatableString &msg, double &progress, float offset)
Definition: Normalize.cpp:468
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:59
DB_TO_LINEAR
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
Effect::SetLinearEffectFlag
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:2001
Effect::EnableApply
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1926
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:2071
EffectNormalize::mLevelTextCtrl
wxTextCtrl * mLevelTextCtrl
Definition: Normalize.h:84
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1280
Effect::mT1
double mT1
Definition: Effect.h:467
Validator
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
Definition: Validators.h:53
ShuttleGui::MinSize
ShuttleGui & MinSize()
Definition: ShuttleGui.h:733
XO
#define XO(s)
Definition: Internat.h:31
WaveTrack::GetMinMax
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
Definition: WaveTrack.cpp:1920
EffectNormalize::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: Normalize.h:26
Track::Any
bool Any() const
Definition: Track.cpp:370
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
EffectNormalize::ProcessData
void ProcessData(float *buffer, size_t len, float offset)
Definition: Normalize.cpp:529
Effect::SaveUserPreset
bool SaveUserPreset(const RegistryPath &name) override
Definition: Effect.cpp:570
EffectNormalize::mGainCheckBox
wxCheckBox * mGainCheckBox
Definition: Normalize.h:82
fillZero
@ fillZero
Definition: SampleFormat.h:54
EffectNormalize::mPeakLevel
double mPeakLevel
Definition: Normalize.h:72
EffectNormalize::mCurT0
double mCurT0
Definition: Normalize.h:77
floatSample
@ floatSample
Definition: SampleFormat.h:34
EffectNormalize::AnalyseTrackData
bool AnalyseTrackData(const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset)
Definition: Normalize.cpp:403
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
Effect::mT0
double mT0
Definition: Effect.h:466
sampleCount::as_double
double as_double() const
Definition: SampleCount.h:45
EffectNormalize::mSum
double mSum
Definition: Normalize.h:80
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
EffectNormalize::mWarning
wxStaticText * mWarning
Definition: Normalize.h:86
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2193
EffectNormalize::mMult
float mMult
Definition: Normalize.h:79
ShuttleGui::Validator
ShuttleGui & Validator(const Factory &f)
Definition: ShuttleGui.h:678
EffectNormalize::AnalyseTrack
bool AnalyseTrack(const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset, float &extent)
Definition: Normalize.cpp:364
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:465
EffectNormalize::mGain
bool mGain
Definition: Normalize.h:73
ReadAndVerifyDouble
#define ReadAndVerifyDouble(name)
Definition: Effect.h:633
Effect::GetCurrentSettingsGroup
RegistryPath GetCurrentSettingsGroup() override
Definition: Effect.cpp:866
EffectNormalize::AnalyseDataDC
void AnalyseDataDC(float *buffer, size_t len)
Definition: Normalize.cpp:523
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
WaveTrack::GetMaxBlockSize
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:1669
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
ShuttleGui::Name
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:663
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
WaveTrack::TimeToLongSamples
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1865
EffectNormalize::mDC
bool mDC
Definition: Normalize.h:74
Effect::mUIParent
wxWindow * mUIParent
Definition: Effect.h:478
Track::IsLeader
bool IsLeader() const
Definition: Track.cpp:379
EffectNormalize::mLeveldB
wxStaticText * mLeveldB
Definition: Normalize.h:85
_
#define _(s)
Definition: Internat.h:75
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
Effect::TotalProgress
bool TotalProgress(double frac, const TranslatableString &={})
Definition: Effect.cpp:2017
Effect::GetNumWaveTracks
int GetNumWaveTracks()
Definition: Effect.h:345
TrapDouble
double TrapDouble(double x, double min, double max)
Definition: Effect.h:564
WaveTrack::GetBestBlockSize
size_t GetBestBlockSize(sampleCount t) const
Definition: WaveTrack.cpp:1651
EffectNormalize::mCurT1
double mCurT1
Definition: Normalize.h:78
ShuttleGuiBase::AddVariableText
wxStaticText * AddVariableText(const TranslatableString &Str, bool bCenter=false, int PositionFlags=0, int wrapWidth=0)
Definition: ShuttleGui.cpp:463
TrackList::SingletonRange
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1439
limitSampleBufferSize
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
WaveTrack::GetFloats
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: WaveTrack.h:265
EffectNormalize::mCreating
bool mCreating
Definition: Normalize.h:88
ArrayOf< float >
EffectNormalize::mDCCheckBox
wxCheckBox * mDCCheckBox
Definition: Normalize.h:83
EffectNormalize::mStereoIndCheckBox
wxCheckBox * mStereoIndCheckBox
Definition: Normalize.h:87
ReadAndVerifyBool
#define ReadAndVerifyBool(name)
Definition: Effect.h:635