Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Static 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, InstanceFinder finder={})
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
bool IsLinearEffect () const
 
bool PreviewsFullSelection () const
 
void SetTracks (TrackList *pTracks)
 
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void CountWaveTracks ()
 
- 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 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 (EffectBase &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 Public Member Functions inherited from EffectBase
static std::optional< InstancePointerFindInstance (EffectPlugin &plugin)
 
static InstanceFinder DefaultInstanceFinder (EffectPlugin &plugin)
 
- 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 Types

using ProgressReport = std::function< bool(double fraction)>
 

Private Member Functions

bool ProcessOne (WaveChannel &track, const TranslatableString &msg, double &progress, float offset)
 
void ProcessData (float *buffer, size_t len, float offset)
 
void OnUpdateUI (wxCommandEvent &evt)
 
void UpdateUI ()
 
const EffectParameterMethodsParameters () const override
 

Static Private Member Functions

static bool AnalyseTrack (const WaveChannel &track, const ProgressReport &report, bool gain, bool dc, double curT0, double curT1, float &offset, float &extent)
 
static bool AnalyseTrackData (const WaveChannel &track, const ProgressReport &report, double curT0, double curT1, float &offset)
 
static double AnalyseDataDC (float *buffer, size_t len, double sum)
 

Private Attributes

wxWeakRef< wxWindow > mUIParent {}
 
double mPeakLevel
 
bool mGain
 
bool mDC
 
bool mStereoInd
 
double mCurT0
 
double mCurT1
 
float mMult
 
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
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 
- 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, sampleCount *start, sampleCount *len)
 
- Protected Member Functions inherited from EffectBase
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from EffectBase
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

Detailed Description

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

Definition at line 27 of file Normalize.h.

Member Typedef Documentation

◆ ProgressReport

using EffectNormalize::ProgressReport = std::function<bool(double fraction)>
private

Definition at line 62 of file Normalize.h.

Constructor & Destructor Documentation

◆ EffectNormalize()

EffectNormalize::EffectNormalize ( )

Definition at line 52 of file Normalize.cpp.

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

59{
60}

Member Function Documentation

◆ AnalyseDataDC()

double EffectNormalize::AnalyseDataDC ( float *  buffer,
size_t  len,
double  sum 
)
staticprivate
See also
AnalyseDataLoudnessDC

Definition at line 458 of file Normalize.cpp.

459{
460 for(decltype(len) i = 0; i < len; i++)
461 sum += (double)buffer[i];
462 return sum;
463}

Referenced by AnalyseTrackData().

Here is the caller graph for this function:

◆ AnalyseTrack()

bool EffectNormalize::AnalyseTrack ( const WaveChannel track,
const ProgressReport report,
bool  gain,
bool  dc,
double  curT0,
double  curT1,
float &  offset,
float &  extent 
)
staticprivate

Definition at line 299 of file Normalize.cpp.

303{
304 bool result = true;
305 float min, max;
306 if (gain) {
307 // set mMin, mMax. No progress bar here as it's fast.
308 auto pair = track.GetMinMax(curT0, curT1); // may throw
309 min = pair.first, max = pair.second;
310
311 if (dc) {
312 result = AnalyseTrackData(track, report, curT0, curT1, offset);
313 min += offset;
314 max += offset;
315 }
316 }
317 else if (dc) {
318 min = -1.0, max = 1.0; // sensible defaults?
319 result = AnalyseTrackData(track, report, curT0, curT1, offset);
320 min += offset;
321 max += offset;
322 }
323 else {
324 wxFAIL_MSG("Analysing Track when nothing to do!");
325 min = -1.0, max = 1.0; // sensible defaults?
326 offset = 0.0;
327 }
328 extent = fmax(fabs(min), fabs(max));
329 return result;
330}
int min(int a, int b)
static bool AnalyseTrackData(const WaveChannel &track, const ProgressReport &report, double curT0, double curT1, float &offset)
Definition: Normalize.cpp:334
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
Definition: WaveTrack.cpp:2727

References AnalyseTrackData(), WaveChannel::GetMinMax(), 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 WaveChannel track,
const ProgressReport report,
double  curT0,
double  curT1,
float &  offset 
)
staticprivate

Definition at line 334 of file Normalize.cpp.

337{
338 bool rc = true;
339
340 //Transform the marker timepoints to samples
341 auto start = track.TimeToLongSamples(curT0);
342 auto end = track.TimeToLongSamples(curT1);
343
344 //Get the length of the buffer (as double). len is
345 //used simply to calculate a progress meter, so it is easier
346 //to make it a double now than it is to do it later
347 auto len = (end - start).as_double();
348
349 //Initiate a processing buffer. This buffer will (most likely)
350 //be shorter than the length of the track being processed.
351 Floats buffer{ track.GetMaxBlockSize() };
352
353 double sum = 0.0; // dc offset inits
354
355 sampleCount blockSamples;
356 sampleCount totalSamples = 0;
357
358 //Go through the track one buffer at a time. s counts which
359 //sample the current buffer starts at.
360 auto s = start;
361 while (s < end) {
362 //Get a block of samples (smaller than the size of the buffer)
363 //Adjust the block size if it is the final block in the track
364 const auto block = limitSampleBufferSize(
365 track.GetBestBlockSize(s),
366 end - s
367 );
368
369 //Get the samples from the track and put them in the buffer
370 track.GetFloats(
371 buffer.get(), s, block, FillFormat::fillZero, true, &blockSamples);
372 totalSamples += blockSamples;
373
374 //Process the buffer.
375 sum = AnalyseDataDC(buffer.get(), block, sum);
376
377 //Increment s one blockfull of samples
378 s += block;
379
380 //Update the Progress meter
381 if (!report((s - start).as_double() / len)) {
382 rc = false; //lda .. break, not return, so that buffer is deleted
383 break;
384 }
385 }
386 if (totalSamples > 0)
387 // calculate actual offset (amount that needs to be added on)
388 offset = -sum / totalSamples.as_double();
389 else
390 offset = 0.0;
391
392 //Return true because the effect processing succeeded ... unless cancelled
393 return rc;
394}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
static double AnalyseDataDC(float *buffer, size_t len, double sum)
Definition: Normalize.cpp:458
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
Definition: WaveTrack.h:152
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
Definition: WaveTrack.h:1131
size_t GetMaxBlockSize() const
Definition: WaveTrack.h:1139
sampleCount TimeToLongSamples(double t0) const
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, WaveChannel::GetBestBlockSize(), WaveChannel::GetFloats(), WaveChannel::GetMaxBlockSize(), limitSampleBufferSize(), and WideSampleSequence::TimeToLongSamples().

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

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

References mDC, and mGain.

◆ FetchParameters()

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

Definition at line 31 of file Normalize.h.

31{ return &e; }

◆ GetDescription()

TranslatableString EffectNormalize::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 69 of file Normalize.cpp.

70{
71 return XO("Sets the peak amplitude of one or more tracks");
72}
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 64 of file Normalize.cpp.

65{
66 return Symbol;
67}
static const ComponentInterfaceSymbol Symbol
Definition: Normalize.h:32

References Symbol.

◆ GetType()

EffectType EffectNormalize::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 81 of file Normalize.cpp.

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

75{
76 return L"Normalize";
77}

◆ OnUpdateUI()

void EffectNormalize::OnUpdateUI ( wxCommandEvent &  evt)
private

Definition at line 473 of file Normalize.cpp.

474{
475 UpdateUI();
476}

References UpdateUI().

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectNormalize::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 34 of file Normalize.cpp.

35{
38 > parameters;
39 return parameters;
40}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter RemoveDC
Definition: Normalize.h:101
static constexpr EffectParameter StereoInd
Definition: Normalize.h:105
static constexpr EffectParameter PeakLevel
Definition: Normalize.h:99
static constexpr EffectParameter ApplyGain
Definition: Normalize.h:103

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

223{
224 mUIParent = S.GetParent();
225 mCreating = true;
226
227 S.StartVerticalLay(0);
228 {
229 S.StartMultiColumn(2, wxALIGN_CENTER);
230 {
231 S.StartVerticalLay(false);
232 {
233 mDCCheckBox = S.Validator<wxGenericValidator>(&mDC)
234 .AddCheckBox(XXO("&Remove DC offset (center on 0.0 vertically)"),
235 mDC);
236
237 S.StartHorizontalLay(wxALIGN_LEFT, false);
238 {
240 .MinSize()
241 .Validator<wxGenericValidator>(&mGain)
242 .AddCheckBox(XXO("&Normalize peak amplitude to "),
243 mGain);
244
246 .Name(XO("Peak amplitude dB"))
247 .Validator<FloatingPointValidator<double>>(
248 2,
249 &mPeakLevel,
250 NumValidatorStyle::ONE_TRAILING_ZERO,
252 PeakLevel.max )
253 .AddTextBox( {}, L"", 10);
254 mLeveldB = S.AddVariableText(XO("dB"), false,
255 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
256 mWarning = S.AddVariableText( {}, false,
257 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
258 }
259 S.EndHorizontalLay();
260
262 .Validator<wxGenericValidator>(&mStereoInd)
263 .AddCheckBox(XXO("N&ormalize stereo channels independently"),
264 mStereoInd);
265 }
266 S.EndVerticalLay();
267 }
268 S.EndMultiColumn();
269 }
270 S.EndVerticalLay();
271 mCreating = false;
272 return nullptr;
273}
XXO("&Cut/Copy/Paste Toolbar")
#define S(N)
Definition: ToChars.cpp:64
wxStaticText * mWarning
Definition: Normalize.h:92
wxStaticText * mLeveldB
Definition: Normalize.h:91
wxWeakRef< wxWindow > mUIParent
Definition: Normalize.h:77
double mPeakLevel
Definition: Normalize.h:79
wxCheckBox * mGainCheckBox
Definition: Normalize.h:88
wxCheckBox * mDCCheckBox
Definition: Normalize.h:89
wxTextCtrl * mLevelTextCtrl
Definition: Normalize.h:90
wxCheckBox * mStereoIndCheckBox
Definition: Normalize.h:93
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 93 of file Normalize.cpp.

94{
95 if (mGain == false && mDC == false)
96 return true;
97
98 float ratio;
99 if( mGain )
100 {
101 // same value used for all tracks
102 ratio = DB_TO_LINEAR(std::clamp<double>(mPeakLevel, PeakLevel.min, PeakLevel.max));
103 }
104 else {
105 ratio = 1.0;
106 }
107
108 //Iterate over each track
109 EffectOutputTracks outputs { *mTracks, {{ mT0, mT1 }} };
110 bool bGoodResult = true;
111 double progress = 0;
112 TranslatableString topMsg;
113 if(mDC && mGain)
114 topMsg = XO("Removing DC offset and Normalizing...\n");
115 else if(mDC && !mGain)
116 topMsg = XO("Removing DC offset...\n");
117 else if(!mDC && mGain)
118 topMsg = XO("Normalizing without removing DC offset...\n");
119 else if(!mDC && !mGain)
120 topMsg = XO("Not doing anything...\n"); // shouldn't get here
121
122 for (auto track : outputs.Get().Selected<WaveTrack>()) {
123 // Get start and end times from track
124 double trackStart = track->GetStartTime();
125 double trackEnd = track->GetEndTime();
126
127 // Set the current bounds to whichever left marker is
128 // greater and whichever right marker is less:
129 mCurT0 = std::max(trackStart, mT0);
130 mCurT1 = std::min(trackEnd, mT1);
131
132 // Process only if the right marker is to the right of the left marker
133 if (mCurT1 > mCurT0) {
134 wxString trackName = track->GetName();
135
136 std::vector<float> extents;
137 float maxExtent{ std::numeric_limits<float>::lowest() };
138 std::vector<float> offsets;
139
140 const auto channels = track->Channels();
141 // mono or 'stereo tracks independently'
142 const bool oneChannel = (channels.size() == 1 || mStereoInd);
143 auto msg = oneChannel
144 ? topMsg +
145 XO("Analyzing: %s").Format(trackName)
146 : topMsg +
147 // TODO: more-than-two-channels-message
148 XO("Analyzing first track of stereo pair: %s").Format(trackName);
149
150 const auto progressReport = [&](double fraction){
151 return !TotalProgress(
152 (progress + fraction / double(2 * GetNumWaveTracks())), msg);
153 };
154
155 // Analysis loop over channels collects offsets and extent
156 for (auto channel : channels) {
157 float offset = 0;
158 float extent = 0;
159 bGoodResult = AnalyseTrack(*channel, progressReport, mGain, mDC,
160 mCurT0, mCurT1, offset, extent);
161 if (!bGoodResult)
162 goto break2;
163 progress += 1.0 / double(2 * GetNumWaveTracks());
164 extents.push_back(extent);
165 maxExtent = std::max(maxExtent, extent);
166 offsets.push_back(offset);
167 // TODO: more-than-two-channels-message
168 if (!oneChannel)
169 msg = topMsg +
170 XO("Analyzing second track of stereo pair: %s")
171 .Format(trackName);
172 }
173
174 if (oneChannel) {
175 if (TrackList::NChannels(*track) == 1)
176 // really mono
177 msg = topMsg +
178 XO("Processing: %s").Format(trackName);
179 else
180 //'stereo tracks independently'
181 // TODO: more-than-two-channels-message
182 msg = topMsg +
183 XO("Processing stereo channels independently: %s")
184 .Format(trackName);
185 }
186 else
187 msg = topMsg +
188 // TODO: more-than-two-channels-message
189 XO("Processing first track of stereo pair: %s")
190 .Format(trackName);
191
192 // Use multiplier in the second, processing loop over channels
193 auto pOffset = offsets.begin();
194 auto pExtent = extents.begin();
195 for (const auto channel : channels) {
196 const auto extent = oneChannel ? *pExtent++: maxExtent;
197 if ((extent > 0) && mGain)
198 mMult = ratio / extent;
199 else
200 mMult = 1.0;
201 if (false ==
202 (bGoodResult = ProcessOne(*channel, msg, progress, *pOffset++)))
203 goto break2;
204 // TODO: more-than-two-channels-message
205 msg = topMsg +
206 XO("Processing second track of stereo pair: %s")
207 .Format(trackName);
208 }
209 }
210 }
211
212 break2:
213
214 if (bGoodResult)
215 outputs.Commit();
216
217 return bGoodResult;
218}
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:561
double mT1
Definition: EffectBase.h:116
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:109
double mT0
Definition: EffectBase.h:115
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:341
int GetNumWaveTracks() const
Definition: Effect.h:139
double mCurT0
Definition: Normalize.h:84
double mCurT1
Definition: Normalize.h:85
bool ProcessOne(WaveChannel &track, const TranslatableString &msg, double &progress, float offset)
Definition: Normalize.cpp:400
static bool AnalyseTrack(const WaveChannel &track, const ProgressReport &report, bool gain, bool dc, double curT0, double curT1, float &offset, float &extent)
Definition: Normalize.cpp:299
Use this object to copy the input tracks to tentative outputTracks.
size_t NChannels() const
Definition: Track.cpp:977
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:220

References AnalyseTrack(), DB_TO_LINEAR, Effect::GetNumWaveTracks(), EffectParameter< Structure, Member, Type, Value >::max, mCurT0, mCurT1, mDC, mGain, EffectParameter< Structure, Member, Type, Value >::min, min(), mMult, mPeakLevel, mStereoInd, EffectBase::mT0, EffectBase::mT1, EffectBase::mTracks, TrackList::NChannels(), PeakLevel, ProcessOne(), Effect::TotalProgress(), 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 465 of file Normalize.cpp.

466{
467 for(decltype(len) i = 0; i < len; i++) {
468 float adjFrame = (buffer[i] + offset) * mMult;
469 buffer[i] = adjFrame;
470 }
471}

References mMult.

Referenced by ProcessOne().

Here is the caller graph for this function:

◆ ProcessOne()

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

Definition at line 400 of file Normalize.cpp.

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

References PackedArray::end(), floatSample, WaveChannel::GetBestBlockSize(), WaveChannel::GetFloats(), WaveChannel::GetMaxBlockSize(), Effect::GetNumWaveTracks(), limitSampleBufferSize(), mCurT0, mCurT1, ProcessData(), WaveChannel::Set(), WideSampleSequence::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 287 of file Normalize.cpp.

288{
289 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
290 {
291 return false;
292 }
293
294 return true;
295}

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

276{
277 if (!mUIParent->TransferDataToWindow())
278 {
279 return false;
280 }
281
282 UpdateUI();
283
284 return true;
285}

References mUIParent, and UpdateUI().

Here is the call graph for this function:

◆ UpdateUI()

void EffectNormalize::UpdateUI ( )
private

Definition at line 478 of file Normalize.cpp.

479{
480
481 if (!mUIParent->TransferDataFromWindow())
482 {
483 mWarning->SetLabel(_("(Maximum 0dB)"));
485 return;
486 }
487 mWarning->SetLabel(wxT(""));
488
489 // Disallow level stuff if not normalizing
490 mLevelTextCtrl->Enable(mGain);
491 mLeveldB->Enable(mGain);
492 mStereoIndCheckBox->Enable(mGain);
493
494 // Disallow OK/Preview if doing nothing
496}
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 103 of file Normalize.h.

Referenced by Parameters().

◆ mCreating

bool EffectNormalize::mCreating
private

Definition at line 94 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mCurT0

double EffectNormalize::mCurT0
private

Definition at line 84 of file Normalize.h.

Referenced by Process(), and ProcessOne().

◆ mCurT1

double EffectNormalize::mCurT1
private

Definition at line 85 of file Normalize.h.

Referenced by Process(), and ProcessOne().

◆ mDC

bool EffectNormalize::mDC
private

Definition at line 81 of file Normalize.h.

Referenced by CheckWhetherSkipEffect(), PopulateOrExchange(), Process(), and UpdateUI().

◆ mDCCheckBox

wxCheckBox* EffectNormalize::mDCCheckBox
private

Definition at line 89 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mGain

bool EffectNormalize::mGain
private

Definition at line 80 of file Normalize.h.

Referenced by CheckWhetherSkipEffect(), PopulateOrExchange(), Process(), and UpdateUI().

◆ mGainCheckBox

wxCheckBox* EffectNormalize::mGainCheckBox
private

Definition at line 88 of file Normalize.h.

Referenced by PopulateOrExchange().

◆ mLeveldB

wxStaticText* EffectNormalize::mLeveldB
private

Definition at line 91 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mLevelTextCtrl

wxTextCtrl* EffectNormalize::mLevelTextCtrl
private

Definition at line 90 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mMult

float EffectNormalize::mMult
private

Definition at line 86 of file Normalize.h.

Referenced by Process(), and ProcessData().

◆ mPeakLevel

double EffectNormalize::mPeakLevel
private

Definition at line 79 of file Normalize.h.

Referenced by PopulateOrExchange(), and Process().

◆ mStereoInd

bool EffectNormalize::mStereoInd
private

Definition at line 82 of file Normalize.h.

Referenced by PopulateOrExchange(), and Process().

◆ mStereoIndCheckBox

wxCheckBox* EffectNormalize::mStereoIndCheckBox
private

Definition at line 93 of file Normalize.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mUIParent

wxWeakRef<wxWindow> EffectNormalize::mUIParent {}
private

◆ mWarning

wxStaticText* EffectNormalize::mWarning
private

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

Referenced by Parameters().

◆ StereoInd

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

Definition at line 105 of file Normalize.h.

Referenced by Parameters().

◆ Symbol

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

Definition at line 32 of file Normalize.h.

Referenced by GetSymbol().


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