Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
EqualizationBase Class Reference

#include <EqualizationBase.h>

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

Classes

struct  Task
 

Public Member Functions

 EqualizationBase (int Options=kEqLegacy)
 
virtual ~EqualizationBase ()
 
TranslatableString GetDescription () const override
 
ManualPageID ManualPage () const override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
OptionalMessage DoLoadFactoryDefaults (EffectSettings &settings)
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
bool Init () override
 
bool Process (EffectInstance &instance, 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)
 
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 EqualizationParametersFetchParameters (EqualizationBase &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 { XO("Equalization") }
 
- 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

bool ProcessOne (Task &task, int count, const WaveChannel &t, sampleCount start, sampleCount len)
 
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

EqualizationFilter mParameters
 
EqualizationCurvesList mCurvesList { mParameters }
 
const int mOptions
 
- Protected Attributes inherited from EffectBase
double mF0 {}
 
double mF1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

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 Attributes inherited from EffectBase
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 

Detailed Description

Definition at line 11 of file EqualizationBase.h.

Constructor & Destructor Documentation

◆ EqualizationBase()

EqualizationBase::EqualizationBase ( int  Options = kEqLegacy)

Definition at line 36 of file EqualizationBase.cpp.

38 , mOptions { Options }
39{
40 auto& hiFreq = mParameters.mHiFreq;
41 auto& curves = mCurvesList.mCurves;
42
43 Parameters().Reset(*this);
44
46
47 // Load the EQ curves
48 EQCurveReader { curves, GetName(), mOptions }.LoadCurves();
49
50 // Note: initial curve is set in TransferDataToWindow
51
52 // double loLog = log10(mLoFreq);
53 // double stepLog = (log10(hiFreq) - loLog)/((double)NUM_PTS-1.);
54
55 // We expect these Hi and Lo frequencies to be overridden by Init().
56 // Don't use inputTracks(). See bug 2321.
57#if 0
58 auto trackList = inputTracks();
59 const auto t = trackList
60 ? *trackList->Any<const WaveTrack>().first
61 : nullptr
62 ;
63 hiFreq =
64 (t
65 ? t->GetRate()
67 / 2.0;
68#endif
69 hiFreq = mProjectRate / 2.0;
70}
TranslatableString GetName() const
Deserializer of curves from XML files.
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:210
const TrackList * inputTracks() const
Definition: EffectBase.h:102
double mProjectRate
Definition: EffectBase.h:119
const EffectSettingsManager & GetDefinition() const override
Definition: Effect.cpp:182
virtual void Reset(Effect &effect) const =0
EqualizationCurvesList mCurvesList
EqualizationFilter mParameters
const EffectParameterMethods & Parameters() const override
A Track that contains audio waveform data.
Definition: WaveTrack.h:203

References ComponentInterface::GetName(), EffectBase::inputTracks(), EqualizationCurvesList::mCurves, mCurvesList, EqualizationFilter::mHiFreq, mOptions, mParameters, EffectBase::mProjectRate, 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:

◆ ~EqualizationBase()

EqualizationBase::~EqualizationBase ( )
virtual

Definition at line 72 of file EqualizationBase.cpp.

73{
74}

Member Function Documentation

◆ DoLoadFactoryDefaults()

OptionalMessage EqualizationBase::DoLoadFactoryDefaults ( EffectSettings settings)

Definition at line 161 of file EqualizationBase.cpp.

162{
165}
static Settings & settings()
Definition: TrackInfo.cpp:51
OptionalMessage LoadFactoryDefaults(EffectSettings &settings) const override
Definition: Effect.cpp:165

References EqualizationParameters::LoadDefaults(), Effect::LoadFactoryDefaults(), mOptions, mParameters, and settings().

Referenced by LoadFactoryDefaults().

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

◆ FetchParameters()

static EqualizationParameters * EqualizationBase::FetchParameters ( EqualizationBase e,
EffectSettings  
)
inlinestatic

Definition at line 15 of file EqualizationBase.h.

16 {
17 return &e.mParameters;
18 }

References mParameters.

◆ GetDescription()

TranslatableString EqualizationBase::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 78 of file EqualizationBase.cpp.

79{
80 return XO("Adjusts the volume levels of particular frequencies");
81}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetFactoryPresets()

RegistryPaths EqualizationBase::GetFactoryPresets ( ) const
overridevirtual

Report names of factory presets.

Implements EffectSettingsManager.

Definition at line 205 of file EqualizationBase.cpp.

206{
208
209 for (size_t i = 0; i < WXSIZEOF(FactoryPresets); i++)
210 {
211 if (
213 (FactoryPresets[i].bForBoth == false))
214 continue;
215 names.push_back(FactoryPresets[i].name.Translation());
216 }
217
218 return names;
219}
static const struct @104 FactoryPresets[]
const TranslatableString name
const int kEqOptionGraphic
std::vector< RegistryPath > RegistryPaths
Definition: Identifier.h:219
static TranslatableStrings names
Definition: TagsEditor.cpp:153
wxString Translation() const

References FactoryPresets, kEqOptionGraphic, mOptions, name, names, and TranslatableString::Translation().

Here is the call graph for this function:

◆ GetType()

EffectType EqualizationBase::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 95 of file EqualizationBase.cpp.

96{
97 return EffectTypeProcess;
98}
@ EffectTypeProcess

References EffectTypeProcess.

Referenced by Process().

Here is the caller graph for this function:

◆ Init()

bool EqualizationBase::Init ( )
overridevirtual

Default implementation does nothing, returns true

Reimplemented from StatefulEffectBase.

Definition at line 254 of file EqualizationBase.cpp.

255{
256 constexpr auto loFreqI = EqualizationFilter::loFreqI;
257
258 const auto& lin = mParameters.mLin;
259 const auto& curveName = mParameters.mCurveName;
260 auto& loFreq = mParameters.mLoFreq;
261 auto& hiFreq = mParameters.mHiFreq;
262
263 int selcount = 0;
264 double rate = 0.0;
265
266 if (const auto project = FindProject())
267 {
268 auto trackRange = TrackList::Get(*project).Selected<const WaveTrack>();
269 if (trackRange)
270 {
271 rate = (*(trackRange.first++))->GetRate();
272 ++selcount;
273
274 for (auto track : trackRange)
275 {
276 if (track->GetRate() != rate)
277 {
279 "To apply Equalization, all selected tracks must have the same sample rate."));
280 return (false);
281 }
282 ++selcount;
283 }
284 }
285 }
286 else
287 // Editing macro parameters, use this default
288 rate = 44100.0;
289
290 hiFreq = rate / 2.0;
291 // Unlikely, but better than crashing.
292 if (hiFreq <= loFreqI)
293 {
295 XO("Track sample rate is too low for this effect."));
296 return (false);
297 }
298
299 loFreq = loFreqI;
300
301 mCurvesList.setCurve(curveName);
302
304
305 return (true);
306}
const auto project
const AudacityProject * FindProject() const
Definition: EffectBase.cpp:220
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:967
double GetRate() const override
Definition: WaveTrack.cpp:821
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:287
void setCurve(int currentCurve)
static constexpr int loFreqI

References EqualizationFilter::CalcFilter(), EffectBase::FindProject(), TrackList::Get(), WaveTrack::GetRate(), EqualizationFilter::loFreqI, EqualizationParameters::mCurveName, mCurvesList, EqualizationFilter::mHiFreq, EqualizationParameters::mLin, EqualizationFilter::mLoFreq, mParameters, project, TrackList::Selected(), EqualizationCurvesList::setCurve(), BasicUI::ShowMessageBox(), and XO().

Here is the call graph for this function:

◆ LoadFactoryDefaults()

OptionalMessage EqualizationBase::LoadFactoryDefaults ( EffectSettings settings) const
overridevirtual

Change settings back to "factory default"

Returns
nullopt for failure

Implements EffectSettingsManager.

Definition at line 152 of file EqualizationBase.cpp.

153{
154 // To do: externalize state so const_cast isn't needed
155 if (!const_cast<EqualizationBase&>(*this).DoLoadFactoryDefaults(settings))
156 return {};
157 return { nullptr };
158}
OptionalMessage DoLoadFactoryDefaults(EffectSettings &settings)

References DoLoadFactoryDefaults(), and settings().

Here is the call graph for this function:

◆ LoadFactoryPreset()

OptionalMessage EqualizationBase::LoadFactoryPreset ( int  id,
EffectSettings settings 
) const
overridevirtual

Change settings to the preset whose name is GetFactoryPresets()[id]

Returns
nullopt for failure

Implements EffectSettingsManager.

Definition at line 222 of file EqualizationBase.cpp.

223{
224 int index = -1;
225 for (size_t i = 0; i < WXSIZEOF(FactoryPresets); i++)
226 {
227 if (
229 (FactoryPresets[i].bForBoth == false))
230 continue;
231 if (id-- == 0)
232 {
233 index = i;
234 break;
235 }
236 }
237 if (index < 0)
238 return {};
239
240 // mParams =
241 wxString params = FactoryPresets[index].values;
242
245 S.SetForWriting(&eap);
246 // To do: externalize state so const_cast isn't needed
247 if (!const_cast<EqualizationBase*>(this)->VisitSettings(S, settings))
248 return {};
249 return { nullptr };
250}
EffectDistortionSettings params
#define S(N)
Definition: ToChars.cpp:64
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
bool VisitSettings(SettingsVisitor &visitor, EffectSettings &settings) override
SettingsVisitor that sets parameters to a value (from a string)

References FactoryPresets, kEqOptionGraphic, mOptions, params, S, settings(), and VisitSettings().

Here is the call graph for this function:

◆ ManualPage()

ManualPageID EqualizationBase::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 83 of file EqualizationBase.cpp.

84{
85 // Bug 2509: Must use _ and not space in names.
87 return L"Graphic_EQ";
89 return L"Filter_Curve_EQ";
90 return L"Equalization";
91}
const int kEqOptionCurve

References kEqOptionCurve, kEqOptionGraphic, and mOptions.

◆ Parameters()

const EffectParameterMethods & EqualizationBase::Parameters ( ) const
overrideprotectedvirtual

Reimplemented from Effect.

Definition at line 7 of file EqualizationBase.cpp.

8{
11 // CurveName,
13 // Pretty sure the interpolation name shouldn't have been interpreted when
14 // specified in chains, but must keep it that way for compatibility.
16 parameters { [](EqualizationBase& effect, EffectSettings&,
17 EqualizationParameters& params, bool updating) {
18 constexpr auto nInterpolations =
20 if (updating)
21 {
22 if (params.mInterp >= nInterpolations)
23 params.mInterp -= nInterpolations;
24 }
25 return true;
26 } };
27 return parameters;
28}
Generates EffectParameterMethods overrides from variadic template arguments.
EqualizationBase(int Options=kEqLegacy)
Externalized state of a plug-in.
Parameters of the Equalization effects that persist in configuration files.
static constexpr EnumParameter InterpMeth
static constexpr EffectParameter FilterLength
static constexpr EffectParameter InterpLin

References EqualizationBase(), EqualizationParameters::FilterLength, EqualizationParameters::InterpLin, EqualizationParameters::InterpMeth, EqualizationParameters::nInterpolations, and params.

Referenced by EqualizationBase().

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

◆ Process()

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

Implements StatefulEffectBase.

Definition at line 308 of file EqualizationBase.cpp.

309{
310 EffectOutputTracks outputs { *mTracks, GetType(), { { mT0, mT1 } } };
312 bool bGoodResult = true;
313
314 int count = 0;
315 for (auto track : outputs.Get().Selected<WaveTrack>())
316 {
317 double trackStart = track->GetStartTime();
318 double trackEnd = track->GetEndTime();
319 double t0 = mT0 < trackStart ? trackStart : mT0;
320 double t1 = mT1 > trackEnd ? trackEnd : mT1;
321
322 if (t1 > t0)
323 {
324 auto start = track->TimeToLongSamples(t0);
325 auto end = track->TimeToLongSamples(t1);
326 auto len = end - start;
327
328 auto pTempTrack = track->EmptyCopy();
329 pTempTrack->ConvertToSampleFormat(floatSample);
330 auto iter0 = pTempTrack->Channels().begin();
331
332 for (const auto pChannel : track->Channels())
333 {
334 constexpr auto windowSize = EqualizationFilter::windowSize;
335 const auto& M = mParameters.mM;
336
337 wxASSERT(M - 1 < windowSize);
338 size_t L = windowSize - (M - 1); // Process L samples at a go
339 auto s = start;
340 auto idealBlockLen = pChannel->GetMaxBlockSize() * 4;
341 if (idealBlockLen % L != 0)
342 idealBlockLen += (L - (idealBlockLen % L));
343 auto pNewChannel = *iter0++;
344 Task task { M, idealBlockLen, *pNewChannel };
345 bGoodResult = ProcessOne(task, count, *pChannel, start, len);
346 if (!bGoodResult)
347 goto done;
348 }
349 pTempTrack->Flush();
350 // Remove trailing data from the temp track
351 pTempTrack->Clear(t1 - t0, pTempTrack->GetEndTime());
352 track->ClearAndPaste(t0, t1, *pTempTrack, true, true);
353 }
354
355 count++;
356 }
357done:
358
359 if (bGoodResult)
360 outputs.Commit();
361
362 return bGoodResult;
363}
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.
bool ProcessOne(Task &task, int count, const WaveChannel &t, sampleCount start, sampleCount len)
EffectType GetType() const override
Type determines how it behaves.
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
static constexpr size_t windowSize

References EqualizationFilter::CalcFilter(), details::end(), floatSample, GetType(), EqualizationParameters::mM, mParameters, EffectBase::mT0, EffectBase::mT1, EffectBase::mTracks, ProcessOne(), and EqualizationFilter::windowSize.

Here is the call graph for this function:

◆ ProcessOne()

bool EqualizationBase::ProcessOne ( Task task,
int  count,
const WaveChannel t,
sampleCount  start,
sampleCount  len 
)
protected

Definition at line 367 of file EqualizationBase.cpp.

370{
371 constexpr auto windowSize = EqualizationFilter::windowSize;
372
373 const auto& M = mParameters.mM;
374
375 wxASSERT(M - 1 < windowSize);
376 size_t L = windowSize - (M - 1); // Process L samples at a go
377 auto s = start;
378
379 auto& buffer = task.buffer;
380 auto& window1 = task.window1;
381 auto& window2 = task.window2;
382 auto& thisWindow = task.thisWindow;
383 auto& lastWindow = task.lastWindow;
384
385 auto originalLen = len;
386
387 auto& output = task.output;
388
389 TrackProgress(count, 0.);
390 bool bLoopSuccess = true;
391 size_t wcopy = 0;
392
393 while (len != 0)
394 {
395 auto block = limitSampleBufferSize(task.idealBlockLen, len);
396
397 t.GetFloats(buffer.get(), s, block);
398
399 for (size_t i = 0; i < block;
400 i += L) // go through block in lumps of length L
401 {
402 wcopy = std::min<size_t>(L, block - i);
403 for (size_t j = 0; j < wcopy; j++)
404 thisWindow[j] = buffer[i + j]; // copy the L (or remaining) samples
405 for (auto j = wcopy; j < windowSize; j++)
406 thisWindow[j] = 0; // this includes the padding
407
408 mParameters.Filter(windowSize, thisWindow);
409
410 // Overlap - Add
411 for (size_t j = 0; (j < M - 1) && (j < wcopy); j++)
412 buffer[i + j] = thisWindow[j] + lastWindow[L + j];
413 for (size_t j = M - 1; j < wcopy; j++)
414 buffer[i + j] = thisWindow[j];
415
416 std::swap(thisWindow, lastWindow);
417 } // next i, lump of this block
418
419 task.AccumulateSamples((samplePtr)buffer.get(), block);
420 len -= block;
421 s += block;
422
423 if (TrackProgress(
424 count, (s - start).as_double() / originalLen.as_double()))
425 {
426 bLoopSuccess = false;
427 break;
428 }
429 }
430
431 if (bLoopSuccess)
432 {
433 // M-1 samples of 'tail' left in lastWindow, get them now
434 if (wcopy < (M - 1))
435 {
436 // Still have some overlap left to process
437 // (note that lastWindow and thisWindow have been exchanged at this
438 // point
439 // so that 'thisWindow' is really the window prior to 'lastWindow')
440 size_t j = 0;
441 for (; j < M - 1 - wcopy; j++)
442 buffer[j] = lastWindow[wcopy + j] + thisWindow[L + wcopy + j];
443 // And fill in the remainder after the overlap
444 for (; j < M - 1; j++)
445 buffer[j] = lastWindow[wcopy + j];
446 }
447 else
448 {
449 for (size_t j = 0; j < M - 1; j++)
450 buffer[j] = lastWindow[wcopy + j];
451 }
452 task.AccumulateSamples((samplePtr)buffer.get(), M - 1);
453 }
454 return bLoopSuccess;
455}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
char * samplePtr
Definition: SampleFormat.h:57
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:343
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
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634
void Filter(size_t len, float *buffer) const

References EqualizationBase::Task::AccumulateSamples(), EqualizationBase::Task::buffer, EqualizationFilter::Filter(), WaveChannel::GetFloats(), EqualizationBase::Task::idealBlockLen, EqualizationBase::Task::lastWindow, limitSampleBufferSize(), EqualizationParameters::mM, mParameters, EqualizationBase::Task::output, anonymous_namespace{NoteTrack.cpp}::swap(), EqualizationBase::Task::thisWindow, Effect::TrackProgress(), EqualizationBase::Task::window1, EqualizationBase::Task::window2, and EqualizationFilter::windowSize.

Referenced by Process().

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

◆ VisitSettings() [1/2]

bool EqualizationBase::VisitSettings ( ConstSettingsVisitor visitor,
const EffectSettings settings 
) const
overridevirtual

Visit settings (read-only), if defined. false means no defined settings. Default implementation returns false

Reimplemented from EffectSettingsManager.

Definition at line 100 of file EqualizationBase.cpp.

102{
103 const auto& curves = mCurvesList.mCurves;
105
106 // Curve point parameters -- how many isn't known statically
107 if (dynamic_cast<ShuttleGetAutomation*>(&visitor))
108 {
109 int numPoints = curves[0].points.size();
110 int point;
111 for (point = 0; point < numPoints; point++)
112 {
113 const wxString nameFreq = wxString::Format("f%i", point);
114 const wxString nameVal = wxString::Format("v%i", point);
115 visitor.Define(
116 curves[0].points[point].Freq, nameFreq, 0.0, 0.0, 0.0, 0.0);
117 visitor.Define(
118 curves[0].points[point].dB, nameVal, 0.0, 0.0, 0.0, 0.0);
119 }
120 }
121 return true;
122}
bool VisitSettings(SettingsVisitor &visitor, EffectSettings &settings) override
Definition: Effect.cpp:102
virtual void Define(Arg< bool > var, const wxChar *key, bool vdefault, bool vmin=false, bool vmax=false, bool vscl=false)
SettingsVisitor that gets parameter values into a string.

References SettingsVisitorBase< Const >::Define(), EqualizationCurvesList::mCurves, mCurvesList, settings(), and Effect::VisitSettings().

Here is the call graph for this function:

◆ VisitSettings() [2/2]

bool EqualizationBase::VisitSettings ( SettingsVisitor visitor,
EffectSettings settings 
)
overridevirtual

Visit settings (and maybe change them), if defined. false means no defined settings. Default implementation returns false

Reimplemented from EffectSettingsManager.

Definition at line 124 of file EqualizationBase.cpp.

126{
127 auto& curves = mCurvesList.mCurves;
129
130 // Curve point parameters -- how many isn't known statically
131 {
132 curves[0].points.clear();
133
134 for (int i = 0; i < 200; i++)
135 {
136 const wxString nameFreq = wxString::Format("f%i", i);
137 const wxString nameVal = wxString::Format("v%i", i);
138 double f = -1000.0;
139 double d = 0.0;
140 visitor.Define(f, nameFreq, 0.0, -10000.0, 1000000.0, 0.0);
141 visitor.Define(d, nameVal, 0.0, -10000.0, 10000.0, 0.0);
142 if (f <= 0.0)
143 break;
144 curves[0].points.push_back(EQPoint(f, d));
145 }
147 }
148 return true;
149}
One point in a curve.

References SettingsVisitorBase< Const >::Define(), EqualizationCurvesList::mCurves, mCurvesList, EqualizationCurvesList::setCurve(), settings(), and Effect::VisitSettings().

Referenced by LoadFactoryPreset().

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

Member Data Documentation

◆ mCurvesList

EqualizationCurvesList EqualizationBase::mCurvesList { mParameters }
protected

Definition at line 96 of file EqualizationBase.h.

Referenced by EqualizationBase(), Init(), and VisitSettings().

◆ mOptions

const int EqualizationBase::mOptions
protected

◆ mParameters

EqualizationFilter EqualizationBase::mParameters
protected

◆ Symbol

const ComponentInterfaceSymbol EqualizationBase::Symbol { XO("Equalization") }
static

Definition at line 19 of file EqualizationBase.h.

Referenced by EffectEqualization::GetSymbol().


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