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
 After Init(), tell whether Process() should be skipped. More...
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 
std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 
bool TransferDataFromWindow (EffectSettings &settings) override
 
- Public Member Functions inherited from StatefulEffect
 ~StatefulEffect () override
 
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 ()
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 
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
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize () noexcept
 
- 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
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
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
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
void SetTracks (TrackList *pTracks)
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual void Preview (EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly)=0
 Calculate temporary tracks of limited length with effect applied and play. More...
 
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, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- 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
 
- Public Member Functions inherited from StatefulEffectUIServices
 ~StatefulEffectUIServices () override
 
std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
 Allows PopulateOrExchange to return null. More...
 
virtual std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)
 
virtual bool TransferDataFromWindow (EffectSettings &settings)
 
- Public Member Functions inherited from BasicEffectUIServices
int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
 
void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const override
 
void ShowOptions (const EffectPlugin &plugin) const override
 
bool ValidateUI (const EffectPlugin &context, EffectSettings &) const override
 
bool CloseUI () const override
 
- Public Member Functions inherited from EffectUIServices
virtual ~EffectUIServices ()
 
virtual int ShowHostInterface (EffectPlugin &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
 
virtual int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal=false) const =0
 
virtual std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const =0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const =0
 
virtual void ShowOptions (const EffectPlugin &plugin) const =0
 
virtual bool ValidateUI (const EffectPlugin &context, EffectSettings &settings) const =0
 
virtual bool CloseUI () const =0
 

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 Member Functions inherited from EffectUIServices
static int DoMessageBox (const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 

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

wxWeakRef< wxWindow > mUIParent {}
 
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 EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Public Types inherited from EffectUIServices
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Attributes inherited from EffectBase
TrackListmTracks {}
 
- Protected Member Functions inherited from Effect
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...
 
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)
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
void Preview (EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly) final
 Calculate temporary tracks of limited length with effect applied and play. 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 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 25 of file Normalize.h.

Constructor & Destructor Documentation

◆ EffectNormalize()

EffectNormalize::EffectNormalize ( )

Definition at line 51 of file Normalize.cpp.

52{
53 Parameters().Reset(*this);
55}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:214
const EffectParameterMethods & Parameters() const override
Definition: Normalize.cpp:33
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 57 of file Normalize.cpp.

58{
59}

Member Function Documentation

◆ AnalyseDataDC()

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

Definition at line 449 of file Normalize.cpp.

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

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

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

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

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

After Init(), tell whether Process() should be skipped.

Implements EffectBase.

Definition at line 87 of file Normalize.cpp.

88{
89 return ((mGain == false) && (mDC == false));
90}

References mDC, and mGain.

◆ FetchParameters()

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

Definition at line 29 of file Normalize.h.

29{ return &e; }

◆ GetDescription()

TranslatableString EffectNormalize::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 68 of file Normalize.cpp.

69{
70 return XO("Sets the peak amplitude of one or more tracks");
71}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectNormalize::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 63 of file Normalize.cpp.

64{
65 return Symbol;
66}
static const ComponentInterfaceSymbol Symbol
Definition: Normalize.h:30

References Symbol.

◆ GetType()

EffectType EffectNormalize::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 80 of file Normalize.cpp.

81{
82 return EffectTypeProcess;
83}
@ 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 73 of file Normalize.cpp.

74{
75 return L"Normalize";
76}

◆ OnUpdateUI()

void EffectNormalize::OnUpdateUI ( wxCommandEvent &  evt)
private

Definition at line 463 of file Normalize.cpp.

464{
465 UpdateUI();
466}

References UpdateUI().

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectNormalize::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 33 of file Normalize.cpp.

34{
37 > parameters;
38 return parameters;
39}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter RemoveDC
Definition: Normalize.h:96
static constexpr EffectParameter StereoInd
Definition: Normalize.h:100
static constexpr EffectParameter PeakLevel
Definition: Normalize.h:94
static constexpr EffectParameter ApplyGain
Definition: Normalize.h:98

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

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectEditor > 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 PopulateUI instead of a DefaultEffectEditor; default implementation returns null

Reimplemented from StatefulEffectUIServices.

Definition at line 211 of file Normalize.cpp.

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

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

Here is the call graph for this function:

◆ Process()

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

Implements StatefulEffectBase.

Definition at line 92 of file Normalize.cpp.

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

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

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

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

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

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; default does nothing, returns true

Reimplemented from StatefulEffectUIServices.

Definition at line 278 of file Normalize.cpp.

279{
280 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
281 {
282 return false;
283 }
284
285 return true;
286}

References mUIParent.

◆ TransferDataToWindow()

bool EffectNormalize::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings; default does nothing, returns true

Reimplemented from StatefulEffectUIServices.

Definition at line 266 of file Normalize.cpp.

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

References mUIParent, and UpdateUI().

Here is the call graph for this function:

◆ UpdateUI()

void EffectNormalize::UpdateUI ( )
private

Definition at line 468 of file Normalize.cpp.

469{
470
471 if (!mUIParent->TransferDataFromWindow())
472 {
473 mWarning->SetLabel(_("(Maximum 0dB)"));
475 return;
476 }
477 mWarning->SetLabel(wxT(""));
478
479 // Disallow level stuff if not normalizing
480 mLevelTextCtrl->Enable(mGain);
481 mLeveldB->Enable(mGain);
482 mStereoIndCheckBox->Enable(mGain);
483
484 // Disallow OK/Preview if doing nothing
486}
wxT("CloseDown"))
#define _(s)
Definition: Internat.h:73
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.

References _, EffectEditor::EnableApply(), mDC, mGain, mLeveldB, mLevelTextCtrl, mStereoIndCheckBox, 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 98 of file Normalize.h.

Referenced by Parameters().

◆ mCreating

bool EffectNormalize::mCreating
private

Definition at line 89 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mCurT0

double EffectNormalize::mCurT0
private

Definition at line 78 of file Normalize.h.

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

◆ mCurT1

double EffectNormalize::mCurT1
private

Definition at line 79 of file Normalize.h.

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

◆ mDC

bool EffectNormalize::mDC
private

◆ mDCCheckBox

wxCheckBox* EffectNormalize::mDCCheckBox
private

Definition at line 84 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mGain

bool EffectNormalize::mGain
private

◆ mGainCheckBox

wxCheckBox* EffectNormalize::mGainCheckBox
private

Definition at line 83 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mLeveldB

wxStaticText* EffectNormalize::mLeveldB
private

Definition at line 86 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mLevelTextCtrl

wxTextCtrl* EffectNormalize::mLevelTextCtrl
private

Definition at line 85 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mMult

float EffectNormalize::mMult
private

Definition at line 80 of file Normalize.h.

Referenced by Process(), and ProcessData().

◆ mPeakLevel

double EffectNormalize::mPeakLevel
private

Definition at line 73 of file Normalize.h.

Referenced by PopulateOrExchange(), and Process().

◆ mStereoInd

bool EffectNormalize::mStereoInd
private

Definition at line 76 of file Normalize.h.

Referenced by PopulateOrExchange(), and Process().

◆ mStereoIndCheckBox

wxCheckBox* EffectNormalize::mStereoIndCheckBox
private

Definition at line 88 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mSum

double EffectNormalize::mSum
private

Definition at line 81 of file Normalize.h.

Referenced by AnalyseDataDC(), and AnalyseTrackData().

◆ mUIParent

wxWeakRef<wxWindow> EffectNormalize::mUIParent {}
private

◆ mWarning

wxStaticText* EffectNormalize::mWarning
private

Definition at line 87 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 94 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 96 of file Normalize.h.

Referenced by Parameters().

◆ StereoInd

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

Definition at line 100 of file Normalize.h.

Referenced by Parameters().

◆ Symbol

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

Definition at line 30 of file Normalize.h.

Referenced by GetSymbol().


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