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, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool DoTransferDataToWindow ()
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
- 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, 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
 
- 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
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal) override
 
EffectUIClientInterfaceGetEffectUIClientInterface () override
 Returns the EffectUIClientInterface instance for this effect. More...
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) 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
 
OptionalMessage 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
 
OptionalMessage 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
 
void SetTracks (TrackList *pTracks)
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)=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 OptionalMessage ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=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 EffectUIClientInterfaceGetEffectUIClientInterface ()=0
 Returns the EffectUIClientInterface instance for this effect. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=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, 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...
 
- 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 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 StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- 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, const EffectOutputs *pOutputs)
 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
 
- 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 }
 
- 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:82
const WaveTrack * mControlTrack
Definition: AutoDuck.h:72
const EffectParameterMethods & Parameters() const override
Definition: AutoDuck.cpp:39
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:222
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 439 of file AutoDuck.cpp.

441{
442 bool cancel = false;
443
444 auto start = t->TimeToLongSamples(t0);
445 auto end = t->TimeToLongSamples(t1);
446
447 Floats buf{ kBufSize };
448 auto pos = start;
449
450 auto fadeDownSamples = t->TimeToLongSamples(
452 if (fadeDownSamples < 1)
453 fadeDownSamples = 1;
454
455 auto fadeUpSamples = t->TimeToLongSamples(
457 if (fadeUpSamples < 1)
458 fadeUpSamples = 1;
459
460 float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
461 float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
462
463 while (pos < end)
464 {
465 const auto len = limitSampleBufferSize( kBufSize, end - pos );
466
467 t->GetFloats(buf.get(), pos, len);
468
469 for (auto i = pos; i < pos + len; i++)
470 {
471 float gainDown = fadeDownStep * (i - start).as_float();
472 float gainUp = fadeUpStep * (end - i).as_float();
473
474 float gain;
475 if (gainDown > gainUp)
476 gain = gainDown;
477 else
478 gain = gainUp;
479 if (gain < mDuckAmountDb)
480 gain = mDuckAmountDb;
481
482 // i - pos is bounded by len:
483 buf[ ( i - pos ).as_size_t() ] *= DB_TO_LINEAR(gain);
484 }
485
486 t->Set((samplePtr)buf.get(), floatSample, pos, len);
487
488 pos += len;
489
490 float curTime = t->LongSamplesToTime(pos);
491 float fractionFinished = (curTime - mT0) / (mT1 - mT0);
492 if (TotalProgress( (trackNum + 1 + fractionFinished) /
493 (GetNumWaveTracks() + 1) ))
494 {
495 cancel = true;
496 break;
497 }
498 }
499
500 return cancel;
501}
static const size_t kBufSize
Definition: AutoDuck.cpp:52
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:543
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
double mInnerFadeDownLen
Definition: AutoDuck.h:65
double mDuckAmountDb
Definition: AutoDuck.h:64
double mInnerFadeUpLen
Definition: AutoDuck.h:66
double mOuterFadeDownLen
Definition: AutoDuck.h:67
double mOuterFadeUpLen
Definition: AutoDuck.h:68
double mT1
Definition: EffectBase.h:109
double mT0
Definition: EffectBase.h:108
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:675
int GetNumWaveTracks() const
Definition: Effect.h:224
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:2205
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 415 of file AutoDuck.cpp.

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

References mPanel, and Effect::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 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:104
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
Definition: Effect.cpp:863
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 503 of file AutoDuck.cpp.

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

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:90
static constexpr EffectParameter InnerFadeUpLen
Definition: AutoDuck.h:92
static constexpr EffectParameter OuterFadeDownLen
Definition: AutoDuck.h:94
static constexpr EffectParameter MaximumPause
Definition: AutoDuck.h:100
static constexpr EffectParameter ThresholdDb
Definition: AutoDuck.h:98
static constexpr EffectParameter DuckAmountDb
Definition: AutoDuck.h:88
static constexpr EffectParameter OuterFadeUpLen
Definition: AutoDuck.h:96

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,
const EffectOutputs pOutputs 
)
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.

336{
337 S.SetBorder(5);
338 S.StartVerticalLay(true);
339 {
340 S.AddSpace(0, 5);
341
342 mPanel = safenew EffectAutoDuck::Panel(S.GetParent(), wxID_ANY, this);
343 S.AddWindow(mPanel);
344
345 S.AddSpace(0, 5);
346
347 S.StartMultiColumn(6, wxCENTER);
348 {
349 mDuckAmountDbBox = S.Validator<FloatingPointValidator<double>>(
350 1, &mDuckAmountDb, NumValidatorStyle::NO_TRAILING_ZEROES,
352 .NameSuffix(XO("db"))
353 .AddTextBox(XXO("Duck &amount:"), wxT(""), 10);
354 S.AddUnits(XO("dB"));
355
356 mMaximumPauseBox = S.Validator<FloatingPointValidator<double>>(
357 2, &mMaximumPause, NumValidatorStyle::NO_TRAILING_ZEROES,
359 .NameSuffix(XO("seconds"))
360 .AddTextBox(XXO("Ma&ximum pause:"), wxT(""), 10);
361 S.AddUnits(XO("seconds"));
362
363 mOuterFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
364 2, &mOuterFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
366 .NameSuffix(XO("seconds"))
367 .AddTextBox(XXO("Outer fade &down length:"), wxT(""), 10);
368 S.AddUnits(XO("seconds"));
369
370 mOuterFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
371 2, &mOuterFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
373 .NameSuffix(XO("seconds"))
374 .AddTextBox(XXO("Outer fade &up length:"), wxT(""), 10);
375 S.AddUnits(XO("seconds"));
376
377 mInnerFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
378 2, &mInnerFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
380 .NameSuffix(XO("seconds"))
381 .AddTextBox(XXO("Inner fade d&own length:"), wxT(""), 10);
382 S.AddUnits(XO("seconds"));
383
384 mInnerFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
385 2, &mInnerFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
387 .NameSuffix(XO("seconds"))
388 .AddTextBox(XXO("Inner &fade up length:"), wxT(""), 10);
389 S.AddUnits(XO("seconds"));
390 }
391 S.EndMultiColumn();
392
393 S.StartMultiColumn(3, wxCENTER);
394 {
395 mThresholdDbBox = S.Validator<FloatingPointValidator<double>>(
396 2, &mThresholdDb, NumValidatorStyle::NO_TRAILING_ZEROES,
398 .NameSuffix(XO("db"))
399 .AddTextBox(XXO("&Threshold:"), wxT(""), 10);
400 S.AddUnits(XO("dB"));
401 }
402 S.EndMultiColumn();
403
404 }
405 S.EndVerticalLay();
406
407 return nullptr;
408}
wxT("CloseDown"))
#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:76
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:75
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:77
double mThresholdDb
Definition: AutoDuck.h:69
wxTextCtrl * mThresholdDbBox
Definition: AutoDuck.h:79
double mMaximumPause
Definition: AutoDuck.h:70
wxTextCtrl * mMaximumPauseBox
Definition: AutoDuck.h:80
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:78
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:74
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, wxT(), XO, and XXO.

Here is the call graph for this function:

◆ 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:439
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:107
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:240
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:733
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: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:

◆ TransferDataFromWindow()

bool EffectAutoDuck::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

Update the given settings from controls.

Implements EffectPlugin.

Definition at line 426 of file AutoDuck.cpp.

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

References Effect::mUIParent.

◆ TransferDataToWindow()

bool EffectAutoDuck::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Implements EffectPlugin.

Definition at line 410 of file AutoDuck.cpp.

411{
412 return DoTransferDataToWindow();
413}
bool DoTransferDataToWindow()
Definition: AutoDuck.cpp:415

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 88 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 90 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 92 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 100 of file AutoDuck.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mControlTrack

const WaveTrack* EffectAutoDuck::mControlTrack
private

Definition at line 72 of file AutoDuck.h.

Referenced by Init(), and Process().

◆ mDuckAmountDb

double EffectAutoDuck::mDuckAmountDb
private

Definition at line 64 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mDuckAmountDbBox

wxTextCtrl* EffectAutoDuck::mDuckAmountDbBox
private

Definition at line 74 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mInnerFadeDownLen

double EffectAutoDuck::mInnerFadeDownLen
private

Definition at line 65 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mInnerFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeDownLenBox
private

Definition at line 75 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mInnerFadeUpLen

double EffectAutoDuck::mInnerFadeUpLen
private

Definition at line 66 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mInnerFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeUpLenBox
private

Definition at line 76 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mMaximumPause

double EffectAutoDuck::mMaximumPause
private

Definition at line 70 of file AutoDuck.h.

Referenced by PopulateOrExchange(), and Process().

◆ mMaximumPauseBox

wxTextCtrl* EffectAutoDuck::mMaximumPauseBox
private

Definition at line 80 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeDownLen

double EffectAutoDuck::mOuterFadeDownLen
private

Definition at line 67 of file AutoDuck.h.

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

◆ mOuterFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeDownLenBox
private

Definition at line 77 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeUpLen

double EffectAutoDuck::mOuterFadeUpLen
private

Definition at line 68 of file AutoDuck.h.

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

◆ mOuterFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeUpLenBox
private

Definition at line 78 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mPanel

Panel* EffectAutoDuck::mPanel
private

Definition at line 83 of file AutoDuck.h.

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

◆ mThresholdDb

double EffectAutoDuck::mThresholdDb
private

Definition at line 69 of file AutoDuck.h.

Referenced by PopulateOrExchange(), and Process().

◆ mThresholdDbBox

wxTextCtrl* EffectAutoDuck::mThresholdDbBox
private

Definition at line 79 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 94 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 96 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 98 of file AutoDuck.h.

Referenced by Parameters(), and PopulateOrExchange().


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