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) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. 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, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (EffectSettings &settings)
 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
 
- 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...
 
bool LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 Change settings to a user-named preset. More...
 
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...
 
bool LoadFactoryPreset (int id, EffectSettings &settings) const override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults (EffectSettings &settings) const override
 Change settings back to "factory default". More...
 
unsigned GetAudioInCount () const override
 How many input buffers to allocate at once. More...
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) 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
 
void 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
 
bool 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
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)=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 void ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=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 void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual bool 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...
 
virtual unsigned GetAudioInCount () const =0
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const =0
 How many output buffers to allocate at once. More...
 
virtual int GetMidiInCount () const
 Function that has not yet found a use. More...
 
virtual int GetMidiOutCount () const
 Function that has not yet found a use. 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...
 
- 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 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)
 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
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 
- 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 }
 
- Protected Attributes inherited from EffectUIClientInterface
friend EffectUIValidator
 
friend DefaultEffectUIValidator
 
- 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:218
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 434 of file Normalize.cpp.

435{
436 for(decltype(len) i = 0; i < len; i++)
437 mSum += (double)buffer[i];
438}

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

277{
278 bool result = true;
279 float min, max;
280
281 if(mGain)
282 {
283 // set mMin, mMax. No progress bar here as it's fast.
284 auto pair = track->GetMinMax(mCurT0, mCurT1); // may throw
285 min = pair.first, max = pair.second;
286
287 if(mDC)
288 {
289 result = AnalyseTrackData(track, msg, progress, offset);
290 min += offset;
291 max += offset;
292 }
293 }
294 else if(mDC)
295 {
296 min = -1.0, max = 1.0; // sensible defaults?
297 result = AnalyseTrackData(track, msg, progress, offset);
298 min += offset;
299 max += offset;
300 }
301 else
302 {
303 wxFAIL_MSG("Analysing Track when nothing to do!");
304 min = -1.0, max = 1.0; // sensible defaults?
305 offset = 0.0;
306 }
307 extent = fmax(fabs(min), fabs(max));
308
309 return result;
310}
int min(int a, int b)
double mCurT0
Definition: Normalize.h:74
bool AnalyseTrackData(const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset)
Definition: Normalize.cpp:314
double mCurT1
Definition: Normalize.h:75
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
Definition: WaveTrack.cpp:2040

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

316{
317 bool rc = true;
318
319 //Transform the marker timepoints to samples
320 auto start = track->TimeToLongSamples(mCurT0);
321 auto end = track->TimeToLongSamples(mCurT1);
322
323 //Get the length of the buffer (as double). len is
324 //used simply to calculate a progress meter, so it is easier
325 //to make it a double now than it is to do it later
326 auto len = (end - start).as_double();
327
328 //Initiate a processing buffer. This buffer will (most likely)
329 //be shorter than the length of the track being processed.
330 Floats buffer{ track->GetMaxBlockSize() };
331
332 mSum = 0.0; // dc offset inits
333
334 sampleCount blockSamples;
335 sampleCount totalSamples = 0;
336
337 //Go through the track one buffer at a time. s counts which
338 //sample the current buffer starts at.
339 auto s = start;
340 while (s < end) {
341 //Get a block of samples (smaller than the size of the buffer)
342 //Adjust the block size if it is the final block in the track
343 const auto block = limitSampleBufferSize(
344 track->GetBestBlockSize(s),
345 end - s
346 );
347
348 //Get the samples from the track and put them in the buffer
349 track->GetFloats(buffer.get(), s, block, fillZero, true, &blockSamples);
350 totalSamples += blockSamples;
351
352 //Process the buffer.
353 AnalyseDataDC(buffer.get(), block);
354
355 //Increment s one blockfull of samples
356 s += block;
357
358 //Update the Progress meter
359 if (TotalProgress(progress +
360 ((s - start).as_double() / len)/double(2*GetNumWaveTracks()), msg)) {
361 rc = false; //lda .. break, not return, so that buffer is deleted
362 break;
363 }
364 }
365 if( totalSamples > 0 )
366 offset = -mSum / totalSamples.as_double(); // calculate actual offset (amount that needs to be added on)
367 else
368 offset = 0.0;
369
370 progress += 1.0/double(2*GetNumWaveTracks());
371 //Return true because the effect processing succeeded ... unless cancelled
372 return rc;
373}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
@ fillZero
Definition: SampleFormat.h:54
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:685
int GetNumWaveTracks() const
Definition: Effect.h:187
void AnalyseDataDC(float *buffer, size_t len)
Definition: Normalize.cpp:434
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:1806
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1788
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
double as_double() const
Definition: SampleCount.h:45
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 448 of file Normalize.cpp.

449{
450 UpdateUI();
451}

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:92
static constexpr EffectParameter StereoInd
Definition: Normalize.h:96
static constexpr EffectParameter PeakLevel
Definition: Normalize.h:90
static constexpr EffectParameter ApplyGain
Definition: Normalize.h:94

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 
)
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.

216{
217 mCreating = true;
218
219 S.StartVerticalLay(0);
220 {
221 S.StartMultiColumn(2, wxALIGN_CENTER);
222 {
223 S.StartVerticalLay(false);
224 {
225 mDCCheckBox = S.Validator<wxGenericValidator>(&mDC)
226 .AddCheckBox(XXO("&Remove DC offset (center on 0.0 vertically)"),
227 mDC);
228
229 S.StartHorizontalLay(wxALIGN_LEFT, false);
230 {
232 .MinSize()
233 .Validator<wxGenericValidator>(&mGain)
234 .AddCheckBox(XXO("&Normalize peak amplitude to "),
235 mGain);
236
238 .Name(XO("Peak amplitude dB"))
239 .Validator<FloatingPointValidator<double>>(
240 2,
241 &mPeakLevel,
242 NumValidatorStyle::ONE_TRAILING_ZERO,
244 PeakLevel.max )
245 .AddTextBox( {}, L"", 10);
246 mLeveldB = S.AddVariableText(XO("dB"), false,
247 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
248 mWarning = S.AddVariableText( {}, false,
249 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
250 }
251 S.EndHorizontalLay();
252
254 .Validator<wxGenericValidator>(&mStereoInd)
255 .AddCheckBox(XXO("N&ormalize stereo channels independently"),
256 mStereoInd);
257 }
258 S.EndVerticalLay();
259 }
260 S.EndMultiColumn();
261 }
262 S.EndVerticalLay();
263 mCreating = false;
264 return nullptr;
265}
#define XXO(s)
Definition: Internat.h:44
#define S(N)
Definition: ToChars.cpp:64
wxStaticText * mWarning
Definition: Normalize.h:83
wxStaticText * mLeveldB
Definition: Normalize.h:82
double mPeakLevel
Definition: Normalize.h:69
wxCheckBox * mGainCheckBox
Definition: Normalize.h:79
wxCheckBox * mDCCheckBox
Definition: Normalize.h:80
wxTextCtrl * mLevelTextCtrl
Definition: Normalize.h:81
wxCheckBox * mStereoIndCheckBox
Definition: Normalize.h:84
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:535
double mT1
Definition: EffectBase.h:107
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:105
double mT0
Definition: EffectBase.h:106
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:236
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:741
bool AnalyseTrack(const WaveTrack *track, const TranslatableString &msg, double &progress, float &offset, float &extent)
Definition: Normalize.cpp:275
bool ProcessOne(WaveTrack *t, const TranslatableString &msg, double &progress, float offset)
Definition: Normalize.cpp:379
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:1336
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1503
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1539
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 440 of file Normalize.cpp.

441{
442 for(decltype(len) i = 0; i < len; i++) {
443 float adjFrame = (buffer[i] + offset) * mMult;
444 buffer[i] = adjFrame;
445 }
446}

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

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

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:

◆ TransferDataToWindow()

bool EffectNormalize::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Reimplemented from Effect.

Definition at line 267 of file Normalize.cpp.

268{
269 UpdateUI();
270 return true;
271}

References UpdateUI().

Here is the call graph for this function:

◆ UpdateUI()

void EffectNormalize::UpdateUI ( )
private

Definition at line 453 of file Normalize.cpp.

454{
455
456 if (!mUIParent->TransferDataFromWindow())
457 {
458 mWarning->SetLabel(_("(Maximum 0dB)"));
459 EnableApply(false);
460 return;
461 }
462 mWarning->SetLabel(wxT(""));
463
464 // Disallow level stuff if not normalizing
465 mLevelTextCtrl->Enable(mGain);
466 mLeveldB->Enable(mGain);
467 mStereoIndCheckBox->Enable(mGain);
468
469 // Disallow OK/Preview if doing nothing
471}
#define _(s)
Definition: Internat.h:75
bool EnableApply(bool enable=true)
Definition: Effect.cpp:613
wxWindow * mUIParent
Definition: Effect.h:270

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

◆ ApplyGain

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

Definition at line 94 of file Normalize.h.

Referenced by Parameters().

◆ mCreating

bool EffectNormalize::mCreating
private

Definition at line 85 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mCurT0

double EffectNormalize::mCurT0
private

Definition at line 74 of file Normalize.h.

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

◆ mCurT1

double EffectNormalize::mCurT1
private

Definition at line 75 of file Normalize.h.

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

◆ mDC

bool EffectNormalize::mDC
private

◆ mDCCheckBox

wxCheckBox* EffectNormalize::mDCCheckBox
private

Definition at line 80 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mGain

bool EffectNormalize::mGain
private

◆ mGainCheckBox

wxCheckBox* EffectNormalize::mGainCheckBox
private

Definition at line 79 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mLeveldB

wxStaticText* EffectNormalize::mLeveldB
private

Definition at line 82 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mLevelTextCtrl

wxTextCtrl* EffectNormalize::mLevelTextCtrl
private

Definition at line 81 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mMult

float EffectNormalize::mMult
private

Definition at line 76 of file Normalize.h.

Referenced by Process(), and ProcessData().

◆ mPeakLevel

double EffectNormalize::mPeakLevel
private

Definition at line 69 of file Normalize.h.

Referenced by PopulateOrExchange(), and Process().

◆ mStereoInd

bool EffectNormalize::mStereoInd
private

Definition at line 72 of file Normalize.h.

Referenced by PopulateOrExchange(), and Process().

◆ mStereoIndCheckBox

wxCheckBox* EffectNormalize::mStereoIndCheckBox
private

Definition at line 84 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mSum

double EffectNormalize::mSum
private

Definition at line 77 of file Normalize.h.

Referenced by AnalyseDataDC(), and AnalyseTrackData().

◆ mWarning

wxStaticText* EffectNormalize::mWarning
private

Definition at line 83 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 90 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 92 of file Normalize.h.

Referenced by Parameters().

◆ StereoInd

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

Definition at line 96 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: