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

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

#include <StereoToMono.h>

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

Public Member Functions

 EffectStereoToMono ()
 
virtual ~EffectStereoToMono ()
 
ComponentInterfaceSymbol GetSymbol () override
 
TranslatableString GetDescription () override
 
EffectType GetType () override
 
bool IsInteractive () override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
bool Process () override
 
bool IsHidden () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
EffectFamilySymbol GetFamily () 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
 
size_t GetBlockSize () const 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, const EffectDialogFactory &factory, bool forceModal=false) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool LoadUserPreset (const RegistryPath &name) override
 
bool SaveUserPreset (const RegistryPath &name) override
 
RegistryPaths GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (ShuttleGui &S) final
 
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
 
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 ()
 
bool HasSharedConfigGroup (const RegistryPath &group) override
 
bool GetSharedConfigSubgroups (const RegistryPath &group, RegistryPaths &subgroups) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, wxString &value, const wxString &defval={}) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, int &value, int defval=0) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const wxString &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const int &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const bool &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const float &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const RegistryPath &group) override
 
bool RemoveSharedConfig (const RegistryPath &group, const RegistryPath &key) override
 
bool HasPrivateConfigGroup (const RegistryPath &group) override
 
bool GetPrivateConfigSubgroups (const RegistryPath &group, RegistryPaths &paths) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, wxString &value, const wxString &defval={}) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const wxString &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const int &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const bool &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const float &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const RegistryPath &group) override
 
bool RemovePrivateConfig (const RegistryPath &group, const RegistryPath &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 RegistryPaths GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual ManualPageID ManualPage ()
 
virtual FilePath HelpPage ()
 
virtual void SetUIFlags (unsigned flags)
 
virtual unsigned TestUIFlags (unsigned mask)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, 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={})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetClassification ()
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
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 ()
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Stereo To Mono") }
 
- 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 (sampleCount &curTime, sampleCount totalTime, WaveTrack *left, WaveTrack *right)
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
using VetoDialogHook = bool(*)(wxDialog *)
 
- Public Types inherited from EffectClientInterface
using EffectDialogFactory = std::function< wxDialog *(wxWindow &parent, EffectHostInterface *, EffectUIClientInterface *) >
 
- Static Public Member Functions inherited from Effect
static VetoDialogHook SetVetoDialogHook (VetoDialogHook hook)
 
static CommandID GetSquashedName (wxString name)
 
static void IncEffectCounter ()
 
- Protected Member Functions inherited from Effect
virtual bool Init ()
 
virtual bool CheckWhetherSkipEffect ()
 
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 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, 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
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
wxWeakRef< NotifyingSelectedRegionmpSelectedRegion {}
 
WaveTrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
unsigned mUIFlags
 
sampleCount mSampleCnt
 
- Static Protected Attributes inherited from Effect
static int nEffectsDone =0
 

Detailed Description

An Effect to convert stereo to mono.

Definition at line 16 of file StereoToMono.h.

Constructor & Destructor Documentation

◆ EffectStereoToMono()

EffectStereoToMono::EffectStereoToMono ( )

Definition at line 32 of file StereoToMono.cpp.

33 {
34 }

◆ ~EffectStereoToMono()

EffectStereoToMono::~EffectStereoToMono ( )
virtual

Definition at line 36 of file StereoToMono.cpp.

37 {
38 }

Member Function Documentation

◆ GetAudioInCount()

unsigned EffectStereoToMono::GetAudioInCount ( )
overridevirtual

Reimplemented from Effect.

Definition at line 67 of file StereoToMono.cpp.

68 {
69  return 2;
70 }

◆ GetAudioOutCount()

unsigned EffectStereoToMono::GetAudioOutCount ( )
overridevirtual

Reimplemented from Effect.

Definition at line 72 of file StereoToMono.cpp.

73 {
74  return 1;
75 }

◆ GetDescription()

TranslatableString EffectStereoToMono::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 47 of file StereoToMono.cpp.

48 {
49  return XO("Converts stereo tracks to mono");
50 }

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectStereoToMono::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 42 of file StereoToMono.cpp.

43 {
44  return Symbol;
45 }

References Symbol.

◆ GetType()

EffectType EffectStereoToMono::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 54 of file StereoToMono.cpp.

55 {
56  // Really EffectTypeProcess, but this prevents it from showing in the Effect Menu
57  return EffectTypeHidden;
58 }

References EffectTypeHidden.

◆ IsHidden()

bool EffectStereoToMono::IsHidden ( )
overridevirtual

Reimplemented from Effect.

Definition at line 222 of file StereoToMono.cpp.

223 {
224  return true;
225 }

◆ IsInteractive()

bool EffectStereoToMono::IsInteractive ( )
overridevirtual

Reimplemented from Effect.

Definition at line 60 of file StereoToMono.cpp.

61 {
62  return false;
63 }

◆ Process()

bool EffectStereoToMono::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 79 of file StereoToMono.cpp.

80 {
81  // Do not use mWaveTracks here. We will possibly DELETE tracks,
82  // so we must use the "real" tracklist.
83  this->CopyInputTracks(); // Set up mOutputTracks.
84  bool bGoodResult = true;
85 
86  // Determine the total time (in samples) used by all of the target tracks
87  sampleCount totalTime = 0;
88 
89  auto trackRange = mOutputTracks->SelectedLeaders< WaveTrack >();
90  while (trackRange.first != trackRange.second)
91  {
92  auto left = *trackRange.first;
93  auto channels = TrackList::Channels(left);
94  if (channels.size() > 1)
95  {
96  auto right = *channels.rbegin();
97  auto leftRate = left->GetRate();
98  auto rightRate = right->GetRate();
99 
100  if (leftRate != rightRate)
101  {
102  if (leftRate != mProjectRate)
103  {
104  mProgress->SetMessage(XO("Resampling left channel"));
105  left->Resample(mProjectRate, mProgress);
106  leftRate = mProjectRate;
107  }
108  if (rightRate != mProjectRate)
109  {
110  mProgress->SetMessage(XO("Resampling right channel"));
111  right->Resample(mProjectRate, mProgress);
112  rightRate = mProjectRate;
113  }
114  }
115  {
116  auto start = wxMin(left->TimeToLongSamples(left->GetStartTime()),
117  right->TimeToLongSamples(right->GetStartTime()));
118  auto end = wxMax(left->TimeToLongSamples(left->GetEndTime()),
119  right->TimeToLongSamples(right->GetEndTime()));
120 
121  totalTime += (end - start);
122  }
123  }
124 
125  ++trackRange.first;
126  }
127 
128  // Process each stereo track
129  sampleCount curTime = 0;
130  bool refreshIter = false;
131 
132  mProgress->SetMessage(XO("Mixing down to mono"));
133 
134  trackRange = mOutputTracks->SelectedLeaders< WaveTrack >();
135  while (trackRange.first != trackRange.second)
136  {
137  auto left = *trackRange.first;
138  auto channels = TrackList::Channels(left);
139  if (channels.size() > 1)
140  {
141  auto right = *channels.rbegin();
142 
143  bGoodResult = ProcessOne(curTime, totalTime, left, right);
144  if (!bGoodResult)
145  {
146  break;
147  }
148 
149  // The right channel has been deleted, so we must restart from the beginning
150  refreshIter = true;
151  }
152 
153  if (refreshIter)
154  {
155  trackRange = mOutputTracks->SelectedLeaders< WaveTrack >();
156  refreshIter = false;
157  }
158  else
159  {
160  ++trackRange.first;
161  }
162  }
163 
164  this->ReplaceProcessedTracks(bGoodResult);
165  return bGoodResult;
166 }

References TrackList::Channels(), Effect::CopyInputTracks(), Effect::mOutputTracks, Effect::mProgress, Effect::mProjectRate, ProcessOne(), Effect::ReplaceProcessedTracks(), ProgressDialog::SetMessage(), and XO.

Here is the call graph for this function:

◆ ProcessOne()

bool EffectStereoToMono::ProcessOne ( sampleCount curTime,
sampleCount  totalTime,
WaveTrack left,
WaveTrack right 
)
private

Definition at line 168 of file StereoToMono.cpp.

169 {
170  auto idealBlockLen = left->GetMaxBlockSize() * 2;
171  bool bResult = true;
172  sampleCount processed = 0;
173 
174  auto start = wxMin(left->GetStartTime(), right->GetStartTime());
175  auto end = wxMax(left->GetEndTime(), right->GetEndTime());
176 
177  WaveTrackConstArray tracks;
178  tracks.push_back(left->SharedPointer< const WaveTrack >());
179  tracks.push_back(right->SharedPointer< const WaveTrack >());
180 
181  Mixer mixer(tracks,
182  true, // Throw to abort mix-and-render if read fails:
184  start,
185  end,
186  1,
187  idealBlockLen,
188  false, // Not interleaved
189  left->GetRate(), // Process() checks that left and right
190  // rates are the same
191  floatSample);
192 
193  auto outTrack = left->EmptyCopy();
194  outTrack->ConvertToSampleFormat(floatSample);
195 
196  while (auto blockLen = mixer.Process(idealBlockLen))
197  {
198  auto buffer = mixer.GetBuffer();
199  for (auto i = 0; i < blockLen; i++)
200  {
201  ((float *)buffer)[i] /= 2.0;
202  }
203  outTrack->Append(buffer, floatSample, blockLen);
204 
205  curTime += blockLen;
206  if (TotalProgress(curTime.as_double() / totalTime.as_double()))
207  {
208  return false;
209  }
210  }
211  outTrack->Flush();
212 
213  double minStart = wxMin(left->GetStartTime(), right->GetStartTime());
214  left->Clear(left->GetStartTime(), left->GetEndTime());
215  left->Paste(minStart, outTrack.get());
216  mOutputTracks->UnlinkChannels(*left);
217  mOutputTracks->Remove(right);
218 
219  return bResult;
220 }

References sampleCount::as_double(), WaveTrack::Clear(), WaveTrack::EmptyCopy(), floatSample, WaveTrack::GetEndTime(), WaveTrack::GetMaxBlockSize(), WaveTrack::GetRate(), WaveTrack::GetStartTime(), Effect::inputTracks(), Effect::mOutputTracks, WaveTrack::Paste(), Track::SharedPointer(), and Effect::TotalProgress().

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 EffectStereoToMono::Symbol { XO("Stereo To Mono") }
static

Definition at line 19 of file StereoToMono.h.

Referenced by GetSymbol().


The documentation for this class was generated from the following files:
WaveTrackConstArray
std::vector< std::shared_ptr< const WaveTrack > > WaveTrackConstArray
Definition: AudioIO.h:49
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
Effect::mProgress
ProgressDialog * mProgress
Definition: Effect.h:457
WaveTrack::GetEndTime
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:1895
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:2071
Mixer::WarpOptions
Definition: Mix.h:81
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
EffectStereoToMono::ProcessOne
bool ProcessOne(sampleCount &curTime, sampleCount totalTime, WaveTrack *left, WaveTrack *right)
Definition: StereoToMono.cpp:168
Track::SharedPointer
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:291
XO
#define XO(s)
Definition: Internat.h:31
WaveTrack::EmptyCopy
Holder EmptyCopy(const SampleBlockFactoryPtr &pFactory={}) const
Definition: WaveTrack.cpp:666
ProgressDialog::SetMessage
void SetMessage(const TranslatableString &message)
Definition: ProgressDialog.cpp:1510
floatSample
@ floatSample
Definition: SampleFormat.h:34
Effect::mProjectRate
double mProjectRate
Definition: Effect.h:458
WaveTrack::Clear
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:751
Effect::inputTracks
const TrackList * inputTracks() const
Definition: Effect.h:463
sampleCount::as_double
double as_double() const
Definition: SampleCount.h:45
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2193
WaveTrack::Paste
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1259
WaveTrack::GetStartTime
double GetStartTime() const override
Get the time at which the first clip in the track starts.
Definition: WaveTrack.cpp:1875
EffectTypeHidden
@ EffectTypeHidden
Definition: EffectInterface.h:57
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:465
WaveTrack::GetMaxBlockSize
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:1669
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
Effect::TotalProgress
bool TotalProgress(double frac, const TranslatableString &={})
Definition: Effect.cpp:2017
Mixer
Functions for doing the mixdown of the tracks.
Definition: Mix.h:76
EffectStereoToMono::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: StereoToMono.h:19
WaveTrack::GetRate
double GetRate() const
Definition: WaveTrack.cpp:452