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

Use the interpolation code to fill in damaged audio. Damage can include pops, clicks, or clipping. As long as the damaged section is short and surrounded by lots of good audio, it is usually quite successful. More...

#include <Repair.h>

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

Public Member Functions

 EffectRepair ()
 
virtual ~EffectRepair ()
 
ComponentInterfaceSymbol GetSymbol () override
 
TranslatableString GetDescription () override
 
EffectType GetType () override
 Type determines how it behaves. More...
 
bool IsInteractive () override
 Whether the effect needs a dialog for entry of settings. More...
 
bool Process () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
EffectFamilySymbol GetFamily () override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsDefault () override
 Whether the effect sorts "above the line" in the menus. More...
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 Whether the effect supports realtime previewing (while audio is playing). More...
 
bool SupportsAutomation () override
 Whether the effect can be used without the UI, in a macro. More...
 
bool GetAutomationParameters (CommandParameters &parms) override
 Save current settings into parms. More...
 
bool SetAutomationParameters (CommandParameters &parms) override
 Change settings to those stored in parms. More...
 
bool LoadUserPreset (const RegistryPath &name) override
 Change settings to a user-named preset. More...
 
bool SaveUserPreset (const RegistryPath &name) override
 Save current settings as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () override
 Report names of factory presets. More...
 
bool LoadFactoryPreset (int id) override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults () override
 Change settings back to "factory default". More...
 
bool SetHost (EffectHostInterface *host) override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 Called for destructive, non-realtime effect computation. More...
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
size_t GetBlockSize () const override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 Called for destructive, non-realtime effect computation. More...
 
bool ProcessFinalize () override
 Called for destructive, non-realtime effect computation. More...
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 Called for destructive, non-realtime effect computation. More...
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () noexcept override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () noexcept override
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
bool PopulateUI (ShuttleGui &S) final
 Adds controls to a panel that is given as the parent window of S More...
 
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
 
EffectDefinitionInterfaceGetDefinition () 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 ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, bool forceModal=false) override
 
unsigned TestUIFlags (unsigned mask)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
virtual bool Startup (EffectUIClientInterface *client)
 
virtual bool GetAutomationParametersAsString (wxString &parms)
 
virtual bool SetAutomationParametersFromString (const wxString &parms)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={})
 
bool Delegate (Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory)
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
virtual bool Startup ()
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
- Public Member Functions inherited from EffectProcessor
virtual ~EffectProcessor ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetClassification ()
 Determines which menu it appears in; default same as GetType(). More...
 
virtual bool EnablesDebug ()
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage ()
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage ()
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus ()
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 
- Public Member Functions inherited from EffectUIHostInterface
virtual ~EffectUIHostInterface ()
 
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Repair") }
 
- 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 ProcessOne (int count, WaveTrack *track, sampleCount start, size_t len, size_t repairStart, size_t repairLen)
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Static Public Member Functions inherited from Effect
static void IncEffectCounter ()
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Protected Member Functions inherited from Effect
bool EnableApply (bool enable=true)
 
bool EnablePreview (bool enable=true)
 
virtual bool Init ()
 
virtual bool CheckWhetherSkipEffect ()
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual void End ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
virtual void Preview (bool dryOnly)
 
virtual void PopulateOrExchange (ShuttleGui &S)
 
virtual bool TransferDataToWindow ()
 
virtual bool TransferDataFromWindow ()
 
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
BasicUI::ProgressDialogmProgress = nullptr
 
double mProjectRate
 
double mSampleRate
 
WaveTrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWeakRef< wxDialog > mUIDialog
 This weak pointer may be the same as the above, or null. More...
 
wxWindow * mUIParent
 
unsigned mUIFlags { 0 }
 
sampleCount mSampleCnt
 
- Static Protected Attributes inherited from Effect
static int nEffectsDone =0
 

Detailed Description

Use the interpolation code to fill in damaged audio. Damage can include pops, clicks, or clipping. As long as the damaged section is short and surrounded by lots of good audio, it is usually quite successful.

This was formerly the PopClickRemoval effect, but it was renamed and focused on the smaller subproblem of repairing the audio, rather than actually finding the clicks.

Definition at line 18 of file Repair.h.

Constructor & Destructor Documentation

◆ EffectRepair()

EffectRepair::EffectRepair ( )

Definition at line 42 of file Repair.cpp.

43 {
44 }

◆ ~EffectRepair()

EffectRepair::~EffectRepair ( )
virtual

Definition at line 46 of file Repair.cpp.

47 {
48 }

Member Function Documentation

◆ GetDescription()

TranslatableString EffectRepair::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 57 of file Repair.cpp.

58 {
59  return XO("Sets the peak amplitude of a one or more tracks");
60 }

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectRepair::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 52 of file Repair.cpp.

53 {
54  return Symbol;
55 }

References Symbol.

◆ GetType()

EffectType EffectRepair::GetType ( )
overridevirtual

Type determines how it behaves.

Reimplemented from Effect.

Definition at line 64 of file Repair.cpp.

65 {
66  return EffectTypeProcess;
67 }

References EffectTypeProcess.

◆ IsInteractive()

bool EffectRepair::IsInteractive ( )
overridevirtual

Whether the effect needs a dialog for entry of settings.

Reimplemented from Effect.

Definition at line 69 of file Repair.cpp.

70 {
71  return false;
72 }

◆ Process()

bool EffectRepair::Process ( )
overridevirtual

If Process() is not overridden, it uses ProcessInitialize(), ProcessBlock(), and ProcessFinalize() methods of EffectProcessor, and also GetLatency() to determine how many leading output samples to discard and how many extra samples to produce.

The Repair effect needs some data to go on.
\nPlease select an area to repair with some audio on at least one side (the more the better).") );

Reimplemented from Effect.

Definition at line 76 of file Repair.cpp.

77 {
78  //v This may be too much copying for EffectRepair. To support Cancel, may be able to copy much less.
79  // But for now, Cancel isn't supported without this.
80  this->CopyInputTracks(); // Set up mOutputTracks. //v This may be too much copying for EffectRepair.
81  bool bGoodResult = true;
82 
83  int count = 0;
84  for( auto track : mOutputTracks->Selected< WaveTrack >() ) {
85  const
86  double trackStart = track->GetStartTime();
87  const double repair_t0 = std::max(mT0, trackStart);
88  const
89  double trackEnd = track->GetEndTime();
90  const double repair_t1 = std::min(mT1, trackEnd);
91  const
92  double repair_deltat = repair_t1 - repair_t0;
93  if (repair_deltat > 0) { // selection is within track audio
94  const auto repair0 = track->TimeToLongSamples(repair_t0);
95  const auto repair1 = track->TimeToLongSamples(repair_t1);
96  const auto repairLen = repair1 - repair0;
97  if (repairLen > 128) {
99  XO(
100 "The Repair effect is intended to be used on very short sections of damaged audio (up to 128 samples).\n\nZoom in and select a tiny fraction of a second to repair.") );
101  bGoodResult = false;
102  break;
103  }
104 
105  const double rate = track->GetRate();
106  const double spacing = std::max(repair_deltat * 2, 128. / rate);
107  const double t0 = std::max(repair_t0 - spacing, trackStart);
108  const double t1 = std::min(repair_t1 + spacing, trackEnd);
109 
110  const auto s0 = track->TimeToLongSamples(t0);
111  const auto s1 = track->TimeToLongSamples(t1);
112  // The difference is at most 2 * 128:
113  const auto repairStart = (repair0 - s0).as_size_t();
114  const auto len = s1 - s0;
115 
116  if (s0 == repair0 && s1 == repair1) {
118  XO(
119 "Repair works by using audio data outside the selection region.\n\nPlease select a region that has audio touching at least one side of it.\n\nThe more surrounding audio, the better it performs.") );
121  bGoodResult = false;
122  break;
123  }
124 
125  if (!ProcessOne(count, track, s0,
126  // len is at most 5 * 128.
127  len.as_size_t(),
128  repairStart,
129  // repairLen is at most 128.
130  repairLen.as_size_t() )) {
131  bGoodResult = false;
132  break;
133  }
134  }
135 
136  count++;
137  }
138 
139  this->ReplaceProcessedTracks(bGoodResult);
140  return bGoodResult;
141 }

References Effect::CopyInputTracks(), Effect::MessageBox(), min(), Effect::mOutputTracks, Effect::mT0, Effect::mT1, ProcessOne(), Effect::ReplaceProcessedTracks(), and XO.

Here is the call graph for this function:

◆ ProcessOne()

bool EffectRepair::ProcessOne ( int  count,
WaveTrack track,
sampleCount  start,
size_t  len,
size_t  repairStart,
size_t  repairLen 
)
private

Definition at line 143 of file Repair.cpp.

147 {
148  Floats buffer{ len };
149  track->GetFloats(buffer.get(), start, len);
150  InterpolateAudio(buffer.get(), len, repairStart, repairLen);
151  track->Set((samplePtr)&buffer[repairStart], floatSample,
152  start + repairStart, repairLen);
153  return !TrackProgress(count, 1.0); // TrackProgress returns true on Cancel.
154 }

References floatSample, SampleTrack::GetFloats(), InterpolateAudio(), WaveTrack::Set(), and Effect::TrackProgress().

Referenced by Process().

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

Member Data Documentation

◆ Symbol

const ComponentInterfaceSymbol EffectRepair::Symbol { XO("Repair") }
static

Definition at line 21 of file Repair.h.

Referenced by GetSymbol().


The documentation for this class was generated from the following files:
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:75
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:56
Effect::MessageBox
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
Definition: Effect.cpp:2238
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:1834
EffectRepair::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: Repair.h:21
InterpolateAudio
void InterpolateAudio(float *buffer, const size_t len, size_t firstBad, size_t numBad)
Definition: InterpolateAudio.cpp:82
Effect::mT1
double mT1
Definition: Effect.h:424
XO
#define XO(s)
Definition: Internat.h:31
WaveTrack::Set
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2194
floatSample
@ floatSample
Definition: SampleFormat.h:34
Effect::mT0
double mT0
Definition: Effect.h:423
SampleTrack::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: SampleTrack.h:64
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:1956
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:422
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
EffectRepair::ProcessOne
bool ProcessOne(int count, WaveTrack *track, sampleCount start, size_t len, size_t repairStart, size_t repairLen)
Definition: Repair.cpp:143
Effect::TrackProgress
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={})
Definition: Effect.cpp:1788
ArrayOf< float >