Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Static Private Member Functions | List of all members
LoudnessBase Class Reference

An Effect to bring the loudness level up to a chosen level. More...

#include <LoudnessBase.h>

Inheritance diagram for LoudnessBase:
[legend]
Collaboration diagram for LoudnessBase:
[legend]

Public Types

enum  kNormalizeTargets { kLoudness , kRMS , nAlgos }
 
- 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 Member Functions

 LoudnessBase ()
 
virtual ~LoudnessBase ()
 
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 Process (EffectInstance &instance, EffectSettings &settings) override
 
bool UpdateProgress ()
 
- 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)
 
double GetDefaultDuration ()
 
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
 

Static Public Member Functions

static LoudnessBaseFetchParameters (LoudnessBase &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 Attributes

static const ComponentInterfaceSymbol Symbol
 
- 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>")
 

Protected Member Functions

const EffectParameterMethodsParameters () const override
 
- 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

bool mStereoInd
 
double mLUFSLevel
 
double mRMSLevel
 
bool mDualMono
 
int mNormalizeTo
 
double mProgressVal
 
int mSteps
 
TranslatableString mProgressMsg
 
double mTrackLen
 
double mCurRate
 
Floats mTrackBuffer [2]
 
size_t mTrackBufferLen
 
size_t mTrackBufferCapacity
 
bool mProcStereo
 
- Protected Attributes inherited from EffectBase
double mF0 {}
 
double mF1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

Static Protected Attributes

static constexpr EffectParameter StereoInd
 
static constexpr EffectParameter LUFSLevel
 
static constexpr EffectParameter RMSLevel
 
static constexpr EffectParameter DualMono
 
static constexpr EffectParameter NormalizeTo
 

Private Member Functions

void AllocBuffers (TrackList &outputs)
 
void FreeBuffers ()
 
bool ProcessOne (WaveChannel &track, size_t nChannels, double curT0, double curT1, float mult, EBUR128 *pLoudnessProcessor)
 
void LoadBufferBlock (WaveChannel &track, size_t nChannels, sampleCount pos, size_t len)
 
bool AnalyseBufferBlock (EBUR128 &loudnessProcessor)
 
bool ProcessBufferBlock (float mult)
 
bool StoreBufferBlock (WaveChannel &track, size_t nChannels, sampleCount pos, size_t len)
 

Static Private Member Functions

static bool GetTrackRMS (WaveChannel &track, double curT0, double curT1, float &rms)
 

Additional Inherited Members

- Public Attributes inherited from EffectBase
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 

Detailed Description

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

Definition at line 20 of file LoudnessBase.h.

Member Enumeration Documentation

◆ kNormalizeTargets

Enumerator
kLoudness 
kRMS 
nAlgos 

Definition at line 23 of file LoudnessBase.h.

24 {
26 kRMS,
27 nAlgos
28 };

Constructor & Destructor Documentation

◆ LoudnessBase()

LoudnessBase::LoudnessBase ( )

Definition at line 34 of file LoudnessBase.cpp.

35{
36 Parameters().Reset(*this);
38}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:210
virtual void Reset(Effect &effect) const =0
const EffectParameterMethods & Parameters() const override

References Parameters(), EffectParameterMethods::Reset(), and EffectBase::SetLinearEffectFlag().

Referenced by Parameters().

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

◆ ~LoudnessBase()

LoudnessBase::~LoudnessBase ( )
virtual

Definition at line 40 of file LoudnessBase.cpp.

41{
42}

Member Function Documentation

◆ AllocBuffers()

void LoudnessBase::AllocBuffers ( TrackList outputs)
private

Get required buffer size for the largest whole track and allocate buffers. This reduces the amount of allocations required.

Definition at line 214 of file LoudnessBase.cpp.

215{
217 bool stereoTrackFound = false;
218 double maxSampleRate = 0;
219 mProcStereo = false;
220
221 for (auto track : outputs.Selected<WaveTrack>() + &Track::Any)
222 {
224 std::max(mTrackBufferCapacity, track->GetMaxBlockSize());
225 maxSampleRate = std::max(maxSampleRate, track->GetRate());
226
227 // There is a stereo track
228 if (track->NChannels() == 2)
229 stereoTrackFound = true;
230 }
231
232 // Initiate a processing buffer. This buffer will (most likely)
233 // be shorter than the length of the track being processed.
235
236 if (!mStereoInd && stereoTrackFound)
238}
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:59
Floats mTrackBuffer[2]
Definition: LoudnessBase.h:84
bool mProcStereo
Definition: LoudnessBase.h:88
size_t mTrackBufferCapacity
Definition: LoudnessBase.h:87
bool Any() const
Definition: Track.cpp:255
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:967
A Track that contains audio waveform data.
Definition: WaveTrack.h:203

References Track::Any(), mProcStereo, mStereoInd, mTrackBuffer, mTrackBufferCapacity, ArrayOf< X >::reinit(), and TrackList::Selected().

Referenced by Process().

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

◆ AnalyseBufferBlock()

bool LoudnessBase::AnalyseBufferBlock ( EBUR128 loudnessProcessor)
private

Calculates sample sum (for DC) and EBU R128 weighted square sum (for loudness).

Definition at line 336 of file LoudnessBase.cpp.

337{
338 for (size_t i = 0; i < mTrackBufferLen; i++)
339 {
340 loudnessProcessor.ProcessSampleFromChannel(mTrackBuffer[0][i], 0);
341 if (mProcStereo)
342 loudnessProcessor.ProcessSampleFromChannel(mTrackBuffer[1][i], 1);
343 loudnessProcessor.NextSample();
344 }
345
346 if (!UpdateProgress())
347 return false;
348 return true;
349}
void ProcessSampleFromChannel(float x_in, size_t channel) const
Definition: EBUR128.cpp:83
void NextSample()
Definition: EBUR128.cpp:98
bool UpdateProgress()
size_t mTrackBufferLen
Definition: LoudnessBase.h:86

References mProcStereo, mTrackBuffer, mTrackBufferLen, EBUR128::NextSample(), EBUR128::ProcessSampleFromChannel(), and UpdateProgress().

Referenced by ProcessOne().

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

◆ FetchParameters()

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

Definition at line 30 of file LoudnessBase.h.

31 {
32 return &e;
33 }

◆ FreeBuffers()

void LoudnessBase::FreeBuffers ( )
private

Definition at line 240 of file LoudnessBase.cpp.

241{
242 mTrackBuffer[0].reset();
243 mTrackBuffer[1].reset();
244}

References mTrackBuffer.

Referenced by Process().

Here is the caller graph for this function:

◆ GetDescription()

TranslatableString LoudnessBase::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 51 of file LoudnessBase.cpp.

52{
53 return XO("Sets the loudness of one or more tracks");
54}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol LoudnessBase::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 46 of file LoudnessBase.cpp.

47{
48 return Symbol;
49}
static const ComponentInterfaceSymbol Symbol
Definition: LoudnessBase.h:34

References Symbol.

◆ GetTrackRMS()

bool LoudnessBase::GetTrackRMS ( WaveChannel track,
double  curT0,
double  curT1,
float &  rms 
)
staticprivate

Definition at line 246 of file LoudnessBase.cpp.

248{
249 // set mRMS. No progress bar here as it's fast.
250 float _rms = WaveChannelUtilities::GetRMS(track, curT0, curT1); // may throw
251 rms = _rms;
252 return true;
253}
WAVE_TRACK_API float GetRMS(const WaveChannel &channel, double t0, double t1, bool mayThrow=true)

References WaveChannelUtilities::GetRMS().

Referenced by Process().

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

◆ GetType()

EffectType LoudnessBase::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 63 of file LoudnessBase.cpp.

64{
65 return EffectTypeProcess;
66}
@ EffectTypeProcess

References EffectTypeProcess.

Referenced by Process().

Here is the caller graph for this function:

◆ LoadBufferBlock()

void LoudnessBase::LoadBufferBlock ( WaveChannel track,
size_t  nChannels,
sampleCount  pos,
size_t  len 
)
private

Definition at line 314 of file LoudnessBase.cpp.

316{
317 size_t idx = 0;
318 const auto getOne = [&](WaveChannel& channel) {
319 // Get the samples from the track and put them in the buffer
320 channel.GetFloats(mTrackBuffer[idx].get(), pos, len);
321 };
322
323 if (nChannels == 1)
324 getOne(track);
325 else
326 for (const auto channel : track.GetTrack().Channels())
327 {
328 getOne(*channel);
329 ++idx;
330 }
331 mTrackBufferLen = len;
332}
WaveTrack & GetTrack()
Definition: WaveTrack.h:841
auto Channels()
Definition: WaveTrack.h:263

References WaveTrack::Channels(), WaveChannel::GetTrack(), mTrackBuffer, and mTrackBufferLen.

Referenced by ProcessOne().

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

◆ ManualPage()

ManualPageID LoudnessBase::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 56 of file LoudnessBase.cpp.

57{
58 return L"Loudness_Normalization";
59}

◆ Parameters()

const EffectParameterMethods & LoudnessBase::Parameters ( ) const
overrideprotectedvirtual

Reimplemented from Effect.

Definition at line 26 of file LoudnessBase.cpp.

27{
28 static CapturedParameters<
30 parameters;
31 return parameters;
32}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter LUFSLevel
Definition: LoudnessBase.h:95
static constexpr EffectParameter StereoInd
Definition: LoudnessBase.h:92
static constexpr EffectParameter DualMono
Definition: LoudnessBase.h:101
static constexpr EffectParameter NormalizeTo
Definition: LoudnessBase.h:104
static constexpr EffectParameter RMSLevel
Definition: LoudnessBase.h:98

References DualMono, LoudnessBase(), LUFSLevel, NormalizeTo, RMSLevel, and StereoInd.

Referenced by LoudnessBase().

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

◆ Process()

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

Implements StatefulEffectBase.

Definition at line 70 of file LoudnessBase.cpp.

71{
72 const float ratio = DB_TO_LINEAR(
73 (mNormalizeTo == kLoudness) ? // LU use 10*log10(...) instead of
74 // 20*log10(...) so multiply level by 2
75 std::clamp<double>(
76 mLUFSLevel * 2, LUFSLevel.min, LUFSLevel.max) : // RMS
77 std::clamp<double>(mRMSLevel, RMSLevel.min, RMSLevel.max));
78
79 // Iterate over each track
80 EffectOutputTracks outputs { *mTracks, GetType(), { { mT0, mT1 } } };
81 bool bGoodResult = true;
82 auto topMsg = XO("Normalizing Loudness...\n");
83
84 AllocBuffers(outputs.Get());
85 mProgressVal = 0;
86
87 for (auto pTrack : outputs.Get().Selected<WaveTrack>())
88 {
89 // Get start and end times from track
90 double trackStart = pTrack->GetStartTime();
91 double trackEnd = pTrack->GetEndTime();
92
93 // Set the current bounds to whichever left marker is
94 // greater and whichever right marker is less:
95 const double curT0 = std::max(trackStart, mT0);
96 const double curT1 = std::min(trackEnd, mT1);
97
98 // Get the track rate
99 mCurRate = pTrack->GetRate();
100
101 wxString msg;
102 auto trackName = pTrack->GetName();
103 // This affects only the progress indicator update during ProcessOne
104 mSteps = (mNormalizeTo == kLoudness) ? 2 : 1;
105
106 mProgressMsg = topMsg + XO("Analyzing: %s").Format(trackName);
107
108 const auto channels = pTrack->Channels();
109 auto nChannels = mStereoInd ? 1 : channels.size();
110 mProcStereo = nChannels > 1;
111
112 const auto processOne = [&](WaveChannel& track) {
113 std::optional<EBUR128> loudnessProcessor;
114 float RMS[2];
115
116 if (mNormalizeTo == kLoudness)
117 {
118 loudnessProcessor.emplace(mCurRate, nChannels);
119 if (!ProcessOne(
120 track, nChannels, curT0, curT1, 0, &*loudnessProcessor))
121 // Processing failed -> abort
122 return false;
123 }
124 else
125 {
126 // RMS
127 if (mProcStereo)
128 {
129 size_t idx = 0;
130 for (const auto pChannel : channels)
131 {
132 if (!GetTrackRMS(*pChannel, curT0, curT1, RMS[idx]))
133 return false;
134 ++idx;
135 }
136 }
137 else
138 {
139 if (!GetTrackRMS(track, curT0, curT1, RMS[0]))
140 return false;
141 }
142 }
143
144 // Calculate normalization values the analysis results
145 float extent;
146 if (mNormalizeTo == kLoudness)
147 extent = loudnessProcessor->IntegrativeLoudness();
148 else
149 {
150 // RMS
151 extent = RMS[0];
152 if (mProcStereo)
153 // RMS: use average RMS, average must be calculated in quadratic
154 // domain.
155 extent = sqrt((RMS[0] * RMS[0] + RMS[1] * RMS[1]) / 2.0);
156 }
157
158 if (extent == 0.0)
159 {
160 FreeBuffers();
161 return false;
162 }
163 float mult = ratio / extent;
164
165 if (mNormalizeTo == kLoudness)
166 {
167 // Target half the LUFS value if mono (or independent processed
168 // stereo) shall be treated as dual mono.
169 if (nChannels == 1 && (mDualMono || !IsMono(track)))
170 mult /= 2.0;
171
172 // LUFS are related to square values so the multiplier must be the
173 // xroot.
174 mult = sqrt(mult);
175 }
176
177 mProgressMsg = topMsg + XO("Processing: %s").Format(trackName);
178 if (!ProcessOne(track, nChannels, curT0, curT1, mult, nullptr))
179 {
180 // Processing failed -> abort
181 return false;
182 }
183 return true;
184 };
185
186 if (mStereoInd)
187 {
188 for (const auto pChannel : channels)
189 if (!(bGoodResult = processOne(*pChannel)))
190 goto done;
191 }
192 else
193 {
194 // processOne captured nChannels which is 2 and is passed to
195 // LoadBufferBlock, StoreBufferBlock which find the track from the
196 // channel and iterate channels
197 if (!(bGoodResult = processOne(**pTrack->Channels().begin())))
198 break;
199 }
200 }
201done:
202
203 if (bGoodResult)
204 outputs.Commit();
205
206 FreeBuffers();
207 return bGoodResult;
208}
int min(int a, int b)
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:338
double mT1
Definition: EffectBase.h:123
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:116
double mT0
Definition: EffectBase.h:122
Use this object to copy the input tracks to tentative outputTracks.
double mProgressVal
Definition: LoudnessBase.h:78
double mLUFSLevel
Definition: LoudnessBase.h:73
EffectType GetType() const override
Type determines how it behaves.
void AllocBuffers(TrackList &outputs)
double mCurRate
Definition: LoudnessBase.h:82
TranslatableString mProgressMsg
Definition: LoudnessBase.h:80
static bool GetTrackRMS(WaveChannel &track, double curT0, double curT1, float &rms)
void FreeBuffers()
bool ProcessOne(WaveChannel &track, size_t nChannels, double curT0, double curT1, float mult, EBUR128 *pLoudnessProcessor)
double mRMSLevel
Definition: LoudnessBase.h:74
bool IsMono(const Channel &channel)
Whether the channel is mono.
__finl float_x4 __vecc sqrt(const float_x4 &a)
const Type min
Minimum value.
const Type max
Maximum value.

References AllocBuffers(), DB_TO_LINEAR, FreeBuffers(), GetTrackRMS(), GetType(), AudioGraph::IsMono(), kLoudness, LUFSLevel, EffectParameter< Structure, Member, Type, Value >::max, mCurRate, mDualMono, EffectParameter< Structure, Member, Type, Value >::min, min(), mLUFSLevel, mNormalizeTo, mProcStereo, mProgressMsg, mProgressVal, mRMSLevel, mSteps, mStereoInd, EffectBase::mT0, EffectBase::mT1, EffectBase::mTracks, ProcessOne(), RMSLevel, staffpad::audio::simd::sqrt(), and XO().

Here is the call graph for this function:

◆ ProcessBufferBlock()

bool LoudnessBase::ProcessBufferBlock ( float  mult)
private

Definition at line 351 of file LoudnessBase.cpp.

352{
353 for (size_t i = 0; i < mTrackBufferLen; i++)
354 {
355 mTrackBuffer[0][i] = mTrackBuffer[0][i] * mult;
356 if (mProcStereo)
357 mTrackBuffer[1][i] = mTrackBuffer[1][i] * mult;
358 }
359
360 if (!UpdateProgress())
361 return false;
362 return true;
363}

References mProcStereo, mTrackBuffer, mTrackBufferLen, and UpdateProgress().

Referenced by ProcessOne().

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

◆ ProcessOne()

bool LoudnessBase::ProcessOne ( WaveChannel track,
size_t  nChannels,
double  curT0,
double  curT1,
float  mult,
EBUR128 pLoudnessProcessor 
)
private

ProcessOne() takes a track, transforms it to bunch of buffer-blocks, and executes ProcessData, on it... uses mMult to normalize a track. mMult must be set before this is called In analyse mode, it executes the selected analyse operation on it... mMult does not have to be set before this is called

Definition at line 261 of file LoudnessBase.cpp.

264{
265 // Transform the marker timepoints to samples
266 auto start = track.TimeToLongSamples(curT0);
267 auto end = track.TimeToLongSamples(curT1);
268
269 // Get the length of the buffer (as double). len is
270 // used simply to calculate a progress meter, so it is easier
271 // to make it a double now than it is to do it later
272 mTrackLen = (end - start).as_double();
273
274 // Abort if the right marker is not to the right of the left marker
275 if (curT1 <= curT0)
276 return false;
277
278 // Go through the track one buffer at a time. s counts which
279 // sample the current buffer starts at.
280 auto s = start;
281 while (s < end)
282 {
283 // Get a block of samples (smaller than the size of the buffer)
284 // Adjust the block size if it is the final block in the track
285 auto blockLen =
287
288 const size_t remainingLen = (end - s).as_size_t();
289 blockLen = blockLen > remainingLen ? remainingLen : blockLen;
290 LoadBufferBlock(track, nChannels, s, blockLen);
291
292 // Process the buffer.
293 if (pLoudnessProcessor)
294 {
295 if (!AnalyseBufferBlock(*pLoudnessProcessor))
296 return false;
297 }
298 else
299 {
300 if (!ProcessBufferBlock(mult))
301 return false;
302 if (!StoreBufferBlock(track, nChannels, s, blockLen))
303 return false;
304 }
305
306 // Increment s one blockfull of samples
307 s += blockLen;
308 }
309
310 // Return true because the effect processing succeeded ... unless cancelled
311 return true;
312}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
void LoadBufferBlock(WaveChannel &track, size_t nChannels, sampleCount pos, size_t len)
bool AnalyseBufferBlock(EBUR128 &loudnessProcessor)
double mTrackLen
Definition: LoudnessBase.h:81
bool StoreBufferBlock(WaveChannel &track, size_t nChannels, sampleCount pos, size_t len)
bool ProcessBufferBlock(float mult)
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
Definition: WaveTrack.h:851
sampleCount TimeToLongSamples(double t0) const
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References AnalyseBufferBlock(), details::end(), WaveChannel::GetBestBlockSize(), limitSampleBufferSize(), LoadBufferBlock(), mTrackBufferCapacity, mTrackLen, ProcessBufferBlock(), StoreBufferBlock(), and WideSampleSequence::TimeToLongSamples().

Referenced by Process().

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

◆ StoreBufferBlock()

bool LoudnessBase::StoreBufferBlock ( WaveChannel track,
size_t  nChannels,
sampleCount  pos,
size_t  len 
)
private

Definition at line 365 of file LoudnessBase.cpp.

367{
368 size_t idx = 0;
369 const auto setOne = [&](WaveChannel& channel) {
370 // Copy the newly-changed samples back onto the track.
371 return channel.SetFloats(mTrackBuffer[idx].get(), pos, len);
372 };
373
374 if (nChannels == 1)
375 return setOne(track);
376 else
377 {
378 for (auto channel : track.GetTrack().Channels())
379 {
380 if (!setOne(*channel))
381 return false;
382 ++idx;
383 }
384 return true;
385 }
386}

References WaveTrack::Channels(), WaveChannel::GetTrack(), and mTrackBuffer.

Referenced by ProcessOne().

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

◆ UpdateProgress()

bool LoudnessBase::UpdateProgress ( )

Definition at line 388 of file LoudnessBase.cpp.

389{
390 mProgressVal +=
391 (double(1 + mProcStereo) * double(mTrackBufferLen) /
392 (double(GetNumWaveTracks()) * double(mSteps) * mTrackLen));
394}
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:335
int GetNumWaveTracks() const
Definition: Effect.h:139

References Effect::GetNumWaveTracks(), mProcStereo, mProgressMsg, mProgressVal, mSteps, mTrackBufferLen, mTrackLen, and Effect::TotalProgress().

Referenced by AnalyseBufferBlock(), and ProcessBufferBlock().

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

Member Data Documentation

◆ DualMono

constexpr EffectParameter LoudnessBase::DualMono
staticconstexprprotected
Initial value:
{
&LoudnessBase::mDualMono, L"DualMono", true, false, true, 1
}

Definition at line 101 of file LoudnessBase.h.

Referenced by Parameters().

◆ LUFSLevel

constexpr EffectParameter LoudnessBase::LUFSLevel
staticconstexprprotected
Initial value:
{
&LoudnessBase::mLUFSLevel, L"LUFSLevel", -23.0, -145.0, 0.0, 1
}

Definition at line 95 of file LoudnessBase.h.

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

◆ mCurRate

double LoudnessBase::mCurRate
protected

Definition at line 82 of file LoudnessBase.h.

Referenced by Process().

◆ mDualMono

bool LoudnessBase::mDualMono
protected

Definition at line 75 of file LoudnessBase.h.

Referenced by EffectLoudness::PopulateOrExchange(), and Process().

◆ mLUFSLevel

double LoudnessBase::mLUFSLevel
protected

Definition at line 73 of file LoudnessBase.h.

Referenced by EffectLoudness::PopulateOrExchange(), and Process().

◆ mNormalizeTo

int LoudnessBase::mNormalizeTo
protected

◆ mProcStereo

bool LoudnessBase::mProcStereo
protected

◆ mProgressMsg

TranslatableString LoudnessBase::mProgressMsg
protected

Definition at line 80 of file LoudnessBase.h.

Referenced by Process(), and UpdateProgress().

◆ mProgressVal

double LoudnessBase::mProgressVal
protected

Definition at line 78 of file LoudnessBase.h.

Referenced by Process(), and UpdateProgress().

◆ mRMSLevel

double LoudnessBase::mRMSLevel
protected

Definition at line 74 of file LoudnessBase.h.

Referenced by EffectLoudness::PopulateOrExchange(), and Process().

◆ mSteps

int LoudnessBase::mSteps
protected

Definition at line 79 of file LoudnessBase.h.

Referenced by Process(), and UpdateProgress().

◆ mStereoInd

bool LoudnessBase::mStereoInd
protected

Definition at line 72 of file LoudnessBase.h.

Referenced by AllocBuffers(), EffectLoudness::PopulateOrExchange(), and Process().

◆ mTrackBuffer

Floats LoudnessBase::mTrackBuffer[2]
protected

◆ mTrackBufferCapacity

size_t LoudnessBase::mTrackBufferCapacity
protected

Definition at line 87 of file LoudnessBase.h.

Referenced by AllocBuffers(), and ProcessOne().

◆ mTrackBufferLen

size_t LoudnessBase::mTrackBufferLen
protected

◆ mTrackLen

double LoudnessBase::mTrackLen
protected

Definition at line 81 of file LoudnessBase.h.

Referenced by ProcessOne(), and UpdateProgress().

◆ NormalizeTo

constexpr EffectParameter LoudnessBase::NormalizeTo
staticconstexprprotected
Initial value:
L"NormalizeTo",
(int)kLoudness,
0,
nAlgos - 1,
1 }

Definition at line 104 of file LoudnessBase.h.

Referenced by Parameters().

◆ RMSLevel

constexpr EffectParameter LoudnessBase::RMSLevel
staticconstexprprotected
Initial value:
{
&LoudnessBase::mRMSLevel, L"RMSLevel", -20.0, -145.0, 0.0, 1
}

Definition at line 98 of file LoudnessBase.h.

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

◆ StereoInd

constexpr EffectParameter LoudnessBase::StereoInd
staticconstexprprotected
Initial value:
{
&LoudnessBase::mStereoInd, L"StereoIndependent", false, false, true, 1
}

Definition at line 92 of file LoudnessBase.h.

Referenced by Parameters().

◆ Symbol

const ComponentInterfaceSymbol LoudnessBase::Symbol
static
Initial value:
{ XO(
"Loudness Normalization") }

Definition at line 34 of file LoudnessBase.h.

Referenced by GetSymbol().


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