Audacity  2.2.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
EffectClickRemoval Class Referencefinal

An Effect for removing clicks. More...

#include <ClickRemoval.h>

Inheritance diagram for EffectClickRemoval:
Effect EffectClientInterface EffectUIClientInterface EffectHostInterface EffectDefinitionInterface ConfigClientInterface IdentInterface ParamsInterface

Public Member Functions

 EffectClickRemoval ()
 
virtual ~EffectClickRemoval ()
 
IdentInterfaceSymbol GetSymbol () override
 
wxString GetDescription () override
 
wxString ManualPage () override
 
EffectType GetType () override
 
bool DefineParams (ShuttleParams &S) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool CheckWhetherSkipEffect () override
 
bool Startup () 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
 
IdentInterfaceSymbol GetSymbol () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () override
 
wxString GetDescription () override
 
EffectType GetType () override
 
IdentInterfaceSymbol GetFamilyId () 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 (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &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
 
NumericFormatId GetDurationFormat () override
 
virtual NumericFormatId 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, 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{})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
- Public Member Functions inherited from IdentInterface
virtual ~IdentInterface ()
 
const wxString & GetTranslatedName ()
 
- Public Member Functions inherited from ParamsInterface
virtual ~ParamsInterface ()
 
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 ()
 

Private Member Functions

bool ProcessOne (int count, WaveTrack *track, sampleCount start, sampleCount len)
 
bool RemoveClicks (size_t len, float *buffer)
 
void OnWidthText (wxCommandEvent &evt)
 
void OnThreshText (wxCommandEvent &evt)
 
void OnWidthSlider (wxCommandEvent &evt)
 
void OnThreshSlider (wxCommandEvent &evt)
 

Private Attributes

EnvelopemEnvelope
 
bool mbDidSomething
 
size_t windowSize
 
int mThresholdLevel
 
int mClickWidth
 
int sep
 
wxSlider * mWidthS
 
wxSlider * mThreshS
 
wxTextCtrl * mWidthT
 
wxTextCtrl * mThreshT
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Protected Member Functions inherited from Effect
virtual bool Init ()
 
virtual bool PromptUser (wxWindow *parent)
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual int GetPass ()
 
virtual void End ()
 
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
 
SelectedRegionmpSelectedRegion {}
 
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

An Effect for removing clicks.

Clicks are identified as small regions of high amplitude compared to the surrounding chunk of sound. Anything sufficiently tall compared to a large (2048 sample) window around it, and sufficiently narrow, is considered to be a click.

The structure was largely stolen from Domonic Mazzoni's NoiseRemoval module, and reworked for the NEW effect.

This file is intended to become part of Audacity. You may modify and/or distribute it under the same terms as Audacity itself.

Definition at line 31 of file ClickRemoval.h.

Constructor & Destructor Documentation

EffectClickRemoval::EffectClickRemoval ( )

Definition at line 61 of file ClickRemoval.cpp.

62 {
63  mThresholdLevel = DEF_Threshold;
64  mClickWidth = DEF_Width;
65 
66  SetLinearEffectFlag(false);
67 
68  windowSize = 8192;
69  sep = 2049;
70 }
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1961
EffectClickRemoval::~EffectClickRemoval ( )
virtual

Definition at line 72 of file ClickRemoval.cpp.

73 {
74 }

Member Function Documentation

bool EffectClickRemoval::CheckWhetherSkipEffect ( )
overridevirtual

Reimplemented from Effect.

Definition at line 128 of file ClickRemoval.cpp.

References mClickWidth, and mThresholdLevel.

129 {
130  return ((mClickWidth == 0) || (mThresholdLevel == 0));
131 }
bool EffectClickRemoval::DefineParams ( ShuttleParams S)
override

Definition at line 101 of file ClickRemoval.cpp.

References mClickWidth, and mThresholdLevel.

101  {
102  S.SHUTTLE_PARAM( mThresholdLevel, Threshold );
103  S.SHUTTLE_PARAM( mClickWidth, Width );
104  return true;
105 }
bool EffectClickRemoval::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Implements EffectClientInterface.

Definition at line 107 of file ClickRemoval.cpp.

References mClickWidth, and mThresholdLevel.

108 {
109  parms.Write(KEY_Threshold, mThresholdLevel);
110  parms.Write(KEY_Width, mClickWidth);
111 
112  return true;
113 }
wxString EffectClickRemoval::GetDescription ( )
overridevirtual

Implements IdentInterface.

Definition at line 83 of file ClickRemoval.cpp.

References _().

84 {
85  return _("Click Removal is designed to remove clicks on audio tracks");
86 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
IdentInterfaceSymbol EffectClickRemoval::GetSymbol ( )
overridevirtual

Implements IdentInterface.

Definition at line 78 of file ClickRemoval.cpp.

References CLICKREMOVAL_PLUGIN_SYMBOL.

79 {
81 }
#define CLICKREMOVAL_PLUGIN_SYMBOL
Definition: ClickRemoval.h:29
EffectType EffectClickRemoval::GetType ( )
overridevirtual

Implements EffectDefinitionInterface.

Definition at line 95 of file ClickRemoval.cpp.

References EffectTypeProcess.

96 {
97  return EffectTypeProcess;
98 }
wxString EffectClickRemoval::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 88 of file ClickRemoval.cpp.

89 {
90  return wxT("Click_Removal");
91 }
void EffectClickRemoval::OnThreshSlider ( wxCommandEvent &  evt)
private

Definition at line 412 of file ClickRemoval.cpp.

References mThreshS, and mThreshT.

413 {
414  mThreshS->GetValidator()->TransferFromWindow();
415  mThreshT->GetValidator()->TransferToWindow();
416 }
wxSlider * mThreshS
Definition: ClickRemoval.h:83
wxTextCtrl * mThreshT
Definition: ClickRemoval.h:85
void EffectClickRemoval::OnThreshText ( wxCommandEvent &  evt)
private

Definition at line 400 of file ClickRemoval.cpp.

References mThreshS, and mThreshT.

401 {
402  mThreshT->GetValidator()->TransferFromWindow();
403  mThreshS->GetValidator()->TransferToWindow();
404 }
wxSlider * mThreshS
Definition: ClickRemoval.h:83
wxTextCtrl * mThreshT
Definition: ClickRemoval.h:85
void EffectClickRemoval::OnWidthSlider ( wxCommandEvent &  evt)
private

Definition at line 406 of file ClickRemoval.cpp.

References mWidthS, and mWidthT.

407 {
408  mWidthS->GetValidator()->TransferFromWindow();
409  mWidthT->GetValidator()->TransferToWindow();
410 }
wxSlider * mWidthS
Definition: ClickRemoval.h:82
wxTextCtrl * mWidthT
Definition: ClickRemoval.h:84
void EffectClickRemoval::OnWidthText ( wxCommandEvent &  evt)
private

Definition at line 394 of file ClickRemoval.cpp.

References mWidthS, and mWidthT.

395 {
396  mWidthT->GetValidator()->TransferFromWindow();
397  mWidthS->GetValidator()->TransferToWindow();
398 }
wxSlider * mWidthS
Definition: ClickRemoval.h:82
wxTextCtrl * mWidthT
Definition: ClickRemoval.h:84
void EffectClickRemoval::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 333 of file ClickRemoval.cpp.

References _(), ShuttleGuiBase::AddSlider(), ShuttleGui::AddSpace(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::EndMultiColumn(), ShuttleGui::Id(), ID_Thresh, ID_Width, mClickWidth, mThresholdLevel, mThreshS, mThreshT, mWidthS, mWidthT, ShuttleGuiBase::SetBorder(), ShuttleGuiBase::SetStretchyCol(), ShuttleGuiBase::SetStyle(), and ShuttleGuiBase::StartMultiColumn().

334 {
335  S.AddSpace(0, 5);
336  S.SetBorder(10);
337 
338  S.StartMultiColumn(3, wxEXPAND);
339  S.SetStretchyCol(2);
340  {
341  // Threshold
342  IntegerValidator<int> vldThresh(&mThresholdLevel);
343  vldThresh.SetRange(MIN_Threshold, MAX_Threshold);
344  mThreshT = S.Id(ID_Thresh).AddTextBox(_("Threshold (lower is more sensitive):"),
345  wxT(""),
346  10);
347  mThreshT->SetValidator(vldThresh);
348 
349  S.SetStyle(wxSL_HORIZONTAL);
350  mThreshS = S.Id(ID_Thresh).AddSlider( {}, mThresholdLevel, MAX_Threshold, MIN_Threshold);
351  mThreshS->SetName(_("Threshold"));
352  mThreshS->SetValidator(wxGenericValidator(&mThresholdLevel));
353  mThreshS->SetMinSize(wxSize(150, -1));
354 
355  // Click width
356  IntegerValidator<int> vldWidth(&mClickWidth);
357  vldWidth.SetRange(MIN_Width, MAX_Width);
358  mWidthT = S.Id(ID_Width).AddTextBox(_("Max Spike Width (higher is more sensitive):"),
359  wxT(""),
360  10);
361  mWidthT->SetValidator(vldWidth);
362 
363  S.SetStyle(wxSL_HORIZONTAL);
364  mWidthS = S.Id(ID_Width).AddSlider( {}, mClickWidth, MAX_Width, MIN_Width);
365  mWidthS->SetName(_("Max Spike Width"));
366  mWidthS->SetValidator(wxGenericValidator(&mClickWidth));
367  mWidthS->SetMinSize(wxSize(150, -1));
368  }
369  S.EndMultiColumn();
370 
371  return;
372 }
wxSlider * mWidthS
Definition: ClickRemoval.h:82
void EndMultiColumn()
wxSlider * mThreshS
Definition: ClickRemoval.h:83
wxTextCtrl * mWidthT
Definition: ClickRemoval.h:84
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
ShuttleGui & Id(int id)
void SetStyle(int Style)
Definition: ShuttleGui.h:287
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxTextCtrl * mThreshT
Definition: ClickRemoval.h:85
wxSizerItem * AddSpace(int width, int height)
void SetBorder(int Border)
Definition: ShuttleGui.h:286
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:203
wxSlider * AddSlider(const wxString &Prompt, int pos, int Max, int Min=0)
Definition: ShuttleGui.cpp:497
bool EffectClickRemoval::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 169 of file ClickRemoval.cpp.

References _(), Effect::CopyInputTracks(), WaveTrack::GetStartTime(), mbDidSomething, Effect::MessageBox(), Effect::mOutputTracks, Effect::mT0, Effect::mT1, ProcessOne(), Effect::ReplaceProcessedTracks(), and Track::Wave.

170 {
171  this->CopyInputTracks(); // Set up mOutputTracks.
172  bool bGoodResult = true;
173  mbDidSomething = false;
174 
176  WaveTrack *track = (WaveTrack *) iter.First();
177  int count = 0;
178  while (track) {
179  double trackStart = track->GetStartTime();
180  double trackEnd = track->GetEndTime();
181  double t0 = mT0 < trackStart? trackStart: mT0;
182  double t1 = mT1 > trackEnd? trackEnd: mT1;
183 
184  if (t1 > t0) {
185  auto start = track->TimeToLongSamples(t0);
186  auto end = track->TimeToLongSamples(t1);
187  auto len = end - start;
188 
189  if (!ProcessOne(count, track, start, len))
190  {
191  bGoodResult = false;
192  break;
193  }
194  }
195 
196  track = (WaveTrack *) iter.Next();
197  count++;
198  }
199  if (bGoodResult && !mbDidSomething) // Processing successful, but ineffective.
201  _("Algorithm not effective on this audio. Nothing changed."),
202  wxOK | wxICON_ERROR);
203 
204  this->ReplaceProcessedTracks(bGoodResult && mbDidSomething);
205  return bGoodResult && mbDidSomething;
206 }
double mT1
Definition: Effect.h:461
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
void CopyInputTracks()
Definition: Effect.cpp:2036
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
double GetStartTime() const override
Get the time at which the first clip in the track starts.
Definition: WaveTrack.cpp:1853
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
bool ProcessOne(int count, WaveTrack *track, sampleCount start, sampleCount len)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
double mT0
Definition: Effect.h:460
bool EffectClickRemoval::ProcessOne ( int  count,
WaveTrack track,
sampleCount  start,
sampleCount  len 
)
private

Definition at line 208 of file ClickRemoval.cpp.

References _(), sampleCount::as_double(), floatSample, WaveTrack::Get(), WaveTrack::GetMaxBlockSize(), limitSampleBufferSize(), mbDidSomething, Effect::MessageBox(), min(), RemoveClicks(), WaveTrack::Set(), Effect::TrackProgress(), and windowSize.

Referenced by Process().

209 {
210  if (len <= windowSize / 2)
211  {
213  wxString::Format(_("Selection must be larger than %d samples."),
214  windowSize / 2),
215  wxOK | wxICON_ERROR);
216  return false;
217  }
218 
219  auto idealBlockLen = track->GetMaxBlockSize() * 4;
220  if (idealBlockLen % windowSize != 0)
221  idealBlockLen += (windowSize - (idealBlockLen % windowSize));
222 
223  bool bResult = true;
224  decltype(len) s = 0;
225  Floats buffer{ idealBlockLen };
226  Floats datawindow{ windowSize };
227  while ((len - s) > windowSize / 2)
228  {
229  auto block = limitSampleBufferSize( idealBlockLen, len - s );
230 
231  track->Get((samplePtr) buffer.get(), floatSample, start + s, block);
232 
233  for (decltype(block) i = 0; i + windowSize / 2 < block; i += windowSize / 2)
234  {
235  auto wcopy = std::min( windowSize, block - i );
236 
237  for(decltype(wcopy) j = 0; j < wcopy; j++)
238  datawindow[j] = buffer[i+j];
239  for(auto j = wcopy; j < windowSize; j++)
240  datawindow[j] = 0;
241 
242  mbDidSomething |= RemoveClicks(windowSize, datawindow.get());
243 
244  for(decltype(wcopy) j = 0; j < wcopy; j++)
245  buffer[i+j] = datawindow[j];
246  }
247 
248  if (mbDidSomething) // RemoveClicks() actually did something.
249  track->Set((samplePtr) buffer.get(), floatSample, start + s, block);
250 
251  s += block;
252 
253  if (TrackProgress(count, s.as_double() /
254  len.as_double())) {
255  bResult = false;
256  break;
257  }
258  }
259 
260  return bResult;
261 }
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
bool TrackProgress(int whichTrack, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1985
double as_double() const
Definition: Types.h:88
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
void Set(samplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2052
char * samplePtr
Definition: Types.h:203
int min(int a, int b)
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:1625
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
bool RemoveClicks(size_t len, float *buffer)
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumCopied=nullptr) const
Definition: WaveTrack.cpp:1971
bool EffectClickRemoval::RemoveClicks ( size_t  len,
float *  buffer 
)
private

Definition at line 263 of file ClickRemoval.cpp.

References mClickWidth, mThresholdLevel, and sep.

Referenced by ProcessOne().

264 {
265  bool bResult = false; // This effect usually does nothing.
266  size_t i;
267  size_t j;
268  int left = 0;
269 
270  float msw;
271  int ww;
272  int s2 = sep/2;
273  Floats ms_seq{ len };
274  Floats b2{ len };
275 
276  for( i=0; i<len; i++)
277  b2[i] = buffer[i]*buffer[i];
278 
279  /* Shortcut for rms - multiple passes through b2, accumulating
280  * as we go.
281  */
282  for(i=0;i<len;i++)
283  ms_seq[i]=b2[i];
284 
285  for(i=1; (int)i < sep; i *= 2) {
286  for(j=0;j<len-i; j++)
287  ms_seq[j] += ms_seq[j+i];
288  }
289 
290  /* Cheat by truncating sep to next-lower power of two... */
291  sep = i;
292 
293  for( i=0; i<len-sep; i++ ) {
294  ms_seq[i] /= sep;
295  }
296  /* ww runs from about 4 to mClickWidth. wrc is the reciprocal;
297  * chosen so that integer roundoff doesn't clobber us.
298  */
299  int wrc;
300  for(wrc=mClickWidth/4; wrc>=1; wrc /= 2) {
301  ww = mClickWidth/wrc;
302 
303  for( i=0; i<len-sep; i++ ){
304  msw = 0;
305  for( j=0; (int)j<ww; j++) {
306  msw += b2[i+s2+j];
307  }
308  msw /= ww;
309 
310  if(msw >= mThresholdLevel * ms_seq[i]/10) {
311  if( left == 0 ) {
312  left = i+s2;
313  }
314  } else {
315  if(left != 0 && ((int)i-left+s2) <= ww*2) {
316  float lv = buffer[left];
317  float rv = buffer[i+ww+s2];
318  for(j=left; j<i+ww+s2; j++) {
319  bResult = true;
320  buffer[j]= (rv*(j-left) + lv*(i+ww+s2-j))/(float)(i+ww+s2-left);
321  b2[j] = buffer[j]*buffer[j];
322  }
323  left=0;
324  } else if(left != 0) {
325  left = 0;
326  }
327  }
328  }
329  }
330  return bResult;
331 }
bool EffectClickRemoval::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Implements EffectClientInterface.

Definition at line 115 of file ClickRemoval.cpp.

References mClickWidth, mThresholdLevel, and ReadAndVerifyInt.

116 {
117  ReadAndVerifyInt(Threshold);
118  ReadAndVerifyInt(Width);
119 
120  mThresholdLevel = Threshold;
121  mClickWidth = Width;
122 
123  return true;
124 }
#define ReadAndVerifyInt(name)
Definition: Effect.h:797
bool EffectClickRemoval::Startup ( )
overridevirtual

Reimplemented from Effect.

Definition at line 133 of file ClickRemoval.cpp.

References Effect::GetCurrentSettingsGroup(), gPrefs, mClickWidth, mThresholdLevel, and Effect::SaveUserPreset().

134 {
135  wxString base = wxT("/Effects/ClickRemoval/");
136 
137  // Migrate settings from 2.1.0 or before
138 
139  // Already migrated, so bail
140  if (gPrefs->Exists(base + wxT("Migrated")))
141  {
142  return true;
143  }
144 
145  // Load the old "current" settings
146  if (gPrefs->Exists(base))
147  {
148  mThresholdLevel = gPrefs->Read(base + wxT("ClickThresholdLevel"), 200);
149  if ((mThresholdLevel < MIN_Threshold) || (mThresholdLevel > MAX_Threshold))
150  { // corrupted Prefs?
151  mThresholdLevel = 0; //Off-skip
152  }
153  mClickWidth = gPrefs->Read(base + wxT("ClickWidth"), 20);
154  if ((mClickWidth < MIN_Width) || (mClickWidth > MAX_Width))
155  { // corrupted Prefs?
156  mClickWidth = 0; //Off-skip
157  }
158 
160 
161  // Do not migrate again
162  gPrefs->Write(base + wxT("Migrated"), true);
163  gPrefs->Flush();
164  }
165 
166  return true;
167 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool SaveUserPreset(const wxString &name) override
Definition: Effect.cpp:600
wxString GetCurrentSettingsGroup() override
Definition: Effect.cpp:801
bool EffectClickRemoval::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 384 of file ClickRemoval.cpp.

References Effect::mUIParent.

385 {
386  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
387  {
388  return false;
389  }
390 
391  return true;
392 }
wxWindow * mUIParent
Definition: Effect.h:472
bool EffectClickRemoval::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 374 of file ClickRemoval.cpp.

References Effect::mUIParent.

375 {
376  if (!mUIParent->TransferDataToWindow())
377  {
378  return false;
379  }
380 
381  return true;
382 }
wxWindow * mUIParent
Definition: Effect.h:472

Member Data Documentation

bool EffectClickRemoval::mbDidSomething
private

Definition at line 76 of file ClickRemoval.h.

Referenced by Process(), and ProcessOne().

int EffectClickRemoval::mClickWidth
private
Envelope* EffectClickRemoval::mEnvelope
private

Definition at line 74 of file ClickRemoval.h.

int EffectClickRemoval::mThresholdLevel
private
wxSlider* EffectClickRemoval::mThreshS
private

Definition at line 83 of file ClickRemoval.h.

Referenced by OnThreshSlider(), OnThreshText(), and PopulateOrExchange().

wxTextCtrl* EffectClickRemoval::mThreshT
private

Definition at line 85 of file ClickRemoval.h.

Referenced by OnThreshSlider(), OnThreshText(), and PopulateOrExchange().

wxSlider* EffectClickRemoval::mWidthS
private

Definition at line 82 of file ClickRemoval.h.

Referenced by OnWidthSlider(), OnWidthText(), and PopulateOrExchange().

wxTextCtrl* EffectClickRemoval::mWidthT
private

Definition at line 84 of file ClickRemoval.h.

Referenced by OnWidthSlider(), OnWidthText(), and PopulateOrExchange().

int EffectClickRemoval::sep
private

Definition at line 80 of file ClickRemoval.h.

Referenced by RemoveClicks().

size_t EffectClickRemoval::windowSize
private

Definition at line 77 of file ClickRemoval.h.

Referenced by ProcessOne().


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