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

An Effect to convert stereo to mono. More...

#include <StereoToMono.h>

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

Public Member Functions

 EffectStereoToMono ()
 
virtual ~EffectStereoToMono ()
 
IdentInterfaceSymbol GetSymbol () override
 
wxString GetDescription () override
 
EffectType GetType () override
 
bool IsInteractive () override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
bool Process () override
 
void End () override
 
bool IsHidden () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
wxString GetPath () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () override
 
IdentInterfaceSymbol GetFamilyId () override
 
bool IsDefault () override
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 
bool SupportsAutomation () override
 
bool SetHost (EffectHostInterface *host) 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 ()
 
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)
 

Private Attributes

sampleCount mStart
 
sampleCount mEnd
 
WaveTrackmLeftTrack
 
WaveTrackmRightTrack
 
std::unique_ptr< WaveTrackmOutTrack
 

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 CheckWhetherSkipEffect ()
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual int GetPass ()
 
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 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 to convert stereo to mono.

Definition at line 20 of file StereoToMono.h.

Constructor & Destructor Documentation

EffectStereoToMono::EffectStereoToMono ( )

Definition at line 24 of file StereoToMono.cpp.

25 {
26 }
EffectStereoToMono::~EffectStereoToMono ( )
virtual

Definition at line 28 of file StereoToMono.cpp.

29 {
30 }

Member Function Documentation

void EffectStereoToMono::End ( )
overridevirtual

Reimplemented from Effect.

Definition at line 132 of file StereoToMono.cpp.

References mOutTrack.

133 {
134  mOutTrack.reset();
135 }
std::unique_ptr< WaveTrack > mOutTrack
Definition: StereoToMono.h:57
unsigned EffectStereoToMono::GetAudioInCount ( )
overridevirtual

Reimplemented from Effect.

Definition at line 59 of file StereoToMono.cpp.

60 {
61  return 2;
62 }
unsigned EffectStereoToMono::GetAudioOutCount ( )
overridevirtual

Reimplemented from Effect.

Definition at line 64 of file StereoToMono.cpp.

65 {
66  return 1;
67 }
wxString EffectStereoToMono::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 39 of file StereoToMono.cpp.

References _().

40 {
41  return _("Converts stereo tracks to mono");
42 }
_("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 EffectStereoToMono::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 34 of file StereoToMono.cpp.

References STEREOTOMONO_PLUGIN_SYMBOL.

35 {
37 }
#define STEREOTOMONO_PLUGIN_SYMBOL
Definition: StereoToMono.h:18
EffectType EffectStereoToMono::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 46 of file StereoToMono.cpp.

References EffectTypeHidden.

47 {
48  // Really EffectTypeProcess, but this prevents it from showing in the Effect Menu
49  return EffectTypeHidden;
50 }
bool EffectStereoToMono::IsHidden ( )
overridevirtual

Reimplemented from Effect.

Definition at line 177 of file StereoToMono.cpp.

178 {
179  return true;
180 }
bool EffectStereoToMono::IsInteractive ( )
overridevirtual

Reimplemented from Effect.

Definition at line 52 of file StereoToMono.cpp.

53 {
54  return false;
55 }
bool EffectStereoToMono::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 71 of file StereoToMono.cpp.

References Effect::CopyInputTracks(), floatSample, GetActiveProject(), WaveTrack::GetEndTime(), WaveTrack::GetRate(), WaveTrack::GetStartTime(), AudacityProject::GetTrackFactory(), mEnd, mLeftTrack, Effect::mOutputTracks, mOutTrack, mRightTrack, mStart, TrackFactory::NewWaveTrack(), ProcessOne(), Effect::ReplaceProcessedTracks(), WaveTrack::TimeToLongSamples(), and Track::Wave.

72 {
73  // Do not use mWaveTracks here. We will possibly DELETE tracks,
74  // so we must use the "real" tracklist.
75  this->CopyInputTracks(); // Set up mOutputTracks.
76  bool bGoodResult = true;
77 
79  mLeftTrack = (WaveTrack *)iter.First();
80  bool refreshIter = false;
81 
82  if(mLeftTrack)
83  {
84  // create a NEW WaveTrack to hold all of the output
86  mOutTrack = p->GetTrackFactory()->NewWaveTrack(floatSample, mLeftTrack->GetRate());
87  }
88 
89  int count = 0;
90  while (mLeftTrack) {
91  if (mLeftTrack->GetKind() == Track::Wave &&
92  mLeftTrack->GetSelected() &&
93  mLeftTrack->GetLinked()) {
94 
95  // Assume linked track is wave
96  mRightTrack = static_cast<WaveTrack*>(iter.Next());
97 
98  if ((mLeftTrack->GetRate() == mRightTrack->GetRate())) {
99  auto leftTrackStart = mLeftTrack->TimeToLongSamples(mLeftTrack->GetStartTime());
100  auto rightTrackStart = mRightTrack->TimeToLongSamples(mRightTrack->GetStartTime());
101  mStart = wxMin(leftTrackStart, rightTrackStart);
102 
103  auto leftTrackEnd = mLeftTrack->TimeToLongSamples(mLeftTrack->GetEndTime());
104  auto rightTrackEnd = mRightTrack->TimeToLongSamples(mRightTrack->GetEndTime());
105  mEnd = wxMax(leftTrackEnd, rightTrackEnd);
106 
107  bGoodResult = ProcessOne(count);
108  if (!bGoodResult)
109  break;
110 
111  mOutTrack->Clear(mOutTrack->GetStartTime(), mOutTrack->GetEndTime());
112 
113  // The right channel has been deleted, so we must restart from the beginning
114  refreshIter = true;
115  }
116  }
117 
118  if (refreshIter) {
119  mLeftTrack = (WaveTrack *)iter.First();
120  refreshIter = false;
121  }
122  else {
123  mLeftTrack = (WaveTrack *)iter.Next();
124  }
125  count++;
126  }
127 
128  this->ReplaceProcessedTracks(bGoodResult);
129  return bGoodResult;
130 }
bool ProcessOne(int count)
void CopyInputTracks()
Definition: Effect.cpp:2036
std::unique_ptr< WaveTrack > mOutTrack
Definition: StereoToMono.h:57
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:1873
sampleCount mStart
Definition: StereoToMono.h:53
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
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
std::unique_ptr< WaveTrack > NewWaveTrack(sampleFormat format=(sampleFormat) 0, double rate=0)
Definition: WaveTrack.cpp:78
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
WaveTrack * mLeftTrack
Definition: StereoToMono.h:55
WaveTrack * mRightTrack
Definition: StereoToMono.h:56
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
double GetRate() const
Definition: WaveTrack.cpp:398
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
TrackFactory * GetTrackFactory()
Definition: Project.cpp:1434
sampleCount mEnd
Definition: StereoToMono.h:54
bool EffectStereoToMono::ProcessOne ( int  count)
private

Definition at line 137 of file StereoToMono.cpp.

References WaveTrack::Clear(), floatSample, WaveTrack::Get(), WaveTrack::GetEndTime(), WaveTrack::GetMaxBlockSize(), WaveTrack::GetStartTime(), limitSampleBufferSize(), mEnd, mLeftTrack, Track::MonoChannel, Effect::mOutputTracks, mOutTrack, mRightTrack, mStart, WaveTrack::Paste(), Track::SetChannel(), Track::SetLinked(), and Effect::TrackProgress().

Referenced by Process().

138 {
139  float curLeftFrame;
140  float curRightFrame;
141  float curMonoFrame;
142 
143  auto idealBlockLen = mLeftTrack->GetMaxBlockSize() * 2;
144  auto index = mStart;
145  Floats leftBuffer { idealBlockLen };
146  Floats rightBuffer{ idealBlockLen };
147  bool bResult = true;
148 
149  while (index < mEnd) {
150  bResult &= mLeftTrack->Get((samplePtr)leftBuffer.get(), floatSample, index, idealBlockLen);
151  bResult &= mRightTrack->Get((samplePtr)rightBuffer.get(), floatSample, index, idealBlockLen);
152  auto limit = limitSampleBufferSize( idealBlockLen, mEnd - index );
153  for (decltype(limit) i = 0; i < limit; ++i) {
154  index++;
155  curLeftFrame = leftBuffer[i];
156  curRightFrame = rightBuffer[i];
157  curMonoFrame = (curLeftFrame + curRightFrame) / 2.0;
158  leftBuffer[i] = curMonoFrame;
159  }
160  mOutTrack->Append((samplePtr)leftBuffer.get(), floatSample, limit);
161  if (TrackProgress(count, 2.*(index.as_double() / (mEnd - mStart).as_double())))
162  return false;
163  }
164 
165  double minStart = wxMin(mLeftTrack->GetStartTime(), mRightTrack->GetStartTime());
167  mOutTrack->Flush();
168  mLeftTrack->Paste(minStart, mOutTrack.get());
169  mLeftTrack->SetLinked(false);
170  mRightTrack->SetLinked(false);
172  mOutputTracks->Remove(mRightTrack);
173 
174  return bResult;
175 }
bool TrackProgress(int whichTrack, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1985
void SetLinked(bool l)
Definition: Track.cpp:244
std::unique_ptr< WaveTrack > mOutTrack
Definition: StereoToMono.h:57
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:678
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:1873
sampleCount mStart
Definition: StereoToMono.h:53
void SetChannel(int c)
Definition: Track.h:292
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
double GetStartTime() const override
Get the time at which the first clip in the track starts.
Definition: WaveTrack.cpp:1853
char * samplePtr
Definition: Types.h:203
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1192
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:1625
WaveTrack * mLeftTrack
Definition: StereoToMono.h:55
WaveTrack * mRightTrack
Definition: StereoToMono.h:56
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
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
sampleCount mEnd
Definition: StereoToMono.h:54

Member Data Documentation

sampleCount EffectStereoToMono::mEnd
private

Definition at line 54 of file StereoToMono.h.

Referenced by Process(), and ProcessOne().

WaveTrack* EffectStereoToMono::mLeftTrack
private

Definition at line 55 of file StereoToMono.h.

Referenced by Process(), and ProcessOne().

std::unique_ptr<WaveTrack> EffectStereoToMono::mOutTrack
private

Definition at line 57 of file StereoToMono.h.

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

WaveTrack* EffectStereoToMono::mRightTrack
private

Definition at line 56 of file StereoToMono.h.

Referenced by Process(), and ProcessOne().

sampleCount EffectStereoToMono::mStart
private

Definition at line 53 of file StereoToMono.h.

Referenced by Process(), and ProcessOne().


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