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
 
ManualPageID 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 FilePath HelpPage ()
 
virtual void SetUIFlags (unsigned flags)
 
virtual unsigned TestUIFlags (unsigned mask)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={})
 
bool Delegate (Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory)
 
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 102 of file ToneGen.cpp.

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

References kInterStrings, kWaveStrings, nInterpolations, and nWaveforms.

◆ ~EffectToneGen()

EffectToneGen::~EffectToneGen ( )
virtual

Definition at line 124 of file ToneGen.cpp.

125 {
126 }

Member Function Documentation

◆ DefineParams()

bool EffectToneGen::DefineParams ( ShuttleParams S)
override

Definition at line 274 of file ToneGen.cpp.

274  {
275  if( mChirp ){
276  S.SHUTTLE_PARAM( mFrequency[0], StartFreq );
277  S.SHUTTLE_PARAM( mFrequency[1], EndFreq );
278  S.SHUTTLE_PARAM( mAmplitude[0], StartAmp );
279  S.SHUTTLE_PARAM( mAmplitude[1], EndAmp );
280  } else {
281  S.SHUTTLE_PARAM( mFrequency[0], Frequency );
282  S.SHUTTLE_PARAM( mAmplitude[0], Amplitude );
283  // Slightly hacky way to set freq and ampl
284  // since we do this whatever query to params was made.
285  mFrequency[1] = mFrequency[0];
286  mAmplitude[1] = mAmplitude[0];
287  }
288  S.SHUTTLE_ENUM_PARAM( mWaveform, Waveform, kWaveStrings, nWaveforms );
289  S.SHUTTLE_ENUM_PARAM( mInterpolation, Interp, kInterStrings, nInterpolations );
290 
291 
292 // double freqMax = (FindProject() ? FindProject()->GetRate() : 44100.0) / 2.0;
293 // mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax);
294 
295 
296  return true;
297 }

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

◆ GetAudioOutCount()

unsigned EffectToneGen::GetAudioOutCount ( )
overridevirtual

Reimplemented from Effect.

Definition at line 160 of file ToneGen.cpp.

161 {
162  return 1;
163 }

◆ GetAutomationParameters()

bool EffectToneGen::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 299 of file ToneGen.cpp.

300 {
301  if (mChirp)
302  {
303  parms.Write(KEY_StartFreq, mFrequency[0]);
304  parms.Write(KEY_EndFreq, mFrequency[1]);
305  parms.Write(KEY_StartAmp, mAmplitude[0]);
306  parms.Write(KEY_EndAmp, mAmplitude[1]);
307  }
308  else
309  {
310  parms.Write(KEY_Frequency, mFrequency[0]);
311  parms.Write(KEY_Amplitude, mAmplitude[0]);
312  }
313 
314  parms.Write(KEY_Waveform, kWaveStrings[mWaveform].Internal());
315  parms.Write(KEY_Interp, kInterStrings[mInterpolation].Internal());
316 
317  return true;
318 }

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

◆ GetDescription()

TranslatableString EffectToneGen::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 137 of file ToneGen.cpp.

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

References mChirp, and XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectToneGen::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 130 of file ToneGen.cpp.

131 {
132  return mChirp
135 }

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

◆ GetType()

EffectType EffectToneGen::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 153 of file ToneGen.cpp.

154 {
155  return EffectTypeGenerate;
156 }

References EffectTypeGenerate.

◆ ManualPage()

ManualPageID EffectToneGen::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 144 of file ToneGen.cpp.

145 {
146  return mChirp
147  ? L"Chirp"
148  : L"Tone";
149 }

References mChirp.

◆ OnControlUpdate()

void EffectToneGen::OnControlUpdate ( wxCommandEvent &  evt)
private

Definition at line 517 of file ToneGen.cpp.

518 {
519  if (!EnableApply(mUIParent->TransferDataFromWindow()))
520  {
521  return;
522  }
523 }

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 360 of file ToneGen.cpp.

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

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 173 of file ToneGen.cpp.

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

References sampleCount::as_double(), kLogarithmic, kSawtooth, kSine, kSquare, kSquareNoAlias, kTriangle, 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 165 of file ToneGen.cpp.

166 {
167  mPositionInCycles = 0.0;
168  mSample = 0;
169 
170  return true;
171 }

References mPositionInCycles, and mSample.

◆ SetAutomationParameters()

bool EffectToneGen::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 320 of file ToneGen.cpp.

321 {
324  if (mChirp)
325  {
326  ReadAndVerifyDouble(StartFreq);
327  ReadAndVerifyDouble(EndFreq);
328  ReadAndVerifyDouble(StartAmp);
329  ReadAndVerifyDouble(EndAmp);
330  mFrequency[0] = StartFreq;
331  mFrequency[1] = EndFreq;
332  mAmplitude[0] = StartAmp;
333  mAmplitude[1] = EndAmp;
334  }
335  else
336  {
337  ReadAndVerifyDouble(Frequency);
338  ReadAndVerifyDouble(Amplitude);
339  mFrequency[0] = Frequency;
340  mFrequency[1] = Frequency;
341  mAmplitude[0] = Amplitude;
342  mAmplitude[1] = Amplitude;
343  }
344 
346  mInterpolation = Interp;
347 
348  double freqMax =
349  (FindProject()
351  : 44100.0)
352  / 2.0;
353  mFrequency[1] = TrapDouble(mFrequency[1], MIN_EndFreq, freqMax);
354 
355  return true;
356 }

References Effect::FindProject(), ProjectRate::Get(), ProjectRate::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 497 of file ToneGen.cpp.

498 {
499  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
500  {
501  return false;
502  }
503 
504  if (!mChirp)
505  {
506  mFrequency[1] = mFrequency[0];
507  mAmplitude[1] = mAmplitude[0];
508  }
509 
511 
512  return true;
513 }

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 485 of file ToneGen.cpp.

486 {
487  if (!mUIParent->TransferDataToWindow())
488  {
489  return false;
490  }
491 
493 
494  return true;
495 }

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:482
EffectToneGen::mSample
sampleCount mSample
Definition: ToneGen.h:62
Effect::FindProject
const AudacityProject * FindProject() const
Definition: Effect.cpp:2272
Effect::GetDuration
double GetDuration() override
Definition: Effect.cpp:816
Effect::SetLinearEffectFlag
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:2001
Effect::EnableApply
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1926
NumericTextCtrl::Options::AutoPos
Options & AutoPos(bool enable)
Definition: NumericTextCtrl.h:190
kSquareNoAlias
@ kSquareNoAlias
Definition: ToneGen.cpp:58
ShuttleGuiBase::AddTitle
void AddTitle(const TranslatableString &Prompt, int wrapWidth=0)
Centred text string.
Definition: ShuttleGui.cpp:281
ProjectRate::Get
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:42
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:31
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
EffectToneGen::mToneDurationT
NumericTextCtrl * mToneDurationT
Definition: ToneGen.h:73
NumericTextCtrl
Definition: NumericTextCtrl.h:172
NumericTextCtrl::SetValue
void SetValue(double newValue)
Definition: NumericTextCtrl.cpp:1472
NumericTextCtrl::Options
Definition: NumericTextCtrl.h:178
kSquare
@ kSquare
Definition: ToneGen.cpp:56
Effect::mProjectRate
double mProjectRate
Definition: Effect.h:458
ReadAndVerifyEnum
#define ReadAndVerifyEnum(name, list, listSize)
Definition: Effect.h:621
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:44
EffectToneGen::mLogFrequency
double mLogFrequency[2]
Definition: ToneGen.h:71
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
sampleCount::as_double
double as_double() const
Definition: SampleCount.h:45
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
EffectChirp::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: ToneGen.h:81
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:440
NumericConverter::TIME
@ TIME
Definition: NumericTextCtrl.h:52
EffectToneGen::mFrequency
double mFrequency[2]
Definition: ToneGen.h:69
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:496
ShuttleGui::Validator
ShuttleGui & Validator(const Factory &f)
Definition: ShuttleGui.h:678
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:299
ProjectRate::GetRate
double GetRate() const
Definition: ProjectRate.cpp:68
nWaveforms
@ nWaveforms
Definition: ToneGen.cpp:60
Msgids
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
Definition: ShuttleGui.cpp:2522
ReadAndVerifyDouble
#define ReadAndVerifyDouble(name)
Definition: Effect.h:633
EffectToneGen::mInterpolation
int mInterpolation
Definition: ToneGen.h:68
Effect::SetDuration
void SetDuration(double duration) override
Definition: Effect.cpp:838
ShuttleGui::Name
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:663
Effect::mSampleRate
double mSampleRate
Definition: Effect.h:460
ShuttleGui::Position
ShuttleGui & Position(int flags)
Definition: ShuttleGui.h:712
EffectToneGen::mPositionInCycles
double mPositionInCycles
Definition: ToneGen.h:63
Effect::mUIParent
wxWindow * mUIParent
Definition: Effect.h:478
kTriangle
@ kTriangle
Definition: ToneGen.cpp:59
ExceptionType::Internal
@ Internal
Indicates internal failure from Audacity.
M_PI
#define M_PI
Definition: Distortion.cpp:29
TrapDouble
double TrapDouble(double x, double min, double max)
Definition: Effect.h:564
Effect::GetDurationFormat
NumericFormatSymbol GetDurationFormat() override
Definition: Effect.cpp:826
ShuttleGuiBase::AddPrompt
void AddPrompt(const TranslatableString &Prompt, int wrapWidth=0)
Right aligned text string.
Definition: ShuttleGui.cpp:238
safenew
#define safenew
Definition: MemoryX.h:10
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:63