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
 Call once to set up state for whole list of tracks to be processed. More...
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 Actually do the effect here. More...
 
std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool DoTransferDataToWindow ()
 
- Public Member Functions inherited from StatefulEffect
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 ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 Actually do the effect here. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (EffectSettings &settings)
 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
 
- 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...
 
bool LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 Change settings to a user-named preset. More...
 
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...
 
bool LoadFactoryPreset (int id, EffectSettings &settings) const override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults (EffectSettings &settings) const override
 Change settings back to "factory default". More...
 
unsigned GetAudioInCount () const override
 How many input buffers to allocate at once. More...
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
 Adds controls to a panel that is given as the parent window of S More...
 
bool IsGraphicalUI () override
 
bool ValidateUI (EffectSettings &) override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets (const EffectSettings &settings) const override
 
void ImportPresets (EffectSettings &settings) override
 
bool HasOptions () override
 
void ShowOptions () override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
 Usually applies factory to self and given access. More...
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
bool LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
 
bool EnableApply (bool enable=true)
 
wxWindow * GetUIParent ()
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)=0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual bool CanExportPresets ()=0
 
virtual void ExportPresets (const EffectSettings &settings) const =0
 
virtual void ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)=0
 Usually applies factory to self and given access. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual bool 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, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={}, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 Unfortunately complicated dual-use function. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)=0
 Update controls for the settings. More...
 
virtual bool TransferDataFromWindow (EffectSettings &settings)=0
 Update the given settings from controls. More...
 
- 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...
 
virtual unsigned GetAudioInCount () const =0
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const =0
 How many output buffers to allocate at once. More...
 
virtual int GetMidiInCount () const
 Function that has not yet found a use. More...
 
virtual int GetMidiOutCount () const
 Function that has not yet found a use. 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...
 
- 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 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 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

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 Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , Since_3_2 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Protected Member Functions inherited from Effect
bool EnablePreview (bool enable=true)
 
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...
 
virtual std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)
 Add controls to effect panel; always succeeds. 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)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
void Preview (EffectSettingsAccess &access, bool dryOnly) override
 
bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent, const EffectDialogFactory &dialogFactory, const EffectSettingsAccessPtr &pAccess) override
 Unfortunately complicated dual-use function. 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
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 
- Protected Attributes inherited from Effect
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWindow * mUIParent {}
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Protected Attributes inherited from EffectUIClientInterface
friend EffectUIValidator
 
friend DefaultEffectUIValidator
 
- 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 84 of file AutoDuck.cpp.

85{
86 Parameters().Reset(*this);
87
89
90 mControlTrack = NULL;
91
92 mPanel = NULL;
93}
Panel * mPanel
Definition: AutoDuck.h:81
const WaveTrack * mControlTrack
Definition: AutoDuck.h:71
const EffectParameterMethods & Parameters() const override
Definition: AutoDuck.cpp:39
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:218
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 95 of file AutoDuck.cpp.

96{
97}

Member Function Documentation

◆ ApplyDuckFade()

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

Definition at line 423 of file AutoDuck.cpp.

425{
426 bool cancel = false;
427
428 auto start = t->TimeToLongSamples(t0);
429 auto end = t->TimeToLongSamples(t1);
430
431 Floats buf{ kBufSize };
432 auto pos = start;
433
434 auto fadeDownSamples = t->TimeToLongSamples(
436 if (fadeDownSamples < 1)
437 fadeDownSamples = 1;
438
439 auto fadeUpSamples = t->TimeToLongSamples(
441 if (fadeUpSamples < 1)
442 fadeUpSamples = 1;
443
444 float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
445 float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
446
447 while (pos < end)
448 {
449 const auto len = limitSampleBufferSize( kBufSize, end - pos );
450
451 t->GetFloats(buf.get(), pos, len);
452
453 for (auto i = pos; i < pos + len; i++)
454 {
455 float gainDown = fadeDownStep * (i - start).as_float();
456 float gainUp = fadeUpStep * (end - i).as_float();
457
458 float gain;
459 if (gainDown > gainUp)
460 gain = gainDown;
461 else
462 gain = gainUp;
463 if (gain < mDuckAmountDb)
464 gain = mDuckAmountDb;
465
466 // i - pos is bounded by len:
467 buf[ ( i - pos ).as_size_t() ] *= DB_TO_LINEAR(gain);
468 }
469
470 t->Set((samplePtr)buf.get(), floatSample, pos, len);
471
472 pos += len;
473
474 float curTime = t->LongSamplesToTime(pos);
475 float fractionFinished = (curTime - mT0) / (mT1 - mT0);
476 if (TotalProgress( (trackNum + 1 + fractionFinished) /
477 (GetNumWaveTracks() + 1) ))
478 {
479 cancel = true;
480 break;
481 }
482 }
483
484 return cancel;
485}
static const size_t kBufSize
Definition: AutoDuck.cpp:52
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:535
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
double mInnerFadeDownLen
Definition: AutoDuck.h:64
double mDuckAmountDb
Definition: AutoDuck.h:63
double mInnerFadeUpLen
Definition: AutoDuck.h:65
double mOuterFadeDownLen
Definition: AutoDuck.h:66
double mOuterFadeUpLen
Definition: AutoDuck.h:67
double mT1
Definition: EffectBase.h:107
double mT0
Definition: EffectBase.h:106
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:685
int GetNumWaveTracks() const
Definition: Effect.h:187
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:67
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:47
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:42
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2195
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 mPanel->Refresh(false);
417 return true;
418}

References mPanel.

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 106 of file AutoDuck.cpp.

107{
108 return XO("Reduces (ducks) the volume of one or more tracks whenever the volume of a specified \"control\" track reaches a particular level");
109}
#define XO(s)
Definition: Internat.h:31

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectAutoDuck::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 101 of file AutoDuck.cpp.

102{
103 return Symbol;
104}
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 118 of file AutoDuck.cpp.

119{
120 return EffectTypeProcess;
121}
@ EffectTypeProcess

References EffectTypeProcess.

◆ Init()

bool EffectAutoDuck::Init ( )
overridevirtual

Call once to set up state for whole list of tracks to be processed.

Returns
success Default implementation does nothing, returns true Default implementation does nothing, returns true

Reimplemented from StatefulEffectBase.

Definition at line 125 of file AutoDuck.cpp.

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

References EffectBase::inputTracks(), mControlTrack, Effect::MessageBox(), 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 111 of file AutoDuck.cpp.

112{
113 return L"Auto_Duck";
114}

◆ OnValueChanged()

void EffectAutoDuck::OnValueChanged ( wxCommandEvent &  evt)
private

Definition at line 487 of file AutoDuck.cpp.

488{
489 mPanel->Refresh(false);
490}

References mPanel.

◆ Parameters()

const EffectParameterMethods & EffectAutoDuck::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 39 of file AutoDuck.cpp.

40{
44 > parameters;
45 return parameters;
46}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter InnerFadeDownLen
Definition: AutoDuck.h:89
static constexpr EffectParameter InnerFadeUpLen
Definition: AutoDuck.h:91
static constexpr EffectParameter OuterFadeDownLen
Definition: AutoDuck.h:93
static constexpr EffectParameter MaximumPause
Definition: AutoDuck.h:99
static constexpr EffectParameter ThresholdDb
Definition: AutoDuck.h:97
static constexpr EffectParameter DuckAmountDb
Definition: AutoDuck.h:87
static constexpr EffectParameter OuterFadeUpLen
Definition: AutoDuck.h:95

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

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectUIValidator > EffectAutoDuck::PopulateOrExchange ( ShuttleGui S,
EffectInstance instance,
EffectSettingsAccess access 
)
overridevirtual

Add controls to effect panel; always succeeds.

Returns
if not null, then return it from Effect::PopulateUI instead of a DefaultEffectUIValidator; default implementation returns null

Reimplemented from Effect.

Definition at line 333 of file AutoDuck.cpp.

335{
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}
#define XXO(s)
Definition: Internat.h:44
#define safenew
Definition: MemoryX.h:10
#define S(N)
Definition: ToChars.cpp:64
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:75
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:74
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:76
double mThresholdDb
Definition: AutoDuck.h:68
wxTextCtrl * mThresholdDbBox
Definition: AutoDuck.h:78
double mMaximumPause
Definition: AutoDuck.h:69
wxTextCtrl * mMaximumPauseBox
Definition: AutoDuck.h:79
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:77
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:73
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31

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, OuterFadeDownLen, OuterFadeUpLen, S, safenew, ThresholdDb, XO, and XXO.

◆ Process()

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

Actually do the effect here.

Returns
success

Implements StatefulEffectBase.

Definition at line 178 of file AutoDuck.cpp.

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

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:

◆ TransferDataToWindow()

bool EffectAutoDuck::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Implements EffectPlugin.

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 87 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 89 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 91 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 99 of file AutoDuck.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mControlTrack

const WaveTrack* EffectAutoDuck::mControlTrack
private

Definition at line 71 of file AutoDuck.h.

Referenced by Init(), and Process().

◆ mDuckAmountDb

double EffectAutoDuck::mDuckAmountDb
private

Definition at line 63 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mDuckAmountDbBox

wxTextCtrl* EffectAutoDuck::mDuckAmountDbBox
private

Definition at line 73 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mInnerFadeDownLen

double EffectAutoDuck::mInnerFadeDownLen
private

Definition at line 64 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mInnerFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeDownLenBox
private

Definition at line 74 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mInnerFadeUpLen

double EffectAutoDuck::mInnerFadeUpLen
private

Definition at line 65 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mInnerFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeUpLenBox
private

Definition at line 75 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mMaximumPause

double EffectAutoDuck::mMaximumPause
private

Definition at line 69 of file AutoDuck.h.

Referenced by PopulateOrExchange(), and Process().

◆ mMaximumPauseBox

wxTextCtrl* EffectAutoDuck::mMaximumPauseBox
private

Definition at line 79 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeDownLen

double EffectAutoDuck::mOuterFadeDownLen
private

Definition at line 66 of file AutoDuck.h.

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

◆ mOuterFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeDownLenBox
private

Definition at line 76 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeUpLen

double EffectAutoDuck::mOuterFadeUpLen
private

Definition at line 67 of file AutoDuck.h.

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

◆ mOuterFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeUpLenBox
private

Definition at line 77 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mPanel

Panel* EffectAutoDuck::mPanel
private

Definition at line 82 of file AutoDuck.h.

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

◆ mThresholdDb

double EffectAutoDuck::mThresholdDb
private

Definition at line 68 of file AutoDuck.h.

Referenced by PopulateOrExchange(), and Process().

◆ mThresholdDbBox

wxTextCtrl* EffectAutoDuck::mThresholdDbBox
private

Definition at line 78 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ OuterFadeDownLen

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

Definition at line 93 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 95 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 97 of file AutoDuck.h.

Referenced by Parameters(), and PopulateOrExchange().


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