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
 
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 NumericFormatID 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
double mF0 {}
 
double mF1 {}
 
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 53 of file Normalize.cpp.

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

60{
61}

Member Function Documentation

◆ AnalyseDataDC()

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

Definition at line 460 of file Normalize.cpp.

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

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

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

References AnalyseTrackData(), WaveChannelUtilities::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 336 of file Normalize.cpp.

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

References AnalyseDataDC(), sampleCount::as_double(), details::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 89 of file Normalize.cpp.

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

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

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

66{
67 return Symbol;
68}
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 82 of file Normalize.cpp.

83{
84 return EffectTypeProcess;
85}
@ EffectTypeProcess

References EffectTypeProcess.

Referenced by Process().

Here is the caller graph for this function:

◆ ManualPage()

ManualPageID EffectNormalize::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 75 of file Normalize.cpp.

76{
77 return L"Normalize";
78}

◆ OnUpdateUI()

void EffectNormalize::OnUpdateUI ( wxCommandEvent &  evt)
private

Definition at line 475 of file Normalize.cpp.

476{
477 UpdateUI();
478}

References UpdateUI().

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectNormalize::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 35 of file Normalize.cpp.

36{
39 > parameters;
40 return parameters;
41}
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 221 of file Normalize.cpp.

224{
225 mUIParent = S.GetParent();
226 mCreating = true;
227
228 S.StartVerticalLay(0);
229 {
230 S.StartMultiColumn(2, wxALIGN_CENTER);
231 {
232 S.StartVerticalLay(false);
233 {
234 mDCCheckBox = S.Validator<wxGenericValidator>(&mDC)
235 .AddCheckBox(XXO("&Remove DC offset (center on 0.0 vertically)"),
236 mDC);
237
238 S.StartHorizontalLay(wxALIGN_LEFT, false);
239 {
241 .MinSize()
242 .Validator<wxGenericValidator>(&mGain)
243 .AddCheckBox(XXO("&Normalize peak amplitude to "),
244 mGain);
245
247 .Name(XO("Peak amplitude dB"))
248 .Validator<FloatingPointValidator<double>>(
249 2,
250 &mPeakLevel,
251 NumValidatorStyle::ONE_TRAILING_ZERO,
253 PeakLevel.max )
254 .AddTextBox( {}, L"", 10);
255 mLeveldB = S.AddVariableText(XO("dB"), false,
256 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
257 mWarning = S.AddVariableText( {}, false,
258 wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
259 }
260 S.EndHorizontalLay();
261
263 .Validator<wxGenericValidator>(&mStereoInd)
264 .AddCheckBox(XXO("N&ormalize stereo channels independently"),
265 mStereoInd);
266 }
267 S.EndVerticalLay();
268 }
269 S.EndMultiColumn();
270 }
271 S.EndVerticalLay();
272 mCreating = false;
273 return nullptr;
274}
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:54
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 94 of file Normalize.cpp.

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

References AnalyseTrack(), DB_TO_LINEAR, Effect::GetNumWaveTracks(), GetType(), 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, 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 467 of file Normalize.cpp.

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

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

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

References details::end(), WaveChannel::GetBestBlockSize(), WaveChannel::GetFloats(), WaveChannel::GetMaxBlockSize(), Effect::GetNumWaveTracks(), limitSampleBufferSize(), mCurT0, mCurT1, ProcessData(), WaveChannel::SetFloats(), 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 288 of file Normalize.cpp.

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

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

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

References mUIParent, and UpdateUI().

Here is the call graph for this function:

◆ UpdateUI()

void EffectNormalize::UpdateUI ( )
private

Definition at line 480 of file Normalize.cpp.

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