Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static 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 () const override
 
TranslatableString GetDescription () const override
 
ManualPageID ManualPage () const override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 Actually do the effect here. More...
 
std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
- Public Member Functions inherited from StatefulEffect
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 Actually do the effect here. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () const
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal) override
 
EffectUIClientInterfaceGetEffectUIClientInterface () override
 Returns the EffectUIClientInterface instance for this effect. More...
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Adds controls to a panel that is given as the parent window of S More...
 
bool IsGraphicalUI () override
 
bool ValidateUI (EffectSettings &) override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets (const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (EffectSettings &settings) override
 
bool HasOptions () override
 
void ShowOptions () override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
 Usually applies factory to self and given access. More...
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
 
bool EnableApply (bool enable=true)
 
wxWindow * GetUIParent ()
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
void SetTracks (TrackList *pTracks)
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)=0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual bool CanExportPresets ()=0
 
virtual void ExportPresets (const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)=0
 Usually applies factory to self and given access. More...
 
virtual EffectUIClientInterfaceGetEffectUIClientInterface ()=0
 Returns the EffectUIClientInterface instance for this effect. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={}, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 Unfortunately complicated dual-use function. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)=0
 Update controls for the settings. More...
 
virtual bool TransferDataFromWindow (EffectSettings &settings)=0
 Update the given settings from controls. More...
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Static Public Member Functions

static EffectNormalizeFetchParameters (EffectNormalize &e, EffectSettings &)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
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...
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Normalize") }
 
- Static Public Attributes inherited from EffectPlugin
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 ()
 
const EffectParameterMethodsParameters () const override
 

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
 

Static Private Attributes

static constexpr EffectParameter PeakLevel
 
static constexpr EffectParameter RemoveDC
 
static constexpr EffectParameter ApplyGain
 
static constexpr EffectParameter StereoInd
 

Additional Inherited Members

- Public Types inherited from StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , Since_3_2 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Protected Member Functions inherited from Effect
bool EnablePreview (bool enable=true)
 
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
virtual std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
void Preview (EffectSettingsAccess &access, bool dryOnly) override
 
bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent, const EffectDialogFactory &dialogFactory, const EffectSettingsAccessPtr &pAccess) override
 Unfortunately complicated dual-use function. More...
 
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from Effect
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWindow * mUIParent {}
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

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

Definition at line 24 of file Normalize.h.

Constructor & Destructor Documentation

◆ EffectNormalize()

EffectNormalize::EffectNormalize ( )

Definition at line 54 of file Normalize.cpp.

55{
56 Parameters().Reset(*this);
58}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:222
const EffectParameterMethods & Parameters() const override
Definition: Normalize.cpp:36
virtual void Reset(Effect &effect) const =0

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectNormalize()

EffectNormalize::~EffectNormalize ( )
virtual

Definition at line 60 of file Normalize.cpp.

61{
62}

Member Function Documentation

◆ AnalyseDataDC()

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

Definition at line 451 of file Normalize.cpp.

452{
453 for(decltype(len) i = 0; i < len; i++)
454 mSum += (double)buffer[i];
455}

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 292 of file Normalize.cpp.

294{
295 bool result = true;
296 float min, max;
297
298 if(mGain)
299 {
300 // set mMin, mMax. No progress bar here as it's fast.
301 auto pair = track->GetMinMax(mCurT0, mCurT1); // may throw
302 min = pair.first, max = pair.second;
303
304 if(mDC)
305 {
306 result = AnalyseTrackData(track, msg, progress, offset);
307 min += offset;
308 max += offset;
309 }
310 }
311 else if(mDC)
312 {
313 min = -1.0, max = 1.0; // sensible defaults?
314 result = AnalyseTrackData(track, msg, progress, offset);
315 min += offset;
316 max += offset;
317 }
318 else
319 {
320 wxFAIL_MSG("Analysing Track when nothing to do!");
321 min = -1.0, max = 1.0; // sensible defaults?
322 offset = 0.0;
323 }
324 extent = fmax(fabs(min), fabs(max));
325
326 return result;
327}
int min(int a, int b)
double mCurT0
Definition: Normalize.h:75
bool AnalyseTrackData(const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset)
Definition: Normalize.cpp:331
double mCurT1
Definition: Normalize.h:76
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
Definition: WaveTrack.cpp:2050

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 331 of file Normalize.cpp.

333{
334 bool rc = true;
335
336 //Transform the marker timepoints to samples
337 auto start = track->TimeToLongSamples(mCurT0);
338 auto end = track->TimeToLongSamples(mCurT1);
339
340 //Get the length of the buffer (as double). len is
341 //used simply to calculate a progress meter, so it is easier
342 //to make it a double now than it is to do it later
343 auto len = (end - start).as_double();
344
345 //Initiate a processing buffer. This buffer will (most likely)
346 //be shorter than the length of the track being processed.
347 Floats buffer{ track->GetMaxBlockSize() };
348
349 mSum = 0.0; // dc offset inits
350
351 sampleCount blockSamples;
352 sampleCount totalSamples = 0;
353
354 //Go through the track one buffer at a time. s counts which
355 //sample the current buffer starts at.
356 auto s = start;
357 while (s < end) {
358 //Get a block of samples (smaller than the size of the buffer)
359 //Adjust the block size if it is the final block in the track
360 const auto block = limitSampleBufferSize(
361 track->GetBestBlockSize(s),
362 end - s
363 );
364
365 //Get the samples from the track and put them in the buffer
366 track->GetFloats(buffer.get(), s, block, fillZero, true, &blockSamples);
367 totalSamples += blockSamples;
368
369 //Process the buffer.
370 AnalyseDataDC(buffer.get(), block);
371
372 //Increment s one blockfull of samples
373 s += block;
374
375 //Update the Progress meter
376 if (TotalProgress(progress +
377 ((s - start).as_double() / len)/double(2*GetNumWaveTracks()), msg)) {
378 rc = false; //lda .. break, not return, so that buffer is deleted
379 break;
380 }
381 }
382 if( totalSamples > 0 )
383 offset = -mSum / totalSamples.as_double(); // calculate actual offset (amount that needs to be added on)
384 else
385 offset = 0.0;
386
387 progress += 1.0/double(2*GetNumWaveTracks());
388 //Return true because the effect processing succeeded ... unless cancelled
389 return rc;
390}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
@ fillZero
Definition: SampleFormat.h:54
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:675
int GetNumWaveTracks() const
Definition: Effect.h:224
void AnalyseDataDC(float *buffer, size_t len)
Definition: Normalize.cpp:451
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: SampleTrack.h:67
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:42
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1816
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1798
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double as_double() const
Definition: SampleCount.h:46
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References AnalyseDataDC(), sampleCount::as_double(), PackedArray::end(), fillZero, WaveTrack::GetBestBlockSize(), SampleTrack::GetFloats(), WaveTrack::GetMaxBlockSize(), Effect::GetNumWaveTracks(), limitSampleBufferSize(), mCurT0, mCurT1, mSum, SampleTrack::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 ( const EffectSettings settings) const
overridevirtual

Default implementation returns false.

Reimplemented from Effect.

Definition at line 90 of file Normalize.cpp.

91{
92 return ((mGain == false) && (mDC == false));
93}

References mDC, and mGain.

◆ FetchParameters()

static EffectNormalize * EffectNormalize::FetchParameters ( EffectNormalize e,
EffectSettings  
)
inlinestatic

Definition at line 28 of file Normalize.h.

28{ return &e; }

◆ GetDescription()

TranslatableString EffectNormalize::GetDescription ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 71 of file Normalize.cpp.

72{
73 return XO("Sets the peak amplitude of one or more tracks");
74}
#define XO(s)
Definition: Internat.h:31

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectNormalize::GetSymbol ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 66 of file Normalize.cpp.

67{
68 return Symbol;
69}
static const ComponentInterfaceSymbol Symbol
Definition: Normalize.h:29

References Symbol.

◆ GetType()

EffectType EffectNormalize::GetType ( ) const
overridevirtual

Type determines how it behaves.

Reimplemented from Effect.

Definition at line 83 of file Normalize.cpp.

84{
85 return EffectTypeProcess;
86}
@ EffectTypeProcess

References EffectTypeProcess.

◆ ManualPage()

ManualPageID EffectNormalize::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 76 of file Normalize.cpp.

77{
78 return L"Normalize";
79}

◆ OnUpdateUI()

void EffectNormalize::OnUpdateUI ( wxCommandEvent &  evt)
private

Definition at line 465 of file Normalize.cpp.

466{
467 UpdateUI();
468}

References UpdateUI().

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectNormalize::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 36 of file Normalize.cpp.

37{
40 > parameters;
41 return parameters;
42}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter RemoveDC
Definition: Normalize.h:93
static constexpr EffectParameter StereoInd
Definition: Normalize.h:97
static constexpr EffectParameter PeakLevel
Definition: Normalize.h:91
static constexpr EffectParameter ApplyGain
Definition: Normalize.h:95

References ApplyGain, EffectNormalize(), PeakLevel, RemoveDC, and StereoInd.

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectUIValidator > EffectNormalize::PopulateOrExchange ( ShuttleGui S,
EffectInstance instance,
EffectSettingsAccess access,
const EffectOutputs pOutputs 
)
overridevirtual

Add controls to effect panel; always succeeds.

Returns
if not null, then return it from Effect::PopulateUI instead of a DefaultEffectUIValidator; default implementation returns null

Reimplemented from Effect.

Definition at line 214 of file Normalize.cpp.

217{
218 mCreating = true;
219
220 S.StartVerticalLay(0);
221 {
222 S.StartMultiColumn(2, wxALIGN_CENTER);
223 {
224 S.StartVerticalLay(false);
225 {
226 mDCCheckBox = S.Validator<wxGenericValidator>(&mDC)
227 .AddCheckBox(XXO("&Remove DC offset (center on 0.0 vertically)"),
228 mDC);
229
230 S.StartHorizontalLay(wxALIGN_LEFT, false);
231 {
233 .MinSize()
234 .Validator<wxGenericValidator>(&mGain)
235 .AddCheckBox(XXO("&Normalize peak amplitude to "),
236 mGain);
237
239 .Name(XO("Peak amplitude dB"))
240 .Validator<FloatingPointValidator<double>>(
241 2,
242 &mPeakLevel,
243 NumValidatorStyle::ONE_TRAILING_ZERO,
245 PeakLevel.max )
246 .AddTextBox( {}, L"", 10);
247 mLeveldB = S.AddVariableText(XO("dB"), false,
248 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
249 mWarning = S.AddVariableText( {}, false,
250 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
251 }
252 S.EndHorizontalLay();
253
255 .Validator<wxGenericValidator>(&mStereoInd)
256 .AddCheckBox(XXO("N&ormalize stereo channels independently"),
257 mStereoInd);
258 }
259 S.EndVerticalLay();
260 }
261 S.EndMultiColumn();
262 }
263 S.EndVerticalLay();
264 mCreating = false;
265 return nullptr;
266}
#define XXO(s)
Definition: Internat.h:44
#define S(N)
Definition: ToChars.cpp:64
wxStaticText * mWarning
Definition: Normalize.h:84
wxStaticText * mLeveldB
Definition: Normalize.h:83
double mPeakLevel
Definition: Normalize.h:70
wxCheckBox * mGainCheckBox
Definition: Normalize.h:80
wxCheckBox * mDCCheckBox
Definition: Normalize.h:81
wxTextCtrl * mLevelTextCtrl
Definition: Normalize.h:82
wxCheckBox * mStereoIndCheckBox
Definition: Normalize.h:85
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
Definition: Validators.h:53
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31

References EffectParameter< Structure, Member, Type, Value >::max, mCreating, mDC, mDCCheckBox, mGain, mGainCheckBox, EffectParameter< Structure, Member, Type, Value >::min, mLeveldB, mLevelTextCtrl, mPeakLevel, mStereoInd, mStereoIndCheckBox, mWarning, PeakLevel, S, XO, and XXO.

◆ Process()

bool EffectNormalize::Process ( EffectInstance instance,
EffectSettings settings 
)
overridevirtual

Actually do the effect here.

Returns
success

Implements StatefulEffectBase.

Definition at line 95 of file Normalize.cpp.

96{
97 if (mGain == false && mDC == false)
98 return true;
99
100 float ratio;
101 if( mGain )
102 {
103 // same value used for all tracks
104 ratio = DB_TO_LINEAR(std::clamp<double>(mPeakLevel, PeakLevel.min, PeakLevel.max));
105 }
106 else {
107 ratio = 1.0;
108 }
109
110 //Iterate over each track
111 this->CopyInputTracks(); // Set up mOutputTracks.
112 bool bGoodResult = true;
113 double progress = 0;
114 TranslatableString topMsg;
115 if(mDC && mGain)
116 topMsg = XO("Removing DC offset and Normalizing...\n");
117 else if(mDC && !mGain)
118 topMsg = XO("Removing DC offset...\n");
119 else if(!mDC && mGain)
120 topMsg = XO("Normalizing without removing DC offset...\n");
121 else if(!mDC && !mGain)
122 topMsg = XO("Not doing anything...\n"); // shouldn't get here
123
124 for ( auto track : mOutputTracks->Selected< WaveTrack >()
126 //Get start and end times from track
127 // PRL: No accounting for multiple channels?
128 double trackStart = track->GetStartTime();
129 double trackEnd = track->GetEndTime();
130
131 //Set the current bounds to whichever left marker is
132 //greater and whichever right marker is less:
133 mCurT0 = mT0 < trackStart? trackStart: mT0;
134 mCurT1 = mT1 > trackEnd? trackEnd: mT1;
135
136 auto range = mStereoInd
138 : TrackList::Channels(track);
139
140 // Process only if the right marker is to the right of the left marker
141 if (mCurT1 > mCurT0) {
142 wxString trackName = track->GetName();
143
144 float extent;
145 // Will compute a maximum
146 extent = std::numeric_limits<float>::lowest();
147 std::vector<float> offsets;
148
149 auto msg = (range.size() == 1)
150 // mono or 'stereo tracks independently'
151 ? topMsg +
152 XO("Analyzing: %s").Format( trackName )
153 : topMsg +
154 // TODO: more-than-two-channels-message
155 XO("Analyzing first track of stereo pair: %s").Format( trackName );
156
157 // Analysis loop over channels collects offsets and extent
158 for (auto channel : range) {
159 float offset = 0;
160 float extent2 = 0;
161 bGoodResult =
162 AnalyseTrack( channel, msg, progress, offset, extent2 );
163 if ( ! bGoodResult )
164 goto break2;
165 extent = std::max( extent, extent2 );
166 offsets.push_back(offset);
167 // TODO: more-than-two-channels-message
168 msg = topMsg +
169 XO("Analyzing second track of stereo pair: %s").Format( trackName );
170 }
171
172 // Compute the multiplier using extent
173 if( (extent > 0) && mGain ) {
174 mMult = ratio / extent;
175 }
176 else
177 mMult = 1.0;
178
179 if (range.size() == 1) {
180 if (TrackList::Channels(track).size() == 1)
181 // really mono
182 msg = topMsg +
183 XO("Processing: %s").Format( trackName );
184 else
185 //'stereo tracks independently'
186 // TODO: more-than-two-channels-message
187 msg = topMsg +
188 XO("Processing stereo channels independently: %s").Format( trackName );
189 }
190 else
191 msg = topMsg +
192 // TODO: more-than-two-channels-message
193 XO("Processing first track of stereo pair: %s").Format( trackName );
194
195 // Use multiplier in the second, processing loop over channels
196 auto pOffset = offsets.begin();
197 for (auto channel : range) {
198 if (false ==
199 (bGoodResult = ProcessOne(channel, msg, progress, *pOffset++)) )
200 goto break2;
201 // TODO: more-than-two-channels-message
202 msg = topMsg +
203 XO("Processing second track of stereo pair: %s").Format( trackName );
204 }
205 }
206 }
207
208 break2:
209
210 this->ReplaceProcessedTracks(bGoodResult);
211 return bGoodResult;
212}
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:543
double mT1
Definition: EffectBase.h:109
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:107
double mT0
Definition: EffectBase.h:108
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:240
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:733
bool AnalyseTrack(const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset, float &extent)
Definition: Normalize.cpp:292
bool ProcessOne(WaveTrack *t, const TranslatableString &msg, double &progress, float offset)
Definition: Normalize.cpp:396
bool IsLeader() const
Definition: Track.cpp:405
bool Any() const
Definition: Track.cpp:399
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1338
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1505
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1541
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:57

References AnalyseTrack(), Track::Any(), TrackList::Channels(), Effect::CopyInputTracks(), DB_TO_LINEAR, Track::IsLeader(), EffectParameter< Structure, Member, Type, Value >::max, mCurT0, mCurT1, mDC, mGain, EffectParameter< Structure, Member, Type, Value >::min, mMult, EffectBase::mOutputTracks, mPeakLevel, mStereoInd, EffectBase::mT0, EffectBase::mT1, PeakLevel, ProcessOne(), EffectBase::ReplaceProcessedTracks(), TrackList::SingletonRange(), size, 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 457 of file Normalize.cpp.

458{
459 for(decltype(len) i = 0; i < len; i++) {
460 float adjFrame = (buffer[i] + offset) * mMult;
461 buffer[i] = adjFrame;
462 }
463}

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 396 of file Normalize.cpp.

398{
399 bool rc = true;
400
401 //Transform the marker timepoints to samples
402 auto start = track->TimeToLongSamples(mCurT0);
403 auto end = track->TimeToLongSamples(mCurT1);
404
405 //Get the length of the buffer (as double). len is
406 //used simply to calculate a progress meter, so it is easier
407 //to make it a double now than it is to do it later
408 auto len = (end - start).as_double();
409
410 //Initiate a processing buffer. This buffer will (most likely)
411 //be shorter than the length of the track being processed.
412 Floats buffer{ track->GetMaxBlockSize() };
413
414 //Go through the track one buffer at a time. s counts which
415 //sample the current buffer starts at.
416 auto s = start;
417 while (s < end) {
418 //Get a block of samples (smaller than the size of the buffer)
419 //Adjust the block size if it is the final block in the track
420 const auto block = limitSampleBufferSize(
421 track->GetBestBlockSize(s),
422 end - s
423 );
424
425 //Get the samples from the track and put them in the buffer
426 track->GetFloats(buffer.get(), s, block);
427
428 //Process the buffer.
429 ProcessData(buffer.get(), block, offset);
430
431 //Copy the newly-changed samples back onto the track.
432 track->Set((samplePtr) buffer.get(), floatSample, s, block);
433
434 //Increment s one blockfull of samples
435 s += block;
436
437 //Update the Progress meter
438 if (TotalProgress(progress +
439 ((s - start).as_double() / len)/double(2*GetNumWaveTracks()), msg)) {
440 rc = false; //lda .. break, not return, so that buffer is deleted
441 break;
442 }
443 }
444 progress += 1.0/double(2*GetNumWaveTracks());
445
446 //Return true because the effect processing succeeded ... unless cancelled
447 return rc;
448}
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
void ProcessData(float *buffer, size_t len, float offset)
Definition: Normalize.cpp:457

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

Referenced by Process().

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

◆ TransferDataFromWindow()

bool EffectNormalize::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

Update the given settings from controls.

Reimplemented from Effect.

Definition at line 280 of file Normalize.cpp.

281{
282 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
283 {
284 return false;
285 }
286
287 return true;
288}
wxWindow * mUIParent
Definition: Effect.h:307

References Effect::mUIParent.

◆ TransferDataToWindow()

bool EffectNormalize::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Reimplemented from Effect.

Definition at line 268 of file Normalize.cpp.

269{
270 if (!mUIParent->TransferDataToWindow())
271 {
272 return false;
273 }
274
275 UpdateUI();
276
277 return true;
278}

References Effect::mUIParent, and UpdateUI().

Here is the call graph for this function:

◆ UpdateUI()

void EffectNormalize::UpdateUI ( )
private

Definition at line 470 of file Normalize.cpp.

471{
472
473 if (!mUIParent->TransferDataFromWindow())
474 {
475 mWarning->SetLabel(_("(Maximum 0dB)"));
476 EnableApply(false);
477 return;
478 }
479 mWarning->SetLabel(wxT(""));
480
481 // Disallow level stuff if not normalizing
482 mLevelTextCtrl->Enable(mGain);
483 mLeveldB->Enable(mGain);
484 mStereoIndCheckBox->Enable(mGain);
485
486 // Disallow OK/Preview if doing nothing
488}
wxT("CloseDown"))
#define _(s)
Definition: Internat.h:75
bool EnableApply(bool enable=true)
Definition: Effect.cpp:612

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

Referenced by OnUpdateUI(), and TransferDataToWindow().

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

Member Data Documentation

◆ ApplyGain

constexpr EffectParameter EffectNormalize::ApplyGain
staticconstexprprivate
Initial value:
L"ApplyGain", true, false, true, 1 }

Definition at line 95 of file Normalize.h.

Referenced by Parameters().

◆ mCreating

bool EffectNormalize::mCreating
private

Definition at line 86 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mCurT0

double EffectNormalize::mCurT0
private

Definition at line 75 of file Normalize.h.

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

◆ mCurT1

double EffectNormalize::mCurT1
private

Definition at line 76 of file Normalize.h.

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

◆ mDC

bool EffectNormalize::mDC
private

◆ mDCCheckBox

wxCheckBox* EffectNormalize::mDCCheckBox
private

Definition at line 81 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mGain

bool EffectNormalize::mGain
private

◆ mGainCheckBox

wxCheckBox* EffectNormalize::mGainCheckBox
private

Definition at line 80 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mLeveldB

wxStaticText* EffectNormalize::mLeveldB
private

Definition at line 83 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mLevelTextCtrl

wxTextCtrl* EffectNormalize::mLevelTextCtrl
private

Definition at line 82 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mMult

float EffectNormalize::mMult
private

Definition at line 77 of file Normalize.h.

Referenced by Process(), and ProcessData().

◆ mPeakLevel

double EffectNormalize::mPeakLevel
private

Definition at line 70 of file Normalize.h.

Referenced by PopulateOrExchange(), and Process().

◆ mStereoInd

bool EffectNormalize::mStereoInd
private

Definition at line 73 of file Normalize.h.

Referenced by PopulateOrExchange(), and Process().

◆ mStereoIndCheckBox

wxCheckBox* EffectNormalize::mStereoIndCheckBox
private

Definition at line 85 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mSum

double EffectNormalize::mSum
private

Definition at line 78 of file Normalize.h.

Referenced by AnalyseDataDC(), and AnalyseTrackData().

◆ mWarning

wxStaticText* EffectNormalize::mWarning
private

Definition at line 84 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ PeakLevel

constexpr EffectParameter EffectNormalize::PeakLevel
staticconstexprprivate
Initial value:
L"PeakLevel", -1.0, -145.0, 0.0, 1 }

Definition at line 91 of file Normalize.h.

Referenced by Parameters(), PopulateOrExchange(), and Process().

◆ RemoveDC

constexpr EffectParameter EffectNormalize::RemoveDC
staticconstexprprivate
Initial value:
L"RemoveDcOffset", true, false, true, 1 }

Definition at line 93 of file Normalize.h.

Referenced by Parameters().

◆ StereoInd

constexpr EffectParameter EffectNormalize::StereoInd
staticconstexprprivate
Initial value:
L"StereoIndependent", false, false, true, 1 }

Definition at line 97 of file Normalize.h.

Referenced by Parameters().

◆ Symbol

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

Definition at line 29 of file Normalize.h.

Referenced by GetSymbol().


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