Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EffectAutoDuck Class Referencefinal

Implements the Auto Ducking effect. More...

#include <AutoDuck.h>

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

Classes

class  Panel
 

Public Member Functions

 EffectAutoDuck ()
 
virtual ~EffectAutoDuck ()
 
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 Init () override
 
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 DoTransferDataToWindow ()
 
bool TransferDataFromWindow (EffectSettings &settings) override
 
- Public Member Functions inherited from StatefulEffect
 ~StatefulEffect () override
 
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () const
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize () noexcept
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
void SetTracks (TrackList *pTracks)
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual void Preview (EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly)=0
 Calculate temporary tracks of limited length with effect applied and play. More...
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 
- Public Member Functions inherited from StatefulEffectUIServices
 ~StatefulEffectUIServices () override
 
std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
 Allows PopulateOrExchange to return null. More...
 
virtual std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)
 
virtual bool TransferDataFromWindow (EffectSettings &settings)
 
- Public Member Functions inherited from BasicEffectUIServices
int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
 
void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const override
 
void ShowOptions (const EffectPlugin &plugin) const override
 
bool ValidateUI (const EffectPlugin &context, EffectSettings &) const override
 
bool CloseUI () const override
 
- Public Member Functions inherited from EffectUIServices
virtual ~EffectUIServices ()
 
virtual int ShowHostInterface (EffectPlugin &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
 
virtual int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal=false) const =0
 
virtual std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const =0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const =0
 
virtual void ShowOptions (const EffectPlugin &plugin) const =0
 
virtual bool ValidateUI (const EffectPlugin &context, EffectSettings &settings) const =0
 
virtual bool CloseUI () const =0
 

Static Public Member Functions

static EffectAutoDuckFetchParameters (EffectAutoDuck &e, EffectSettings &)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
static void IncEffectCounter ()
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Static Public Member Functions inherited from EffectUIServices
static int DoMessageBox (const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Auto Duck") }
 
- Static Public Attributes inherited from EffectPlugin
static const wxString kUserPresetIdent = wxT("User Preset:")
 
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
 
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
 
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
 

Private Member Functions

bool ApplyDuckFade (int trackNum, WaveTrack *t, double t0, double t1)
 
void OnValueChanged (wxCommandEvent &evt)
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

wxWeakRef< wxWindow > mUIParent {}
 
double mDuckAmountDb
 
double mInnerFadeDownLen
 
double mInnerFadeUpLen
 
double mOuterFadeDownLen
 
double mOuterFadeUpLen
 
double mThresholdDb
 
double mMaximumPause
 
const WaveTrackmControlTrack
 
wxTextCtrl * mDuckAmountDbBox
 
wxTextCtrl * mInnerFadeDownLenBox
 
wxTextCtrl * mInnerFadeUpLenBox
 
wxTextCtrl * mOuterFadeDownLenBox
 
wxTextCtrl * mOuterFadeUpLenBox
 
wxTextCtrl * mThresholdDbBox
 
wxTextCtrl * mMaximumPauseBox
 
PanelmPanel
 

Static Private Attributes

static constexpr EffectParameter DuckAmountDb
 
static constexpr EffectParameter InnerFadeDownLen
 
static constexpr EffectParameter InnerFadeUpLen
 
static constexpr EffectParameter OuterFadeDownLen
 
static constexpr EffectParameter OuterFadeUpLen
 
static constexpr EffectParameter ThresholdDb
 
static constexpr EffectParameter MaximumPause
 

Additional Inherited Members

- Public Types inherited from StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Public Types inherited from EffectUIServices
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Attributes inherited from EffectBase
TrackListmTracks {}
 
- Protected Member Functions inherited from Effect
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
void Preview (EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly) final
 Calculate temporary tracks of limited length with effect applied and play. More...
 
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

Implements the Auto Ducking effect.

Definition at line 25 of file AutoDuck.h.

Constructor & Destructor Documentation

◆ EffectAutoDuck()

EffectAutoDuck::EffectAutoDuck ( )

Definition at line 82 of file AutoDuck.cpp.

83{
84 Parameters().Reset(*this);
85
87
88 mControlTrack = NULL;
89
90 mPanel = NULL;
91}
Panel * mPanel
Definition: AutoDuck.h:84
const WaveTrack * mControlTrack
Definition: AutoDuck.h:74
const EffectParameterMethods & Parameters() const override
Definition: AutoDuck.cpp:37
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:214
virtual void Reset(Effect &effect) const =0

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectAutoDuck()

EffectAutoDuck::~EffectAutoDuck ( )
virtual

Definition at line 93 of file AutoDuck.cpp.

94{
95}

Member Function Documentation

◆ ApplyDuckFade()

bool EffectAutoDuck::ApplyDuckFade ( int  trackNum,
WaveTrack t,
double  t0,
double  t1 
)
private

Definition at line 438 of file AutoDuck.cpp.

440{
441 bool cancel = false;
442
443 auto start = t->TimeToLongSamples(t0);
444 auto end = t->TimeToLongSamples(t1);
445
446 Floats buf{ kBufSize };
447 auto pos = start;
448
449 auto fadeDownSamples = t->TimeToLongSamples(
451 if (fadeDownSamples < 1)
452 fadeDownSamples = 1;
453
454 auto fadeUpSamples = t->TimeToLongSamples(
456 if (fadeUpSamples < 1)
457 fadeUpSamples = 1;
458
459 float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
460 float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
461
462 while (pos < end)
463 {
464 const auto len = limitSampleBufferSize( kBufSize, end - pos );
465
466 t->GetFloats(buf.get(), pos, len);
467
468 for (auto i = pos; i < pos + len; i++)
469 {
470 float gainDown = fadeDownStep * (i - start).as_float();
471 float gainUp = fadeUpStep * (end - i).as_float();
472
473 float gain;
474 if (gainDown > gainUp)
475 gain = gainDown;
476 else
477 gain = gainUp;
478 if (gain < mDuckAmountDb)
479 gain = mDuckAmountDb;
480
481 // i - pos is bounded by len:
482 buf[ ( i - pos ).as_size_t() ] *= DB_TO_LINEAR(gain);
483 }
484
485 t->Set((samplePtr)buf.get(), floatSample, pos, len);
486
487 pos += len;
488
489 float curTime = t->LongSamplesToTime(pos);
490 float fractionFinished = (curTime - mT0) / (mT1 - mT0);
491 if (TotalProgress( (trackNum + 1 + fractionFinished) /
492 (GetNumWaveTracks() + 1) ))
493 {
494 cancel = true;
495 break;
496 }
497 }
498
499 return cancel;
500}
static const size_t kBufSize
Definition: AutoDuck.cpp:50
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:560
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
char * samplePtr
Definition: SampleFormat.h:55
double mInnerFadeDownLen
Definition: AutoDuck.h:67
double mDuckAmountDb
Definition: AutoDuck.h:66
double mInnerFadeUpLen
Definition: AutoDuck.h:68
double mOuterFadeDownLen
Definition: AutoDuck.h:69
double mOuterFadeUpLen
Definition: AutoDuck.h:70
double mT1
Definition: EffectBase.h:113
double mT0
Definition: EffectBase.h:112
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:338
int GetNumWaveTracks() const
Definition: Effect.h:140
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:82
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:48
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:43
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Definition: WaveTrack.cpp:2002
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References DB_TO_LINEAR, PackedArray::end(), floatSample, SampleTrack::GetFloats(), Effect::GetNumWaveTracks(), kBufSize, limitSampleBufferSize(), SampleTrack::LongSamplesToTime(), mDuckAmountDb, mInnerFadeDownLen, mInnerFadeUpLen, mOuterFadeDownLen, mOuterFadeUpLen, EffectBase::mT0, EffectBase::mT1, WaveTrack::Set(), SampleTrack::TimeToLongSamples(), and Effect::TotalProgress().

Referenced by Process().

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

◆ DoTransferDataToWindow()

bool EffectAutoDuck::DoTransferDataToWindow ( )

Definition at line 414 of file AutoDuck.cpp.

415{
416 // Issue 2324: don't remove these two lines
417 if (!mUIParent->TransferDataToWindow())
418 return false;
419
420 mPanel->Refresh(false);
421
422 return true;
423}
wxWeakRef< wxWindow > mUIParent
Definition: AutoDuck.h:64

References mPanel, and mUIParent.

Referenced by TransferDataToWindow().

Here is the caller graph for this function:

◆ FetchParameters()

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

Definition at line 29 of file AutoDuck.h.

29{ return &e; }

◆ GetDescription()

TranslatableString EffectAutoDuck::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 104 of file AutoDuck.cpp.

105{
106 return XO("Reduces (ducks) the volume of one or more tracks whenever the volume of a specified \"control\" track reaches a particular level");
107}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectAutoDuck::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 99 of file AutoDuck.cpp.

100{
101 return Symbol;
102}
static const ComponentInterfaceSymbol Symbol
Definition: AutoDuck.h:30

References Symbol.

◆ GetType()

EffectType EffectAutoDuck::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 116 of file AutoDuck.cpp.

117{
118 return EffectTypeProcess;
119}
@ EffectTypeProcess

References EffectTypeProcess.

◆ Init()

bool EffectAutoDuck::Init ( )
overridevirtual

Default implementation does nothing, returns true

Reimplemented from StatefulEffectBase.

Definition at line 123 of file AutoDuck.cpp.

124{
125 mControlTrack = NULL;
126
127 bool lastWasSelectedWaveTrack = false;
128 const WaveTrack *controlTrackCandidate = NULL;
129
130 for (auto t : inputTracks()->Any())
131 {
132 if (lastWasSelectedWaveTrack && !t->GetSelected()) {
133 // This could be the control track, so remember it
134 controlTrackCandidate = track_cast<const WaveTrack *>(t);
135 }
136
137 lastWasSelectedWaveTrack = false;
138
139 if (t->GetSelected()) {
140 bool ok = t->TypeSwitch<bool>(
141 [&](const WaveTrack *) {
142 lastWasSelectedWaveTrack = true;
143 return true;
144 },
145 [&](const Track *) {
147 /* i18n-hint: Auto duck is the name of an effect that 'ducks' (reduces the volume)
148 * of the audio automatically when there is sound on another track. Not as
149 * in 'Donald-Duck'!*/
150 XO("You selected a track which does not contain audio. AutoDuck can only process audio tracks."),
151 wxICON_ERROR );
152 return false;
153 }
154 );
155 if (!ok)
156 return false;
157 }
158 }
159
160 if (!controlTrackCandidate)
161 {
163 /* i18n-hint: Auto duck is the name of an effect that 'ducks' (reduces the volume)
164 * of the audio automatically when there is sound on another track. Not as
165 * in 'Donald-Duck'!*/
166 XO("Auto Duck needs a control track which must be placed below the selected track(s)."),
167 wxICON_ERROR );
168 return false;
169 }
170
171 mControlTrack = controlTrackCandidate;
172
173 return true;
174}
const TrackList * inputTracks() const
Definition: EffectBase.h:108
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:226
A Track that contains audio waveform data.
Definition: WaveTrack.h:51

References EffectUIServices::DoMessageBox(), EffectBase::inputTracks(), mControlTrack, and XO().

Here is the call graph for this function:

◆ ManualPage()

ManualPageID EffectAutoDuck::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 109 of file AutoDuck.cpp.

110{
111 return L"Auto_Duck";
112}

◆ OnValueChanged()

void EffectAutoDuck::OnValueChanged ( wxCommandEvent &  evt)
private

Definition at line 502 of file AutoDuck.cpp.

503{
504 mPanel->Refresh(false);
505}

References mPanel.

◆ Parameters()

const EffectParameterMethods & EffectAutoDuck::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 37 of file AutoDuck.cpp.

38{
42 > parameters;
43 return parameters;
44}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter InnerFadeDownLen
Definition: AutoDuck.h:92
static constexpr EffectParameter InnerFadeUpLen
Definition: AutoDuck.h:94
static constexpr EffectParameter OuterFadeDownLen
Definition: AutoDuck.h:96
static constexpr EffectParameter MaximumPause
Definition: AutoDuck.h:102
static constexpr EffectParameter ThresholdDb
Definition: AutoDuck.h:100
static constexpr EffectParameter DuckAmountDb
Definition: AutoDuck.h:90
static constexpr EffectParameter OuterFadeUpLen
Definition: AutoDuck.h:98

References DuckAmountDb, EffectAutoDuck(), InnerFadeDownLen, InnerFadeUpLen, MaximumPause, OuterFadeDownLen, OuterFadeUpLen, and ThresholdDb.

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectEditor > EffectAutoDuck::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 331 of file AutoDuck.cpp.

334{
335 mUIParent = S.GetParent();
336 S.SetBorder(5);
337 S.StartVerticalLay(true);
338 {
339 S.AddSpace(0, 5);
340
341 mPanel = safenew EffectAutoDuck::Panel(S.GetParent(), wxID_ANY, this);
342 S.AddWindow(mPanel);
343
344 S.AddSpace(0, 5);
345
346 S.StartMultiColumn(6, wxCENTER);
347 {
348 mDuckAmountDbBox = S.Validator<FloatingPointValidator<double>>(
349 1, &mDuckAmountDb, NumValidatorStyle::NO_TRAILING_ZEROES,
351 .NameSuffix(XO("db"))
352 .AddTextBox(XXO("Duck &amount:"), wxT(""), 10);
353 S.AddUnits(XO("dB"));
354
355 mMaximumPauseBox = S.Validator<FloatingPointValidator<double>>(
356 2, &mMaximumPause, NumValidatorStyle::NO_TRAILING_ZEROES,
358 .NameSuffix(XO("seconds"))
359 .AddTextBox(XXO("Ma&ximum pause:"), wxT(""), 10);
360 S.AddUnits(XO("seconds"));
361
362 mOuterFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
363 2, &mOuterFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
365 .NameSuffix(XO("seconds"))
366 .AddTextBox(XXO("Outer fade &down length:"), wxT(""), 10);
367 S.AddUnits(XO("seconds"));
368
369 mOuterFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
370 2, &mOuterFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
372 .NameSuffix(XO("seconds"))
373 .AddTextBox(XXO("Outer fade &up length:"), wxT(""), 10);
374 S.AddUnits(XO("seconds"));
375
376 mInnerFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
377 2, &mInnerFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
379 .NameSuffix(XO("seconds"))
380 .AddTextBox(XXO("Inner fade d&own length:"), wxT(""), 10);
381 S.AddUnits(XO("seconds"));
382
383 mInnerFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
384 2, &mInnerFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
386 .NameSuffix(XO("seconds"))
387 .AddTextBox(XXO("Inner &fade up length:"), wxT(""), 10);
388 S.AddUnits(XO("seconds"));
389 }
390 S.EndMultiColumn();
391
392 S.StartMultiColumn(3, wxCENTER);
393 {
394 mThresholdDbBox = S.Validator<FloatingPointValidator<double>>(
395 2, &mThresholdDb, NumValidatorStyle::NO_TRAILING_ZEROES,
397 .NameSuffix(XO("db"))
398 .AddTextBox(XXO("&Threshold:"), wxT(""), 10);
399 S.AddUnits(XO("dB"));
400 }
401 S.EndMultiColumn();
402
403 }
404 S.EndVerticalLay();
405
406 return nullptr;
407}
wxT("CloseDown"))
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
#define S(N)
Definition: ToChars.cpp:64
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:78
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:77
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:79
double mThresholdDb
Definition: AutoDuck.h:71
wxTextCtrl * mThresholdDbBox
Definition: AutoDuck.h:81
double mMaximumPause
Definition: AutoDuck.h:72
wxTextCtrl * mMaximumPauseBox
Definition: AutoDuck.h:82
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:80
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:76
const Type min
Minimum value.
const Type max
Maximum value.

References DuckAmountDb, InnerFadeDownLen, InnerFadeUpLen, EffectParameter< Structure, Member, Type, Value >::max, MaximumPause, mDuckAmountDb, mDuckAmountDbBox, EffectParameter< Structure, Member, Type, Value >::min, mInnerFadeDownLen, mInnerFadeDownLenBox, mInnerFadeUpLen, mInnerFadeUpLenBox, mMaximumPause, mMaximumPauseBox, mOuterFadeDownLen, mOuterFadeDownLenBox, mOuterFadeUpLen, mOuterFadeUpLenBox, mPanel, mThresholdDb, mThresholdDbBox, mUIParent, OuterFadeDownLen, OuterFadeUpLen, S, safenew, ThresholdDb, wxT(), XO(), and XXO().

Here is the call graph for this function:

◆ Process()

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

Implements StatefulEffectBase.

Definition at line 176 of file AutoDuck.cpp.

177{
178 if (GetNumWaveTracks() == 0 || !mControlTrack)
179 return false;
180
181 bool cancel = false;
182
183 auto start =
185 auto end =
187
188 if (end <= start)
189 return false;
190
191 // the minimum number of samples we have to wait until the maximum
192 // pause has been exceeded
193 double maxPause = mMaximumPause;
194
195 // We don't fade in until we have time enough to actually fade out again
196 if (maxPause < mOuterFadeDownLen + mOuterFadeUpLen)
198
199 auto minSamplesPause =
201
202 double threshold = DB_TO_LINEAR(mThresholdDb);
203
204 // adjust the threshold so we can compare it to the rmsSum value
205 threshold = threshold * threshold * kRMSWindowSize;
206
207 int rmsPos = 0;
208 double rmsSum = 0;
209 // to make the progress bar appear more natural, we first look for all
210 // duck regions and apply them all at once afterwards
211 std::vector<AutoDuckRegion> regions;
212 bool inDuckRegion = false;
213 {
214 Floats rmsWindow{ kRMSWindowSize, true };
215
216 Floats buf{ kBufSize };
217
218 // initialize the following two variables to prevent compiler warning
219 double duckRegionStart = 0;
220 sampleCount curSamplesPause = 0;
221
222 auto pos = start;
223
224 while (pos < end)
225 {
226 const auto len = limitSampleBufferSize( kBufSize, end - pos );
227
228 mControlTrack->GetFloats(buf.get(), pos, len);
229
230 for (auto i = pos; i < pos + len; i++)
231 {
232 rmsSum -= rmsWindow[rmsPos];
233 // i - pos is bounded by len:
234 auto index = ( i - pos ).as_size_t();
235 rmsWindow[rmsPos] = buf[ index ] * buf[ index ];
236 rmsSum += rmsWindow[rmsPos];
237 rmsPos = (rmsPos + 1) % kRMSWindowSize;
238
239 bool thresholdExceeded = rmsSum > threshold;
240
241 if (thresholdExceeded)
242 {
243 // everytime the threshold is exceeded, reset our count for
244 // the number of pause samples
245 curSamplesPause = 0;
246
247 if (!inDuckRegion)
248 {
249 // the threshold has been exceeded for the first time, so
250 // let the duck region begin here
251 inDuckRegion = true;
252 duckRegionStart = mControlTrack->LongSamplesToTime(i);
253 }
254 }
255
256 if (!thresholdExceeded && inDuckRegion)
257 {
258 // the threshold has not been exceeded and we are in a duck
259 // region, but only fade in if the maximum pause has been
260 // exceeded
261 curSamplesPause += 1;
262
263 if (curSamplesPause >= minSamplesPause)
264 {
265 // do the actual duck fade and reset all values
266 double duckRegionEnd =
267 mControlTrack->LongSamplesToTime(i - curSamplesPause);
268
269 regions.push_back(AutoDuckRegion(
270 duckRegionStart - mOuterFadeDownLen,
271 duckRegionEnd + mOuterFadeUpLen));
272
273 inDuckRegion = false;
274 }
275 }
276 }
277
278 pos += len;
279
280 if (TotalProgress(
281 (pos - start).as_double() /
282 (end - start).as_double() /
283 (GetNumWaveTracks() + 1)
284 ))
285 {
286 cancel = true;
287 break;
288 }
289 }
290
291 // apply last duck fade, if any
292 if (inDuckRegion)
293 {
294 double duckRegionEnd =
295 mControlTrack->LongSamplesToTime(end - curSamplesPause);
296 regions.push_back(AutoDuckRegion(
297 duckRegionStart - mOuterFadeDownLen,
298 duckRegionEnd + mOuterFadeUpLen));
299 }
300 }
301
302 if (!cancel)
303 {
304 CopyInputTracks(); // Set up mOutputTracks.
305
306 int trackNum = 0;
307
308 for( auto iterTrack : mOutputTracks->Selected< WaveTrack >() )
309 {
310 for (size_t i = 0; i < regions.size(); i++)
311 {
312 const AutoDuckRegion& region = regions[i];
313 if (ApplyDuckFade(trackNum, iterTrack, region.t0, region.t1))
314 {
315 cancel = true;
316 break;
317 }
318 }
319
320 if (cancel)
321 break;
322
323 trackNum++;
324 }
325 }
326
327 ReplaceProcessedTracks(!cancel);
328 return !cancel;
329}
static const size_t kRMSWindowSize
Definition: AutoDuck.cpp:51
bool ApplyDuckFade(int trackNum, WaveTrack *t, double t0, double t1)
Definition: AutoDuck.cpp:438
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:111
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:232
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:396
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
a struct that holds a start and end time.
Definition: AutoDuck.cpp:58

References ApplyDuckFade(), Effect::CopyInputTracks(), DB_TO_LINEAR, PackedArray::end(), SampleTrack::GetFloats(), Effect::GetNumWaveTracks(), kBufSize, kRMSWindowSize, limitSampleBufferSize(), SampleTrack::LongSamplesToTime(), mControlTrack, mMaximumPause, mOuterFadeDownLen, mOuterFadeUpLen, EffectBase::mOutputTracks, EffectBase::mT0, EffectBase::mT1, mThresholdDb, EffectBase::ReplaceProcessedTracks(), AutoDuckRegion::t0, AutoDuckRegion::t1, SampleTrack::TimeToLongSamples(), and Effect::TotalProgress().

Here is the call graph for this function:

◆ TransferDataFromWindow()

bool EffectAutoDuck::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

Update the given settings from controls; default does nothing, returns true

Reimplemented from StatefulEffectUIServices.

Definition at line 425 of file AutoDuck.cpp.

426{
427 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
428 {
429 return false;
430 }
431
432 return true;
433}

References mUIParent.

◆ TransferDataToWindow()

bool EffectAutoDuck::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

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

Reimplemented from StatefulEffectUIServices.

Definition at line 409 of file AutoDuck.cpp.

410{
411 return DoTransferDataToWindow();
412}
bool DoTransferDataToWindow()
Definition: AutoDuck.cpp:414

References DoTransferDataToWindow().

Here is the call graph for this function:

Member Data Documentation

◆ DuckAmountDb

constexpr EffectParameter EffectAutoDuck::DuckAmountDb
staticconstexprprivate
Initial value:
L"DuckAmountDb", -12.0, -24.0, 0.0, 1 }

Definition at line 90 of file AutoDuck.h.

Referenced by EffectAutoDuck::Panel::OnMotion(), EffectAutoDuck::Panel::OnPaint(), Parameters(), and PopulateOrExchange().

◆ InnerFadeDownLen

constexpr EffectParameter EffectAutoDuck::InnerFadeDownLen
staticconstexprprivate
Initial value:
L"InnerFadeDownLen", 0.0, 0.0, 3.0, 1 }

Definition at line 92 of file AutoDuck.h.

Referenced by EffectAutoDuck::Panel::OnMotion(), EffectAutoDuck::Panel::OnPaint(), Parameters(), and PopulateOrExchange().

◆ InnerFadeUpLen

constexpr EffectParameter EffectAutoDuck::InnerFadeUpLen
staticconstexprprivate
Initial value:
L"InnerFadeUpLen", 0.0, 0.0, 3.0, 1 }

Definition at line 94 of file AutoDuck.h.

Referenced by EffectAutoDuck::Panel::OnMotion(), EffectAutoDuck::Panel::OnPaint(), Parameters(), and PopulateOrExchange().

◆ MaximumPause

constexpr EffectParameter EffectAutoDuck::MaximumPause
staticconstexprprivate
Initial value:
L"MaximumPause", 1.0, 0.0, DBL_MAX, 1 }

Definition at line 102 of file AutoDuck.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mControlTrack

const WaveTrack* EffectAutoDuck::mControlTrack
private

Definition at line 74 of file AutoDuck.h.

Referenced by Init(), and Process().

◆ mDuckAmountDb

double EffectAutoDuck::mDuckAmountDb
private

Definition at line 66 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mDuckAmountDbBox

wxTextCtrl* EffectAutoDuck::mDuckAmountDbBox
private

Definition at line 76 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mInnerFadeDownLen

double EffectAutoDuck::mInnerFadeDownLen
private

Definition at line 67 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mInnerFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeDownLenBox
private

Definition at line 77 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mInnerFadeUpLen

double EffectAutoDuck::mInnerFadeUpLen
private

Definition at line 68 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mInnerFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeUpLenBox
private

Definition at line 78 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mMaximumPause

double EffectAutoDuck::mMaximumPause
private

Definition at line 72 of file AutoDuck.h.

Referenced by PopulateOrExchange(), and Process().

◆ mMaximumPauseBox

wxTextCtrl* EffectAutoDuck::mMaximumPauseBox
private

Definition at line 82 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeDownLen

double EffectAutoDuck::mOuterFadeDownLen
private

Definition at line 69 of file AutoDuck.h.

Referenced by ApplyDuckFade(), PopulateOrExchange(), and Process().

◆ mOuterFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeDownLenBox
private

Definition at line 79 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeUpLen

double EffectAutoDuck::mOuterFadeUpLen
private

Definition at line 70 of file AutoDuck.h.

Referenced by ApplyDuckFade(), PopulateOrExchange(), and Process().

◆ mOuterFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeUpLenBox
private

Definition at line 80 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mPanel

Panel* EffectAutoDuck::mPanel
private

Definition at line 85 of file AutoDuck.h.

Referenced by DoTransferDataToWindow(), OnValueChanged(), and PopulateOrExchange().

◆ mThresholdDb

double EffectAutoDuck::mThresholdDb
private

Definition at line 71 of file AutoDuck.h.

Referenced by PopulateOrExchange(), and Process().

◆ mThresholdDbBox

wxTextCtrl* EffectAutoDuck::mThresholdDbBox
private

Definition at line 81 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mUIParent

wxWeakRef<wxWindow> EffectAutoDuck::mUIParent {}
private

Definition at line 64 of file AutoDuck.h.

Referenced by DoTransferDataToWindow(), PopulateOrExchange(), and TransferDataFromWindow().

◆ OuterFadeDownLen

constexpr EffectParameter EffectAutoDuck::OuterFadeDownLen
staticconstexprprivate
Initial value:
L"OuterFadeDownLen", 0.5, 0.0, 3.0, 1 }

Definition at line 96 of file AutoDuck.h.

Referenced by EffectAutoDuck::Panel::OnMotion(), EffectAutoDuck::Panel::OnPaint(), Parameters(), and PopulateOrExchange().

◆ OuterFadeUpLen

constexpr EffectParameter EffectAutoDuck::OuterFadeUpLen
staticconstexprprivate
Initial value:
L"OuterFadeUpLen", 0.5, 0.0, 3.0, 1 }

Definition at line 98 of file AutoDuck.h.

Referenced by EffectAutoDuck::Panel::OnMotion(), EffectAutoDuck::Panel::OnPaint(), Parameters(), and PopulateOrExchange().

◆ Symbol

const ComponentInterfaceSymbol EffectAutoDuck::Symbol { XO("Auto Duck") }
static

Definition at line 30 of file AutoDuck.h.

Referenced by GetSymbol().

◆ ThresholdDb

constexpr EffectParameter EffectAutoDuck::ThresholdDb
staticconstexprprivate
Initial value:
L"ThresholdDb", -30.0, -100.0, 0.0, 1 }

Definition at line 100 of file AutoDuck.h.

Referenced by Parameters(), and PopulateOrExchange().


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