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
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatID GetSelectionFormat ()
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings, InstanceFinder finder={})
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
bool IsLinearEffect () const
 
bool PreviewsFullSelection () const
 
void SetTracks (TrackList *pTracks)
 
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void CountWaveTracks ()
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 
- 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 (EffectBase &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 Public Member Functions inherited from EffectBase
static std::optional< InstancePointerFindInstance (EffectPlugin &plugin)
 
static InstanceFinder DefaultInstanceFinder (EffectPlugin &plugin)
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Static Public 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, WaveChannel &track, 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
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 
- Protected Member Functions inherited from Effect
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, sampleCount *start, sampleCount *len)
 
- Protected Member Functions inherited from EffectBase
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from EffectBase
double mF0 {}
 
double mF1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

Detailed Description

Implements the Auto Ducking effect.

Definition at line 26 of file AutoDuck.h.

Constructor & Destructor Documentation

◆ EffectAutoDuck()

EffectAutoDuck::EffectAutoDuck ( )

Definition at line 87 of file AutoDuck.cpp.

88{
89 Parameters().Reset(*this);
91}
const EffectParameterMethods & Parameters() const override
Definition: AutoDuck.cpp:42
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:210
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,
WaveChannel track,
double  t0,
double  t1 
)
private

Definition at line 459 of file AutoDuck.cpp.

461{
462 bool cancel = false;
463
464 auto start = track.TimeToLongSamples(t0);
465 auto end = track.TimeToLongSamples(t1);
466
467 Floats buf{ kBufSize };
468 auto pos = start;
469
470 auto fadeDownSamples = track.TimeToLongSamples(
472 if (fadeDownSamples < 1)
473 fadeDownSamples = 1;
474
475 auto fadeUpSamples = track.TimeToLongSamples(
477 if (fadeUpSamples < 1)
478 fadeUpSamples = 1;
479
480 float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
481 float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
482
483 while (pos < end) {
484 const auto len = limitSampleBufferSize(kBufSize, end - pos);
485 track.GetFloats(buf.get(), pos, len);
486 for (auto i = pos; i < pos + len; ++i) {
487 float gainDown = fadeDownStep * (i - start).as_float();
488 float gainUp = fadeUpStep * (end - i).as_float();
489
490 float gain;
491 if (gainDown > gainUp)
492 gain = gainDown;
493 else
494 gain = gainUp;
495 if (gain < mDuckAmountDb)
496 gain = mDuckAmountDb;
497
498 // i - pos is bounded by len:
499 buf[ ( i - pos ).as_size_t() ] *= DB_TO_LINEAR(gain);
500 }
501
502 if (!track.SetFloats(buf.get(), pos, len)) {
503 cancel = true;
504 break;
505 }
506
507 pos += len;
508
509 float curTime = track.LongSamplesToTime(pos);
510 float fractionFinished = (curTime - mT0) / (mT1 - mT0);
511 if (TotalProgress((trackNum + 1 + fractionFinished) /
512 (GetNumWaveTracks() + 1))
513 ) {
514 cancel = true;
515 break;
516 }
517 }
518
519 return cancel;
520}
static const size_t kBufSize
Definition: AutoDuck.cpp:55
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:337
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
double mInnerFadeDownLen
Definition: AutoDuck.h:68
double mDuckAmountDb
Definition: AutoDuck.h:67
double mInnerFadeUpLen
Definition: AutoDuck.h:69
double mOuterFadeDownLen
Definition: AutoDuck.h:70
double mOuterFadeUpLen
Definition: AutoDuck.h:71
double mT1
Definition: EffectBase.h:114
double mT0
Definition: EffectBase.h:113
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:335
int GetNumWaveTracks() const
Definition: Effect.h:139
bool SetFloats(const float *buffer, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Random-access assignment of a range of samples.
Definition: WaveTrack.h:162
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
Definition: WaveTrack.h:129
double LongSamplesToTime(sampleCount pos) const
sampleCount TimeToLongSamples(double t0) const
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References DB_TO_LINEAR, details::end(), WaveChannel::GetFloats(), Effect::GetNumWaveTracks(), kBufSize, limitSampleBufferSize(), WideSampleSequence::LongSamplesToTime(), mDuckAmountDb, mInnerFadeDownLen, mInnerFadeUpLen, mOuterFadeDownLen, mOuterFadeUpLen, EffectBase::mT0, EffectBase::mT1, WaveChannel::SetFloats(), WideSampleSequence::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 435 of file AutoDuck.cpp.

436{
437 // Issue 2324: don't remove these two lines
438 if (!mUIParent->TransferDataToWindow())
439 return false;
440
441 mPanel->Refresh(false);
442
443 return true;
444}
Panel * mPanel
Definition: AutoDuck.h:86
wxWeakRef< wxWindow > mUIParent
Definition: AutoDuck.h:65

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 30 of file AutoDuck.h.

30{ 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:31

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.

Referenced by Process().

Here is the caller graph for this function:

◆ 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 = nullptr;
126
127 // Find the control track, which is the non-selected wave track immediately
128 // after the last selected wave track. Fail if there is no such track or if
129 // any selected track is not a wave track.
130 bool lastWasSelectedWaveTrack = false;
131 const WaveTrack *controlTrackCandidate = nullptr;
132 for (auto t : *inputTracks()) {
133 if (lastWasSelectedWaveTrack && !t->GetSelected())
134 // This could be the control track, so remember it
135 controlTrackCandidate = dynamic_cast<const WaveTrack *>(t);
136
137 lastWasSelectedWaveTrack = false;
138 if (t->GetSelected()) {
139 bool ok = t->TypeSwitch<bool>(
140 [&](const WaveTrack &) {
141 lastWasSelectedWaveTrack = true;
142 controlTrackCandidate = nullptr;
143 return true;
144 },
145 [&](const Track &) {
147 /* i18n-hint: Auto duck is the name of an effect that 'ducks'
148 (reduces the volume) of the audio automatically when there is
149 sound on another track. Not as in 'Donald-Duck'!*/
150 XO("You selected a track which does not contain audio. "
151 "AutoDuck can only process audio tracks."),
152 wxICON_ERROR);
153 return false;
154 }
155 );
156 if (!ok)
157 return false;
158 }
159 }
160
161 if (!controlTrackCandidate) {
163 /* i18n-hint: Auto duck is the name of an effect that 'ducks' (reduces
164 the volume) of the audio automatically when there is sound on another
165 track. Not as in 'Donald-Duck'!*/
166 XO("Auto Duck needs a control track which must be placed below the "
167 "selected track(s)."),
168 wxICON_ERROR);
169 return false;
170 }
171
172 mControlTrack = controlTrackCandidate;
173 return true;
174}
const WaveTrack * mControlTrack
Definition: AutoDuck.h:75
const TrackList * inputTracks() const
Definition: EffectBase.h:91
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:110
R TypeSwitch(const Functions &...functions)
Definition: Track.h:381
A Track that contains audio waveform data.
Definition: WaveTrack.h:203

References EffectUIServices::DoMessageBox(), EffectBase::inputTracks(), mControlTrack, Track::TypeSwitch(), 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 522 of file AutoDuck.cpp.

523{
524 mPanel->Refresh(false);
525}

References mPanel.

◆ Parameters()

const EffectParameterMethods & EffectAutoDuck::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 42 of file AutoDuck.cpp.

43{
47 > parameters;
48 return parameters;
49}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter InnerFadeDownLen
Definition: AutoDuck.h:93
static constexpr EffectParameter InnerFadeUpLen
Definition: AutoDuck.h:95
static constexpr EffectParameter OuterFadeDownLen
Definition: AutoDuck.h:97
static constexpr EffectParameter MaximumPause
Definition: AutoDuck.h:103
static constexpr EffectParameter ThresholdDb
Definition: AutoDuck.h:101
static constexpr EffectParameter DuckAmountDb
Definition: AutoDuck.h:91
static constexpr EffectParameter OuterFadeUpLen
Definition: AutoDuck.h:99

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

355{
356 mUIParent = S.GetParent();
357 S.SetBorder(5);
358 S.StartVerticalLay(true);
359 {
360 S.AddSpace(0, 5);
361
362 mPanel = safenew EffectAutoDuck::Panel(S.GetParent(), wxID_ANY, this);
363 S.AddWindow(mPanel);
364
365 S.AddSpace(0, 5);
366
367 S.StartMultiColumn(6, wxCENTER);
368 {
369 mDuckAmountDbBox = S.Validator<FloatingPointValidator<double>>(
370 1, &mDuckAmountDb, NumValidatorStyle::NO_TRAILING_ZEROES,
372 .NameSuffix(XO("db"))
373 .AddTextBox(XXO("Duck &amount:"), wxT(""), 10);
374 S.AddUnits(XO("dB"));
375
376 mMaximumPauseBox = S.Validator<FloatingPointValidator<double>>(
377 2, &mMaximumPause, NumValidatorStyle::NO_TRAILING_ZEROES,
379 .NameSuffix(XO("seconds"))
380 .AddTextBox(XXO("Ma&ximum pause:"), wxT(""), 10);
381 S.AddUnits(XO("seconds"));
382
383 mOuterFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
384 2, &mOuterFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
386 .NameSuffix(XO("seconds"))
387 .AddTextBox(XXO("Outer fade &down length:"), wxT(""), 10);
388 S.AddUnits(XO("seconds"));
389
390 mOuterFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
391 2, &mOuterFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
393 .NameSuffix(XO("seconds"))
394 .AddTextBox(XXO("Outer fade &up length:"), wxT(""), 10);
395 S.AddUnits(XO("seconds"));
396
397 mInnerFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
398 2, &mInnerFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
400 .NameSuffix(XO("seconds"))
401 .AddTextBox(XXO("Inner fade d&own length:"), wxT(""), 10);
402 S.AddUnits(XO("seconds"));
403
404 mInnerFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
405 2, &mInnerFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
407 .NameSuffix(XO("seconds"))
408 .AddTextBox(XXO("Inner &fade up length:"), wxT(""), 10);
409 S.AddUnits(XO("seconds"));
410 }
411 S.EndMultiColumn();
412
413 S.StartMultiColumn(3, wxCENTER);
414 {
415 mThresholdDbBox = S.Validator<FloatingPointValidator<double>>(
416 2, &mThresholdDb, NumValidatorStyle::NO_TRAILING_ZEROES,
418 .NameSuffix(XO("db"))
419 .AddTextBox(XXO("&Threshold:"), wxT(""), 10);
420 S.AddUnits(XO("dB"));
421 }
422 S.EndMultiColumn();
423
424 }
425 S.EndVerticalLay();
426
427 return nullptr;
428}
wxT("CloseDown"))
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:9
#define S(N)
Definition: ToChars.cpp:64
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:79
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:78
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:80
double mThresholdDb
Definition: AutoDuck.h:72
wxTextCtrl * mThresholdDbBox
Definition: AutoDuck.h:82
double mMaximumPause
Definition: AutoDuck.h:73
wxTextCtrl * mMaximumPauseBox
Definition: AutoDuck.h:83
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:81
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:77
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 WaveTrack::Holder pFirstTrack;
192 auto pControlTrack = mControlTrack;
193 // If there is any stretch in the control track, substitute a temporary
194 // rendering before trying to use GetFloats
195 {
196 const auto t0 = pControlTrack->LongSamplesToTime(start);
197 const auto t1 = pControlTrack->LongSamplesToTime(end);
198 if (TimeStretching::HasPitchOrSpeed(*pControlTrack, t0, t1)) {
199 pFirstTrack = pControlTrack->Duplicate()->SharedPointer<WaveTrack>();
200 if (pFirstTrack) {
202 [&](const ProgressReporter& reportProgress) {
203 pFirstTrack->ApplyPitchAndSpeed(
204 { { t0, t1 } }, reportProgress);
205 },
207 XO("Rendering Control-Track Time-Stretched Audio"));
208 pControlTrack = pFirstTrack.get();
209 }
210 }
211 }
212
213 // the minimum number of samples we have to wait until the maximum
214 // pause has been exceeded
215 double maxPause = mMaximumPause;
216
217 // We don't fade in until we have time enough to actually fade out again
218 if (maxPause < mOuterFadeDownLen + mOuterFadeUpLen)
220
221 auto minSamplesPause =
222 pControlTrack->TimeToLongSamples(maxPause);
223
224 double threshold = DB_TO_LINEAR(mThresholdDb);
225
226 // adjust the threshold so we can compare it to the rmsSum value
227 threshold = threshold * threshold * kRMSWindowSize;
228
229 int rmsPos = 0;
230 double rmsSum = 0;
231 // to make the progress bar appear more natural, we first look for all
232 // duck regions and apply them all at once afterwards
233 std::vector<AutoDuckRegion> regions;
234 bool inDuckRegion = false;
235 {
236 Floats rmsWindow{ kRMSWindowSize, true };
237
238 Floats buf{ kBufSize };
239
240 // initialize the following two variables to prevent compiler warning
241 double duckRegionStart = 0;
242 sampleCount curSamplesPause = 0;
243
244 auto pos = start;
245
246 const auto pControlChannel = *pControlTrack->Channels().begin();
247 while (pos < end)
248 {
249 const auto len = limitSampleBufferSize( kBufSize, end - pos );
250
251 pControlChannel->GetFloats(buf.get(), pos, len);
252
253 for (auto i = pos; i < pos + len; i++)
254 {
255 rmsSum -= rmsWindow[rmsPos];
256 // i - pos is bounded by len:
257 auto index = ( i - pos ).as_size_t();
258 rmsWindow[rmsPos] = buf[ index ] * buf[ index ];
259 rmsSum += rmsWindow[rmsPos];
260 rmsPos = (rmsPos + 1) % kRMSWindowSize;
261
262 bool thresholdExceeded = rmsSum > threshold;
263
264 if (thresholdExceeded)
265 {
266 // everytime the threshold is exceeded, reset our count for
267 // the number of pause samples
268 curSamplesPause = 0;
269
270 if (!inDuckRegion)
271 {
272 // the threshold has been exceeded for the first time, so
273 // let the duck region begin here
274 inDuckRegion = true;
275 duckRegionStart = pControlTrack->LongSamplesToTime(i);
276 }
277 }
278
279 if (!thresholdExceeded && inDuckRegion)
280 {
281 // the threshold has not been exceeded and we are in a duck
282 // region, but only fade in if the maximum pause has been
283 // exceeded
284 curSamplesPause += 1;
285
286 if (curSamplesPause >= minSamplesPause)
287 {
288 // do the actual duck fade and reset all values
289 double duckRegionEnd =
290 pControlTrack->LongSamplesToTime(i - curSamplesPause);
291
292 regions.push_back(AutoDuckRegion(
293 duckRegionStart - mOuterFadeDownLen,
294 duckRegionEnd + mOuterFadeUpLen));
295
296 inDuckRegion = false;
297 }
298 }
299 }
300
301 pos += len;
302
303 if (TotalProgress(
304 (pos - start).as_double() /
305 (end - start).as_double() /
306 (GetNumWaveTracks() + 1)
307 ))
308 {
309 cancel = true;
310 break;
311 }
312 }
313
314 // apply last duck fade, if any
315 if (inDuckRegion)
316 {
317 double duckRegionEnd =
318 pControlTrack->LongSamplesToTime(end - curSamplesPause);
319 regions.push_back(AutoDuckRegion(
320 duckRegionStart - mOuterFadeDownLen,
321 duckRegionEnd + mOuterFadeUpLen));
322 }
323 }
324
325 if (!cancel) {
326 EffectOutputTracks outputs { *mTracks, GetType(), { { mT0, mT1 } } };
327
328 int trackNum = 0;
329
330 for (auto iterTrack : outputs.Get().Selected<WaveTrack>()) {
331 for (const auto pChannel : iterTrack->Channels())
332 for (size_t i = 0; i < regions.size(); ++i) {
333 const AutoDuckRegion& region = regions[i];
334 if (ApplyDuckFade(trackNum++, *pChannel, region.t0, region.t1)) {
335 cancel = true;
336 goto done;
337 }
338 }
339
340 done:
341 if (cancel)
342 break;
343 }
344
345 if (!cancel)
346 outputs.Commit();
347 }
348
349 return !cancel;
350}
static const size_t kRMSWindowSize
Definition: AutoDuck.cpp:56
std::function< void(double)> ProgressReporter
Definition: Track.h:48
bool ApplyDuckFade(int trackNum, WaveChannel &track, double t0, double t1)
Definition: AutoDuck.cpp:459
EffectType GetType() const override
Type determines how it behaves.
Definition: AutoDuck.cpp:116
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:107
Use this object to copy the input tracks to tentative outputTracks.
static void WithCancellableProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title, TranslatableString message)
A frequently useful convenience wraps a lambda and may throw this type.
std::shared_ptr< WaveTrack > Holder
Definition: WaveTrack.h:247
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
WAVE_TRACK_API const TranslatableString defaultStretchRenderingTitle
WAVE_TRACK_API bool HasPitchOrSpeed(const WaveTrack &track, double t0, double t1)
a struct that holds a start and end time.
Definition: AutoDuck.cpp:63

References ApplyDuckFade(), DB_TO_LINEAR, TimeStretching::defaultStretchRenderingTitle, details::end(), Effect::GetNumWaveTracks(), GetType(), TimeStretching::HasPitchOrSpeed(), kBufSize, kRMSWindowSize, limitSampleBufferSize(), WideSampleSequence::LongSamplesToTime(), mControlTrack, mMaximumPause, mOuterFadeDownLen, mOuterFadeUpLen, EffectBase::mT0, EffectBase::mT1, mThresholdDb, EffectBase::mTracks, AutoDuckRegion::t0, AutoDuckRegion::t1, WideSampleSequence::TimeToLongSamples(), Effect::TotalProgress(), UserException::WithCancellableProgress(), and XO().

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

447{
448 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
449 {
450 return false;
451 }
452
453 return true;
454}

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

431{
432 return DoTransferDataToWindow();
433}
bool DoTransferDataToWindow()
Definition: AutoDuck.cpp:435

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 91 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 93 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 95 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 103 of file AutoDuck.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mControlTrack

const WaveTrack* EffectAutoDuck::mControlTrack {}
private

Definition at line 75 of file AutoDuck.h.

Referenced by Init(), and Process().

◆ mDuckAmountDb

double EffectAutoDuck::mDuckAmountDb
private

Definition at line 67 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mDuckAmountDbBox

wxTextCtrl* EffectAutoDuck::mDuckAmountDbBox
private

Definition at line 77 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mInnerFadeDownLen

double EffectAutoDuck::mInnerFadeDownLen
private

Definition at line 68 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mInnerFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeDownLenBox
private

Definition at line 78 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mInnerFadeUpLen

double EffectAutoDuck::mInnerFadeUpLen
private

Definition at line 69 of file AutoDuck.h.

Referenced by ApplyDuckFade(), and PopulateOrExchange().

◆ mInnerFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeUpLenBox
private

Definition at line 79 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mMaximumPause

double EffectAutoDuck::mMaximumPause
private

Definition at line 73 of file AutoDuck.h.

Referenced by PopulateOrExchange(), and Process().

◆ mMaximumPauseBox

wxTextCtrl* EffectAutoDuck::mMaximumPauseBox
private

Definition at line 83 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeDownLen

double EffectAutoDuck::mOuterFadeDownLen
private

Definition at line 70 of file AutoDuck.h.

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

◆ mOuterFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeDownLenBox
private

Definition at line 80 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeUpLen

double EffectAutoDuck::mOuterFadeUpLen
private

Definition at line 71 of file AutoDuck.h.

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

◆ mOuterFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeUpLenBox
private

Definition at line 81 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mPanel

Panel* EffectAutoDuck::mPanel {}
private

Definition at line 86 of file AutoDuck.h.

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

◆ mThresholdDb

double EffectAutoDuck::mThresholdDb
private

Definition at line 72 of file AutoDuck.h.

Referenced by PopulateOrExchange(), and Process().

◆ mThresholdDbBox

wxTextCtrl* EffectAutoDuck::mThresholdDbBox
private

Definition at line 82 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mUIParent

wxWeakRef<wxWindow> EffectAutoDuck::mUIParent {}
private

Definition at line 65 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 97 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 99 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 31 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 101 of file AutoDuck.h.

Referenced by Parameters(), and PopulateOrExchange().


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