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

An Effect that can generate a sine, square or sawtooth wave. An extended mode of EffectToneGen supports 'chirps' where the frequency changes smoothly during the tone. More...

#include <ToneGen.h>

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

Public Member Functions

 EffectToneGen (bool isChirp)
 
virtual ~EffectToneGen ()
 
IdentInterfaceSymbol GetSymbol () override
 
wxString GetDescription () override
 
wxString ManualPage () override
 
EffectType GetType () override
 
unsigned GetAudioOutCount () override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) 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
 
void PopulateOrExchange (ShuttleGui &S) override
 
bool TransferDataFromWindow () override
 
bool TransferDataToWindow () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
wxString GetPath () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () 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
 
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 ProcessFinalize () 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 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 OnControlUpdate (wxCommandEvent &evt)
 

Private Attributes

bool mChirp
 
sampleCount mSample
 
double mPositionInCycles
 
int mWaveform
 
int mInterpolation
 
double mFrequency [2]
 
double mAmplitude [2]
 
double mLogFrequency [2]
 
NumericTextCtrlmToneDurationT
 

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 Process ()
 
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 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 can generate a sine, square or sawtooth wave. An extended mode of EffectToneGen supports 'chirps' where the frequency changes smoothly during the tone.

Definition at line 28 of file ToneGen.h.

Constructor & Destructor Documentation

EffectToneGen::EffectToneGen ( bool  isChirp)

Definition at line 86 of file ToneGen.cpp.

References nInterpolations, and nWaveforms.

87 {
88  wxASSERT(nWaveforms == WXSIZEOF(kWaveStrings));
89  wxASSERT(nInterpolations == WXSIZEOF(kInterStrings));
90 
91  mChirp = isChirp;
92 
93  mWaveform = DEF_Waveform;
94  mFrequency[0] = DEF_StartFreq;
95  mFrequency[1] = DEF_EndFreq;
96  mAmplitude[0] = DEF_StartAmp;
97  mAmplitude[1] = DEF_EndAmp;
98  mInterpolation = DEF_Interp;
99 
100  // Chirp varies over time so must use selected duration.
101  // TODO: When previewing, calculate only the first 'preview length'.
102  if (isChirp)
103  SetLinearEffectFlag(false);
104  else
105  SetLinearEffectFlag(true);
106 }
int mInterpolation
Definition: ToneGen.h:75
static const IdentInterfaceSymbol kInterStrings[nInterpolations]
Definition: ToneGen.cpp:42
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1961
double mFrequency[2]
Definition: ToneGen.h:76
double mAmplitude[2]
Definition: ToneGen.h:77
bool mChirp
Definition: ToneGen.h:65
static const IdentInterfaceSymbol kWaveStrings[nWaveforms]
Definition: ToneGen.cpp:58
int mWaveform
Definition: ToneGen.h:74
EffectToneGen::~EffectToneGen ( )
virtual

Definition at line 108 of file ToneGen.cpp.

109 {
110 }

Member Function Documentation

bool EffectToneGen::DefineParams ( ShuttleParams S)
override

Definition at line 248 of file ToneGen.cpp.

References mAmplitude, mChirp, mFrequency, mInterpolation, mWaveform, nInterpolations, and nWaveforms.

248  {
249  if( mChirp ){
250  S.SHUTTLE_PARAM( mFrequency[0], StartFreq );
251  S.SHUTTLE_PARAM( mFrequency[1], EndFreq );
252  S.SHUTTLE_PARAM( mAmplitude[0], StartAmp );
253  S.SHUTTLE_PARAM( mAmplitude[1], EndAmp );
254  } else {
255  S.SHUTTLE_PARAM( mFrequency[0], Frequency );
256  S.SHUTTLE_PARAM( mAmplitude[0], Amplitude );
257  // Slightly hacky way to set freq and ampl
258  // since we do this whatever query to params was made.
259  mFrequency[1] = mFrequency[0];
260  mAmplitude[1] = mAmplitude[0];
261  }
262  S.SHUTTLE_ENUM_PARAM( mWaveform, Waveform, kWaveStrings, nWaveforms );
263  S.SHUTTLE_ENUM_PARAM( mInterpolation, Interp, kInterStrings, nInterpolations );
264 
265 
266 // double freqMax = (GetActiveProject() ? GetActiveProject()->GetRate() : 44100.0) / 2.0;
267 // mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax);
268 
269 
270  return true;
271 }
int mInterpolation
Definition: ToneGen.h:75
static const IdentInterfaceSymbol kInterStrings[nInterpolations]
Definition: ToneGen.cpp:42
double mFrequency[2]
Definition: ToneGen.h:76
double mAmplitude[2]
Definition: ToneGen.h:77
bool mChirp
Definition: ToneGen.h:65
static const IdentInterfaceSymbol kWaveStrings[nWaveforms]
Definition: ToneGen.cpp:58
int mWaveform
Definition: ToneGen.h:74
unsigned EffectToneGen::GetAudioOutCount ( )
overridevirtual

Reimplemented from Effect.

Definition at line 144 of file ToneGen.cpp.

145 {
146  return 1;
147 }
bool EffectToneGen::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 273 of file ToneGen.cpp.

References mAmplitude, mChirp, mFrequency, mInterpolation, and mWaveform.

274 {
275  if (mChirp)
276  {
277  parms.Write(KEY_StartFreq, mFrequency[0]);
278  parms.Write(KEY_EndFreq, mFrequency[1]);
279  parms.Write(KEY_StartAmp, mAmplitude[0]);
280  parms.Write(KEY_EndAmp, mAmplitude[1]);
281  }
282  else
283  {
284  parms.Write(KEY_Frequency, mFrequency[0]);
285  parms.Write(KEY_Amplitude, mAmplitude[0]);
286  }
287 
288  parms.Write(KEY_Waveform, kWaveStrings[mWaveform].Internal());
289  parms.Write(KEY_Interp, kInterStrings[mInterpolation].Internal());
290 
291  return true;
292 }
int mInterpolation
Definition: ToneGen.h:75
static const IdentInterfaceSymbol kInterStrings[nInterpolations]
Definition: ToneGen.cpp:42
double mFrequency[2]
Definition: ToneGen.h:76
double mAmplitude[2]
Definition: ToneGen.h:77
bool mChirp
Definition: ToneGen.h:65
static const IdentInterfaceSymbol kWaveStrings[nWaveforms]
Definition: ToneGen.cpp:58
int mWaveform
Definition: ToneGen.h:74
wxString EffectToneGen::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 121 of file ToneGen.cpp.

References _(), and mChirp.

122 {
123  return mChirp
124  ? _("Generates an ascending or descending tone of one of four types")
125  : _("Generates a constant frequency tone of one of four types");
126 }
bool mChirp
Definition: ToneGen.h:65
_("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 EffectToneGen::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 114 of file ToneGen.cpp.

References CHIRP_PLUGIN_SYMBOL, mChirp, and TONE_PLUGIN_SYMBOL.

115 {
116  return mChirp
119 }
#define TONE_PLUGIN_SYMBOL
Definition: ToneGen.h:26
#define CHIRP_PLUGIN_SYMBOL
Definition: ToneGen.h:25
bool mChirp
Definition: ToneGen.h:65
EffectType EffectToneGen::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 137 of file ToneGen.cpp.

References EffectTypeGenerate.

138 {
139  return EffectTypeGenerate;
140 }
wxString EffectToneGen::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 128 of file ToneGen.cpp.

References mChirp.

129 {
130  return mChirp
131  ? wxT("Chirp")
132  : wxT("Tone");
133 }
bool mChirp
Definition: ToneGen.h:65
void EffectToneGen::OnControlUpdate ( wxCommandEvent &  evt)
private

Definition at line 475 of file ToneGen.cpp.

References Effect::EnableApply(), and Effect::mUIParent.

476 {
477  if (!EnableApply(mUIParent->TransferDataFromWindow()))
478  {
479  return;
480  }
481 }
wxWindow * mUIParent
Definition: Effect.h:472
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1886
void EffectToneGen::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 330 of file ToneGen.cpp.

References _(), ShuttleGuiBase::AddChoice(), ShuttleGuiBase::AddFixedText(), ShuttleGuiBase::AddPrompt(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::AddTitle(), ShuttleGuiBase::AddWindow(), NumericTextCtrl::Options::AutoPos(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), GetActiveProject(), Effect::GetDuration(), Effect::GetDurationFormat(), ShuttleGuiBase::GetParent(), LocalizedStrings(), mAmplitude, mChirp, mFrequency, mInterpolation, Effect::mProjectRate, mToneDurationT, mWaveform, nInterpolations, nWaveforms, safenew, ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), and NumericConverter::TIME.

331 {
332  wxTextCtrl *t;
333 
334  S.StartMultiColumn(2, wxCENTER);
335  {
336  auto waveforms = LocalizedStrings(kWaveStrings, nWaveforms);
337  wxChoice *c = S.AddChoice(_("Waveform:"), wxT(""), &waveforms);
338  c->SetValidator(wxGenericValidator(&mWaveform));
339 
340  if (mChirp)
341  {
342  S.AddFixedText( {} );
343  S.StartHorizontalLay(wxEXPAND);
344  {
345  S.StartHorizontalLay(wxLEFT, 50);
346  {
347  S.AddTitle(_("Start"));
348  }
349  S.EndHorizontalLay();
350 
351  S.StartHorizontalLay(wxLEFT, 50);
352  {
353  S.AddTitle(_("End"));
354  }
355  S.EndHorizontalLay();
356  }
357  S.EndHorizontalLay();
358 
359  S.AddPrompt(_("Frequency (Hz):"));
360  S.StartHorizontalLay(wxEXPAND);
361  {
362  S.StartHorizontalLay(wxLEFT, 50);
363  {
364  FloatingPointValidator<double> vldStartFreq(6, &mFrequency[0], NumValidatorStyle::NO_TRAILING_ZEROES);
365  vldStartFreq.SetRange(MIN_StartFreq, GetActiveProject()->GetRate() / 2.0);
366  t = S.AddTextBox( {}, wxT(""), 12);
367  t->SetName(_("Frequency Hertz Start"));
368  t->SetValidator(vldStartFreq);
369  }
370  S.EndHorizontalLay();
371 
372  S.StartHorizontalLay(wxLEFT, 50);
373  {
374  FloatingPointValidator<double> vldEndFreq(6, &mFrequency[1], NumValidatorStyle::NO_TRAILING_ZEROES);
375  vldEndFreq.SetRange(MIN_EndFreq, GetActiveProject()->GetRate() / 2.0);
376  t = S.AddTextBox( {}, wxT(""), 12);
377  t->SetName(_("Frequency Hertz End"));
378  t->SetValidator(vldEndFreq);
379  }
380  S.EndHorizontalLay();
381  }
382  S.EndHorizontalLay();
383 
384  S.AddPrompt(_("Amplitude (0-1):"));
385  S.StartHorizontalLay(wxEXPAND);
386  {
387  S.StartHorizontalLay(wxLEFT, 50);
388  {
389  FloatingPointValidator<double> vldStartAmp(6, &mAmplitude[0], NumValidatorStyle::NO_TRAILING_ZEROES);
390  vldStartAmp.SetRange(MIN_StartAmp, MAX_StartAmp);
391  t = S.AddTextBox( {}, wxT(""), 12);
392  t->SetName(_("Amplitude Start"));
393  t->SetValidator(vldStartAmp);
394  }
395  S.EndHorizontalLay();
396 
397  S.StartHorizontalLay(wxLEFT, 50);
398  {
399  FloatingPointValidator<double> vldEndAmp(6, &mAmplitude[1], NumValidatorStyle::NO_TRAILING_ZEROES);
400  vldEndAmp.SetRange(MIN_EndAmp, MAX_EndAmp);
401  t = S.AddTextBox( {}, wxT(""), 12);
402  t->SetName(_("Amplitude End"));
403  t->SetValidator(vldEndAmp);
404  }
405  S.EndHorizontalLay();
406  }
407  S.EndHorizontalLay();
408 
409  auto interpolations = LocalizedStrings(kInterStrings, nInterpolations);
410  c = S.AddChoice(_("Interpolation:"), wxT(""), &interpolations);
411  c->SetValidator(wxGenericValidator(&mInterpolation));
412  }
413  else
414  {
415  FloatingPointValidator<double> vldFrequency(6, &mFrequency[0], NumValidatorStyle::NO_TRAILING_ZEROES);
416  vldFrequency.SetRange(MIN_Frequency, GetActiveProject()->GetRate() / 2.0);
417  t = S.AddTextBox(_("Frequency (Hz):"), wxT(""), 12);
418  t->SetValidator(vldFrequency);
419 
420  FloatingPointValidator<double> vldAmplitude(6, &mAmplitude[0], NumValidatorStyle::NO_TRAILING_ZEROES);
421  vldAmplitude.SetRange(MIN_Amplitude, MAX_Amplitude);
422  t = S.AddTextBox(_("Amplitude (0-1):"), wxT(""), 12);
423  t->SetValidator(vldAmplitude);
424  }
425 
426  S.AddPrompt(_("Duration:"));
428  NumericTextCtrl(S.GetParent(), wxID_ANY,
431  GetDuration(),
432  mProjectRate,
434  .AutoPos(true));
435  mToneDurationT->SetName(_("Duration"));
436  S.AddWindow(mToneDurationT, wxALIGN_LEFT | wxALL);
437  }
438  S.EndMultiColumn();
439 
440  return;
441 }
int mInterpolation
Definition: ToneGen.h:75
static const IdentInterfaceSymbol kInterStrings[nInterpolations]
Definition: ToneGen.cpp:42
double GetDuration() override
Definition: Effect.cpp:722
wxWindow * AddWindow(wxWindow *pWindow, int Flags=wxALIGN_CENTRE|wxALL)
Definition: ShuttleGui.cpp:288
double mFrequency[2]
Definition: ToneGen.h:76
wxArrayString LocalizedStrings(const IdentInterfaceSymbol strings[], size_t nStrings)
Definition: Internat.cpp:303
void EndMultiColumn()
NumericFormatId GetDurationFormat() override
Definition: Effect.cpp:732
#define safenew
Definition: Audacity.h:230
void EndHorizontalLay()
void AddPrompt(const wxString &Prompt)
Right aligned text string.
Definition: ShuttleGui.cpp:239
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
double mAmplitude[2]
Definition: ToneGen.h:77
wxWindow * GetParent()
Definition: ShuttleGui.h:294
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
wxChoice * AddChoice(const wxString &Prompt, const wxString &Selected, const wxArrayString *pChoices)
Definition: ShuttleGui.cpp:371
void AddFixedText(const wxString &Str, bool bCenter=false)
Definition: ShuttleGui.cpp:397
void AddTitle(const wxString &Prompt)
Centred text string.
Definition: ShuttleGui.cpp:274
NumericTextCtrl * mToneDurationT
Definition: ToneGen.h:80
double mProjectRate
Definition: Effect.h:453
bool mChirp
Definition: ToneGen.h:65
_("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
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
Options & AutoPos(bool value)
static const IdentInterfaceSymbol kWaveStrings[nWaveforms]
Definition: ToneGen.cpp:58
int mWaveform
Definition: ToneGen.h:74
size_t EffectToneGen::ProcessBlock ( float **  inBlock,
float **  outBlock,
size_t  blockLen 
)
overridevirtual

Reimplemented from Effect.

Definition at line 157 of file ToneGen.cpp.

References sampleCount::as_double(), kLogarithmic, kSawtooth, kSine, kSquare, kSquareNoAlias, M_PI, mAmplitude, mFrequency, mInterpolation, mLogFrequency, mPositionInCycles, mSample, Effect::mSampleCnt, Effect::mSampleRate, and mWaveform.

158 {
159  float *buffer = outBlock[0];
160  double throwaway = 0; //passed to modf but never used
161  double f = 0.0;
162  double a, b;
163  int k;
164 
165  double frequencyQuantum;
166  double BlendedFrequency;
167  double BlendedAmplitude;
168  double BlendedLogFrequency = 0.0;
169 
170  // calculate delta, and reposition from where we left
171  auto doubleSampleCount = mSampleCnt.as_double();
172  auto doubleSample = mSample.as_double();
173  double amplitudeQuantum =
174  (mAmplitude[1] - mAmplitude[0]) / doubleSampleCount;
175  BlendedAmplitude = mAmplitude[0] +
176  amplitudeQuantum * doubleSample;
177 
178  // precalculations:
179  double pre2PI = 2.0 * M_PI;
180  double pre4divPI = 4.0 / M_PI;
181 
182  // initial setup should calculate deltas
184  {
185  // this for log interpolation
186  mLogFrequency[0] = log10(mFrequency[0]);
187  mLogFrequency[1] = log10(mFrequency[1]);
188  // calculate delta, and reposition from where we left
189  frequencyQuantum = (mLogFrequency[1] - mLogFrequency[0]) / doubleSampleCount;
190  BlendedLogFrequency = mLogFrequency[0] + frequencyQuantum * doubleSample;
191  BlendedFrequency = pow(10.0, BlendedLogFrequency);
192  }
193  else
194  {
195  // this for regular case, linear interpolation
196  frequencyQuantum = (mFrequency[1] - mFrequency[0]) / doubleSampleCount;
197  BlendedFrequency = mFrequency[0] + frequencyQuantum * doubleSample;
198  }
199 
200  // synth loop
201  for (decltype(blockLen) i = 0; i < blockLen; i++)
202  {
203  switch (mWaveform)
204  {
205  case kSine:
206  f = sin(pre2PI * mPositionInCycles / mSampleRate);
207  break;
208  case kSquare:
209  f = (modf(mPositionInCycles / mSampleRate, &throwaway) < 0.5) ? 1.0 : -1.0;
210  break;
211  case kSawtooth:
212  f = (2.0 * modf(mPositionInCycles / mSampleRate + 0.5, &throwaway)) - 1.0;
213  break;
214  case kSquareNoAlias: // Good down to 110Hz @ 44100Hz sampling.
215  //do fundamental (k=1) outside loop
216  b = (1.0 + cos((pre2PI * BlendedFrequency) / mSampleRate)) / pre4divPI; //scaling
217  f = pre4divPI * sin(pre2PI * mPositionInCycles / mSampleRate);
218  for (k = 3; (k < 200) && (k * BlendedFrequency < mSampleRate / 2.0); k += 2)
219  {
220  //Hanning Window in freq domain
221  a = 1.0 + cos((pre2PI * k * BlendedFrequency) / mSampleRate);
222  //calc harmonic, apply window, scale to amplitude of fundamental
223  f += a * sin(pre2PI * mPositionInCycles / mSampleRate * k) / (b * k);
224  }
225  }
226  // insert value in buffer
227  buffer[i] = (float) (BlendedAmplitude * f);
228  // update freq,amplitude
229  mPositionInCycles += BlendedFrequency;
230  BlendedAmplitude += amplitudeQuantum;
232  {
233  BlendedLogFrequency += frequencyQuantum;
234  BlendedFrequency = pow(10.0, BlendedLogFrequency);
235  }
236  else
237  {
238  BlendedFrequency += frequencyQuantum;
239  }
240  }
241 
242  // update external placeholder
243  mSample += blockLen;
244 
245  return blockLen;
246 }
int mInterpolation
Definition: ToneGen.h:75
double mLogFrequency[2]
Definition: ToneGen.h:78
double mFrequency[2]
Definition: ToneGen.h:76
double as_double() const
Definition: Types.h:88
double mSampleRate
Definition: Effect.h:455
double mPositionInCycles
Definition: ToneGen.h:70
sampleCount mSample
Definition: ToneGen.h:69
double mAmplitude[2]
Definition: ToneGen.h:77
#define M_PI
Definition: Distortion.cpp:28
sampleCount mSampleCnt
Definition: Effect.h:475
int mWaveform
Definition: ToneGen.h:74
bool EffectToneGen::ProcessInitialize ( sampleCount  totalLen,
ChannelNames  chanMap = NULL 
)
overridevirtual

Reimplemented from Effect.

Definition at line 149 of file ToneGen.cpp.

References mPositionInCycles, and mSample.

150 {
151  mPositionInCycles = 0.0;
152  mSample = 0;
153 
154  return true;
155 }
double mPositionInCycles
Definition: ToneGen.h:70
sampleCount mSample
Definition: ToneGen.h:69
bool EffectToneGen::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 294 of file ToneGen.cpp.

References GetActiveProject(), AudacityProject::GetRate(), mAmplitude, mChirp, mFrequency, mInterpolation, mWaveform, nInterpolations, nWaveforms, ReadAndVerifyDouble, ReadAndVerifyEnum, and TrapDouble().

295 {
298  if (mChirp)
299  {
300  ReadAndVerifyDouble(StartFreq);
301  ReadAndVerifyDouble(EndFreq);
302  ReadAndVerifyDouble(StartAmp);
303  ReadAndVerifyDouble(EndAmp);
304  mFrequency[0] = StartFreq;
305  mFrequency[1] = EndFreq;
306  mAmplitude[0] = StartAmp;
307  mAmplitude[1] = EndAmp;
308  }
309  else
310  {
311  ReadAndVerifyDouble(Frequency);
312  ReadAndVerifyDouble(Amplitude);
313  mFrequency[0] = Frequency;
314  mFrequency[1] = Frequency;
315  mAmplitude[0] = Amplitude;
316  mAmplitude[1] = Amplitude;
317  }
318 
319  mWaveform = Waveform;
320  mInterpolation = Interp;
321 
322  double freqMax = (GetActiveProject() ? GetActiveProject()->GetRate() : 44100.0) / 2.0;
323  mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax);
324 
325  return true;
326 }
int mInterpolation
Definition: ToneGen.h:75
static const IdentInterfaceSymbol kInterStrings[nInterpolations]
Definition: ToneGen.cpp:42
double mFrequency[2]
Definition: ToneGen.h:76
#define ReadAndVerifyEnum(name, list, listSize)
Definition: Effect.h:786
double mAmplitude[2]
Definition: ToneGen.h:77
#define ReadAndVerifyDouble(name)
Definition: Effect.h:798
double TrapDouble(double x, double min, double max)
Definition: Effect.h:729
bool mChirp
Definition: ToneGen.h:65
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
double GetRate() const
Definition: Project.h:199
static const IdentInterfaceSymbol kWaveStrings[nWaveforms]
Definition: ToneGen.cpp:58
int mWaveform
Definition: ToneGen.h:74
bool EffectToneGen::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 455 of file ToneGen.cpp.

References NumericConverter::GetValue(), mAmplitude, mChirp, mFrequency, mToneDurationT, Effect::mUIParent, and Effect::SetDuration().

456 {
457  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
458  {
459  return false;
460  }
461 
462  if (!mChirp)
463  {
464  mFrequency[1] = mFrequency[0];
465  mAmplitude[1] = mAmplitude[0];
466  }
467 
469 
470  return true;
471 }
double mFrequency[2]
Definition: ToneGen.h:76
double mAmplitude[2]
Definition: ToneGen.h:77
void SetDuration(double duration) override
Definition: Effect.cpp:742
NumericTextCtrl * mToneDurationT
Definition: ToneGen.h:80
wxWindow * mUIParent
Definition: Effect.h:472
bool mChirp
Definition: ToneGen.h:65
bool EffectToneGen::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 443 of file ToneGen.cpp.

References Effect::GetDuration(), mToneDurationT, Effect::mUIParent, and NumericTextCtrl::SetValue().

444 {
445  if (!mUIParent->TransferDataToWindow())
446  {
447  return false;
448  }
449 
451 
452  return true;
453 }
double GetDuration() override
Definition: Effect.cpp:722
void SetValue(double newValue)
NumericTextCtrl * mToneDurationT
Definition: ToneGen.h:80
wxWindow * mUIParent
Definition: Effect.h:472

Member Data Documentation

double EffectToneGen::mAmplitude[2]
private
bool EffectToneGen::mChirp
private
double EffectToneGen::mFrequency[2]
private
int EffectToneGen::mInterpolation
private
double EffectToneGen::mLogFrequency[2]
private

Definition at line 78 of file ToneGen.h.

Referenced by ProcessBlock().

double EffectToneGen::mPositionInCycles
private

Definition at line 70 of file ToneGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

sampleCount EffectToneGen::mSample
private

Definition at line 69 of file ToneGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

NumericTextCtrl* EffectToneGen::mToneDurationT
private

Definition at line 80 of file ToneGen.h.

Referenced by PopulateOrExchange(), TransferDataFromWindow(), and TransferDataToWindow().

int EffectToneGen::mWaveform
private

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