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

Implements the Auto Ducking effect. More...

#include <AutoDuck.h>

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

Classes

class  Panel
 

Public Member Functions

 EffectAutoDuck ()
 
virtual ~EffectAutoDuck ()
 
ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
ManualPageID ManualPage () const override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
bool Init () override
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 
std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 
bool DoTransferDataToWindow ()
 
bool TransferDataFromWindow (EffectSettings &settings) override
 
- Public Member Functions inherited from StatefulEffect
 ~StatefulEffect () override
 
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () const
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize () noexcept
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings, 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
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:214
virtual void Reset(Effect &effect) const =0

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectAutoDuck()

EffectAutoDuck::~EffectAutoDuck ( )
virtual

Definition at line 93 of file AutoDuck.cpp.

94{
95}

Member Function Documentation

◆ ApplyDuckFade()

bool EffectAutoDuck::ApplyDuckFade ( int  trackNum,
WaveChannel track,
double  t0,
double  t1 
)
private

Definition at line 468 of file AutoDuck.cpp.

470{
471 bool cancel = false;
472
473 auto start = track.TimeToLongSamples(t0);
474 auto end = track.TimeToLongSamples(t1);
475
476 Floats buf{ kBufSize };
477 auto pos = start;
478
479 auto fadeDownSamples = track.TimeToLongSamples(
481 if (fadeDownSamples < 1)
482 fadeDownSamples = 1;
483
484 auto fadeUpSamples = track.TimeToLongSamples(
486 if (fadeUpSamples < 1)
487 fadeUpSamples = 1;
488
489 float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
490 float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
491
492 while (pos < end) {
493 const auto len = limitSampleBufferSize(kBufSize, end - pos);
494 track.GetFloats(buf.get(), pos, len);
495 for (auto i = pos; i < pos + len; ++i) {
496 float gainDown = fadeDownStep * (i - start).as_float();
497 float gainUp = fadeUpStep * (end - i).as_float();
498
499 float gain;
500 if (gainDown > gainUp)
501 gain = gainDown;
502 else
503 gain = gainUp;
504 if (gain < mDuckAmountDb)
505 gain = mDuckAmountDb;
506
507 // i - pos is bounded by len:
508 buf[ ( i - pos ).as_size_t() ] *= DB_TO_LINEAR(gain);
509 }
510
511 if (!track.Set((samplePtr)buf.get(), floatSample, pos, len)) {
512 cancel = true;
513 break;
514 }
515
516 pos += len;
517
518 float curTime = track.LongSamplesToTime(pos);
519 float fractionFinished = (curTime - mT0) / (mT1 - mT0);
520 if (TotalProgress((trackNum + 1 + fractionFinished) /
521 (GetNumWaveTracks() + 1))
522 ) {
523 cancel = true;
524 break;
525 }
526 }
527
528 return cancel;
529}
static const size_t kBufSize
Definition: AutoDuck.cpp:55
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:561
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
char * samplePtr
Definition: SampleFormat.h:55
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:116
double mT0
Definition: EffectBase.h:115
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:341
int GetNumWaveTracks() const
Definition: Effect.h:139
bool Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Random-access assignment of a range of samples.
Definition: WaveTrack.cpp:3169
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:152
double LongSamplesToTime(sampleCount pos) const
sampleCount TimeToLongSamples(double t0) const
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

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

445{
446 // Issue 2324: don't remove these two lines
447 if (!mUIParent->TransferDataToWindow())
448 return false;
449
450 mPanel->Refresh(false);
451
452 return true;
453}
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.

◆ 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:123
R TypeSwitch(const Functions &...functions)
Definition: Track.h:427
A Track that contains audio waveform data.
Definition: WaveTrack.h:220

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

532{
533 mPanel->Refresh(false);
534}

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

364{
365 mUIParent = S.GetParent();
366 S.SetBorder(5);
367 S.StartVerticalLay(true);
368 {
369 S.AddSpace(0, 5);
370
371 mPanel = safenew EffectAutoDuck::Panel(S.GetParent(), wxID_ANY, this);
372 S.AddWindow(mPanel);
373
374 S.AddSpace(0, 5);
375
376 S.StartMultiColumn(6, wxCENTER);
377 {
378 mDuckAmountDbBox = S.Validator<FloatingPointValidator<double>>(
379 1, &mDuckAmountDb, NumValidatorStyle::NO_TRAILING_ZEROES,
381 .NameSuffix(XO("db"))
382 .AddTextBox(XXO("Duck &amount:"), wxT(""), 10);
383 S.AddUnits(XO("dB"));
384
385 mMaximumPauseBox = S.Validator<FloatingPointValidator<double>>(
386 2, &mMaximumPause, NumValidatorStyle::NO_TRAILING_ZEROES,
388 .NameSuffix(XO("seconds"))
389 .AddTextBox(XXO("Ma&ximum pause:"), wxT(""), 10);
390 S.AddUnits(XO("seconds"));
391
392 mOuterFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
393 2, &mOuterFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
395 .NameSuffix(XO("seconds"))
396 .AddTextBox(XXO("Outer fade &down length:"), wxT(""), 10);
397 S.AddUnits(XO("seconds"));
398
399 mOuterFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
400 2, &mOuterFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
402 .NameSuffix(XO("seconds"))
403 .AddTextBox(XXO("Outer fade &up length:"), wxT(""), 10);
404 S.AddUnits(XO("seconds"));
405
406 mInnerFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
407 2, &mInnerFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
409 .NameSuffix(XO("seconds"))
410 .AddTextBox(XXO("Inner fade d&own length:"), wxT(""), 10);
411 S.AddUnits(XO("seconds"));
412
413 mInnerFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
414 2, &mInnerFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
416 .NameSuffix(XO("seconds"))
417 .AddTextBox(XXO("Inner &fade up length:"), wxT(""), 10);
418 S.AddUnits(XO("seconds"));
419 }
420 S.EndMultiColumn();
421
422 S.StartMultiColumn(3, wxCENTER);
423 {
424 mThresholdDbBox = S.Validator<FloatingPointValidator<double>>(
425 2, &mThresholdDb, NumValidatorStyle::NO_TRAILING_ZEROES,
427 .NameSuffix(XO("db"))
428 .AddTextBox(XXO("&Threshold:"), wxT(""), 10);
429 S.AddUnits(XO("dB"));
430 }
431 S.EndMultiColumn();
432
433 }
434 S.EndVerticalLay();
435
436 return nullptr;
437}
wxT("CloseDown"))
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
#define S(N)
Definition: ToChars.cpp:64
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h: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 TrackListHolder tempTracks;
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 auto &clips = pControlTrack->GetClips();
197 const auto t0 = pControlTrack->LongSamplesToTime(start);
198 const auto t1 = pControlTrack->LongSamplesToTime(end);
199 if (WaveTrackUtilities::HasStretch(*pControlTrack, t0, t1)) {
200 tempTracks = pControlTrack->Duplicate();
201 if (tempTracks) {
202 const auto pFirstTrack = *tempTracks->Any<WaveTrack>().begin();
203 if (pFirstTrack)
204 {
205 using namespace BasicUI;
206 const auto progress = MakeProgress(
207 XO("Pre-processing"),
208 XO("Rendering Control-Track Time-Stretched Audio"),
210 pFirstTrack->ApplyStretchRatio(
211 { { t0, t1 } }, [&](double progressFraction) {
212 const auto result =
213 progress->Poll(progressFraction * 1000, 1000);
214 if (result != ProgressResult::Success)
215 throw UserException {};
216 });
217 pControlTrack = pFirstTrack;
218 }
219 }
220 }
221 }
222
223 // the minimum number of samples we have to wait until the maximum
224 // pause has been exceeded
225 double maxPause = mMaximumPause;
226
227 // We don't fade in until we have time enough to actually fade out again
228 if (maxPause < mOuterFadeDownLen + mOuterFadeUpLen)
230
231 auto minSamplesPause =
232 pControlTrack->TimeToLongSamples(maxPause);
233
234 double threshold = DB_TO_LINEAR(mThresholdDb);
235
236 // adjust the threshold so we can compare it to the rmsSum value
237 threshold = threshold * threshold * kRMSWindowSize;
238
239 int rmsPos = 0;
240 double rmsSum = 0;
241 // to make the progress bar appear more natural, we first look for all
242 // duck regions and apply them all at once afterwards
243 std::vector<AutoDuckRegion> regions;
244 bool inDuckRegion = false;
245 {
246 Floats rmsWindow{ kRMSWindowSize, true };
247
248 Floats buf{ kBufSize };
249
250 // initialize the following two variables to prevent compiler warning
251 double duckRegionStart = 0;
252 sampleCount curSamplesPause = 0;
253
254 auto pos = start;
255
256 while (pos < end)
257 {
258 const auto len = limitSampleBufferSize( kBufSize, end - pos );
259
260 pControlTrack->GetFloats(buf.get(), pos, len);
261
262 for (auto i = pos; i < pos + len; i++)
263 {
264 rmsSum -= rmsWindow[rmsPos];
265 // i - pos is bounded by len:
266 auto index = ( i - pos ).as_size_t();
267 rmsWindow[rmsPos] = buf[ index ] * buf[ index ];
268 rmsSum += rmsWindow[rmsPos];
269 rmsPos = (rmsPos + 1) % kRMSWindowSize;
270
271 bool thresholdExceeded = rmsSum > threshold;
272
273 if (thresholdExceeded)
274 {
275 // everytime the threshold is exceeded, reset our count for
276 // the number of pause samples
277 curSamplesPause = 0;
278
279 if (!inDuckRegion)
280 {
281 // the threshold has been exceeded for the first time, so
282 // let the duck region begin here
283 inDuckRegion = true;
284 duckRegionStart = pControlTrack->LongSamplesToTime(i);
285 }
286 }
287
288 if (!thresholdExceeded && inDuckRegion)
289 {
290 // the threshold has not been exceeded and we are in a duck
291 // region, but only fade in if the maximum pause has been
292 // exceeded
293 curSamplesPause += 1;
294
295 if (curSamplesPause >= minSamplesPause)
296 {
297 // do the actual duck fade and reset all values
298 double duckRegionEnd =
299 pControlTrack->LongSamplesToTime(i - curSamplesPause);
300
301 regions.push_back(AutoDuckRegion(
302 duckRegionStart - mOuterFadeDownLen,
303 duckRegionEnd + mOuterFadeUpLen));
304
305 inDuckRegion = false;
306 }
307 }
308 }
309
310 pos += len;
311
312 if (TotalProgress(
313 (pos - start).as_double() /
314 (end - start).as_double() /
315 (GetNumWaveTracks() + 1)
316 ))
317 {
318 cancel = true;
319 break;
320 }
321 }
322
323 // apply last duck fade, if any
324 if (inDuckRegion)
325 {
326 double duckRegionEnd =
327 pControlTrack->LongSamplesToTime(end - curSamplesPause);
328 regions.push_back(AutoDuckRegion(
329 duckRegionStart - mOuterFadeDownLen,
330 duckRegionEnd + mOuterFadeUpLen));
331 }
332 }
333
334 if (!cancel) {
335 EffectOutputTracks outputs { *mTracks, {{ mT0, mT1 }} };
336
337 int trackNum = 0;
338
339 for (auto iterTrack : outputs.Get().Selected<WaveTrack>()) {
340 for (const auto pChannel : iterTrack->Channels())
341 for (size_t i = 0; i < regions.size(); ++i) {
342 const AutoDuckRegion& region = regions[i];
343 if (ApplyDuckFade(trackNum++, *pChannel, region.t0, region.t1)) {
344 cancel = true;
345 goto done;
346 }
347 }
348
349 done:
350 if (cancel)
351 break;
352 }
353
354 if (!cancel)
355 outputs.Commit();
356 }
357
358 return !cancel;
359}
static const size_t kRMSWindowSize
Definition: AutoDuck.cpp:56
std::shared_ptr< TrackList > TrackListHolder
Definition: Track.h:43
bool ApplyDuckFade(int trackNum, WaveChannel &track, double t0, double t1)
Definition: AutoDuck.cpp:468
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:109
Use this object to copy the input tracks to tentative outputTracks.
Can be thrown when user cancels operations, as with a progress dialog. Delayed handler does nothing.
Definition: UserException.h:17
WaveClipHolders & GetClips()
Definition: WaveTrack.h:690
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
@ ProgressShowCancel
Definition: BasicUI.h:141
std::unique_ptr< ProgressDialog > MakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
Create and display a progress dialog.
Definition: BasicUI.h:289
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
WAVE_TRACK_API bool HasStretch(const WaveTrack &track, double t0, double t1)
a struct that holds a start and end time.
Definition: AutoDuck.cpp:63

References ApplyDuckFade(), PackedArray::begin(), DB_TO_LINEAR, PackedArray::end(), WaveTrack::GetClips(), Effect::GetNumWaveTracks(), WaveTrackUtilities::HasStretch(), kBufSize, kRMSWindowSize, limitSampleBufferSize(), BasicUI::MakeProgress(), mControlTrack, mMaximumPause, mOuterFadeDownLen, mOuterFadeUpLen, EffectBase::mT0, EffectBase::mT1, mThresholdDb, EffectBase::mTracks, BasicUI::ProgressShowCancel, BasicUI::Success, AutoDuckRegion::t0, AutoDuckRegion::t1, WideSampleSequence::TimeToLongSamples(), Effect::TotalProgress(), 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 455 of file AutoDuck.cpp.

456{
457 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
458 {
459 return false;
460 }
461
462 return true;
463}

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

440{
441 return DoTransferDataToWindow();
442}
bool DoTransferDataToWindow()
Definition: AutoDuck.cpp:444

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: