Audacity  3.2.0
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
EffectLoudness Class Referencefinal

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

#include <Loudness.h>

Inheritance diagram for EffectLoudness:
[legend]
Collaboration diagram for EffectLoudness:
[legend]

Public Member Functions

 EffectLoudness ()
 
virtual ~EffectLoudness ()
 
ComponentInterfaceSymbol GetSymbol () override
 
TranslatableString GetDescription () override
 
ManualPageID ManualPage () override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
EffectType GetType () override
 Type determines how it behaves. More...
 
bool GetAutomationParameters (CommandParameters &parms) override
 Save current settings into parms. More...
 
bool SetAutomationParameters (CommandParameters &parms) override
 Change settings to those stored in parms. More...
 
bool DefineParams (ShuttleParams &S) 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
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () override
 Whether the effect sorts "above the line" in the menus. More...
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 Whether the effect supports realtime previewing (while audio is playing). More...
 
bool SupportsAutomation () override
 Whether the effect can be used without the UI, in a macro. More...
 
bool LoadUserPreset (const RegistryPath &name) override
 Change settings to a user-named preset. More...
 
bool SaveUserPreset (const RegistryPath &name) override
 Save current settings as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () override
 Report names of factory presets. More...
 
bool LoadFactoryPreset (int id) override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults () override
 Change settings back to "factory default". More...
 
bool SetHost (EffectHostInterface *host) override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 Called for destructive, non-realtime effect computation. More...
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
size_t GetBlockSize () const override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 Called for destructive, non-realtime effect computation. More...
 
bool ProcessFinalize () override
 Called for destructive, non-realtime effect computation. More...
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 Called for destructive, non-realtime effect computation. More...
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () noexcept override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () noexcept override
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
bool PopulateUI (ShuttleGui &S) final
 Adds controls to a panel that is given as the parent window of S More...
 
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
 
EffectDefinitionInterfaceGetDefinition () 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 ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, bool forceModal=false) override
 
unsigned TestUIFlags (unsigned mask)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
virtual bool Startup (EffectUIClientInterface *client)
 
virtual bool GetAutomationParametersAsString (wxString &parms)
 
virtual bool SetAutomationParametersFromString (const wxString &parms)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={})
 
bool Delegate (Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory)
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
- Public Member Functions inherited from EffectProcessor
virtual ~EffectProcessor ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetClassification ()
 Determines which menu it appears in; default same as GetType(). More...
 
virtual bool EnablesDebug ()
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual FilePath HelpPage ()
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus ()
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 
- Public Member Functions inherited from EffectUIHostInterface
virtual ~EffectUIHostInterface ()
 
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Loudness Normalization") }
 
- 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

void AllocBuffers ()
 
void FreeBuffers ()
 
bool GetTrackRMS (WaveTrack *track, float &rms)
 
bool ProcessOne (TrackIterRange< WaveTrack > range, bool analyse)
 
void LoadBufferBlock (TrackIterRange< WaveTrack > range, sampleCount pos, size_t len)
 
bool AnalyseBufferBlock ()
 
bool ProcessBufferBlock ()
 
void StoreBufferBlock (TrackIterRange< WaveTrack > range, sampleCount pos, size_t len)
 
bool UpdateProgress ()
 
void OnChoice (wxCommandEvent &evt)
 
void OnUpdateUI (wxCommandEvent &evt)
 
void UpdateUI ()
 

Private Attributes

bool mStereoInd
 
double mLUFSLevel
 
double mRMSLevel
 
bool mDualMono
 
int mNormalizeTo
 
double mCurT0
 
double mCurT1
 
double mProgressVal
 
int mSteps
 
TranslatableString mProgressMsg
 
double mTrackLen
 
double mCurRate
 
float mMult
 
float mRatio
 
float mRMS [2]
 
std::unique_ptr< EBUR128mLoudnessProcessor
 
wxSimplebook * mBook
 
wxChoice * mChoice
 
wxStaticText * mWarning
 
wxCheckBox * mStereoIndCheckBox
 
wxCheckBox * mDualMonoCheckBox
 
Floats mTrackBuffer [2]
 
size_t mTrackBufferLen
 
size_t mTrackBufferCapacity
 
bool mProcStereo
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Static Public Member Functions inherited from Effect
static void IncEffectCounter ()
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Protected Member Functions inherited from Effect
bool EnableApply (bool enable=true)
 
bool EnablePreview (bool enable=true)
 
virtual bool Init ()
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual void End ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
virtual void Preview (bool dryOnly)
 
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
BasicUI::ProgressDialogmProgress = nullptr
 
double mProjectRate
 
double mSampleRate
 
WaveTrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWeakRef< wxDialog > mUIDialog
 This weak pointer may be the same as the above, or null. More...
 
wxWindow * mUIParent
 
unsigned mUIFlags { 0 }
 
sampleCount mSampleCnt
 
- Static Protected Attributes inherited from Effect
static int nEffectsDone =0
 

Detailed Description

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

Definition at line 29 of file Loudness.h.

Constructor & Destructor Documentation

◆ EffectLoudness()

EffectLoudness::EffectLoudness ( )

Definition at line 69 of file Loudness.cpp.

70 {
71  mStereoInd = DEF_StereoInd;
72  mLUFSLevel = DEF_LUFSLevel;
73  mRMSLevel = DEF_RMSLevel;
74  mDualMono = DEF_DualMono;
75  mNormalizeTo = DEF_NormalizeTo;
76 
77  SetLinearEffectFlag(false);
78 }

References mDualMono, mLUFSLevel, mNormalizeTo, mRMSLevel, mStereoInd, and Effect::SetLinearEffectFlag().

Here is the call graph for this function:

◆ ~EffectLoudness()

EffectLoudness::~EffectLoudness ( )
virtual

Definition at line 80 of file Loudness.cpp.

81 {
82 }

Member Function Documentation

◆ AllocBuffers()

void EffectLoudness::AllocBuffers ( )
private

Get required buffer size for the largest whole track and allocate buffers. This reduces the amount of allocations required.

Definition at line 413 of file Loudness.cpp.

414 {
416  bool stereoTrackFound = false;
417  double maxSampleRate = 0;
418  mProcStereo = false;
419 
420  for(auto track : mOutputTracks->Selected<WaveTrack>() + &Track::Any)
421  {
422  mTrackBufferCapacity = std::max(mTrackBufferCapacity, track->GetMaxBlockSize());
423  maxSampleRate = std::max(maxSampleRate, track->GetRate());
424 
425  // There is a stereo track
426  if(track->IsLeader())
427  stereoTrackFound = true;
428  }
429 
430  // Initiate a processing buffer. This buffer will (most likely)
431  // be shorter than the length of the track being processed.
433 
434  if(!mStereoInd && stereoTrackFound)
436 }

References Track::Any(), Effect::mOutputTracks, mProcStereo, mStereoInd, mTrackBuffer, mTrackBufferCapacity, and ArrayOf< X >::reinit().

Referenced by Process().

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

◆ AnalyseBufferBlock()

bool EffectLoudness::AnalyseBufferBlock ( )
private

Calculates sample sum (for DC) and EBU R128 weighted square sum (for loudness).

Definition at line 526 of file Loudness.cpp.

527 {
528  for(size_t i = 0; i < mTrackBufferLen; i++)
529  {
530  mLoudnessProcessor->ProcessSampleFromChannel(mTrackBuffer[0][i], 0);
531  if(mProcStereo)
532  mLoudnessProcessor->ProcessSampleFromChannel(mTrackBuffer[1][i], 1);
533  mLoudnessProcessor->NextSample();
534  }
535 
536  if(!UpdateProgress())
537  return false;
538  return true;
539 }

References mLoudnessProcessor, mProcStereo, mTrackBuffer, mTrackBufferLen, and UpdateProgress().

Referenced by ProcessOne().

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

◆ CheckWhetherSkipEffect()

bool EffectLoudness::CheckWhetherSkipEffect ( )
overridevirtual

Reimplemented from Effect.

Definition at line 149 of file Loudness.cpp.

150 {
151  return false;
152 }

◆ DefineParams()

bool EffectLoudness::DefineParams ( ShuttleParams S)
override

Definition at line 109 of file Loudness.cpp.

110 {
111  S.SHUTTLE_PARAM( mStereoInd, StereoInd );
112  S.SHUTTLE_PARAM( mLUFSLevel, LUFSLevel );
113  S.SHUTTLE_PARAM( mRMSLevel, RMSLevel );
114  S.SHUTTLE_PARAM( mDualMono, DualMono );
115  S.SHUTTLE_PARAM( mNormalizeTo, NormalizeTo );
116  return true;
117 }

References mDualMono, mLUFSLevel, mNormalizeTo, mRMSLevel, mStereoInd, and S.

◆ FreeBuffers()

void EffectLoudness::FreeBuffers ( )
private

Definition at line 438 of file Loudness.cpp.

439 {
440  mTrackBuffer[0].reset();
441  mTrackBuffer[1].reset();
442 }

References mTrackBuffer.

Referenced by Process().

Here is the caller graph for this function:

◆ GetAutomationParameters()

bool EffectLoudness::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Save current settings into parms.

Reimplemented from Effect.

Definition at line 119 of file Loudness.cpp.

120 {
121  parms.Write(KEY_StereoInd, mStereoInd);
122  parms.Write(KEY_LUFSLevel, mLUFSLevel);
123  parms.Write(KEY_RMSLevel, mRMSLevel);
124  parms.Write(KEY_DualMono, mDualMono);
125  parms.Write(KEY_NormalizeTo, mNormalizeTo);
126 
127  return true;
128 }

References mDualMono, mLUFSLevel, mNormalizeTo, mRMSLevel, and mStereoInd.

◆ GetDescription()

TranslatableString EffectLoudness::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 91 of file Loudness.cpp.

92 {
93  return XO("Sets the loudness of one or more tracks");
94 }

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectLoudness::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 86 of file Loudness.cpp.

87 {
88  return Symbol;
89 }

References Symbol.

◆ GetTrackRMS()

bool EffectLoudness::GetTrackRMS ( WaveTrack track,
float &  rms 
)
private

Definition at line 444 of file Loudness.cpp.

445 {
446  // set mRMS. No progress bar here as it's fast.
447  float _rms = track->GetRMS(mCurT0, mCurT1); // may throw
448  rms = _rms;
449  return true;
450 }

References WaveTrack::GetRMS(), mCurT0, and mCurT1.

Referenced by Process().

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

◆ GetType()

EffectType EffectLoudness::GetType ( )
overridevirtual

Type determines how it behaves.

Reimplemented from Effect.

Definition at line 103 of file Loudness.cpp.

104 {
105  return EffectTypeProcess;
106 }

References EffectTypeProcess.

◆ LoadBufferBlock()

void EffectLoudness::LoadBufferBlock ( TrackIterRange< WaveTrack range,
sampleCount  pos,
size_t  len 
)
private

Definition at line 511 of file Loudness.cpp.

513 {
514  // Get the samples from the track and put them in the buffer
515  int idx = 0;
516  for(auto channel : range)
517  {
518  channel->GetFloats(mTrackBuffer[idx].get(), pos, len );
519  ++idx;
520  }
521  mTrackBufferLen = len;
522 }

References mTrackBuffer, and mTrackBufferLen.

Referenced by ProcessOne().

Here is the caller graph for this function:

◆ ManualPage()

ManualPageID EffectLoudness::ManualPage ( )
overridevirtual

Name of a page in the Audacity alpha manual, default is empty.

Reimplemented from EffectDefinitionInterface.

Definition at line 96 of file Loudness.cpp.

97 {
98  return L"Loudness_Normalization";
99 }

◆ OnChoice()

void EffectLoudness::OnChoice ( wxCommandEvent &  evt)
private

Definition at line 574 of file Loudness.cpp.

575 {
576  mChoice->GetValidator()->TransferFromWindow();
577  mBook->SetSelection( mNormalizeTo );
578  UpdateUI();
580 }

References kLoudness, mBook, mChoice, mDualMonoCheckBox, mNormalizeTo, and UpdateUI().

Referenced by TransferDataToWindow().

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

◆ OnUpdateUI()

void EffectLoudness::OnUpdateUI ( wxCommandEvent &  evt)
private

Definition at line 582 of file Loudness.cpp.

583 {
584  UpdateUI();
585 }

References UpdateUI().

Here is the call graph for this function:

◆ PopulateOrExchange()

void EffectLoudness::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 291 of file Loudness.cpp.

292 {
293  S.StartVerticalLay(0);
294  {
295  S.StartMultiColumn(2, wxALIGN_CENTER);
296  {
297  S.StartVerticalLay(false);
298  {
299  S.StartHorizontalLay(wxALIGN_LEFT, false);
300  {
301  S.AddVariableText(XO("&Normalize"), false,
302  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
303 
304  mChoice = S
305  .Validator<wxGenericValidator>( &mNormalizeTo )
306  .AddChoice( {},
308  mNormalizeTo );
309  S
310  .AddVariableText(XO("t&o"), false,
311  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
312 
313  // Use a notebook so we can have two controls but show only one
314  // They target different variables with their validators
315  mBook =
316  S
317  .StartSimplebook();
318  {
319  S.StartNotebookPage({});
320  {
321  S.StartHorizontalLay(wxALIGN_LEFT, false);
322  {
323  S
324  /* i18n-hint: LUFS is a particular method for measuring loudnesss */
325  .Name( XO("Loudness LUFS") )
326  .Validator<FloatingPointValidator<double>>(
327  2, &mLUFSLevel,
328  NumValidatorStyle::ONE_TRAILING_ZERO,
329  MIN_LUFSLevel, MAX_LUFSLevel )
330  .AddTextBox( {}, wxT(""), 10);
331 
332  /* i18n-hint: LUFS is a particular method for measuring loudnesss */
333  S
334  .AddVariableText(XO("LUFS"), false,
335  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
336  }
337  S.EndHorizontalLay();
338  }
339  S.EndNotebookPage();
340 
341  S.StartNotebookPage({});
342  {
343  S.StartHorizontalLay(wxALIGN_LEFT, false);
344  {
345  S
346  .Name( XO("RMS dB") )
347  .Validator<FloatingPointValidator<double>>(
348  2, &mRMSLevel,
349  NumValidatorStyle::ONE_TRAILING_ZERO,
350  MIN_RMSLevel, MAX_RMSLevel )
351  .AddTextBox( {}, wxT(""), 10);
352 
353  S
354  .AddVariableText(XO("dB"), false,
355  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
356  }
357  S.EndHorizontalLay();
358  }
359  S.EndNotebookPage();
360  }
361  S.EndSimplebook();
362 
363  mWarning =
364  S
365  .AddVariableText( {}, false,
366  wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
367  }
368  S.EndHorizontalLay();
369 
371  .Validator<wxGenericValidator>( &mStereoInd )
372  .AddCheckBox(XXO("Normalize &stereo channels independently"),
373  mStereoInd );
374 
376  .Validator<wxGenericValidator>( &mDualMono )
377  .AddCheckBox(XXO("&Treat mono as dual-mono (recommended)"),
378  mDualMono );
379  }
380  S.EndVerticalLay();
381  }
382  S.EndMultiColumn();
383  }
384  S.EndVerticalLay();
385 }

References kNormalizeTargetStrings, mBook, mChoice, mDualMono, mDualMonoCheckBox, mLUFSLevel, mNormalizeTo, mRMSLevel, Msgids(), mStereoInd, mStereoIndCheckBox, mWarning, nAlgos, S, XO, and XXO.

Here is the call graph for this function:

◆ Process()

bool EffectLoudness::Process ( )
overridevirtual

If Process() is not overridden, it uses ProcessInitialize(), ProcessBlock(), and ProcessFinalize() methods of EffectProcessor, and also GetLatency() to determine how many leading output samples to discard and how many extra samples to produce.

Reimplemented from Effect.

Definition at line 173 of file Loudness.cpp.

174 {
175  if(mNormalizeTo == kLoudness)
176  // LU use 10*log10(...) instead of 20*log10(...)
177  // so multiply level by 2 and use standard DB_TO_LINEAR macro.
178  mRatio = DB_TO_LINEAR(TrapDouble(mLUFSLevel*2, MIN_LUFSLevel, MAX_LUFSLevel));
179  else // RMS
180  mRatio = DB_TO_LINEAR(TrapDouble(mRMSLevel, MIN_RMSLevel, MAX_RMSLevel));
181 
182  // Iterate over each track
183  this->CopyInputTracks(); // Set up mOutputTracks.
184  bool bGoodResult = true;
185  auto topMsg = XO("Normalizing Loudness...\n");
186 
187  AllocBuffers();
188  mProgressVal = 0;
189 
190  for(auto track : mOutputTracks->Selected<WaveTrack>()
192  {
193  // Get start and end times from track
194  // PRL: No accounting for multiple channels ?
195  double trackStart = track->GetStartTime();
196  double trackEnd = track->GetEndTime();
197 
198  // Set the current bounds to whichever left marker is
199  // greater and whichever right marker is less:
200  mCurT0 = mT0 < trackStart? trackStart: mT0;
201  mCurT1 = mT1 > trackEnd? trackEnd: mT1;
202 
203  // Get the track rate
204  mCurRate = track->GetRate();
205 
206  wxString msg;
207  auto trackName = track->GetName();
208  mSteps = 2;
209 
210  mProgressMsg =
211  topMsg + XO("Analyzing: %s").Format( trackName );
212 
213  auto range = mStereoInd
215  : TrackList::Channels(track);
216 
217  mProcStereo = range.size() > 1;
218 
219  if(mNormalizeTo == kLoudness)
220  {
221  mLoudnessProcessor.reset(safenew EBUR128(mCurRate, range.size()));
222  mLoudnessProcessor->Initialize();
223  if(!ProcessOne(range, true))
224  {
225  // Processing failed -> abort
226  bGoodResult = false;
227  break;
228  }
229  }
230  else // RMS
231  {
232  size_t idx = 0;
233  for(auto channel : range)
234  {
235  if(!GetTrackRMS(channel, mRMS[idx]))
236  {
237  bGoodResult = false;
238  return false;
239  }
240  ++idx;
241  }
242  mSteps = 1;
243  }
244 
245  // Calculate normalization values the analysis results
246  float extent;
247  if(mNormalizeTo == kLoudness)
248  extent = mLoudnessProcessor->IntegrativeLoudness();
249  else // RMS
250  {
251  extent = mRMS[0];
252  if(mProcStereo)
253  // RMS: use average RMS, average must be calculated in quadratic domain.
254  extent = sqrt((mRMS[0] * mRMS[0] + mRMS[1] * mRMS[1]) / 2.0);
255  }
256 
257  if(extent == 0.0)
258  {
259  mLoudnessProcessor.reset();
260  FreeBuffers();
261  return false;
262  }
263  mMult = mRatio / extent;
264 
265  if(mNormalizeTo == kLoudness)
266  {
267  // Target half the LUFS value if mono (or independent processed stereo)
268  // shall be treated as dual mono.
269  if(range.size() == 1 && (mDualMono || track->GetChannel() != Track::MonoChannel))
270  mMult /= 2.0;
271 
272  // LUFS are related to square values so the multiplier must be the root.
273  mMult = sqrt(mMult);
274  }
275 
276  mProgressMsg = topMsg + XO("Processing: %s").Format( trackName );
277  if(!ProcessOne(range, false))
278  {
279  // Processing failed -> abort
280  bGoodResult = false;
281  break;
282  }
283  }
284 
285  this->ReplaceProcessedTracks(bGoodResult);
286  mLoudnessProcessor.reset();
287  FreeBuffers();
288  return bGoodResult;
289 }

References AllocBuffers(), Track::Any(), TrackList::Channels(), Effect::CopyInputTracks(), DB_TO_LINEAR(), FreeBuffers(), GetTrackRMS(), Track::IsLeader(), kLoudness, mCurRate, mCurT0, mCurT1, mDualMono, mLoudnessProcessor, mLUFSLevel, mMult, mNormalizeTo, Track::MonoChannel, Effect::mOutputTracks, mProcStereo, mProgressMsg, mProgressVal, mRatio, mRMS, mRMSLevel, mSteps, mStereoInd, Effect::mT0, Effect::mT1, ProcessOne(), Effect::ReplaceProcessedTracks(), safenew, TrackList::SingletonRange(), TrapDouble(), and XO.

Here is the call graph for this function:

◆ ProcessBufferBlock()

bool EffectLoudness::ProcessBufferBlock ( )
private

Definition at line 541 of file Loudness.cpp.

542 {
543  for(size_t i = 0; i < mTrackBufferLen; i++)
544  {
545  mTrackBuffer[0][i] = mTrackBuffer[0][i] * mMult;
546  if(mProcStereo)
547  mTrackBuffer[1][i] = mTrackBuffer[1][i] * mMult;
548  }
549 
550  if(!UpdateProgress())
551  return false;
552  return true;
553 }

References mMult, mProcStereo, mTrackBuffer, mTrackBufferLen, and UpdateProgress().

Referenced by ProcessOne().

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

◆ ProcessOne()

bool EffectLoudness::ProcessOne ( TrackIterRange< WaveTrack range,
bool  analyse 
)
private

ProcessOne() takes a track, transforms it to bunch of buffer-blocks, and executes ProcessData, on it... uses mMult to normalize a track. mMult must be set before this is called In analyse mode, it executes the selected analyse operation on it... mMult does not have to be set before this is called

Definition at line 458 of file Loudness.cpp.

459 {
460  WaveTrack* track = *range.begin();
461 
462  // Transform the marker timepoints to samples
463  auto start = track->TimeToLongSamples(mCurT0);
464  auto end = track->TimeToLongSamples(mCurT1);
465 
466  // Get the length of the buffer (as double). len is
467  // used simply to calculate a progress meter, so it is easier
468  // to make it a double now than it is to do it later
469  mTrackLen = (end - start).as_double();
470 
471  // Abort if the right marker is not to the right of the left marker
472  if(mCurT1 <= mCurT0)
473  return false;
474 
475  // Go through the track one buffer at a time. s counts which
476  // sample the current buffer starts at.
477  auto s = start;
478  while(s < end)
479  {
480  // Get a block of samples (smaller than the size of the buffer)
481  // Adjust the block size if it is the final block in the track
482  auto blockLen = limitSampleBufferSize(
483  track->GetBestBlockSize(s),
485 
486  const size_t remainingLen = (end - s).as_size_t();
487  blockLen = blockLen > remainingLen ? remainingLen : blockLen;
488  LoadBufferBlock(range, s, blockLen);
489 
490  // Process the buffer.
491  if(analyse)
492  {
493  if(!AnalyseBufferBlock())
494  return false;
495  }
496  else
497  {
498  if(!ProcessBufferBlock())
499  return false;
500  StoreBufferBlock(range, s, blockLen);
501  }
502 
503  // Increment s one blockfull of samples
504  s += blockLen;
505  }
506 
507  // Return true because the effect processing succeeded ... unless cancelled
508  return true;
509 }

References AnalyseBufferBlock(), WaveTrack::GetBestBlockSize(), limitSampleBufferSize(), LoadBufferBlock(), mCurT0, mCurT1, mTrackBufferCapacity, mTrackLen, ProcessBufferBlock(), StoreBufferBlock(), and SampleTrack::TimeToLongSamples().

Referenced by Process().

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

◆ SetAutomationParameters()

bool EffectLoudness::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Change settings to those stored in parms.

Reimplemented from Effect.

Definition at line 130 of file Loudness.cpp.

131 {
132  ReadAndVerifyBool(StereoInd);
133  ReadAndVerifyDouble(LUFSLevel);
134  ReadAndVerifyDouble(RMSLevel);
135  ReadAndVerifyBool(DualMono);
136  ReadAndVerifyInt(NormalizeTo);
137 
138  mStereoInd = StereoInd;
139  mLUFSLevel = LUFSLevel;
140  mRMSLevel = RMSLevel;
141  mDualMono = DualMono;
142  mNormalizeTo = NormalizeTo;
143 
144  return true;
145 }

References mDualMono, mLUFSLevel, mNormalizeTo, mRMSLevel, mStereoInd, ReadAndVerifyBool, ReadAndVerifyDouble, and ReadAndVerifyInt.

◆ Startup()

bool EffectLoudness::Startup ( )
overridevirtual

Reimplemented from Effect.

Definition at line 154 of file Loudness.cpp.

155 {
156  wxString base = wxT("/Effects/Loudness/");
157  // Load the old "current" settings
158  if (gPrefs->Exists(base))
159  {
160  mStereoInd = false;
161  mDualMono = DEF_DualMono;
163  mLUFSLevel = DEF_LUFSLevel;
164  mRMSLevel = DEF_RMSLevel;
165 
167 
168  gPrefs->Flush();
169  }
170  return true;
171 }

References FileConfig::Flush(), Effect::GetCurrentSettingsGroup(), gPrefs, kLoudness, mDualMono, mLUFSLevel, mNormalizeTo, mRMSLevel, mStereoInd, and Effect::SaveUserPreset().

Here is the call graph for this function:

◆ StoreBufferBlock()

void EffectLoudness::StoreBufferBlock ( TrackIterRange< WaveTrack range,
sampleCount  pos,
size_t  len 
)
private

Definition at line 555 of file Loudness.cpp.

557 {
558  int idx = 0;
559  for(auto channel : range)
560  {
561  // Copy the newly-changed samples back onto the track.
562  channel->Set((samplePtr) mTrackBuffer[idx].get(), floatSample, pos, len);
563  ++idx;
564  }
565 }

References floatSample, and mTrackBuffer.

Referenced by ProcessOne().

Here is the caller graph for this function:

◆ TransferDataFromWindow()

bool EffectLoudness::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 400 of file Loudness.cpp.

401 {
402  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
403  {
404  return false;
405  }
406  return true;
407 }

References Effect::mUIParent.

◆ TransferDataToWindow()

bool EffectLoudness::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 387 of file Loudness.cpp.

388 {
389  if (!mUIParent->TransferDataToWindow())
390  {
391  return false;
392  }
393 
394  // adjust controls which depend on mchoice
395  wxCommandEvent dummy;
396  OnChoice(dummy);
397  return true;
398 }

References Effect::mUIParent, and OnChoice().

Here is the call graph for this function:

◆ UpdateProgress()

bool EffectLoudness::UpdateProgress ( )
private

Definition at line 567 of file Loudness.cpp.

568 {
569  mProgressVal += (double(1+mProcStereo) * double(mTrackBufferLen)
570  / (double(GetNumWaveTracks()) * double(mSteps) * mTrackLen));
572 }

References Effect::GetNumWaveTracks(), mProcStereo, mProgressMsg, mProgressVal, mSteps, mTrackBufferLen, mTrackLen, and Effect::TotalProgress().

Referenced by AnalyseBufferBlock(), and ProcessBufferBlock().

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

◆ UpdateUI()

void EffectLoudness::UpdateUI ( void  )
private

Definition at line 587 of file Loudness.cpp.

588 {
589  if (!mUIParent->TransferDataFromWindow())
590  {
591  mWarning->SetLabel(_("(Maximum 0dB)"));
592  // TODO: recalculate layout here
593  EnableApply(false);
594  return;
595  }
596  mWarning->SetLabel(wxT(""));
597  EnableApply(true);
598 }

References _, Effect::EnableApply(), Effect::mUIParent, and mWarning.

Referenced by OnChoice(), and OnUpdateUI().

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

Member Data Documentation

◆ mBook

wxSimplebook* EffectLoudness::mBook
private

Definition at line 101 of file Loudness.h.

Referenced by OnChoice(), and PopulateOrExchange().

◆ mChoice

wxChoice* EffectLoudness::mChoice
private

Definition at line 102 of file Loudness.h.

Referenced by OnChoice(), and PopulateOrExchange().

◆ mCurRate

double EffectLoudness::mCurRate
private

Definition at line 94 of file Loudness.h.

Referenced by Process().

◆ mCurT0

double EffectLoudness::mCurT0
private

Definition at line 88 of file Loudness.h.

Referenced by GetTrackRMS(), Process(), and ProcessOne().

◆ mCurT1

double EffectLoudness::mCurT1
private

Definition at line 89 of file Loudness.h.

Referenced by GetTrackRMS(), Process(), and ProcessOne().

◆ mDualMono

bool EffectLoudness::mDualMono
private

◆ mDualMonoCheckBox

wxCheckBox* EffectLoudness::mDualMonoCheckBox
private

Definition at line 105 of file Loudness.h.

Referenced by OnChoice(), and PopulateOrExchange().

◆ mLoudnessProcessor

std::unique_ptr<EBUR128> EffectLoudness::mLoudnessProcessor
private

Definition at line 99 of file Loudness.h.

Referenced by AnalyseBufferBlock(), and Process().

◆ mLUFSLevel

double EffectLoudness::mLUFSLevel
private

◆ mMult

float EffectLoudness::mMult
private

Definition at line 96 of file Loudness.h.

Referenced by Process(), and ProcessBufferBlock().

◆ mNormalizeTo

int EffectLoudness::mNormalizeTo
private

◆ mProcStereo

bool EffectLoudness::mProcStereo
private

◆ mProgressMsg

TranslatableString EffectLoudness::mProgressMsg
private

Definition at line 92 of file Loudness.h.

Referenced by Process(), and UpdateProgress().

◆ mProgressVal

double EffectLoudness::mProgressVal
private

Definition at line 90 of file Loudness.h.

Referenced by Process(), and UpdateProgress().

◆ mRatio

float EffectLoudness::mRatio
private

Definition at line 97 of file Loudness.h.

Referenced by Process().

◆ mRMS

float EffectLoudness::mRMS[2]
private

Definition at line 98 of file Loudness.h.

Referenced by Process().

◆ mRMSLevel

double EffectLoudness::mRMSLevel
private

◆ mSteps

int EffectLoudness::mSteps
private

Definition at line 91 of file Loudness.h.

Referenced by Process(), and UpdateProgress().

◆ mStereoInd

bool EffectLoudness::mStereoInd
private

◆ mStereoIndCheckBox

wxCheckBox* EffectLoudness::mStereoIndCheckBox
private

Definition at line 104 of file Loudness.h.

Referenced by PopulateOrExchange().

◆ mTrackBuffer

Floats EffectLoudness::mTrackBuffer[2]
private

◆ mTrackBufferCapacity

size_t EffectLoudness::mTrackBufferCapacity
private

Definition at line 109 of file Loudness.h.

Referenced by AllocBuffers(), and ProcessOne().

◆ mTrackBufferLen

size_t EffectLoudness::mTrackBufferLen
private

◆ mTrackLen

double EffectLoudness::mTrackLen
private

Definition at line 93 of file Loudness.h.

Referenced by ProcessOne(), and UpdateProgress().

◆ mWarning

wxStaticText* EffectLoudness::mWarning
private

Definition at line 103 of file Loudness.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ Symbol

const ComponentInterfaceSymbol EffectLoudness::Symbol { XO("Loudness Normalization") }
static

Definition at line 32 of file Loudness.h.

Referenced by GetSymbol().


The documentation for this class was generated from the following files:
EffectLoudness::mCurT0
double mCurT0
Definition: Loudness.h:88
EffectLoudness::GetTrackRMS
bool GetTrackRMS(WaveTrack *track, float &rms)
Definition: Loudness.cpp:444
EffectLoudness::mDualMonoCheckBox
wxCheckBox * mDualMonoCheckBox
Definition: Loudness.h:105
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:75
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:56
DB_TO_LINEAR
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
Effect::SetLinearEffectFlag
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1764
Effect::EnableApply
bool EnableApply(bool enable=true)
Definition: Effect.cpp:1694
EffectLoudness::mMult
float mMult
Definition: Loudness.h:96
S
#define S(N)
Definition: ToChars.cpp:64
EffectLoudness::mTrackBufferLen
size_t mTrackBufferLen
Definition: Loudness.h:108
EffectLoudness::mSteps
int mSteps
Definition: Loudness.h:91
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:71
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:1834
EffectLoudness::OnChoice
void OnChoice(wxCommandEvent &evt)
Definition: Loudness.cpp:574
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1288
EffectLoudness::mCurRate
double mCurRate
Definition: Loudness.h:94
Effect::mT1
double mT1
Definition: Effect.h:424
ArrayOf::reinit
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:57
Validator
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
Definition: Validators.h:53
nAlgos
@ nAlgos
Definition: Loudness.cpp:41
EffectLoudness::mProgressMsg
TranslatableString mProgressMsg
Definition: Loudness.h:92
EffectLoudness::mRatio
float mRatio
Definition: Loudness.h:97
XO
#define XO(s)
Definition: Internat.h:31
WaveTrack::GetBestBlockSize
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1793
EffectLoudness::mStereoInd
bool mStereoInd
Definition: Loudness.h:82
Track::Any
bool Any() const
Definition: Track.cpp:292
WaveTrack::GetRMS
float GetRMS(double t0, double t1, bool mayThrow=true) const
Definition: WaveTrack.cpp:2078
EffectLoudness::UpdateUI
void UpdateUI()
Definition: Loudness.cpp:587
EffectLoudness::mWarning
wxStaticText * mWarning
Definition: Loudness.h:103
Effect::SaveUserPreset
bool SaveUserPreset(const RegistryPath &name) override
Save current settings as a user-named preset.
Definition: Effect.cpp:547
EffectLoudness::mBook
wxSimplebook * mBook
Definition: Loudness.h:101
EffectLoudness::AllocBuffers
void AllocBuffers()
Definition: Loudness.cpp:413
EffectLoudness::FreeBuffers
void FreeBuffers()
Definition: Loudness.cpp:438
floatSample
@ floatSample
Definition: SampleFormat.h:34
EffectLoudness::AnalyseBufferBlock
bool AnalyseBufferBlock()
Definition: Loudness.cpp:526
EffectLoudness::mRMSLevel
double mRMSLevel
Definition: Loudness.h:84
ReadAndVerifyInt
#define ReadAndVerifyInt(name)
Definition: Effect.h:591
XXO
#define XXO(s)
Definition: Internat.h:44
Effect::mT0
double mT0
Definition: Effect.h:423
EffectLoudness::mLoudnessProcessor
std::unique_ptr< EBUR128 > mLoudnessProcessor
Definition: Loudness.h:99
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:1956
EffectLoudness::mProcStereo
bool mProcStereo
Definition: Loudness.h:110
EffectLoudness::ProcessBufferBlock
bool ProcessBufferBlock()
Definition: Loudness.cpp:541
EffectLoudness::UpdateProgress
bool UpdateProgress()
Definition: Loudness.cpp:567
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:422
Msgids
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
Definition: ShuttleGui.cpp:2523
ReadAndVerifyDouble
#define ReadAndVerifyDouble(name)
Definition: Effect.h:592
EffectLoudness::mTrackLen
double mTrackLen
Definition: Loudness.h:93
EffectLoudness::mDualMono
bool mDualMono
Definition: Loudness.h:85
EffectLoudness::mNormalizeTo
int mNormalizeTo
Definition: Loudness.h:86
Effect::GetCurrentSettingsGroup
RegistryPath GetCurrentSettingsGroup() override
Definition: Effect.cpp:820
EffectLoudness::mChoice
wxChoice * mChoice
Definition: Loudness.h:102
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
EffectLoudness::ProcessOne
bool ProcessOne(TrackIterRange< WaveTrack > range, bool analyse)
Definition: Loudness.cpp:458
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
Effect::mUIParent
wxWindow * mUIParent
Definition: Effect.h:438
Track::IsLeader
bool IsLeader() const
Definition: Track.cpp:298
kLoudness
@ kLoudness
Definition: Loudness.cpp:39
_
#define _(s)
Definition: Internat.h:75
EffectLoudness::mCurT1
double mCurT1
Definition: Loudness.h:89
Track::MonoChannel
@ MonoChannel
Definition: Track.h:263
EffectLoudness::mRMS
float mRMS[2]
Definition: Loudness.h:98
Effect::TotalProgress
bool TotalProgress(double frac, const TranslatableString &={})
Definition: Effect.cpp:1780
SampleTrack::TimeToLongSamples
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:35
EffectLoudness::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: Loudness.h:32
Effect::GetNumWaveTracks
int GetNumWaveTracks()
Definition: Effect.h:304
EffectLoudness::mTrackBuffer
Floats mTrackBuffer[2]
Definition: Loudness.h:107
EffectLoudness::StoreBufferBlock
void StoreBufferBlock(TrackIterRange< WaveTrack > range, sampleCount pos, size_t len)
Definition: Loudness.cpp:555
TrapDouble
double TrapDouble(double x, double min, double max)
Definition: Effect.h:523
EBUR128
Implements EBU-R128 loudness measurement.
Definition: EBUR128.h:22
TrackList::SingletonRange
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1447
safenew
#define safenew
Definition: MemoryX.h:10
limitSampleBufferSize
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
EffectLoudness::LoadBufferBlock
void LoadBufferBlock(TrackIterRange< WaveTrack > range, sampleCount pos, size_t len)
Definition: Loudness.cpp:511
EffectLoudness::mStereoIndCheckBox
wxCheckBox * mStereoIndCheckBox
Definition: Loudness.h:104
ReadAndVerifyBool
#define ReadAndVerifyBool(name)
Definition: Effect.h:594
EffectLoudness::mProgressVal
double mProgressVal
Definition: Loudness.h:90
kNormalizeTargetStrings
static const EnumValueSymbol kNormalizeTargetStrings[nAlgos]
Definition: Loudness.cpp:44
EffectLoudness::mTrackBufferCapacity
size_t mTrackBufferCapacity
Definition: Loudness.h:109
EffectLoudness::mLUFSLevel
double mLUFSLevel
Definition: Loudness.h:83