Audacity  3.0.3
Public Member Functions | Private Member Functions | Private Attributes | List of all members
EffectToneGen Class Reference

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:
[legend]
Collaboration diagram for EffectToneGen:
[legend]

Public Member Functions

 EffectToneGen (bool isChirp)
 
virtual ~EffectToneGen ()
 
ComponentInterfaceSymbol GetSymbol () override
 
TranslatableString 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 ()
 
PluginPath GetPath () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
EffectFamilySymbol GetFamily () 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
 
size_t GetBlockSize () const 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, const EffectDialogFactory &factory, bool forceModal=false) 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 wxString 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)
 
virtual bool IsHidden ()
 
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 ()
 

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 }
 
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 ()
 
- 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>")
 
- Protected Member Functions inherited from Effect
virtual bool Init ()
 
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, 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 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 21 of file ToneGen.h.

Constructor & Destructor Documentation

◆ EffectToneGen()

EffectToneGen::EffectToneGen ( bool  isChirp)

Definition at line 100 of file ToneGen.cpp.

101 {
102  wxASSERT(nWaveforms == WXSIZEOF(kWaveStrings));
103  wxASSERT(nInterpolations == WXSIZEOF(kInterStrings));
104 
105  mChirp = isChirp;
106 
107  mWaveform = DEF_Waveform;
108  mFrequency[0] = DEF_StartFreq;
109  mFrequency[1] = DEF_EndFreq;
110  mAmplitude[0] = DEF_StartAmp;
111  mAmplitude[1] = DEF_EndAmp;
112  mInterpolation = DEF_Interp;
113 
114  // Chirp varies over time so must use selected duration.
115  // TODO: When previewing, calculate only the first 'preview length'.
116  if (isChirp)
117  SetLinearEffectFlag(false);
118  else
119  SetLinearEffectFlag(true);
120 }

References kInterStrings, kWaveStrings, nInterpolations, and nWaveforms.

◆ ~EffectToneGen()

EffectToneGen::~EffectToneGen ( )
virtual

Definition at line 122 of file ToneGen.cpp.

123 {
124 }

Member Function Documentation

◆ DefineParams()

bool EffectToneGen::DefineParams ( ShuttleParams S)
override

Definition at line 262 of file ToneGen.cpp.

262  {
263  if( mChirp ){
264  S.SHUTTLE_PARAM( mFrequency[0], StartFreq );
265  S.SHUTTLE_PARAM( mFrequency[1], EndFreq );
266  S.SHUTTLE_PARAM( mAmplitude[0], StartAmp );
267  S.SHUTTLE_PARAM( mAmplitude[1], EndAmp );
268  } else {
269  S.SHUTTLE_PARAM( mFrequency[0], Frequency );
270  S.SHUTTLE_PARAM( mAmplitude[0], Amplitude );
271  // Slightly hacky way to set freq and ampl
272  // since we do this whatever query to params was made.
273  mFrequency[1] = mFrequency[0];
274  mAmplitude[1] = mAmplitude[0];
275  }
276  S.SHUTTLE_ENUM_PARAM( mWaveform, Waveform, kWaveStrings, nWaveforms );
277  S.SHUTTLE_ENUM_PARAM( mInterpolation, Interp, kInterStrings, nInterpolations );
278 
279 
280 // double freqMax = (FindProject() ? FindProject()->GetRate() : 44100.0) / 2.0;
281 // mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax);
282 
283 
284  return true;
285 }

References kInterStrings, kWaveStrings, mAmplitude, mChirp, mFrequency, mInterpolation, mWaveform, nInterpolations, nWaveforms, and WaveTrackViewConstants::Waveform.

◆ GetAudioOutCount()

unsigned EffectToneGen::GetAudioOutCount ( )
overridevirtual

Reimplemented from Effect.

Definition at line 158 of file ToneGen.cpp.

159 {
160  return 1;
161 }

◆ GetAutomationParameters()

bool EffectToneGen::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 287 of file ToneGen.cpp.

288 {
289  if (mChirp)
290  {
291  parms.Write(KEY_StartFreq, mFrequency[0]);
292  parms.Write(KEY_EndFreq, mFrequency[1]);
293  parms.Write(KEY_StartAmp, mAmplitude[0]);
294  parms.Write(KEY_EndAmp, mAmplitude[1]);
295  }
296  else
297  {
298  parms.Write(KEY_Frequency, mFrequency[0]);
299  parms.Write(KEY_Amplitude, mAmplitude[0]);
300  }
301 
302  parms.Write(KEY_Waveform, kWaveStrings[mWaveform].Internal());
303  parms.Write(KEY_Interp, kInterStrings[mInterpolation].Internal());
304 
305  return true;
306 }

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

◆ GetDescription()

TranslatableString EffectToneGen::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 135 of file ToneGen.cpp.

136 {
137  return mChirp
138  ? XO("Generates an ascending or descending tone of one of four types")
139  : XO("Generates a constant frequency tone of one of four types");
140 }

References mChirp, and XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectToneGen::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 128 of file ToneGen.cpp.

129 {
130  return mChirp
133 }

References mChirp, EffectChirp::Symbol, and EffectTone::Symbol.

◆ GetType()

EffectType EffectToneGen::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 151 of file ToneGen.cpp.

152 {
153  return EffectTypeGenerate;
154 }

References EffectTypeGenerate.

◆ ManualPage()

wxString EffectToneGen::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 142 of file ToneGen.cpp.

143 {
144  return mChirp
145  ? wxT("Chirp")
146  : wxT("Tone");
147 }

References mChirp.

◆ OnControlUpdate()

void EffectToneGen::OnControlUpdate ( wxCommandEvent &  evt)
private

Definition at line 505 of file ToneGen.cpp.

506 {
507  if (!EnableApply(mUIParent->TransferDataFromWindow()))
508  {
509  return;
510  }
511 }

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

Here is the call graph for this function:

◆ PopulateOrExchange()

void EffectToneGen::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 348 of file ToneGen.cpp.

349 {
350  wxTextCtrl *t;
351 
352  S.StartMultiColumn(2, wxCENTER);
353  {
354  S.Validator<wxGenericValidator>(&mWaveform)
355  .AddChoice(XXO("&Waveform:"),
357 
358  if (mChirp)
359  {
360  S.AddFixedText( {} );
361  S.StartHorizontalLay(wxEXPAND);
362  {
363  S.StartHorizontalLay(wxLEFT, 50);
364  {
365  S.AddTitle(XO("Start"));
366  }
367  S.EndHorizontalLay();
368 
369  S.StartHorizontalLay(wxLEFT, 50);
370  {
371  S.AddTitle(XO("End"));
372  }
373  S.EndHorizontalLay();
374  }
375  S.EndHorizontalLay();
376 
377  S.AddPrompt(XXO("&Frequency (Hz):"));
378  S.StartHorizontalLay(wxEXPAND);
379  {
380  S.StartHorizontalLay(wxLEFT, 50);
381  {
382  t = S.Name(XO("Frequency Hertz Start"))
383  .Validator<FloatingPointValidator<double>>(
384  6, &mFrequency[0],
385  NumValidatorStyle::NO_TRAILING_ZEROES,
386  MIN_StartFreq,
387  mProjectRate / 2.0
388  )
389  .AddTextBox( {}, wxT(""), 12);
390  }
391  S.EndHorizontalLay();
392 
393  S.StartHorizontalLay(wxLEFT, 50);
394  {
395  t = S.Name(XO("Frequency Hertz End"))
396  .Validator<FloatingPointValidator<double>>(
397  6, &mFrequency[1],
398  NumValidatorStyle::NO_TRAILING_ZEROES,
399  MIN_EndFreq,
400  mProjectRate / 2.0
401  )
402  .AddTextBox( {}, wxT(""), 12);
403  }
404  S.EndHorizontalLay();
405  }
406  S.EndHorizontalLay();
407 
408  S.AddPrompt(XXO("&Amplitude (0-1):"));
409  S.StartHorizontalLay(wxEXPAND);
410  {
411  S.StartHorizontalLay(wxLEFT, 50);
412  {
413  t = S.Name(XO("Amplitude Start"))
414  .Validator<FloatingPointValidator<double>>(
415  6, &mAmplitude[0], NumValidatorStyle::NO_TRAILING_ZEROES,
416  MIN_StartAmp, MAX_StartAmp
417  )
418  .AddTextBox( {}, wxT(""), 12);
419  }
420  S.EndHorizontalLay();
421 
422  S.StartHorizontalLay(wxLEFT, 50);
423  {
424  t = S.Name(XO("Amplitude End"))
425  .Validator<FloatingPointValidator<double>>(
426  6, &mAmplitude[1], NumValidatorStyle::NO_TRAILING_ZEROES,
427  MIN_EndAmp, MAX_EndAmp
428  )
429  .AddTextBox( {}, wxT(""), 12);
430  }
431  S.EndHorizontalLay();
432  }
433  S.EndHorizontalLay();
434 
435  S.Validator<wxGenericValidator>(&mInterpolation)
436  .AddChoice(XXO("I&nterpolation:"),
438  }
439  else
440  {
441  t = S.Validator<FloatingPointValidator<double>>(
442  6, &mFrequency[0], NumValidatorStyle::NO_TRAILING_ZEROES,
443  MIN_Frequency,
444  mProjectRate / 2.0
445  )
446  .AddTextBox(XXO("&Frequency (Hz):"), wxT(""), 12);
447 
448  t = S.Validator<FloatingPointValidator<double>>(
449  6, &mAmplitude[0], NumValidatorStyle::NO_TRAILING_ZEROES,
450  MIN_Amplitude, MAX_Amplitude
451  )
452  .AddTextBox(XXO("&Amplitude (0-1):"), wxT(""), 12);
453  }
454 
455  S.AddPrompt(XXO("&Duration:"));
457  NumericTextCtrl(S.GetParent(), wxID_ANY,
460  GetDuration(),
461  mProjectRate,
463  .AutoPos(true));
464  S.Name(XO("Duration"))
465  .Position(wxALIGN_LEFT | wxALL)
467  }
468  S.EndMultiColumn();
469 
470  return;
471 }

References ShuttleGuiBase::AddFixedText(), ShuttleGuiBase::AddPrompt(), ShuttleGuiBase::AddTitle(), ShuttleGuiBase::AddWindow(), NumericTextCtrl::Options::AutoPos(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), Effect::GetDuration(), Effect::GetDurationFormat(), ShuttleGuiBase::GetParent(), kInterStrings, kWaveStrings, mAmplitude, mChirp, mFrequency, mInterpolation, Effect::mProjectRate, Msgids(), mToneDurationT, mWaveform, ShuttleGui::Name(), nInterpolations, nWaveforms, ShuttleGui::Position(), safenew, ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), NumericConverter::TIME, ShuttleGui::Validator(), XO, and XXO.

Here is the call graph for this function:

◆ ProcessBlock()

size_t EffectToneGen::ProcessBlock ( float **  inBlock,
float **  outBlock,
size_t  blockLen 
)
overridevirtual

Reimplemented from Effect.

Definition at line 171 of file ToneGen.cpp.

172 {
173  float *buffer = outBlock[0];
174  double throwaway = 0; //passed to modf but never used
175  double f = 0.0;
176  double a, b;
177  int k;
178 
179  double frequencyQuantum;
180  double BlendedFrequency;
181  double BlendedAmplitude;
182  double BlendedLogFrequency = 0.0;
183 
184  // calculate delta, and reposition from where we left
185  auto doubleSampleCount = mSampleCnt.as_double();
186  auto doubleSample = mSample.as_double();
187  double amplitudeQuantum =
188  (mAmplitude[1] - mAmplitude[0]) / doubleSampleCount;
189  BlendedAmplitude = mAmplitude[0] +
190  amplitudeQuantum * doubleSample;
191 
192  // precalculations:
193  double pre2PI = 2.0 * M_PI;
194  double pre4divPI = 4.0 / M_PI;
195 
196  // initial setup should calculate deltas
198  {
199  // this for log interpolation
200  mLogFrequency[0] = log10(mFrequency[0]);
201  mLogFrequency[1] = log10(mFrequency[1]);
202  // calculate delta, and reposition from where we left
203  frequencyQuantum = (mLogFrequency[1] - mLogFrequency[0]) / doubleSampleCount;
204  BlendedLogFrequency = mLogFrequency[0] + frequencyQuantum * doubleSample;
205  BlendedFrequency = pow(10.0, BlendedLogFrequency);
206  }
207  else
208  {
209  // this for regular case, linear interpolation
210  frequencyQuantum = (mFrequency[1] - mFrequency[0]) / doubleSampleCount;
211  BlendedFrequency = mFrequency[0] + frequencyQuantum * doubleSample;
212  }
213 
214  // synth loop
215  for (decltype(blockLen) i = 0; i < blockLen; i++)
216  {
217  switch (mWaveform)
218  {
219  case kSine:
220  f = sin(pre2PI * mPositionInCycles / mSampleRate);
221  break;
222  case kSquare:
223  f = (modf(mPositionInCycles / mSampleRate, &throwaway) < 0.5) ? 1.0 : -1.0;
224  break;
225  case kSawtooth:
226  f = (2.0 * modf(mPositionInCycles / mSampleRate + 0.5, &throwaway)) - 1.0;
227  break;
228  case kSquareNoAlias: // Good down to 110Hz @ 44100Hz sampling.
229  //do fundamental (k=1) outside loop
230  b = (1.0 + cos((pre2PI * BlendedFrequency) / mSampleRate)) / pre4divPI; //scaling
231  f = pre4divPI * sin(pre2PI * mPositionInCycles / mSampleRate);
232  for (k = 3; (k < 200) && (k * BlendedFrequency < mSampleRate / 2.0); k += 2)
233  {
234  //Hann Window in freq domain
235  a = 1.0 + cos((pre2PI * k * BlendedFrequency) / mSampleRate);
236  //calc harmonic, apply window, scale to amplitude of fundamental
237  f += a * sin(pre2PI * mPositionInCycles / mSampleRate * k) / (b * k);
238  }
239  }
240  // insert value in buffer
241  buffer[i] = (float) (BlendedAmplitude * f);
242  // update freq,amplitude
243  mPositionInCycles += BlendedFrequency;
244  BlendedAmplitude += amplitudeQuantum;
246  {
247  BlendedLogFrequency += frequencyQuantum;
248  BlendedFrequency = pow(10.0, BlendedLogFrequency);
249  }
250  else
251  {
252  BlendedFrequency += frequencyQuantum;
253  }
254  }
255 
256  // update external placeholder
257  mSample += blockLen;
258 
259  return blockLen;
260 }

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

Here is the call graph for this function:

◆ ProcessInitialize()

bool EffectToneGen::ProcessInitialize ( sampleCount  totalLen,
ChannelNames  chanMap = NULL 
)
overridevirtual

Reimplemented from Effect.

Definition at line 163 of file ToneGen.cpp.

164 {
165  mPositionInCycles = 0.0;
166  mSample = 0;
167 
168  return true;
169 }

References mPositionInCycles, and mSample.

◆ SetAutomationParameters()

bool EffectToneGen::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 308 of file ToneGen.cpp.

309 {
312  if (mChirp)
313  {
314  ReadAndVerifyDouble(StartFreq);
315  ReadAndVerifyDouble(EndFreq);
316  ReadAndVerifyDouble(StartAmp);
317  ReadAndVerifyDouble(EndAmp);
318  mFrequency[0] = StartFreq;
319  mFrequency[1] = EndFreq;
320  mAmplitude[0] = StartAmp;
321  mAmplitude[1] = EndAmp;
322  }
323  else
324  {
325  ReadAndVerifyDouble(Frequency);
326  ReadAndVerifyDouble(Amplitude);
327  mFrequency[0] = Frequency;
328  mFrequency[1] = Frequency;
329  mAmplitude[0] = Amplitude;
330  mAmplitude[1] = Amplitude;
331  }
332 
334  mInterpolation = Interp;
335 
336  double freqMax =
337  (FindProject()
339  : 44100.0)
340  / 2.0;
341  mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax);
342 
343  return true;
344 }

References Effect::FindProject(), ProjectSettings::Get(), ProjectSettings::GetRate(), kInterStrings, kWaveStrings, mAmplitude, mChirp, mFrequency, mInterpolation, mWaveform, nInterpolations, nWaveforms, ReadAndVerifyDouble, ReadAndVerifyEnum, TrapDouble(), and WaveTrackViewConstants::Waveform.

Here is the call graph for this function:

◆ TransferDataFromWindow()

bool EffectToneGen::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 485 of file ToneGen.cpp.

486 {
487  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
488  {
489  return false;
490  }
491 
492  if (!mChirp)
493  {
494  mFrequency[1] = mFrequency[0];
495  mAmplitude[1] = mAmplitude[0];
496  }
497 
499 
500  return true;
501 }

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

Here is the call graph for this function:

◆ TransferDataToWindow()

bool EffectToneGen::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 473 of file ToneGen.cpp.

474 {
475  if (!mUIParent->TransferDataToWindow())
476  {
477  return false;
478  }
479 
481 
482  return true;
483 }

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

Here is the call graph for this function:

Member Data Documentation

◆ mAmplitude

double EffectToneGen::mAmplitude[2]
private

◆ mChirp

bool EffectToneGen::mChirp
private

◆ mFrequency

double EffectToneGen::mFrequency[2]
private

◆ mInterpolation

int EffectToneGen::mInterpolation
private

◆ mLogFrequency

double EffectToneGen::mLogFrequency[2]
private

Definition at line 71 of file ToneGen.h.

Referenced by ProcessBlock().

◆ mPositionInCycles

double EffectToneGen::mPositionInCycles
private

Definition at line 63 of file ToneGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

◆ mSample

sampleCount EffectToneGen::mSample
private

Definition at line 62 of file ToneGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

◆ mToneDurationT

NumericTextCtrl* EffectToneGen::mToneDurationT
private

Definition at line 73 of file ToneGen.h.

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

◆ mWaveform

int EffectToneGen::mWaveform
private

The documentation for this class was generated from the following files:
Effect::mSampleCnt
sampleCount mSampleCnt
Definition: Effect.h:481
EffectToneGen::mSample
sampleCount mSample
Definition: ToneGen.h:62
Effect::FindProject
const AudacityProject * FindProject() const
Definition: Effect.cpp:2271
Effect::GetDuration
double GetDuration() override
Definition: Effect.cpp:815
Effect::SetLinearEffectFlag
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:2000
Effect::EnableApply
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1925
NumericTextCtrl::Options::AutoPos
Options & AutoPos(bool enable)
Definition: NumericTextCtrl.h:189
kSquareNoAlias
@ kSquareNoAlias
Definition: ToneGen.cpp:58
ShuttleGuiBase::AddTitle
void AddTitle(const TranslatableString &Prompt, int wrapWidth=0)
Centred text string.
Definition: ShuttleGui.cpp:274
EffectTypeGenerate
@ EffectTypeGenerate
Definition: EffectInterface.h:58
EffectTone::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: ToneGen.h:90
EffectToneGen::mChirp
bool mChirp
Definition: ToneGen.h:58
Validator
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
Definition: Validators.h:53
XO
#define XO(s)
Definition: Internat.h:32
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:39
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1212
EffectToneGen::mToneDurationT
NumericTextCtrl * mToneDurationT
Definition: ToneGen.h:73
NumericTextCtrl
Definition: NumericTextCtrl.h:171
NumericTextCtrl::SetValue
void SetValue(double newValue)
Definition: NumericTextCtrl.cpp:1472
NumericTextCtrl::Options
Definition: NumericTextCtrl.h:177
kSquare
@ kSquare
Definition: ToneGen.cpp:56
Effect::mProjectRate
double mProjectRate
Definition: Effect.h:457
ReadAndVerifyEnum
#define ReadAndVerifyEnum(name, list, listSize)
Definition: Effect.h:620
kInterStrings
static const EnumValueSymbol kInterStrings[nInterpolations]
Definition: ToneGen.cpp:46
EffectToneGen::mWaveform
int mWaveform
Definition: ToneGen.h:67
XXO
#define XXO(s)
Definition: Internat.h:45
EffectToneGen::mLogFrequency
double mLogFrequency[2]
Definition: ToneGen.h:71
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1170
sampleCount::as_double
double as_double() const
Definition: Types.h:616
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1160
EffectChirp::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: ToneGen.h:81
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1203
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:433
Msgids
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Definition: Internat.cpp:267
NumericConverter::TIME
@ TIME
Definition: NumericTextCtrl.h:51
EffectToneGen::mFrequency
double mFrequency[2]
Definition: ToneGen.h:69
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:503
ShuttleGui::Validator
ShuttleGui & Validator(const Factory &f)
Definition: ShuttleGui.h:685
nWaveforms
@ nWaveforms
Definition: ToneGen.cpp:59
ReadAndVerifyDouble
#define ReadAndVerifyDouble(name)
Definition: Effect.h:632
EffectToneGen::mInterpolation
int mInterpolation
Definition: ToneGen.h:68
Effect::SetDuration
void SetDuration(double duration) override
Definition: Effect.cpp:837
ShuttleGui::Name
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:670
Effect::mSampleRate
double mSampleRate
Definition: Effect.h:459
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow)
Definition: ShuttleGui.cpp:292
ShuttleGui::Position
ShuttleGui & Position(int flags)
Definition: ShuttleGui.h:719
EffectToneGen::mPositionInCycles
double mPositionInCycles
Definition: ToneGen.h:63
Effect::mUIParent
wxWindow * mUIParent
Definition: Effect.h:477
ProjectSettings::GetRate
double GetRate() const
Definition: ProjectSettings.cpp:166
M_PI
#define M_PI
Definition: Distortion.cpp:29
TrapDouble
double TrapDouble(double x, double min, double max)
Definition: Effect.h:563
Effect::GetDurationFormat
NumericFormatSymbol GetDurationFormat() override
Definition: Effect.cpp:825
ShuttleGuiBase::AddPrompt
void AddPrompt(const TranslatableString &Prompt, int wrapWidth=0)
Right aligned text string.
Definition: ShuttleGui.cpp:231
safenew
#define safenew
Definition: MemoryX.h:8
EffectToneGen::mAmplitude
double mAmplitude[2]
Definition: ToneGen.h:70
kSine
@ kSine
Definition: ToneGen.cpp:55
NumericConverter::GetValue
double GetValue()
Definition: NumericTextCtrl.cpp:1172
nInterpolations
@ nInterpolations
Definition: ToneGen.cpp:43
kSawtooth
@ kSawtooth
Definition: ToneGen.cpp:57
kLogarithmic
@ kLogarithmic
Definition: ToneGen.cpp:42
WaveTrackViewConstants::Waveform
@ Waveform
Definition: WaveTrackViewConstants.h:24
kWaveStrings
static const EnumValueSymbol kWaveStrings[nWaveforms]
Definition: ToneGen.cpp:62