Audacity  3.0.3
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | 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]

Public Member Functions

 EffectAutoDuck ()
 
virtual ~EffectAutoDuck ()
 
ComponentInterfaceSymbol GetSymbol () override
 
TranslatableString GetDescription () override
 
ManualPageID ManualPage () override
 
EffectType GetType () override
 
bool DefineParams (ShuttleParams &S) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool Startup () override
 
bool Init () override
 
void End () override
 
bool Process () override
 
void PopulateOrExchange (ShuttleGui &S) override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () override
 
ComponentInterfaceSymbol GetSymbol () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
TranslatableString GetDescription () override
 
EffectType GetType () override
 
EffectFamilySymbol GetFamily () override
 
bool IsInteractive () override
 
bool IsDefault () override
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 
bool SupportsAutomation () override
 
bool SetHost (EffectHostInterface *host) override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
size_t GetBlockSize () const override
 
bool IsReady () override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 
bool ProcessFinalize () override
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () override
 
bool ShowInterface (wxWindow &parent, const EffectDialogFactory &factory, bool forceModal=false) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool LoadUserPreset (const RegistryPath &name) override
 
bool SaveUserPreset (const RegistryPath &name) override
 
RegistryPaths GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (ShuttleGui &S) final
 
bool IsGraphicalUI () override
 
bool ValidateUI () override
 
bool HideUI () override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets () override
 
void ImportPresets () override
 
bool HasOptions () override
 
void ShowOptions () override
 
double GetDefaultDuration () override
 
double GetDuration () override
 
NumericFormatSymbol GetDurationFormat () override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
void SetDuration (double duration) override
 
RegistryPath GetUserPresetsGroup (const RegistryPath &name) override
 
RegistryPath GetCurrentSettingsGroup () override
 
RegistryPath GetFactoryDefaultsGroup () override
 
virtual wxString GetSavedStateGroup ()
 
bool HasSharedConfigGroup (const RegistryPath &group) override
 
bool GetSharedConfigSubgroups (const RegistryPath &group, RegistryPaths &subgroups) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, wxString &value, const wxString &defval={}) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, int &value, int defval=0) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const wxString &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const int &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const bool &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const float &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const RegistryPath &group) override
 
bool RemoveSharedConfig (const RegistryPath &group, const RegistryPath &key) override
 
bool HasPrivateConfigGroup (const RegistryPath &group) override
 
bool GetPrivateConfigSubgroups (const RegistryPath &group, RegistryPaths &paths) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, wxString &value, const wxString &defval={}) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const wxString &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const int &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const bool &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const float &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const RegistryPath &group) override
 
bool RemovePrivateConfig (const RegistryPath &group, const RegistryPath &key) override
 
virtual PluginID GetID ()
 
virtual bool Startup (EffectClientInterface *client)
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (const wxString &parms)
 
virtual RegistryPaths GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual FilePath HelpPage ()
 
virtual void SetUIFlags (unsigned flags)
 
virtual unsigned TestUIFlags (unsigned mask)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={})
 
bool Delegate (Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory)
 
virtual bool IsHidden ()
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetClassification ()
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()
 
- Public Member Functions inherited from ConfigClientInterface
virtual ~ConfigClientInterface ()
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Auto Duck") }
 
- Static Public Attributes inherited from Effect
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)
 

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
 
EffectAutoDuckPanelmPanel
 

Friends

class EffectAutoDuckPanel
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
using VetoDialogHook = bool(*)(wxDialog *)
 
- Public Types inherited from EffectClientInterface
using EffectDialogFactory = std::function< wxDialog *(wxWindow &parent, EffectHostInterface *, EffectUIClientInterface *) >
 
- Static Public Member Functions inherited from Effect
static VetoDialogHook SetVetoDialogHook (VetoDialogHook hook)
 
static CommandID GetSquashedName (wxString name)
 
static void IncEffectCounter ()
 
- Protected Member Functions inherited from Effect
virtual bool CheckWhetherSkipEffect ()
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual int GetPass ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
virtual void Preview (bool dryOnly)
 
virtual bool EnableApply (bool enable=true)
 
virtual bool EnablePreview (bool enable=true)
 
virtual void EnableDebug (bool enable=true)
 
bool TotalProgress (double frac, const TranslatableString &={})
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={})
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={})
 
int GetNumWaveTracks ()
 
int GetNumWaveGroups ()
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing ()
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from Effect
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
wxWeakRef< NotifyingSelectedRegionmpSelectedRegion {}
 
WaveTrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
unsigned mUIFlags
 
sampleCount mSampleCnt
 
- Static Protected Attributes inherited from Effect
static int nEffectsDone =0
 

Detailed Description

Implements the Auto Ducking effect.

Definition at line 23 of file AutoDuck.h.

Constructor & Destructor Documentation

◆ EffectAutoDuck()

EffectAutoDuck::EffectAutoDuck ( )

Definition at line 88 of file AutoDuck.cpp.

89 {
90  mDuckAmountDb = DEF_DuckAmountDb;
91  mInnerFadeDownLen = DEF_InnerFadeDownLen;
92  mInnerFadeUpLen = DEF_InnerFadeUpLen;
93  mOuterFadeDownLen = DEF_OuterFadeDownLen;
94  mOuterFadeUpLen = DEF_OuterFadeUpLen;
95  mThresholdDb = DEF_ThresholdDb;
96  mMaximumPause = DEF_MaximumPause;
97 
98  SetLinearEffectFlag(true);
99 
100  mControlTrack = NULL;
101 
102  mPanel = NULL;
103 }

◆ ~EffectAutoDuck()

EffectAutoDuck::~EffectAutoDuck ( )
virtual

Definition at line 105 of file AutoDuck.cpp.

106 {
107 }

Member Function Documentation

◆ ApplyDuckFade()

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

Definition at line 534 of file AutoDuck.cpp.

536 {
537  bool cancel = false;
538 
539  auto start = t->TimeToLongSamples(t0);
540  auto end = t->TimeToLongSamples(t1);
541 
542  Floats buf{ kBufSize };
543  auto pos = start;
544 
545  auto fadeDownSamples = t->TimeToLongSamples(
547  if (fadeDownSamples < 1)
548  fadeDownSamples = 1;
549 
550  auto fadeUpSamples = t->TimeToLongSamples(
552  if (fadeUpSamples < 1)
553  fadeUpSamples = 1;
554 
555  float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
556  float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
557 
558  while (pos < end)
559  {
560  const auto len = limitSampleBufferSize( kBufSize, end - pos );
561 
562  t->GetFloats(buf.get(), pos, len);
563 
564  for (auto i = pos; i < pos + len; i++)
565  {
566  float gainDown = fadeDownStep * (i - start).as_float();
567  float gainUp = fadeUpStep * (end - i).as_float();
568 
569  float gain;
570  if (gainDown > gainUp)
571  gain = gainDown;
572  else
573  gain = gainUp;
574  if (gain < mDuckAmountDb)
575  gain = mDuckAmountDb;
576 
577  // i - pos is bounded by len:
578  buf[ ( i - pos ).as_size_t() ] *= DB_TO_LINEAR(gain);
579  }
580 
581  t->Set((samplePtr)buf.get(), floatSample, pos, len);
582 
583  pos += len;
584 
585  float curTime = t->LongSamplesToTime(pos);
586  float fractionFinished = (curTime - mT0) / (mT1 - mT0);
587  if (TotalProgress( (trackNum + 1 + fractionFinished) /
588  (GetNumWaveTracks() + 1) ))
589  {
590  cancel = true;
591  break;
592  }
593  }
594 
595  return cancel;
596 }

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

Referenced by Process().

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

◆ DefineParams()

bool EffectAutoDuck::DefineParams ( ShuttleParams S)
override

Definition at line 134 of file AutoDuck.cpp.

134  {
135  S.SHUTTLE_PARAM( mDuckAmountDb, DuckAmountDb);
136  S.SHUTTLE_PARAM( mInnerFadeDownLen, InnerFadeDownLen);
137  S.SHUTTLE_PARAM( mInnerFadeUpLen, InnerFadeUpLen);
138  S.SHUTTLE_PARAM( mOuterFadeDownLen, OuterFadeDownLen);
139  S.SHUTTLE_PARAM( mOuterFadeUpLen, OuterFadeUpLen);
140  S.SHUTTLE_PARAM( mThresholdDb, ThresholdDb);
141  S.SHUTTLE_PARAM( mMaximumPause, MaximumPause);
142  return true;
143 }

References mDuckAmountDb, mInnerFadeDownLen, mInnerFadeUpLen, mMaximumPause, mOuterFadeDownLen, mOuterFadeUpLen, and mThresholdDb.

◆ End()

void EffectAutoDuck::End ( )
overridevirtual

Reimplemented from Effect.

Definition at line 267 of file AutoDuck.cpp.

268 {
269  mControlTrack = NULL;
270 }

References mControlTrack.

◆ GetAutomationParameters()

bool EffectAutoDuck::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Implements EffectClientInterface.

Definition at line 145 of file AutoDuck.cpp.

146 {
147  parms.Write(KEY_DuckAmountDb, mDuckAmountDb);
148  parms.Write(KEY_InnerFadeDownLen, mInnerFadeDownLen);
149  parms.Write(KEY_InnerFadeUpLen, mInnerFadeUpLen);
150  parms.Write(KEY_OuterFadeDownLen, mOuterFadeDownLen);
151  parms.Write(KEY_OuterFadeUpLen, mOuterFadeUpLen);
152  parms.Write(KEY_ThresholdDb, mThresholdDb);
153  parms.Write(KEY_MaximumPause, mMaximumPause);
154 
155  return true;
156 }

References mDuckAmountDb, mInnerFadeDownLen, mInnerFadeUpLen, mMaximumPause, mOuterFadeDownLen, mOuterFadeUpLen, and mThresholdDb.

◆ GetDescription()

TranslatableString EffectAutoDuck::GetDescription ( )
overridevirtual

Implements ComponentInterface.

Definition at line 116 of file AutoDuck.cpp.

117 {
118  return XO("Reduces (ducks) the volume of one or more tracks whenever the volume of a specified \"control\" track reaches a particular level");
119 }

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectAutoDuck::GetSymbol ( )
overridevirtual

Implements ComponentInterface.

Definition at line 111 of file AutoDuck.cpp.

112 {
113  return Symbol;
114 }

References Symbol.

◆ GetType()

EffectType EffectAutoDuck::GetType ( )
overridevirtual

Implements EffectDefinitionInterface.

Definition at line 128 of file AutoDuck.cpp.

129 {
130  return EffectTypeProcess;
131 }

References EffectTypeProcess.

◆ Init()

bool EffectAutoDuck::Init ( )
overridevirtual

Reimplemented from Effect.

Definition at line 214 of file AutoDuck.cpp.

215 {
216  mControlTrack = NULL;
217 
218  bool lastWasSelectedWaveTrack = false;
219  const WaveTrack *controlTrackCandidate = NULL;
220 
221  for (auto t : inputTracks()->Any())
222  {
223  if (lastWasSelectedWaveTrack && !t->GetSelected()) {
224  // This could be the control track, so remember it
225  controlTrackCandidate = track_cast<const WaveTrack *>(t);
226  }
227 
228  lastWasSelectedWaveTrack = false;
229 
230  if (t->GetSelected()) {
231  bool ok = t->TypeSwitch<bool>(
232  [&](const WaveTrack *) {
233  lastWasSelectedWaveTrack = true;
234  return true;
235  },
236  [&](const Track *) {
238  /* i18n-hint: Auto duck is the name of an effect that 'ducks' (reduces the volume)
239  * of the audio automatically when there is sound on another track. Not as
240  * in 'Donald-Duck'!*/
241  XO("You selected a track which does not contain audio. AutoDuck can only process audio tracks."),
242  wxICON_ERROR );
243  return false;
244  }
245  );
246  if (!ok)
247  return false;
248  }
249  }
250 
251  if (!controlTrackCandidate)
252  {
254  /* i18n-hint: Auto duck is the name of an effect that 'ducks' (reduces the volume)
255  * of the audio automatically when there is sound on another track. Not as
256  * in 'Donald-Duck'!*/
257  XO("Auto Duck needs a control track which must be placed below the selected track(s)."),
258  wxICON_ERROR );
259  return false;
260  }
261 
262  mControlTrack = controlTrackCandidate;
263 
264  return true;
265 }

References Effect::inputTracks(), mControlTrack, Effect::MessageBox(), and XO.

Here is the call graph for this function:

◆ ManualPage()

ManualPageID EffectAutoDuck::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 121 of file AutoDuck.cpp.

122 {
123  return L"Auto_Duck";
124 }

◆ OnValueChanged()

void EffectAutoDuck::OnValueChanged ( wxCommandEvent &  evt)
private

Definition at line 598 of file AutoDuck.cpp.

599 {
600  mPanel->Refresh(false);
601 }

References mPanel.

◆ PopulateOrExchange()

void EffectAutoDuck::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 427 of file AutoDuck.cpp.

428 {
429  S.SetBorder(5);
430  S.StartVerticalLay(true);
431  {
432  S.AddSpace(0, 5);
433 
434  mPanel = safenew EffectAutoDuckPanel(S.GetParent(), wxID_ANY, this);
435  S.AddWindow(mPanel);
436 
437  S.AddSpace(0, 5);
438 
439  S.StartMultiColumn(6, wxCENTER);
440  {
441  mDuckAmountDbBox = S.Validator<FloatingPointValidator<double>>(
442  1, &mDuckAmountDb, NumValidatorStyle::NO_TRAILING_ZEROES,
443  MIN_DuckAmountDb, MAX_DuckAmountDb
444  )
445  .NameSuffix(XO("db"))
446  .AddTextBox(XXO("Duck &amount:"), wxT(""), 10);
447  S.AddUnits(XO("dB"));
448 
449  mMaximumPauseBox = S.Validator<FloatingPointValidator<double>>(
450  2, &mMaximumPause, NumValidatorStyle::NO_TRAILING_ZEROES,
451  MIN_MaximumPause, MAX_MaximumPause
452  )
453  .NameSuffix(XO("seconds"))
454  .AddTextBox(XXO("Ma&ximum pause:"), wxT(""), 10);
455  S.AddUnits(XO("seconds"));
456 
457  mOuterFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
458  2, &mOuterFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
459  MIN_OuterFadeDownLen, MAX_OuterFadeDownLen
460  )
461  .NameSuffix(XO("seconds"))
462  .AddTextBox(XXO("Outer fade &down length:"), wxT(""), 10);
463  S.AddUnits(XO("seconds"));
464 
465  mOuterFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
466  2, &mOuterFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
467  MIN_OuterFadeUpLen, MAX_OuterFadeUpLen
468  )
469  .NameSuffix(XO("seconds"))
470  .AddTextBox(XXO("Outer fade &up length:"), wxT(""), 10);
471  S.AddUnits(XO("seconds"));
472 
473  mInnerFadeDownLenBox = S.Validator<FloatingPointValidator<double>>(
474  2, &mInnerFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
475  MIN_InnerFadeDownLen, MAX_InnerFadeDownLen
476  )
477  .NameSuffix(XO("seconds"))
478  .AddTextBox(XXO("Inner fade d&own length:"), wxT(""), 10);
479  S.AddUnits(XO("seconds"));
480 
481  mInnerFadeUpLenBox = S.Validator<FloatingPointValidator<double>>(
482  2, &mInnerFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
483  MIN_InnerFadeUpLen, MAX_InnerFadeUpLen
484  )
485  .NameSuffix(XO("seconds"))
486  .AddTextBox(XXO("Inner &fade up length:"), wxT(""), 10);
487  S.AddUnits(XO("seconds"));
488  }
489  S.EndMultiColumn();
490 
491  S.StartMultiColumn(3, wxCENTER);
492  {
493  mThresholdDbBox = S.Validator<FloatingPointValidator<double>>(
494  2, &mThresholdDb, NumValidatorStyle::NO_TRAILING_ZEROES,
495  MIN_ThresholdDb, MAX_ThresholdDb
496  )
497  .NameSuffix(XO("db"))
498  .AddTextBox(XXO("&Threshold:"), wxT(""), 10);
499  S.AddUnits(XO("dB"));
500  }
501  S.EndMultiColumn();
502 
503  }
504  S.EndVerticalLay();
505 
506  return;
507 }

References ShuttleGui::AddSpace(), ShuttleGuiBase::AddUnits(), ShuttleGuiBase::AddWindow(), EffectAutoDuckPanel, ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndVerticalLay(), ShuttleGuiBase::GetParent(), mDuckAmountDb, mDuckAmountDbBox, mInnerFadeDownLen, mInnerFadeDownLenBox, mInnerFadeUpLen, mInnerFadeUpLenBox, mMaximumPause, mMaximumPauseBox, mOuterFadeDownLen, mOuterFadeDownLenBox, mOuterFadeUpLen, mOuterFadeUpLenBox, mPanel, mThresholdDb, mThresholdDbBox, safenew, ShuttleGuiBase::SetBorder(), ShuttleGuiBase::StartMultiColumn(), ShuttleGuiBase::StartVerticalLay(), ShuttleGui::Validator(), XO, and XXO.

Here is the call graph for this function:

◆ Process()

bool EffectAutoDuck::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 272 of file AutoDuck.cpp.

273 {
274  if (GetNumWaveTracks() == 0 || !mControlTrack)
275  return false;
276 
277  bool cancel = false;
278 
279  auto start =
281  auto end =
283 
284  if (end <= start)
285  return false;
286 
287  // the minimum number of samples we have to wait until the maximum
288  // pause has been exceeded
289  double maxPause = mMaximumPause;
290 
291  // We don't fade in until we have time enough to actually fade out again
292  if (maxPause < mOuterFadeDownLen + mOuterFadeUpLen)
293  maxPause = mOuterFadeDownLen + mOuterFadeUpLen;
294 
295  auto minSamplesPause =
296  mControlTrack->TimeToLongSamples(maxPause);
297 
298  double threshold = DB_TO_LINEAR(mThresholdDb);
299 
300  // adjust the threshold so we can compare it to the rmsSum value
301  threshold = threshold * threshold * kRMSWindowSize;
302 
303  int rmsPos = 0;
304  double rmsSum = 0;
305  // to make the progress bar appear more natural, we first look for all
306  // duck regions and apply them all at once afterwards
307  std::vector<AutoDuckRegion> regions;
308  bool inDuckRegion = false;
309  {
310  Floats rmsWindow{ kRMSWindowSize, true };
311 
312  Floats buf{ kBufSize };
313 
314  // initialize the following two variables to prevent compiler warning
315  double duckRegionStart = 0;
316  sampleCount curSamplesPause = 0;
317 
318  auto pos = start;
319 
320  while (pos < end)
321  {
322  const auto len = limitSampleBufferSize( kBufSize, end - pos );
323 
324  mControlTrack->GetFloats(buf.get(), pos, len);
325 
326  for (auto i = pos; i < pos + len; i++)
327  {
328  rmsSum -= rmsWindow[rmsPos];
329  // i - pos is bounded by len:
330  auto index = ( i - pos ).as_size_t();
331  rmsWindow[rmsPos] = buf[ index ] * buf[ index ];
332  rmsSum += rmsWindow[rmsPos];
333  rmsPos = (rmsPos + 1) % kRMSWindowSize;
334 
335  bool thresholdExceeded = rmsSum > threshold;
336 
337  if (thresholdExceeded)
338  {
339  // everytime the threshold is exceeded, reset our count for
340  // the number of pause samples
341  curSamplesPause = 0;
342 
343  if (!inDuckRegion)
344  {
345  // the threshold has been exceeded for the first time, so
346  // let the duck region begin here
347  inDuckRegion = true;
348  duckRegionStart = mControlTrack->LongSamplesToTime(i);
349  }
350  }
351 
352  if (!thresholdExceeded && inDuckRegion)
353  {
354  // the threshold has not been exceeded and we are in a duck
355  // region, but only fade in if the maximum pause has been
356  // exceeded
357  curSamplesPause += 1;
358 
359  if (curSamplesPause >= minSamplesPause)
360  {
361  // do the actual duck fade and reset all values
362  double duckRegionEnd =
363  mControlTrack->LongSamplesToTime(i - curSamplesPause);
364 
365  regions.push_back(AutoDuckRegion(
366  duckRegionStart - mOuterFadeDownLen,
367  duckRegionEnd + mOuterFadeUpLen));
368 
369  inDuckRegion = false;
370  }
371  }
372  }
373 
374  pos += len;
375 
376  if (TotalProgress(
377  (pos - start).as_double() /
378  (end - start).as_double() /
379  (GetNumWaveTracks() + 1)
380  ))
381  {
382  cancel = true;
383  break;
384  }
385  }
386 
387  // apply last duck fade, if any
388  if (inDuckRegion)
389  {
390  double duckRegionEnd =
391  mControlTrack->LongSamplesToTime(end - curSamplesPause);
392  regions.push_back(AutoDuckRegion(
393  duckRegionStart - mOuterFadeDownLen,
394  duckRegionEnd + mOuterFadeUpLen));
395  }
396  }
397 
398  if (!cancel)
399  {
400  CopyInputTracks(); // Set up mOutputTracks.
401 
402  int trackNum = 0;
403 
404  for( auto iterTrack : mOutputTracks->Selected< WaveTrack >() )
405  {
406  for (size_t i = 0; i < regions.size(); i++)
407  {
408  const AutoDuckRegion& region = regions[i];
409  if (ApplyDuckFade(trackNum, iterTrack, region.t0, region.t1))
410  {
411  cancel = true;
412  break;
413  }
414  }
415 
416  if (cancel)
417  break;
418 
419  trackNum++;
420  }
421  }
422 
423  ReplaceProcessedTracks(!cancel);
424  return !cancel;
425 }

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

Here is the call graph for this function:

◆ SetAutomationParameters()

bool EffectAutoDuck::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Implements EffectClientInterface.

Definition at line 158 of file AutoDuck.cpp.

159 {
160  ReadAndVerifyDouble(DuckAmountDb);
161  ReadAndVerifyDouble(InnerFadeDownLen);
162  ReadAndVerifyDouble(InnerFadeUpLen);
163  ReadAndVerifyDouble(OuterFadeDownLen);
164  ReadAndVerifyDouble(OuterFadeUpLen);
165  ReadAndVerifyDouble(ThresholdDb);
166  ReadAndVerifyDouble(MaximumPause);
167 
168  mDuckAmountDb = DuckAmountDb;
169  mInnerFadeDownLen = InnerFadeDownLen;
170  mInnerFadeUpLen = InnerFadeUpLen;
171  mOuterFadeDownLen = OuterFadeDownLen;
172  mOuterFadeUpLen = OuterFadeUpLen;
173  mThresholdDb = ThresholdDb;
174  mMaximumPause = MaximumPause;
175 
176  return true;
177 }

References mDuckAmountDb, mInnerFadeDownLen, mInnerFadeUpLen, mMaximumPause, mOuterFadeDownLen, mOuterFadeUpLen, mThresholdDb, and ReadAndVerifyDouble.

◆ Startup()

bool EffectAutoDuck::Startup ( )
overridevirtual

Reimplemented from Effect.

Definition at line 181 of file AutoDuck.cpp.

182 {
183  wxString base = wxT("/Effects/AutoDuck/");
184 
185  // Migrate settings from 2.1.0 or before
186 
187  // Already migrated, so bail
188  if (gPrefs->Exists(base + wxT("Migrated")))
189  {
190  return true;
191  }
192 
193  // Load the old "current" settings
194  if (gPrefs->Exists(base))
195  {
196  gPrefs->Read(base + wxT("DuckAmountDb"), &mDuckAmountDb, DEF_DuckAmountDb);
197  gPrefs->Read(base + wxT("InnerFadeDownLen"), &mInnerFadeDownLen, DEF_InnerFadeDownLen);
198  gPrefs->Read(base + wxT("InnerFadeUpLen"), &mInnerFadeUpLen, DEF_InnerFadeUpLen);
199  gPrefs->Read(base + wxT("OuterFadeDownLen"), &mOuterFadeDownLen, DEF_OuterFadeDownLen);
200  gPrefs->Read(base + wxT("OuterFadeUpLen"), &mOuterFadeUpLen, DEF_OuterFadeUpLen);
201  gPrefs->Read(base + wxT("ThresholdDb"), &mThresholdDb, DEF_ThresholdDb);
202  gPrefs->Read(base + wxT("MaximumPause"), &mMaximumPause, DEF_MaximumPause);
203 
205 
206  // Do not migrate again
207  gPrefs->Write(base + wxT("Migrated"), true);
208  gPrefs->Flush();
209  }
210 
211  return true;
212 }

References FileConfig::Flush(), Effect::GetCurrentSettingsGroup(), gPrefs, mDuckAmountDb, mInnerFadeDownLen, mInnerFadeUpLen, mMaximumPause, mOuterFadeDownLen, mOuterFadeUpLen, mThresholdDb, and Effect::SaveUserPreset().

Here is the call graph for this function:

◆ TransferDataFromWindow()

bool EffectAutoDuck::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 521 of file AutoDuck.cpp.

522 {
523  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
524  {
525  return false;
526  }
527 
528  return true;
529 }

References Effect::mUIParent.

◆ TransferDataToWindow()

bool EffectAutoDuck::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 509 of file AutoDuck.cpp.

510 {
511  if (!mUIParent->TransferDataToWindow())
512  {
513  return false;
514  }
515 
516  mPanel->Refresh(false);
517 
518  return true;
519 }

References mPanel, and Effect::mUIParent.

Referenced by EffectAutoDuckPanel::OnMotion().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ EffectAutoDuckPanel

friend class EffectAutoDuckPanel
friend

Definition at line 86 of file AutoDuck.h.

Referenced by PopulateOrExchange().

Member Data Documentation

◆ mControlTrack

const WaveTrack* EffectAutoDuck::mControlTrack
private

Definition at line 73 of file AutoDuck.h.

Referenced by End(), Init(), and Process().

◆ mDuckAmountDb

double EffectAutoDuck::mDuckAmountDb
private

◆ mDuckAmountDbBox

wxTextCtrl* EffectAutoDuck::mDuckAmountDbBox
private

Definition at line 75 of file AutoDuck.h.

Referenced by EffectAutoDuckPanel::OnPaint(), and PopulateOrExchange().

◆ mInnerFadeDownLen

double EffectAutoDuck::mInnerFadeDownLen
private

◆ mInnerFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeDownLenBox
private

Definition at line 76 of file AutoDuck.h.

Referenced by EffectAutoDuckPanel::OnPaint(), and PopulateOrExchange().

◆ mInnerFadeUpLen

double EffectAutoDuck::mInnerFadeUpLen
private

◆ mInnerFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mInnerFadeUpLenBox
private

Definition at line 77 of file AutoDuck.h.

Referenced by EffectAutoDuckPanel::OnPaint(), and PopulateOrExchange().

◆ mMaximumPause

double EffectAutoDuck::mMaximumPause
private

◆ mMaximumPauseBox

wxTextCtrl* EffectAutoDuck::mMaximumPauseBox
private

Definition at line 81 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ mOuterFadeDownLen

double EffectAutoDuck::mOuterFadeDownLen
private

◆ mOuterFadeDownLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeDownLenBox
private

Definition at line 78 of file AutoDuck.h.

Referenced by EffectAutoDuckPanel::OnPaint(), and PopulateOrExchange().

◆ mOuterFadeUpLen

double EffectAutoDuck::mOuterFadeUpLen
private

◆ mOuterFadeUpLenBox

wxTextCtrl* EffectAutoDuck::mOuterFadeUpLenBox
private

Definition at line 79 of file AutoDuck.h.

Referenced by EffectAutoDuckPanel::OnPaint(), and PopulateOrExchange().

◆ mPanel

EffectAutoDuckPanel* EffectAutoDuck::mPanel
private

Definition at line 82 of file AutoDuck.h.

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

◆ mThresholdDb

double EffectAutoDuck::mThresholdDb
private

◆ mThresholdDbBox

wxTextCtrl* EffectAutoDuck::mThresholdDbBox
private

Definition at line 80 of file AutoDuck.h.

Referenced by PopulateOrExchange().

◆ Symbol

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

Definition at line 26 of file AutoDuck.h.

Referenced by GetSymbol().


The documentation for this class was generated from the following files:
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:59
DB_TO_LINEAR
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
Effect::SetLinearEffectFlag
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:2001
EffectAutoDuck::mMaximumPause
double mMaximumPause
Definition: AutoDuck.h:71
EffectAutoDuck::mInnerFadeUpLen
double mInnerFadeUpLen
Definition: AutoDuck.h:67
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
Effect::MessageBox
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
Definition: Effect.cpp:2482
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:2071
EffectAutoDuck::mThresholdDb
double mThresholdDb
Definition: AutoDuck.h:70
EffectAutoDuck::mOuterFadeDownLen
double mOuterFadeDownLen
Definition: AutoDuck.h:68
EffectAutoDuck::mOuterFadeUpLen
double mOuterFadeUpLen
Definition: AutoDuck.h:69
Effect::mT1
double mT1
Definition: Effect.h:467
EffectAutoDuck::mInnerFadeDownLenBox
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:76
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2459
XO
#define XO(s)
Definition: Internat.h:31
EffectAutoDuck::mOuterFadeUpLenBox
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:79
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
kRMSWindowSize
static const size_t kRMSWindowSize
Definition: AutoDuck.cpp:57
EffectAutoDuck::mInnerFadeDownLen
double mInnerFadeDownLen
Definition: AutoDuck.h:66
Effect::SaveUserPreset
bool SaveUserPreset(const RegistryPath &name) override
Definition: Effect.cpp:570
EffectAutoDuck::mInnerFadeUpLenBox
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:77
WaveTrack::Set
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2076
floatSample
@ floatSample
Definition: SampleFormat.h:34
EffectAutoDuck::EffectAutoDuckPanel
friend class EffectAutoDuckPanel
Definition: AutoDuck.h:86
EffectAutoDuck::ApplyDuckFade
bool ApplyDuckFade(int trackNum, WaveTrack *t, double t0, double t1)
Definition: AutoDuck.cpp:534
AutoDuckRegion::t0
double t0
Definition: AutoDuck.cpp:71
EffectAutoDuck::mDuckAmountDbBox
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:75
XXO
#define XXO(s)
Definition: Internat.h:44
Effect::inputTracks
const TrackList * inputTracks() const
Definition: Effect.h:463
Effect::mT0
double mT0
Definition: Effect.h:466
WaveTrack::LongSamplesToTime
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: WaveTrack.cpp:1870
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
EffectAutoDuck::mThresholdDbBox
wxTextCtrl * mThresholdDbBox
Definition: AutoDuck.h:80
ShuttleGuiBase::AddUnits
void AddUnits(const TranslatableString &Prompt, int wrapWidth=0)
Left aligned text string.
Definition: ShuttleGui.cpp:263
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2193
EffectAutoDuck::mPanel
EffectAutoDuckPanel * mPanel
Definition: AutoDuck.h:82
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:496
ShuttleGui::Validator
ShuttleGui & Validator(const Factory &f)
Definition: ShuttleGui.h:678
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:299
EffectAutoDuck::mDuckAmountDb
double mDuckAmountDb
Definition: AutoDuck.h:65
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:465
ReadAndVerifyDouble
#define ReadAndVerifyDouble(name)
Definition: Effect.h:633
Effect::GetCurrentSettingsGroup
RegistryPath GetCurrentSettingsGroup() override
Definition: Effect.cpp:866
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
AutoDuckRegion::t1
double t1
Definition: AutoDuck.cpp:72
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
WaveTrack::TimeToLongSamples
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1865
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
Effect::mUIParent
wxWindow * mUIParent
Definition: Effect.h:478
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
EffectAutoDuck::mControlTrack
const WaveTrack * mControlTrack
Definition: AutoDuck.h:73
EffectAutoDuck::mMaximumPauseBox
wxTextCtrl * mMaximumPauseBox
Definition: AutoDuck.h:81
Effect::TotalProgress
bool TotalProgress(double frac, const TranslatableString &={})
Definition: Effect.cpp:2017
Effect::GetNumWaveTracks
int GetNumWaveTracks()
Definition: Effect.h:345
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
kBufSize
static const size_t kBufSize
Definition: AutoDuck.cpp:56
safenew
#define safenew
Definition: MemoryX.h:10
limitSampleBufferSize
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
WaveTrack::GetFloats
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: WaveTrack.h:265
AutoDuckRegion
a struct that holds a start and end time.
Definition: AutoDuck.cpp:64
ArrayOf< float >
EffectAutoDuck::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: AutoDuck.h:26
EffectAutoDuck::mOuterFadeDownLenBox
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:78