Audacity  2.2.2
Public Member Functions | 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:
Effect

Public Member Functions

 EffectAutoDuck ()
 
virtual ~EffectAutoDuck ()
 
wxString GetSymbol () override
 
wxString GetDescription () override
 
wxString ManualPage () override
 
EffectType GetType () override
 
bool GetAutomationParameters (EffectAutomationParameters &parms) override
 
bool SetAutomationParameters (EffectAutomationParameters &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 ()
 
wxString GetPath () override
 
wxString GetSymbol () override
 
wxString GetName () override
 
wxString GetVendor () override
 
wxString GetVersion () override
 
wxString GetDescription () override
 
EffectType GetType () override
 
wxString 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
 
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, bool forceModal=false) override
 
bool GetAutomationParameters (EffectAutomationParameters &parms) override
 
bool SetAutomationParameters (EffectAutomationParameters &parms) override
 
bool LoadUserPreset (const wxString &name) override
 
bool SaveUserPreset (const wxString &name) override
 
wxArrayString GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (wxWindow *parent) override
 
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
 
wxString GetDurationFormat () override
 
virtual wxString GetSelectionFormat ()
 
void SetDuration (double duration) override
 
bool Apply () override
 
void Preview () override
 
wxDialog * CreateUI (wxWindow *parent, EffectUIClientInterface *client) override
 
wxString GetUserPresetsGroup (const wxString &name) override
 
wxString GetCurrentSettingsGroup () override
 
wxString GetFactoryDefaultsGroup () override
 
virtual wxString GetSavedStateGroup ()
 
bool HasSharedConfigGroup (const wxString &group) override
 
bool GetSharedConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const wxString &group) override
 
bool RemoveSharedConfig (const wxString &group, const wxString &key) override
 
bool HasPrivateConfigGroup (const wxString &group) override
 
bool GetPrivateConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const wxString &group) override
 
bool RemovePrivateConfig (const wxString &group, const wxString &key) override
 
virtual PluginID GetID ()
 
virtual bool Startup (EffectClientInterface *client)
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (const wxString &parms)
 
virtual wxArrayString GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual wxString GetPreset (wxWindow *parent, const wxString &parms)
 
virtual wxString HelpPage ()
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (wxWindow *parent, double projectRate, TrackList *list, TrackFactory *factory, SelectedRegion *selectedRegion, bool shouldPrompt=true)
 
bool Delegate (Effect &delegate, wxWindow *parent, SelectedRegion *selectedRegion, bool shouldPrompt)
 
bool RealtimeAddProcessor (int group, unsigned chans, float rate)
 
size_t RealtimeProcess (int group, unsigned chans, float **inbuf, float **outbuf, size_t numSamples)
 
bool IsRealtimeActive ()
 
virtual bool IsHidden ()
 
int MessageBox (const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
 

Private Member Functions

bool ApplyDuckFade (int trackNumber, 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 }
 
- Protected Member Functions inherited from Effect
virtual bool PromptUser (wxWindow *parent)
 
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)
 
bool TrackProgress (int whichTrack, double frac, const wxString &=wxEmptyString)
 
bool TrackGroupProgress (int whichGroup, double frac, const wxString &=wxEmptyString)
 
int GetNumWaveTracks ()
 
int GetNumWaveGroups ()
 
void GetSamples (const WaveTrack *track, sampleCount *start, sampleCount *len)
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing ()
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void CopyInputTracks ()
 
void CopyInputTracks (int trackType)
 
std::shared_ptr
< AddedAnalysisTrack
AddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
TrackAddToOutputTracks (std::unique_ptr< Track > &&t)
 
TrackListinputTracks () const
 
- Protected Attributes inherited from Effect
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
TrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
double mF0
 
double mF1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
sampleCount mSampleCnt
 
int mOutputTracksType
 

Detailed Description

Implements the Auto Ducking effect.

Definition at line 31 of file AutoDuck.h.

Constructor & Destructor Documentation

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 }
double mInnerFadeDownLen
Definition: AutoDuck.h:71
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1954
double mMaximumPause
Definition: AutoDuck.h:76
double mOuterFadeUpLen
Definition: AutoDuck.h:74
double mDuckAmountDb
Definition: AutoDuck.h:70
double mThresholdDb
Definition: AutoDuck.h:75
EffectAutoDuckPanel * mPanel
Definition: AutoDuck.h:87
const WaveTrack * mControlTrack
Definition: AutoDuck.h:78
double mOuterFadeDownLen
Definition: AutoDuck.h:73
double mInnerFadeUpLen
Definition: AutoDuck.h:72
EffectAutoDuck::~EffectAutoDuck ( )
virtual

Definition at line 105 of file AutoDuck.cpp.

106 {
107 }

Member Function Documentation

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

Definition at line 517 of file AutoDuck.cpp.

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

Referenced by Process().

519 {
520  bool cancel = false;
521 
522  auto start = t->TimeToLongSamples(t0);
523  auto end = t->TimeToLongSamples(t1);
524 
525  Floats buf{ kBufSize };
526  auto pos = start;
527 
528  auto fadeDownSamples = t->TimeToLongSamples(
530  if (fadeDownSamples < 1)
531  fadeDownSamples = 1;
532 
533  auto fadeUpSamples = t->TimeToLongSamples(
535  if (fadeUpSamples < 1)
536  fadeUpSamples = 1;
537 
538  float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
539  float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
540 
541  while (pos < end)
542  {
543  const auto len = limitSampleBufferSize( kBufSize, end - pos );
544 
545  t->Get((samplePtr)buf.get(), floatSample, pos, len);
546 
547  for (auto i = pos; i < pos + len; i++)
548  {
549  float gainDown = fadeDownStep * (i - start).as_float();
550  float gainUp = fadeUpStep * (end - i).as_float();
551 
552  float gain;
553  if (gainDown > gainUp)
554  gain = gainDown;
555  else
556  gain = gainUp;
557  if (gain < mDuckAmountDb)
558  gain = mDuckAmountDb;
559 
560  // i - pos is bounded by len:
561  buf[ ( i - pos ).as_size_t() ] *= DB_TO_LINEAR(gain);
562  }
563 
564  t->Set((samplePtr)buf.get(), floatSample, pos, len);
565 
566  pos += len;
567 
568  float curTime = t->LongSamplesToTime(pos);
569  float fractionFinished = (curTime - mT0) / (mT1 - mT0);
570  if (TotalProgress( (trackNumber + 1 + fractionFinished) /
571  (GetNumWaveTracks() + 1) ))
572  {
573  cancel = true;
574  break;
575  }
576  }
577 
578  return cancel;
579 }
double mT1
Definition: Effect.h:460
bool TotalProgress(double frac)
Definition: Effect.cpp:1970
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true) const
Definition: WaveTrack.cpp:1950
double mInnerFadeDownLen
Definition: AutoDuck.h:71
double mOuterFadeUpLen
Definition: AutoDuck.h:74
double mDuckAmountDb
Definition: AutoDuck.h:70
void Set(samplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2027
int GetNumWaveTracks()
Definition: Effect.h:343
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1822
double LongSamplesToTime(sampleCount pos) const
Convert correctly between an number of samples and an (absolute) time in seconds. ...
Definition: WaveTrack.cpp:1827
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
double mOuterFadeDownLen
Definition: AutoDuck.h:73
double mInnerFadeUpLen
Definition: AutoDuck.h:72
double mT0
Definition: Effect.h:459
static const size_t kBufSize
Definition: AutoDuck.cpp:56
void EffectAutoDuck::End ( )
overridevirtual

Reimplemented from Effect.

Definition at line 259 of file AutoDuck.cpp.

References mControlTrack.

260 {
261  mControlTrack = NULL;
262 }
const WaveTrack * mControlTrack
Definition: AutoDuck.h:78
bool EffectAutoDuck::GetAutomationParameters ( EffectAutomationParameters &  parms)
override

Definition at line 135 of file AutoDuck.cpp.

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

136 {
137  parms.Write(KEY_DuckAmountDb, mDuckAmountDb);
138  parms.Write(KEY_InnerFadeDownLen, mInnerFadeDownLen);
139  parms.Write(KEY_InnerFadeUpLen, mInnerFadeUpLen);
140  parms.Write(KEY_OuterFadeDownLen, mOuterFadeDownLen);
141  parms.Write(KEY_OuterFadeUpLen, mOuterFadeUpLen);
142  parms.Write(KEY_ThresholdDb, mThresholdDb);
143  parms.Write(KEY_MaximumPause, mMaximumPause);
144 
145  return true;
146 }
double mInnerFadeDownLen
Definition: AutoDuck.h:71
double mMaximumPause
Definition: AutoDuck.h:76
double mOuterFadeUpLen
Definition: AutoDuck.h:74
double mDuckAmountDb
Definition: AutoDuck.h:70
double mThresholdDb
Definition: AutoDuck.h:75
double mOuterFadeDownLen
Definition: AutoDuck.h:73
double mInnerFadeUpLen
Definition: AutoDuck.h:72
wxString EffectAutoDuck::GetDescription ( )
override

Definition at line 116 of file AutoDuck.cpp.

References _().

117 {
118  return _("Reduces (ducks) the volume of one or more tracks whenever the volume of a specified \"control\" track reaches a particular level");
119 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
wxString EffectAutoDuck::GetSymbol ( )
override

Definition at line 111 of file AutoDuck.cpp.

References AUTODUCK_PLUGIN_SYMBOL.

112 {
113  return AUTODUCK_PLUGIN_SYMBOL;
114 }
#define AUTODUCK_PLUGIN_SYMBOL
Definition: AutoDuck.h:29
EffectType EffectAutoDuck::GetType ( )
override

Definition at line 128 of file AutoDuck.cpp.

129 {
130  return EffectTypeProcess;
131 }
bool EffectAutoDuck::Init ( )
overridevirtual

Reimplemented from Effect.

Definition at line 204 of file AutoDuck.cpp.

References _(), TrackListIterator::First(), Track::GetKind(), Track::GetSelected(), Effect::inputTracks(), mControlTrack, Effect::MessageBox(), TrackListIterator::Next(), and Track::Wave.

205 {
206  mControlTrack = NULL;
207 
209  Track *t = iter.First();
210 
211  bool lastWasSelectedWaveTrack = false;
212  const WaveTrack *controlTrackCandidate = NULL;
213 
214  while(t)
215  {
216  if (lastWasSelectedWaveTrack && !t->GetSelected() &&
217  t->GetKind() == Track::Wave)
218  {
219  // This could be the control track, so remember it
220  controlTrackCandidate = (WaveTrack*)t;
221  }
222 
223  lastWasSelectedWaveTrack = false;
224 
225  if (t->GetSelected())
226  {
227  if (t->GetKind() == Track::Wave)
228  {
229  lastWasSelectedWaveTrack = true;
230  }
231  else
232  {
234  _("You selected a track which does not contain audio. AutoDuck can only process audio tracks."),
235  /* i18n-hint: Auto duck is the name of an effect that 'ducks' (reduces the volume)
236  * of the audio automatically when there is sound on another track. Not as
237  * in 'Donald-Duck'!*/
238  wxICON_ERROR);
239  return false;
240  }
241  }
242 
243  t = iter.Next();
244  }
245 
246  if (!controlTrackCandidate)
247  {
249  _("Auto Duck needs a control track which must be placed below the selected track(s)."),
250  wxICON_ERROR);
251  return false;
252  }
253 
254  mControlTrack = controlTrackCandidate;
255 
256  return true;
257 }
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2655
bool GetSelected() const
Definition: Track.h:217
TrackList * inputTracks() const
Definition: Effect.h:457
virtual int GetKind() const
Definition: Track.h:267
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:67
An iterator for a TrackList.
Definition: Track.h:339
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
const WaveTrack * mControlTrack
Definition: AutoDuck.h:78
wxString EffectAutoDuck::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 121 of file AutoDuck.cpp.

122 {
123  return wxT("Auto_Duck");
124 }
void EffectAutoDuck::OnValueChanged ( wxCommandEvent &  evt)
private

Definition at line 581 of file AutoDuck.cpp.

References mPanel.

582 {
583  mPanel->Refresh(false);
584 }
EffectAutoDuckPanel * mPanel
Definition: AutoDuck.h:87
void EffectAutoDuck::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 424 of file AutoDuck.cpp.

References _(), ShuttleGui::AddSpace(), ShuttleGuiBase::AddTextBox(), 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(), and ShuttleGuiBase::StartVerticalLay().

425 {
426  S.SetBorder(5);
427  S.StartVerticalLay(true);
428  {
429  S.AddSpace(0, 5);
430 
432  S.AddWindow(mPanel);
433 
434  S.AddSpace(0, 5);
435 
436  S.StartMultiColumn(6, wxCENTER);
437  {
438  FloatingPointValidator<double> vldDuckAmountDb(1, &mDuckAmountDb, NUM_VAL_NO_TRAILING_ZEROES);
439  vldDuckAmountDb.SetRange(MIN_DuckAmountDb, MAX_DuckAmountDb);
440  mDuckAmountDbBox = S.AddTextBox(_("Duck amount:"), wxT(""), 10);
441  mDuckAmountDbBox->SetValidator(vldDuckAmountDb);
442  S.AddUnits(_("dB"));
443 
444  FloatingPointValidator<double> vldMaximumPause(2, &mMaximumPause, NUM_VAL_NO_TRAILING_ZEROES);
445  vldMaximumPause.SetRange(MIN_MaximumPause, MAX_MaximumPause);
446  mMaximumPauseBox = S.AddTextBox(_("Maximum pause:"), wxT(""), 10);
447  mMaximumPauseBox->SetValidator(vldMaximumPause);
448  S.AddUnits(_("seconds"));
449 
450  FloatingPointValidator<double> vldOuterFadeDownLen(2, &mOuterFadeDownLen, NUM_VAL_NO_TRAILING_ZEROES);
451  vldOuterFadeDownLen.SetRange(MIN_OuterFadeDownLen, MAX_OuterFadeDownLen);
452  mOuterFadeDownLenBox = S.AddTextBox(_("Outer fade down length:"), wxT(""), 10);
453  mOuterFadeDownLenBox->SetValidator(vldOuterFadeDownLen);
454  S.AddUnits(_("seconds"));
455 
456  FloatingPointValidator<double> vldOuterFadeUpLen(2, &mOuterFadeUpLen, NUM_VAL_NO_TRAILING_ZEROES);
457  vldOuterFadeUpLen.SetRange(MIN_OuterFadeUpLen, MAX_OuterFadeUpLen);
458  mOuterFadeUpLenBox = S.AddTextBox(_("Outer fade up length:"), wxT(""), 10);
459  mOuterFadeUpLenBox->SetValidator(vldOuterFadeUpLen);
460  S.AddUnits(_("seconds"));
461 
462  FloatingPointValidator<double> vldInnerFadeDownLen(2, &mInnerFadeDownLen, NUM_VAL_NO_TRAILING_ZEROES);
463  vldInnerFadeDownLen.SetRange(MIN_InnerFadeDownLen, MAX_InnerFadeDownLen);
464  mInnerFadeDownLenBox = S.AddTextBox(_("Inner fade down length:"), wxT(""), 10);
465  mInnerFadeDownLenBox->SetValidator(vldInnerFadeDownLen);
466  S.AddUnits(_("seconds"));
467 
468  FloatingPointValidator<double> vldInnerFadeUpLen(2, &mInnerFadeUpLen, NUM_VAL_NO_TRAILING_ZEROES);
469  vldInnerFadeUpLen.SetRange(MIN_InnerFadeUpLen, MAX_InnerFadeUpLen);
470  mInnerFadeUpLenBox = S.AddTextBox(_("Inner fade up length:"), wxT(""), 10);
471  mInnerFadeUpLenBox->SetValidator(vldInnerFadeUpLen);
472  S.AddUnits(_("seconds"));
473  }
474  S.EndMultiColumn();
475 
476  S.StartMultiColumn(3, wxCENTER);
477  {
478  FloatingPointValidator<double> vldThresholdDb(2, &mThresholdDb, NUM_VAL_NO_TRAILING_ZEROES);
479  vldThresholdDb.SetRange(MIN_ThresholdDb, MAX_ThresholdDb);
480  mThresholdDbBox = S.AddTextBox(_("Threshold:"), wxT(""), 10);
481  mThresholdDbBox->SetValidator(vldThresholdDb);
482  S.AddUnits(_("dB"));
483  }
484  S.EndMultiColumn();
485 
486  }
487  S.EndVerticalLay();
488 
489  return;
490 }
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:82
double mInnerFadeDownLen
Definition: AutoDuck.h:71
wxWindow * AddWindow(wxWindow *pWindow, int Flags=wxALIGN_CENTRE|wxALL)
Definition: ShuttleGui.cpp:257
void EndMultiColumn()
wxTextCtrl * mThresholdDbBox
Definition: AutoDuck.h:85
double mMaximumPause
Definition: AutoDuck.h:76
double mOuterFadeUpLen
Definition: AutoDuck.h:74
double mDuckAmountDb
Definition: AutoDuck.h:70
#define safenew
Definition: Audacity.h:223
void AddUnits(const wxString &Prompt)
Left aligned text string.
Definition: ShuttleGui.cpp:229
double mThresholdDb
Definition: AutoDuck.h:75
void EndVerticalLay()
Definition: ShuttleGui.cpp:991
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:493
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:81
wxWindow * GetParent()
Definition: ShuttleGui.h:259
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:84
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
friend class EffectAutoDuckPanel
Definition: AutoDuck.h:91
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:80
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:83
EffectAutoDuckPanel * mPanel
Definition: AutoDuck.h:87
wxSizerItem * AddSpace(int width, int height)
wxTextCtrl * mMaximumPauseBox
Definition: AutoDuck.h:86
void SetBorder(int Border)
Definition: ShuttleGui.h:251
double mOuterFadeDownLen
Definition: AutoDuck.h:73
double mInnerFadeUpLen
Definition: AutoDuck.h:72
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:982
bool EffectAutoDuck::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 264 of file AutoDuck.cpp.

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

265 {
266  if (GetNumWaveTracks() == 0 || !mControlTrack)
267  return false;
268 
269  bool cancel = false;
270 
271  auto start =
273  auto end =
275 
276  if (end <= start)
277  return false;
278 
279  // the minimum number of samples we have to wait until the maximum
280  // pause has been exceeded
281  double maxPause = mMaximumPause;
282 
283  // We don't fade in until we have time enough to actually fade out again
284  if (maxPause < mOuterFadeDownLen + mOuterFadeUpLen)
285  maxPause = mOuterFadeDownLen + mOuterFadeUpLen;
286 
287  auto minSamplesPause =
288  mControlTrack->TimeToLongSamples(maxPause);
289 
290  double threshold = DB_TO_LINEAR(mThresholdDb);
291 
292  // adjust the threshold so we can compare it to the rmsSum value
293  threshold = threshold * threshold * kRMSWindowSize;
294 
295  int rmsPos = 0;
296  float rmsSum = 0;
297  // to make the progress bar appear more natural, we first look for all
298  // duck regions and apply them all at once afterwards
299  AutoDuckRegionArray regions;
300  bool inDuckRegion = false;
301  {
302  Floats rmsWindow{ kRMSWindowSize, true };
303 
304  Floats buf{ kBufSize };
305 
306  // initialize the following two variables to prevent compiler warning
307  double duckRegionStart = 0;
308  sampleCount curSamplesPause = 0;
309 
310  auto pos = start;
311 
312  while (pos < end)
313  {
314  const auto len = limitSampleBufferSize( kBufSize, end - pos );
315 
316  mControlTrack->Get((samplePtr)buf.get(), floatSample, pos, len);
317 
318  for (auto i = pos; i < pos + len; i++)
319  {
320  rmsSum -= rmsWindow[rmsPos];
321  // i - pos is bounded by len:
322  auto index = ( i - pos ).as_size_t();
323  rmsWindow[rmsPos] = buf[ index ] * buf[ index ];
324  rmsSum += rmsWindow[rmsPos];
325  rmsPos = (rmsPos + 1) % kRMSWindowSize;
326 
327  bool thresholdExceeded = rmsSum > threshold;
328 
329  if (thresholdExceeded)
330  {
331  // everytime the threshold is exceeded, reset our count for
332  // the number of pause samples
333  curSamplesPause = 0;
334 
335  if (!inDuckRegion)
336  {
337  // the threshold has been exceeded for the first time, so
338  // let the duck region begin here
339  inDuckRegion = true;
340  duckRegionStart = mControlTrack->LongSamplesToTime(i);
341  }
342  }
343 
344  if (!thresholdExceeded && inDuckRegion)
345  {
346  // the threshold has not been exceeded and we are in a duck
347  // region, but only fade in if the maximum pause has been
348  // exceeded
349  curSamplesPause += 1;
350 
351  if (curSamplesPause >= minSamplesPause)
352  {
353  // do the actual duck fade and reset all values
354  double duckRegionEnd =
355  mControlTrack->LongSamplesToTime(i - curSamplesPause);
356 
357  regions.Add(AutoDuckRegion(
358  duckRegionStart - mOuterFadeDownLen,
359  duckRegionEnd + mOuterFadeUpLen));
360 
361  inDuckRegion = false;
362  }
363  }
364  }
365 
366  pos += len;
367 
368  if (TotalProgress(
369  (pos - start).as_double() /
370  (end - start).as_double() /
371  (GetNumWaveTracks() + 1)
372  ))
373  {
374  cancel = true;
375  break;
376  }
377  }
378 
379  // apply last duck fade, if any
380  if (inDuckRegion)
381  {
382  double duckRegionEnd =
383  mControlTrack->LongSamplesToTime(end - curSamplesPause);
384  regions.Add(AutoDuckRegion(
385  duckRegionStart - mOuterFadeDownLen,
386  duckRegionEnd + mOuterFadeUpLen));
387  }
388  }
389 
390  if (!cancel)
391  {
392  CopyInputTracks(); // Set up mOutputTracks.
394  Track *iterTrack = iter.First();
395 
396  int trackNumber = 0;
397 
398  while (iterTrack)
399  {
400  WaveTrack* t = (WaveTrack*)iterTrack;
401 
402  for (size_t i = 0; i < regions.GetCount(); i++)
403  {
404  const AutoDuckRegion& region = regions[i];
405  if (ApplyDuckFade(trackNumber, t, region.t0, region.t1))
406  {
407  cancel = true;
408  break;
409  }
410  }
411 
412  if (cancel)
413  break;
414 
415  iterTrack = iter.Next();
416  trackNumber++;
417  }
418  }
419 
420  ReplaceProcessedTracks(!cancel);
421  return !cancel;
422 }
double mT1
Definition: Effect.h:460
bool TotalProgress(double frac)
Definition: Effect.cpp:1970
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true) const
Definition: WaveTrack.cpp:1950
void CopyInputTracks()
Definition: Effect.cpp:2029
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2160
static const size_t kRMSWindowSize
Definition: AutoDuck.cpp:57
double mMaximumPause
Definition: AutoDuck.h:76
double mOuterFadeUpLen
Definition: AutoDuck.h:74
double mThresholdDb
Definition: AutoDuck.h:75
bool ApplyDuckFade(int trackNumber, WaveTrack *t, double t0, double t1)
Definition: AutoDuck.cpp:517
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:67
a struct that holds a start and end time.
Definition: AutoDuck.cpp:63
int GetNumWaveTracks()
Definition: Effect.h:343
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1822
double LongSamplesToTime(sampleCount pos) const
Convert correctly between an number of samples and an (absolute) time in seconds. ...
Definition: WaveTrack.cpp:1827
const WaveTrack * mControlTrack
Definition: AutoDuck.h:78
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
double mOuterFadeDownLen
Definition: AutoDuck.h:73
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:458
double mT0
Definition: Effect.h:459
static const size_t kBufSize
Definition: AutoDuck.cpp:56
bool EffectAutoDuck::SetAutomationParameters ( EffectAutomationParameters &  parms)
override

Definition at line 148 of file AutoDuck.cpp.

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

149 {
150  ReadAndVerifyDouble(DuckAmountDb);
151  ReadAndVerifyDouble(InnerFadeDownLen);
152  ReadAndVerifyDouble(InnerFadeUpLen);
153  ReadAndVerifyDouble(OuterFadeDownLen);
154  ReadAndVerifyDouble(OuterFadeUpLen);
155  ReadAndVerifyDouble(ThresholdDb);
156  ReadAndVerifyDouble(MaximumPause);
157 
158  mDuckAmountDb = DuckAmountDb;
159  mInnerFadeDownLen = InnerFadeDownLen;
160  mInnerFadeUpLen = InnerFadeUpLen;
161  mOuterFadeDownLen = OuterFadeDownLen;
162  mOuterFadeUpLen = OuterFadeUpLen;
163  mThresholdDb = ThresholdDb;
164  mMaximumPause = MaximumPause;
165 
166  return true;
167 }
double mInnerFadeDownLen
Definition: AutoDuck.h:71
double mMaximumPause
Definition: AutoDuck.h:76
double mOuterFadeUpLen
Definition: AutoDuck.h:74
double mDuckAmountDb
Definition: AutoDuck.h:70
double mThresholdDb
Definition: AutoDuck.h:75
#define ReadAndVerifyDouble(name)
Definition: Effect.h:787
double mOuterFadeDownLen
Definition: AutoDuck.h:73
double mInnerFadeUpLen
Definition: AutoDuck.h:72
bool EffectAutoDuck::Startup ( )
overridevirtual

Reimplemented from Effect.

Definition at line 171 of file AutoDuck.cpp.

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

172 {
173  wxString base = wxT("/Effects/AutoDuck/");
174 
175  // Migrate settings from 2.1.0 or before
176 
177  // Already migrated, so bail
178  if (gPrefs->Exists(base + wxT("Migrated")))
179  {
180  return true;
181  }
182 
183  // Load the old "current" settings
184  if (gPrefs->Exists(base))
185  {
186  gPrefs->Read(base + wxT("DuckAmountDb"), &mDuckAmountDb, DEF_DuckAmountDb);
187  gPrefs->Read(base + wxT("InnerFadeDownLen"), &mInnerFadeDownLen, DEF_InnerFadeDownLen);
188  gPrefs->Read(base + wxT("InnerFadeUpLen"), &mInnerFadeUpLen, DEF_InnerFadeUpLen);
189  gPrefs->Read(base + wxT("OuterFadeDownLen"), &mOuterFadeDownLen, DEF_OuterFadeDownLen);
190  gPrefs->Read(base + wxT("OuterFadeUpLen"), &mOuterFadeUpLen, DEF_OuterFadeUpLen);
191  gPrefs->Read(base + wxT("ThresholdDb"), &mThresholdDb, DEF_ThresholdDb);
192  gPrefs->Read(base + wxT("MaximumPause"), &mMaximumPause, DEF_MaximumPause);
193 
195 
196  // Do not migrate again
197  gPrefs->Write(base + wxT("Migrated"), true);
198  gPrefs->Flush();
199  }
200 
201  return true;
202 }
bool SaveUserPreset(const wxString &name) override
Definition: Effect.cpp:615
wxString GetCurrentSettingsGroup() override
Definition: Effect.cpp:814
double mInnerFadeDownLen
Definition: AutoDuck.h:71
double mMaximumPause
Definition: AutoDuck.h:76
double mOuterFadeUpLen
Definition: AutoDuck.h:74
double mDuckAmountDb
Definition: AutoDuck.h:70
double mThresholdDb
Definition: AutoDuck.h:75
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
double mOuterFadeDownLen
Definition: AutoDuck.h:73
double mInnerFadeUpLen
Definition: AutoDuck.h:72
bool EffectAutoDuck::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 504 of file AutoDuck.cpp.

References Effect::mUIParent.

505 {
506  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
507  {
508  return false;
509  }
510 
511  return true;
512 }
wxWindow * mUIParent
Definition: Effect.h:471
bool EffectAutoDuck::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 492 of file AutoDuck.cpp.

References mPanel, and Effect::mUIParent.

Referenced by EffectAutoDuckPanel::OnMotion().

493 {
494  if (!mUIParent->TransferDataToWindow())
495  {
496  return false;
497  }
498 
499  mPanel->Refresh(false);
500 
501  return true;
502 }
wxWindow * mUIParent
Definition: Effect.h:471
EffectAutoDuckPanel * mPanel
Definition: AutoDuck.h:87

Friends And Related Function Documentation

friend class EffectAutoDuckPanel
friend

Definition at line 91 of file AutoDuck.h.

Referenced by PopulateOrExchange().

Member Data Documentation

const WaveTrack* EffectAutoDuck::mControlTrack
private

Definition at line 78 of file AutoDuck.h.

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

double EffectAutoDuck::mDuckAmountDb
private
wxTextCtrl* EffectAutoDuck::mDuckAmountDbBox
private

Definition at line 80 of file AutoDuck.h.

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

double EffectAutoDuck::mInnerFadeDownLen
private
wxTextCtrl* EffectAutoDuck::mInnerFadeDownLenBox
private

Definition at line 81 of file AutoDuck.h.

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

double EffectAutoDuck::mInnerFadeUpLen
private
wxTextCtrl* EffectAutoDuck::mInnerFadeUpLenBox
private

Definition at line 82 of file AutoDuck.h.

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

double EffectAutoDuck::mMaximumPause
private
wxTextCtrl* EffectAutoDuck::mMaximumPauseBox
private

Definition at line 86 of file AutoDuck.h.

Referenced by PopulateOrExchange().

double EffectAutoDuck::mOuterFadeDownLen
private
wxTextCtrl* EffectAutoDuck::mOuterFadeDownLenBox
private

Definition at line 83 of file AutoDuck.h.

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

double EffectAutoDuck::mOuterFadeUpLen
private
wxTextCtrl* EffectAutoDuck::mOuterFadeUpLenBox
private

Definition at line 84 of file AutoDuck.h.

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

EffectAutoDuckPanel* EffectAutoDuck::mPanel
private

Definition at line 87 of file AutoDuck.h.

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

double EffectAutoDuck::mThresholdDb
private
wxTextCtrl* EffectAutoDuck::mThresholdDbBox
private

Definition at line 85 of file AutoDuck.h.

Referenced by PopulateOrExchange().


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