Audacity  3.2.0
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
 Type determines how it behaves. More...
 
bool IsInteractive () override
 Whether the effect needs a dialog for entry of settings. More...
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
bool Process () override
 
bool IsHiddenFromMenus () override
 Default is false. More...
 
- 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
 
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...
 
- 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("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 }
 
- 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

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

Type determines how it behaves.

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.

◆ IsHiddenFromMenus()

bool EffectStereoToMono::IsHiddenFromMenus ( )
overridevirtual

Default is false.

Reimplemented from EffectDefinitionInterface.

Definition at line 222 of file StereoToMono.cpp.

223 {
224  return true;
225 }

◆ IsInteractive()

bool EffectStereoToMono::IsInteractive ( )
overridevirtual

Whether the effect needs a dialog for entry of settings.

Reimplemented from Effect.

Definition at line 60 of file StereoToMono.cpp.

61 {
62  return false;
63 }

◆ Process()

bool EffectStereoToMono::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.

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(), BasicUI::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  SampleTrackConstArray tracks;
178  tracks.push_back(left->SharedPointer< const SampleTrack >());
179  tracks.push_back(right->SharedPointer< const SampleTrack >());
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:
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:75
WaveTrack::GetEndTime
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:2014
SampleTrackConstArray
std::vector< std::shared_ptr< const SampleTrack > > SampleTrackConstArray
Definition: Mix.h:33
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:1834
SampleTrack
Definition: SampleTrack.h:21
Mixer::WarpOptions
Definition: Mix.h:63
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1483
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:276
XO
#define XO(s)
Definition: Internat.h:31
BasicUI::ProgressDialog::SetMessage
virtual void SetMessage(const TranslatableString &message)=0
Change an existing dialog's message.
WaveTrack::EmptyCopy
Holder EmptyCopy(const SampleBlockFactoryPtr &pFactory={}) const
Definition: WaveTrack.cpp:709
floatSample
@ floatSample
Definition: SampleFormat.h:34
Effect::mProjectRate
double mProjectRate
Definition: Effect.h:416
WaveTrack::Clear
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:790
Effect::inputTracks
const TrackList * inputTracks() const
Definition: Effect.h:420
sampleCount::as_double
double as_double() const
Definition: SampleCount.h:45
Effect::mProgress
BasicUI::ProgressDialog * mProgress
Definition: Effect.h:415
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:1956
WaveTrack::Paste
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1568
WaveTrack::GetStartTime
double GetStartTime() const override
Get the time at which the first clip in the track starts.
Definition: WaveTrack.cpp:1994
EffectTypeHidden
@ EffectTypeHidden
Definition: EffectInterface.h:54
WaveTrack::GetMaxBlockSize
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1811
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:422
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
WaveTrack::GetRate
double GetRate() const override
Definition: WaveTrack.cpp:495
Effect::TotalProgress
bool TotalProgress(double frac, const TranslatableString &={})
Definition: Effect.cpp:1780
Mixer
Functions for doing the mixdown of the tracks.
Definition: Mix.h:58
EffectStereoToMono::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: StereoToMono.h:19