Audacity  2.2.2
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
EffectTwoPassSimpleMono Class Reference

An Effect base class that implements a two pass process by using EffectSimpleMono. More...

#include <TwoPassSimpleMono.h>

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

Public Member Functions

bool Process () 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 Startup ()
 
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 ManualPage ()
 
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 ()
 

Protected Member Functions

bool InitPass1 () override
 
bool InitPass2 () override
 
virtual bool NewTrackPass1 ()
 
virtual bool NewTrackPass2 ()
 
virtual bool ProcessPass1 (float *WXUNUSED(buffer), size_t WXUNUSED(len))
 
virtual bool ProcessPass2 (float *WXUNUSED(buffer), size_t WXUNUSED(len))
 
virtual bool TwoBufferProcessPass1 (float *buffer1, size_t len1, float *WXUNUSED(buffer2), size_t WXUNUSED(len2))
 
virtual bool TwoBufferProcessPass2 (float *buffer1, size_t len1, float *WXUNUSED(buffer2), size_t WXUNUSED(len2))
 
void DisableSecondPass ()
 
- Protected Member Functions inherited from Effect
virtual bool Init ()
 
virtual bool PromptUser (wxWindow *parent)
 
virtual bool CheckWhetherSkipEffect ()
 
virtual int GetPass ()
 
virtual void End ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
virtual void Preview (bool dryOnly)
 
virtual void PopulateOrExchange (ShuttleGui &S)
 
virtual bool TransferDataToWindow ()
 
virtual bool TransferDataFromWindow ()
 
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

int mCurTrackNum
 
double mCurRate
 
double mCurT0
 
double mCurT1
 
int mCurChannel
 
int mPass
 
bool mSecondPassDisabled
 
- 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
 

Private Member Functions

bool ProcessOne (WaveTrack *t, sampleCount start, sampleCount end)
 
bool ProcessPass () override
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 

Detailed Description

An Effect base class that implements a two pass process by using EffectSimpleMono.

Inherit from it if your effect needs to pass twice over the data. It does the first pass on all selected tracks before going back and doing the second pass over all selected tracks.

Definition at line 20 of file TwoPassSimpleMono.h.

Member Function Documentation

void EffectTwoPassSimpleMono::DisableSecondPass ( )
inlineprotected

Definition at line 67 of file TwoPassSimpleMono.h.

References mSecondPassDisabled.

Referenced by EffectCompressor::InitPass1().

bool EffectTwoPassSimpleMono::InitPass1 ( )
overrideprotectedvirtual

Reimplemented from Effect.

Definition at line 206 of file TwoPassSimpleMono.cpp.

Referenced by Process().

207 {
208  return true;
209 }
bool EffectTwoPassSimpleMono::InitPass2 ( )
overrideprotectedvirtual

Reimplemented from Effect.

Definition at line 213 of file TwoPassSimpleMono.cpp.

Referenced by Process().

214 {
215  return true;
216 }
bool EffectTwoPassSimpleMono::NewTrackPass1 ( )
protectedvirtual

Reimplemented in EffectCompressor.

Definition at line 195 of file TwoPassSimpleMono.cpp.

Referenced by ProcessPass().

196 {
197  return true;
198 }
bool EffectTwoPassSimpleMono::NewTrackPass2 ( )
protectedvirtual

Definition at line 200 of file TwoPassSimpleMono.cpp.

Referenced by ProcessPass().

201 {
202  return true;
203 }
bool EffectTwoPassSimpleMono::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 27 of file TwoPassSimpleMono.cpp.

References Effect::CopyInputTracks(), InitPass1(), InitPass2(), mPass, mSecondPassDisabled, ProcessPass(), and Effect::ReplaceProcessedTracks().

28 {
29  mPass = 0;
30  mSecondPassDisabled = false;
31 
32  InitPass1();
33  this->CopyInputTracks(); // Set up mOutputTracks.
34  bool bGoodResult = ProcessPass();
35 
36  if (bGoodResult && !mSecondPassDisabled)
37  {
38  mPass = 1;
39  if (InitPass2())
40  bGoodResult = ProcessPass();
41  }
42 
43  this->ReplaceProcessedTracks(bGoodResult);
44  return bGoodResult;
45 }
void CopyInputTracks()
Definition: Effect.cpp:2036
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
bool EffectTwoPassSimpleMono::ProcessOne ( WaveTrack t,
sampleCount  start,
sampleCount  end 
)
private

Definition at line 99 of file TwoPassSimpleMono.cpp.

References floatSample, WaveTrack::Get(), WaveTrack::GetBestBlockSize(), WaveTrack::GetMaxBlockSize(), Effect::GetNumWaveTracks(), limitSampleBufferSize(), mCurTrackNum, min(), mPass, mSecondPassDisabled, WaveTrack::Set(), Effect::TotalProgress(), TwoBufferProcessPass1(), and TwoBufferProcessPass2().

Referenced by ProcessPass().

101 {
102  bool ret;
103 
104  //Get the length of the buffer (as double). len is
105  //used simple to calculate a progress meter, so it is easier
106  //to make it a double now than it is to do it later
107  auto len = (end - start).as_double();
108  auto maxblock = track->GetMaxBlockSize();
109 
110  //Initiate a processing buffer. This buffer will (most likely)
111  //be shorter than the length of the track being processed.
112  Floats buffer1{ maxblock };
113  Floats buffer2{ maxblock };
114  auto samples1 = limitSampleBufferSize(
115  std::min( maxblock, track->GetBestBlockSize(start) ), end - start );
116 
117  //Get the samples from the track and put them in the buffer
118  track->Get((samplePtr) buffer1.get(), floatSample, start, samples1);
119 
120  // Process the first buffer with a NULL previous buffer
121  if (mPass == 0)
122  ret = TwoBufferProcessPass1(NULL, 0, buffer1.get(), samples1);
123  else
124  ret = TwoBufferProcessPass2(NULL, 0, buffer1.get(), samples1);
125  if (!ret)
126  //Return false because the effect failed.
127  return false;
128 
129  //Go through the track one buffer at a time. s counts which
130  //sample the current buffer starts at.
131  auto s = start + samples1;
132  while (s < end) {
133  //Get a block of samples (smaller than the size of the buffer)
134  //Adjust the block size if it is the final block in the track
135  auto samples2 = limitSampleBufferSize(
136  std::min( track->GetBestBlockSize(s), maxblock ), end - s
137  );
138 
139  //Get the samples from the track and put them in the buffer
140  track->Get((samplePtr)buffer2.get(), floatSample, s, samples2);
141 
142  //Process the buffer. If it fails, clean up and exit.
143  if (mPass == 0)
144  ret = TwoBufferProcessPass1(buffer1.get(), samples1, buffer2.get(), samples2);
145  else
146  ret = TwoBufferProcessPass2(buffer1.get(), samples1, buffer2.get(), samples2);
147  if (!ret)
148  //Return false because the effect failed.
149  return false;
150 
151  //Processing succeeded. copy the newly-changed samples back
152  //onto the track.
153  track->Set((samplePtr)buffer1.get(), floatSample, s - samples1, samples1);
154 
155  //Increment s one blockfull of samples
156  s += samples2;
157 
158  //Update the Progress meter
160  ret = TotalProgress(
161  (mCurTrackNum + (s-start).as_double()/len) /
162  GetNumWaveTracks());
163  else
164  ret = TotalProgress(
165  (mCurTrackNum + (s-start).as_double()/len + GetNumWaveTracks()*mPass) /
166  (GetNumWaveTracks()*2));
167  if (ret)
168  //Return false because the effect failed.
169  return false;
170 
171  // Rotate the buffers
172  buffer1.swap(buffer2);
173 
174  std::swap(samples1, samples2);
175  }
176 
177  // Send the last buffer with a NULL pointer for the current buffer
178  if (mPass == 0)
179  ret = TwoBufferProcessPass1(buffer1.get(), samples1, NULL, 0);
180  else
181  ret = TwoBufferProcessPass2(buffer1.get(), samples1, NULL, 0);
182 
183  if (!ret)
184  //Return false because the effect failed.
185  return false;
186 
187  //Processing succeeded. copy the newly-changed samples back
188  //onto the track.
189  track->Set((samplePtr)buffer1.get(), floatSample, s - samples1, samples1);
190 
191  //Return true because the effect processing succeeded.
192  return true;
193 }
bool TotalProgress(double frac)
Definition: Effect.cpp:1977
virtual bool TwoBufferProcessPass2(float *buffer1, size_t len1, float *WXUNUSED(buffer2), size_t WXUNUSED(len2))
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
virtual bool TwoBufferProcessPass1(float *buffer1, size_t len1, float *WXUNUSED(buffer2), size_t WXUNUSED(len2))
char * samplePtr
Definition: Types.h:203
int min(int a, int b)
int GetNumWaveTracks()
Definition: Effect.h:343
bool EffectTwoPassSimpleMono::ProcessPass ( )
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 47 of file TwoPassSimpleMono.cpp.

References mCurChannel, mCurRate, mCurT0, mCurT1, mCurTrackNum, Effect::mOutputTracks, mPass, Effect::mT0, Effect::mT1, NewTrackPass1(), NewTrackPass2(), ProcessOne(), and Track::Wave.

Referenced by Process().

48 {
49  //Iterate over each track
51  WaveTrack *track = (WaveTrack *) iter.First();
52  mCurTrackNum = 0;
53  while (track) {
54  //Get start and end times from track
55  double trackStart = track->GetStartTime();
56  double trackEnd = track->GetEndTime();
57 
58  //Set the current bounds to whichever left marker is
59  //greater and whichever right marker is less:
60  mCurT0 = mT0 < trackStart? trackStart: mT0;
61  mCurT1 = mT1 > trackEnd? trackEnd: mT1;
62 
63  // Process only if the right marker is to the right of the left marker
64  if (mCurT1 > mCurT0) {
65 
66  //Transform the marker timepoints to samples
67  auto start = track->TimeToLongSamples(mCurT0);
68  auto end = track->TimeToLongSamples(mCurT1);
69 
70  //Get the track rate and samples
71  mCurRate = track->GetRate();
72  mCurChannel = track->GetChannel();
73 
74  //NewTrackPass1/2() returns true by default
75  bool ret;
76  if (mPass == 0)
77  ret = NewTrackPass1();
78  else
79  ret = NewTrackPass2();
80  if (!ret)
81  return false;
82 
83  //ProcessOne() (implemented below) processes a single track
84  if (!ProcessOne(track, start, end))
85  return false;
86  }
87 
88  //Iterate to the next track
89  track = (WaveTrack *) iter.Next();
90  mCurTrackNum++;
91  }
92 
93  return true;
94 }
double mT1
Definition: Effect.h:461
bool ProcessOne(WaveTrack *t, sampleCount start, sampleCount end)
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
double mT0
Definition: Effect.h:460
virtual bool EffectTwoPassSimpleMono::ProcessPass1 ( float *  WXUNUSEDbuffer,
size_t   WXUNUSEDlen 
)
inlineprotectedvirtual

Definition at line 45 of file TwoPassSimpleMono.h.

Referenced by TwoBufferProcessPass1().

46  { return false; }
virtual bool EffectTwoPassSimpleMono::ProcessPass2 ( float *  WXUNUSEDbuffer,
size_t   WXUNUSEDlen 
)
inlineprotectedvirtual

Definition at line 49 of file TwoPassSimpleMono.h.

Referenced by TwoBufferProcessPass2().

50  { return false; }
virtual bool EffectTwoPassSimpleMono::TwoBufferProcessPass1 ( float *  buffer1,
size_t  len1,
float *  WXUNUSEDbuffer2,
size_t   WXUNUSEDlen2 
)
inlineprotectedvirtual

Definition at line 57 of file TwoPassSimpleMono.h.

References ProcessPass1().

Referenced by ProcessOne().

58  { if(buffer1 != NULL) return ProcessPass1(buffer1, len1); else return true; }
virtual bool ProcessPass1(float *WXUNUSED(buffer), size_t WXUNUSED(len))
virtual bool EffectTwoPassSimpleMono::TwoBufferProcessPass2 ( float *  buffer1,
size_t  len1,
float *  WXUNUSEDbuffer2,
size_t   WXUNUSEDlen2 
)
inlineprotectedvirtual

Definition at line 60 of file TwoPassSimpleMono.h.

References ProcessPass2().

Referenced by ProcessOne().

61  { if(buffer1 != NULL) return ProcessPass2(buffer1, len1); else return true; }
virtual bool ProcessPass2(float *WXUNUSED(buffer), size_t WXUNUSED(len))

Member Data Documentation

int EffectTwoPassSimpleMono::mCurChannel
protected

Definition at line 74 of file TwoPassSimpleMono.h.

Referenced by ProcessPass().

double EffectTwoPassSimpleMono::mCurRate
protected

Definition at line 71 of file TwoPassSimpleMono.h.

Referenced by EffectCompressor::NewTrackPass1(), and ProcessPass().

double EffectTwoPassSimpleMono::mCurT0
protected

Definition at line 72 of file TwoPassSimpleMono.h.

Referenced by ProcessPass().

double EffectTwoPassSimpleMono::mCurT1
protected

Definition at line 73 of file TwoPassSimpleMono.h.

Referenced by ProcessPass().

int EffectTwoPassSimpleMono::mCurTrackNum
protected

Definition at line 70 of file TwoPassSimpleMono.h.

Referenced by ProcessOne(), and ProcessPass().

int EffectTwoPassSimpleMono::mPass
protected

Definition at line 75 of file TwoPassSimpleMono.h.

Referenced by Process(), ProcessOne(), and ProcessPass().

bool EffectTwoPassSimpleMono::mSecondPassDisabled
protected

Definition at line 76 of file TwoPassSimpleMono.h.

Referenced by DisableSecondPass(), Process(), and ProcessOne().


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