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

An Effect that makes a sound louder or softer. More...

#include <Amplify.h>

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

Public Member Functions

 EffectAmplify ()
 
virtual ~EffectAmplify ()
 
IdentInterfaceSymbol GetSymbol () override
 
wxString GetDescription () override
 
wxString ManualPage () override
 
EffectType GetType () override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 
bool DefineParams (ShuttleParams &S) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool LoadFactoryDefaults () override
 
bool Init () override
 
void Preview (bool dryOnly) override
 
void PopulateOrExchange (ShuttleGui &S) override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () 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 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 ()
 

Private Member Functions

void OnAmpText (wxCommandEvent &evt)
 
void OnPeakText (wxCommandEvent &evt)
 
void OnAmpSlider (wxCommandEvent &evt)
 
void OnClipCheckBox (wxCommandEvent &evt)
 
void CheckClip ()
 

Private Attributes

double mPeak
 
double mRatio
 
double mRatioClip
 
double mAmp
 
double mNewPeak
 
bool mCanClip
 
wxSlider * mAmpS
 
wxTextCtrl * mAmpT
 
wxTextCtrl * mNewPeakT
 
wxCheckBox * mClip
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Protected Member Functions inherited from Effect
virtual bool PromptUser (wxWindow *parent)
 
virtual bool CheckWhetherSkipEffect ()
 
virtual bool Process ()
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual int GetPass ()
 
virtual void End ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
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 that makes a sound louder or softer.

This rewritten class supports a smart Amplify effect - it calculates the maximum amount of gain that can be applied to all tracks without causing clipping and selects this as the default parameter.

Definition at line 30 of file Amplify.h.

Constructor & Destructor Documentation

EffectAmplify::EffectAmplify ( )

Definition at line 66 of file Amplify.cpp.

References DB_TO_LINEAR().

67 {
68  mAmp = DEF_Amp;
70  mRatioClip = 0.0;
71  mCanClip = false;
72  mPeak = 0.0;
73 
74  SetLinearEffectFlag(true);
75 }
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1961
double mRatio
Definition: Amplify.h:76
bool mCanClip
Definition: Amplify.h:80
double mPeak
Definition: Amplify.h:74
double mRatioClip
Definition: Amplify.h:77
double mAmp
Definition: Amplify.h:78
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
EffectAmplify::~EffectAmplify ( )
virtual

Definition at line 77 of file Amplify.cpp.

78 {
79 }

Member Function Documentation

void EffectAmplify::CheckClip ( )
private

Definition at line 330 of file Amplify.cpp.

References Effect::EnableApply(), mClip, mPeak, mRatio, and mRatioClip.

Referenced by OnAmpSlider(), OnAmpText(), OnClipCheckBox(), OnPeakText(), and TransferDataToWindow().

331 {
332  EnableApply(mClip->GetValue() || (mPeak > 0.0 && mRatio <= mRatioClip));
333 }
double mRatio
Definition: Amplify.h:76
wxCheckBox * mClip
Definition: Amplify.h:85
double mPeak
Definition: Amplify.h:74
double mRatioClip
Definition: Amplify.h:77
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1886
bool EffectAmplify::DefineParams ( ShuttleParams S)
override

Definition at line 127 of file Amplify.cpp.

References Effect::IsBatchProcessing(), mCanClip, and mRatio.

127  {
128  S.SHUTTLE_PARAM( mRatio, Ratio );
129  if (!IsBatchProcessing())
130  S.SHUTTLE_PARAM( mCanClip, Clipping );
131  return true;
132 }
double mRatio
Definition: Amplify.h:76
bool mCanClip
Definition: Amplify.h:80
virtual bool IsBatchProcessing()
Definition: Effect.cpp:1137
unsigned EffectAmplify::GetAudioInCount ( )
overridevirtual

Implements EffectClientInterface.

Definition at line 108 of file Amplify.cpp.

109 {
110  return 1;
111 }
unsigned EffectAmplify::GetAudioOutCount ( )
overridevirtual

Implements EffectClientInterface.

Definition at line 113 of file Amplify.cpp.

114 {
115  return 1;
116 }
bool EffectAmplify::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Implements EffectClientInterface.

Definition at line 134 of file Amplify.cpp.

References Effect::IsBatchProcessing(), mCanClip, mRatio, and CommandParameters::WriteFloat().

135 {
136  parms.WriteFloat(KEY_Ratio, mRatio);
137  if (!IsBatchProcessing())
138  parms.WriteFloat(KEY_Clipping, mCanClip);
139 
140  return true;
141 }
double mRatio
Definition: Amplify.h:76
bool WriteFloat(const wxString &key, float f)
bool mCanClip
Definition: Amplify.h:80
virtual bool IsBatchProcessing()
Definition: Effect.cpp:1137
wxString EffectAmplify::GetDescription ( )
overridevirtual

Implements IdentInterface.

Definition at line 88 of file Amplify.cpp.

References _().

89 {
90  // Note: This is useful only after ratio has been set.
91  return _("Increases or decreases the volume of the audio you have selected");
92 }
_("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 EffectAmplify::GetSymbol ( )
overridevirtual

Implements IdentInterface.

Definition at line 83 of file Amplify.cpp.

References AMPLIFY_PLUGIN_SYMBOL.

84 {
85  return AMPLIFY_PLUGIN_SYMBOL;
86 }
#define AMPLIFY_PLUGIN_SYMBOL
Definition: Amplify.h:26
EffectType EffectAmplify::GetType ( )
overridevirtual

Implements EffectDefinitionInterface.

Definition at line 101 of file Amplify.cpp.

References EffectTypeProcess.

102 {
103  return EffectTypeProcess;
104 }
bool EffectAmplify::Init ( )
overridevirtual

Reimplemented from Effect.

Definition at line 179 of file Amplify.cpp.

References TrackListCondIterator::First(), Effect::inputTracks(), min(), mPeak, Effect::mT0, Effect::mT1, TrackListCondIterator::Next(), and Track::Wave.

Referenced by LoadFactoryDefaults().

180 {
181  mPeak = 0.0;
182 
184 
185  for (Track *t = iter.First(); t; t = iter.Next())
186  {
187  auto pair = ((WaveTrack *)t)->GetMinMax(mT0, mT1); // may throw
188  const float min = pair.first, max = pair.second;
189  float newpeak = (fabs(min) > fabs(max) ? fabs(min) : fabs(max));
190 
191  if (newpeak > mPeak)
192  {
193  mPeak = newpeak;
194  }
195  }
196 
197  return true;
198 }
double mT1
Definition: Effect.h:461
TrackList * inputTracks() const
Definition: Effect.h:458
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
int min(int a, int b)
double mPeak
Definition: Amplify.h:74
double mT0
Definition: Effect.h:460
bool EffectAmplify::LoadFactoryDefaults ( )
overridevirtual

Implements EffectClientInterface.

Definition at line 158 of file Amplify.cpp.

References Init(), mCanClip, mPeak, mRatio, mRatioClip, and TransferDataToWindow().

159 {
160  Init();
161 
162  mRatioClip = 0.0;
163  if (mPeak > 0.0)
164  {
165  mRatio = 1.0 / mPeak;
166  mRatioClip = mRatio;
167  }
168  else
169  {
170  mRatio = 1.0;
171  }
172  mCanClip = false;
173 
174  return TransferDataToWindow();
175 }
double mRatio
Definition: Amplify.h:76
bool TransferDataToWindow() override
Definition: Amplify.cpp:286
bool Init() override
Definition: Amplify.cpp:179
bool mCanClip
Definition: Amplify.h:80
double mPeak
Definition: Amplify.h:74
double mRatioClip
Definition: Amplify.h:77
wxString EffectAmplify::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 94 of file Amplify.cpp.

95 {
96  return wxT("Amplify");
97 }
void EffectAmplify::OnAmpSlider ( wxCommandEvent &  evt)
private

Definition at line 378 of file Amplify.cpp.

References CheckClip(), DB_TO_LINEAR(), LINEAR_TO_DB, mAmp, mAmpT, mClip, mNewPeak, mNewPeakT, mPeak, mRatio, and TrapDouble().

379 {
380  double dB = evt.GetInt() / SCL_Amp;
381  mRatio = DB_TO_LINEAR(TrapDouble(dB, MIN_Amp, MAX_Amp));
382 
383  double dB2 = (evt.GetInt() - 1) / SCL_Amp;
384  double ratio2 = DB_TO_LINEAR(TrapDouble(dB2, MIN_Amp, MAX_Amp));
385 
386  if (!mClip->GetValue() && mRatio * mPeak > 1.0 && ratio2 * mPeak < 1.0)
387  {
388  mRatio = 1.0 / mPeak;
389  }
390 
392  mAmpT->GetValidator()->TransferToWindow();
393 
395  mNewPeakT->GetValidator()->TransferToWindow();
396 
397  CheckClip();
398 }
wxTextCtrl * mNewPeakT
Definition: Amplify.h:84
double mRatio
Definition: Amplify.h:76
wxCheckBox * mClip
Definition: Amplify.h:85
void CheckClip()
Definition: Amplify.cpp:330
double mPeak
Definition: Amplify.h:74
double TrapDouble(double x, double min, double max)
Definition: Effect.h:729
#define LINEAR_TO_DB(x)
Definition: Audacity.h:217
double mAmp
Definition: Amplify.h:78
wxTextCtrl * mAmpT
Definition: Amplify.h:83
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
double mNewPeak
Definition: Amplify.h:79
void EffectAmplify::OnAmpText ( wxCommandEvent &  evt)
private

Definition at line 335 of file Amplify.cpp.

References CheckClip(), DB_TO_LINEAR(), Effect::EnableApply(), LINEAR_TO_DB, mAmp, mAmpS, mAmpT, mNewPeak, mNewPeakT, mPeak, mRatio, and TrapDouble().

336 {
337  if (!mAmpT->GetValidator()->TransferFromWindow())
338  {
339  EnableApply(false);
340  return;
341  }
342 
343  mRatio = DB_TO_LINEAR(TrapDouble(mAmp * SCL_Amp, MIN_Amp * SCL_Amp, MAX_Amp * SCL_Amp) / SCL_Amp);
344 
345  mAmpS->SetValue((int) (LINEAR_TO_DB(mRatio) * SCL_Amp + 0.5));
346 
348  mNewPeakT->GetValidator()->TransferToWindow();
349 
350  CheckClip();
351 }
wxTextCtrl * mNewPeakT
Definition: Amplify.h:84
double mRatio
Definition: Amplify.h:76
void CheckClip()
Definition: Amplify.cpp:330
wxSlider * mAmpS
Definition: Amplify.h:82
double mPeak
Definition: Amplify.h:74
double TrapDouble(double x, double min, double max)
Definition: Effect.h:729
#define LINEAR_TO_DB(x)
Definition: Audacity.h:217
double mAmp
Definition: Amplify.h:78
wxTextCtrl * mAmpT
Definition: Amplify.h:83
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
double mNewPeak
Definition: Amplify.h:79
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1886
void EffectAmplify::OnClipCheckBox ( wxCommandEvent &  evt)
private

Definition at line 400 of file Amplify.cpp.

References CheckClip().

401 {
402  CheckClip();
403 }
void CheckClip()
Definition: Amplify.cpp:330
void EffectAmplify::OnPeakText ( wxCommandEvent &  evt)
private

Definition at line 353 of file Amplify.cpp.

References CheckClip(), DB_TO_LINEAR(), Effect::EnableApply(), LINEAR_TO_DB, mAmp, mAmpS, mAmpT, mNewPeak, mNewPeakT, mPeak, mRatio, mRatioClip, and TrapDouble().

354 {
355  if (!mNewPeakT->GetValidator()->TransferFromWindow())
356  {
357  EnableApply(false);
358  return;
359  }
360 
361  if (mNewPeak == 0.0)
362  mRatio = mRatioClip;
363  else
365 
366  double ampInit = LINEAR_TO_DB(mRatio);
367  mAmp = TrapDouble(ampInit, MIN_Amp, MAX_Amp);
368  if (mAmp != ampInit)
370 
371  mAmpT->GetValidator()->TransferToWindow();
372 
373  mAmpS->SetValue((int) (mAmp * SCL_Amp + 0.5f));
374 
375  CheckClip();
376 }
wxTextCtrl * mNewPeakT
Definition: Amplify.h:84
double mRatio
Definition: Amplify.h:76
void CheckClip()
Definition: Amplify.cpp:330
wxSlider * mAmpS
Definition: Amplify.h:82
double mPeak
Definition: Amplify.h:74
double TrapDouble(double x, double min, double max)
Definition: Effect.h:729
#define LINEAR_TO_DB(x)
Definition: Audacity.h:217
double mRatioClip
Definition: Amplify.h:77
double mAmp
Definition: Amplify.h:78
wxTextCtrl * mAmpT
Definition: Amplify.h:83
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
double mNewPeak
Definition: Amplify.h:79
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1886
void EffectAmplify::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 208 of file Amplify.cpp.

References _(), ShuttleGuiBase::AddCheckBox(), ShuttleGuiBase::AddSlider(), ShuttleGui::AddSpace(), ShuttleGuiBase::AddTextBox(), Internat::CompatibleToDouble(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndVerticalLay(), ShuttleGui::Id(), ID_Amp, ID_Clip, ID_Peak, Effect::IsBatchProcessing(), LINEAR_TO_DB, mAmp, mAmpS, mAmpT, mCanClip, mClip, mNewPeak, mNewPeakT, mPeak, mRatio, mRatioClip, ShuttleGuiBase::SetStyle(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), ShuttleGuiBase::StartVerticalLay(), and Internat::ToString().

209 {
210  if (IsBatchProcessing())
211  {
212  mPeak = 1.0;
213  }
214  else
215  {
216  if (mPeak > 0.0)
217  {
218  mRatio = 1.0 / mPeak;
219  mRatioClip = mRatio;
220  }
221  else
222  {
223  mRatio = 1.0;
224  }
225  }
226 
227  S.AddSpace(0, 5);
228 
229  S.StartVerticalLay(0);
230  {
231  int precission = 3; // allow (a generous) 3 decimal places for Amplification (dB)
232  // Amplitude
233  S.StartMultiColumn(2, wxCENTER);
234  {
235  FloatingPointValidator<double> vldAmp(precission, &mAmp, NumValidatorStyle::ONE_TRAILING_ZERO);
236  vldAmp.SetRange(MIN_Amp, MAX_Amp);
237  mAmpT = S.Id(ID_Amp).AddTextBox(_("Amplification (dB):"), wxT(""), 12);
238  mAmpT->SetValidator(vldAmp);
239  }
240  S.EndMultiColumn();
241 
242  // Amplitude
243  S.StartHorizontalLay(wxEXPAND);
244  {
245  S.SetStyle(wxSL_HORIZONTAL);
246  mAmpS = S.Id(ID_Amp).AddSlider( {}, 0, MAX_Amp * SCL_Amp, MIN_Amp * SCL_Amp);
247  mAmpS->SetName(_("Amplification dB"));
248  }
249  S.EndHorizontalLay();
250 
251  // Peak
252  S.StartMultiColumn(2, wxCENTER);
253  {
254  // One extra decimal place so that rounding is visible to user (see: bug 958)
255  FloatingPointValidator<double> vldNewPeak(precission + 1, &mNewPeak, NumValidatorStyle::ONE_TRAILING_ZERO);
256  double minAmp = MIN_Amp + LINEAR_TO_DB(mPeak);
257  double maxAmp = MAX_Amp + LINEAR_TO_DB(mPeak);
258 
259  // min and max need same precision as what we're validating (bug 963)
260  minAmp = Internat::CompatibleToDouble(Internat::ToString(minAmp, precission +1));
261  maxAmp = Internat::CompatibleToDouble(Internat::ToString(maxAmp, precission +1));
262 
263  vldNewPeak.SetRange(minAmp, maxAmp);
264  mNewPeakT = S.Id(ID_Peak).AddTextBox(_("New Peak Amplitude (dB):"), wxT(""), 12);
265  mNewPeakT->SetValidator(vldNewPeak);
266  }
267  S.EndMultiColumn();
268 
269  // Clipping
270  S.StartHorizontalLay(wxCENTER);
271  {
272  mClip = S.Id(ID_Clip).AddCheckBox(_("Allow clipping"), wxT("false"));
273  if (IsBatchProcessing())
274  {
275  mClip->Enable(false);
276  mCanClip = true;
277  }
278  }
279  S.EndHorizontalLay();
280  }
281  S.EndVerticalLay();
282 
283  return;
284 }
wxTextCtrl * mNewPeakT
Definition: Amplify.h:84
double mRatio
Definition: Amplify.h:76
void EndMultiColumn()
wxCheckBox * mClip
Definition: Amplify.h:85
void EndHorizontalLay()
void EndVerticalLay()
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:138
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
wxCheckBox * AddCheckBox(const wxString &Prompt, const wxString &Selected)
Definition: ShuttleGui.cpp:298
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:122
bool mCanClip
Definition: Amplify.h:80
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
ShuttleGui & Id(int id)
void SetStyle(int Style)
Definition: ShuttleGui.h:287
wxSlider * mAmpS
Definition: Amplify.h:82
double mPeak
Definition: Amplify.h:74
_("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
#define LINEAR_TO_DB(x)
Definition: Audacity.h:217
double mRatioClip
Definition: Amplify.h:77
double mAmp
Definition: Amplify.h:78
virtual bool IsBatchProcessing()
Definition: Effect.cpp:1137
wxSizerItem * AddSpace(int width, int height)
wxTextCtrl * mAmpT
Definition: Amplify.h:83
double mNewPeak
Definition: Amplify.h:79
wxSlider * AddSlider(const wxString &Prompt, int pos, int Max, int Min=0)
Definition: ShuttleGui.cpp:497
void StartVerticalLay(int iProp=1)
void EffectAmplify::Preview ( bool  dryOnly)
overridevirtual

Reimplemented from Effect.

Definition at line 200 of file Amplify.cpp.

References mPeak, mRatio, Effect::Preview(), and valueRestorer().

201 {
202  auto cleanup1 = valueRestorer( mRatio );
203  auto cleanup2 = valueRestorer( mPeak );
204 
205  Effect::Preview(dryOnly);
206 }
double mRatio
Definition: Amplify.h:76
void Preview() override
Definition: Effect.cpp:771
double mPeak
Definition: Amplify.h:74
ValueRestorer< T > valueRestorer(T &var)
Definition: MemoryX.h:494
size_t EffectAmplify::ProcessBlock ( float **  inBlock,
float **  outBlock,
size_t  blockLen 
)
overridevirtual

Implements EffectClientInterface.

Definition at line 118 of file Amplify.cpp.

References mRatio.

119 {
120  for (decltype(blockLen) i = 0; i < blockLen; i++)
121  {
122  outBlock[0][i] = inBlock[0][i] * mRatio;
123  }
124 
125  return blockLen;
126 }
double mRatio
Definition: Amplify.h:76
bool EffectAmplify::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Implements EffectClientInterface.

Definition at line 143 of file Amplify.cpp.

References Effect::IsBatchProcessing(), mCanClip, mRatio, ReadAndVerifyBool, and ReadAndVerifyFloat.

144 {
145  ReadAndVerifyFloat(Ratio);
146  mRatio = Ratio;
147 
148  if (!IsBatchProcessing()){
149  ReadAndVerifyBool(Clipping);
150  mCanClip = Clipping;
151  } else {
152  mCanClip = true;
153  }
154 
155  return true;
156 }
#define ReadAndVerifyFloat(name)
Definition: Effect.h:799
double mRatio
Definition: Amplify.h:76
bool mCanClip
Definition: Amplify.h:80
#define ReadAndVerifyBool(name)
Definition: Effect.h:800
virtual bool IsBatchProcessing()
Definition: Effect.cpp:1137
bool EffectAmplify::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 309 of file Amplify.cpp.

References DB_TO_LINEAR(), mAmp, mCanClip, mClip, mPeak, mRatio, Effect::mUIParent, and TrapDouble().

310 {
311  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
312  {
313  return false;
314  }
315 
316  mRatio = DB_TO_LINEAR(TrapDouble(mAmp * SCL_Amp, MIN_Amp * SCL_Amp, MAX_Amp * SCL_Amp) / SCL_Amp);
317 
318  mCanClip = mClip->GetValue();
319 
320  if (!mCanClip && mRatio * mPeak > 1.0)
321  {
322  mRatio = 1.0 / mPeak;
323  }
324 
325  return true;
326 }
double mRatio
Definition: Amplify.h:76
wxCheckBox * mClip
Definition: Amplify.h:85
bool mCanClip
Definition: Amplify.h:80
double mPeak
Definition: Amplify.h:74
wxWindow * mUIParent
Definition: Effect.h:472
double TrapDouble(double x, double min, double max)
Definition: Effect.h:729
double mAmp
Definition: Amplify.h:78
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
bool EffectAmplify::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 286 of file Amplify.cpp.

References CheckClip(), DB_TO_LINEAR(), LINEAR_TO_DB, mAmp, mAmpS, mAmpT, mCanClip, mClip, mNewPeak, mNewPeakT, mPeak, mRatio, and TrapDouble().

Referenced by LoadFactoryDefaults().

287 {
288  // limit range of gain
289  double dBInit = LINEAR_TO_DB(mRatio);
290  double dB = TrapDouble(dBInit, MIN_Amp, MAX_Amp);
291  if (dB != dBInit)
292  mRatio = DB_TO_LINEAR(dB);
293 
295  mAmpT->GetValidator()->TransferToWindow();
296 
297  mAmpS->SetValue((int) (mAmp * SCL_Amp + 0.5f));
298 
300  mNewPeakT->GetValidator()->TransferToWindow();
301 
302  mClip->SetValue(mCanClip);
303 
304  CheckClip();
305 
306  return true;
307 }
wxTextCtrl * mNewPeakT
Definition: Amplify.h:84
double mRatio
Definition: Amplify.h:76
wxCheckBox * mClip
Definition: Amplify.h:85
bool mCanClip
Definition: Amplify.h:80
void CheckClip()
Definition: Amplify.cpp:330
wxSlider * mAmpS
Definition: Amplify.h:82
double mPeak
Definition: Amplify.h:74
double TrapDouble(double x, double min, double max)
Definition: Effect.h:729
#define LINEAR_TO_DB(x)
Definition: Audacity.h:217
double mAmp
Definition: Amplify.h:78
wxTextCtrl * mAmpT
Definition: Amplify.h:83
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
double mNewPeak
Definition: Amplify.h:79

Member Data Documentation

double EffectAmplify::mAmp
private
wxSlider* EffectAmplify::mAmpS
private

Definition at line 82 of file Amplify.h.

Referenced by OnAmpText(), OnPeakText(), PopulateOrExchange(), and TransferDataToWindow().

wxTextCtrl* EffectAmplify::mAmpT
private
bool EffectAmplify::mCanClip
private
wxCheckBox* EffectAmplify::mClip
private
double EffectAmplify::mNewPeak
private
wxTextCtrl* EffectAmplify::mNewPeakT
private
double EffectAmplify::mPeak
private
double EffectAmplify::mRatio
private
double EffectAmplify::mRatioClip
private

Definition at line 77 of file Amplify.h.

Referenced by CheckClip(), LoadFactoryDefaults(), OnPeakText(), and PopulateOrExchange().


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