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

An effect that generates DTMF tones. More...

#include <DtmfGen.h>

Inheritance diagram for EffectDtmf:
Effect

Public Member Functions

 EffectDtmf ()
 
virtual ~EffectDtmf ()
 
wxString 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 GetAutomationParameters (EffectAutomationParameters &parms) override
 
bool SetAutomationParameters (EffectAutomationParameters &parms) override
 
bool Startup () override
 
bool Init () override
 
void PopulateOrExchange (ShuttleGui &S) override
 
bool TransferDataFromWindow () override
 
bool TransferDataToWindow () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
wxString GetPath () override
 
wxString GetSymbol () override
 
wxString GetName () override
 
wxString GetVendor () override
 
wxString GetVersion () override
 
wxString GetDescription () override
 
EffectType GetType () override
 
wxString 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
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
bool IsReady () override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 
bool ProcessFinalize () override
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () override
 
bool ShowInterface (wxWindow *parent, bool forceModal=false) override
 
bool GetAutomationParameters (EffectAutomationParameters &parms) override
 
bool SetAutomationParameters (EffectAutomationParameters &parms) override
 
bool LoadUserPreset (const wxString &name) override
 
bool SaveUserPreset (const wxString &name) override
 
wxArrayString GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (wxWindow *parent) override
 
bool IsGraphicalUI () override
 
bool ValidateUI () override
 
bool HideUI () override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets () override
 
void ImportPresets () override
 
bool HasOptions () override
 
void ShowOptions () override
 
double GetDefaultDuration () override
 
double GetDuration () override
 
wxString GetDurationFormat () override
 
virtual wxString 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 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, SelectedRegion *selectedRegion, 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{})
 

Private Member Functions

bool MakeDtmfTone (float *buffer, size_t len, float fs, wxChar tone, sampleCount last, sampleCount total, float amplitude)
 
void Recalculate ()
 
void UpdateUI ()
 
void OnSequence (wxCommandEvent &evt)
 
void OnAmplitude (wxCommandEvent &evt)
 
void OnDuration (wxCommandEvent &evt)
 
void OnDutyCycle (wxCommandEvent &evt)
 

Private Attributes

sampleCount numSamplesSequence
 
sampleCount numSamplesTone
 
sampleCount numSamplesSilence
 
sampleCount diff
 
sampleCount numRemaining
 
sampleCount curTonePos
 
bool isTone
 
int curSeqPos
 
wxString dtmfSequence
 
int dtmfNTones
 
double dtmfTone
 
double dtmfSilence
 
double dtmfDutyCycle
 
double dtmfAmplitude
 
wxTextCtrl * mDtmfSequenceT
 
wxTextCtrl * mDtmfAmplitudeT
 
wxSlider * mDtmfDutyCycleS
 
NumericTextCtrlmDtmfDurationT
 
wxStaticText * mDtmfToneT
 
wxStaticText * mDtmfSilenceT
 
wxStaticText * mDtmfDutyT
 

Additional Inherited Members

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

Definition at line 30 of file DtmfGen.h.

Constructor & Destructor Documentation

EffectDtmf::EffectDtmf ( )

Definition at line 79 of file DtmfGen.cpp.

80 {
81  dtmfDutyCycle = DEF_DutyCycle;
82  dtmfAmplitude = DEF_Amplitude;
83  dtmfSequence = DEF_Sequence;
84  dtmfTone = 0.0;
85  dtmfSilence = 0.0;
86 }
wxString dtmfSequence
Definition: DtmfGen.h:87
double dtmfAmplitude
Definition: DtmfGen.h:92
double dtmfSilence
Definition: DtmfGen.h:90
double dtmfDutyCycle
Definition: DtmfGen.h:91
double dtmfTone
Definition: DtmfGen.h:89
EffectDtmf::~EffectDtmf ( )
virtual

Definition at line 88 of file DtmfGen.cpp.

89 {
90 }

Member Function Documentation

unsigned EffectDtmf::GetAudioOutCount ( )
override

Definition at line 118 of file DtmfGen.cpp.

119 {
120  return 1;
121 }
bool EffectDtmf::GetAutomationParameters ( EffectAutomationParameters &  parms)
override

Definition at line 233 of file DtmfGen.cpp.

References dtmfAmplitude, dtmfDutyCycle, and dtmfSequence.

234 {
235  parms.Write(KEY_Sequence, dtmfSequence);
236  parms.Write(KEY_DutyCycle, dtmfDutyCycle);
237  parms.Write(KEY_Amplitude, dtmfAmplitude);
238 
239  return true;
240 }
wxString dtmfSequence
Definition: DtmfGen.h:87
double dtmfAmplitude
Definition: DtmfGen.h:92
double dtmfDutyCycle
Definition: DtmfGen.h:91
wxString EffectDtmf::GetDescription ( )
override

Definition at line 99 of file DtmfGen.cpp.

References _().

100 {
101  return _("Generates dual-tone multi-frequency (DTMF) tones like those produced by the keypad on telephones");
102 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
wxString EffectDtmf::GetSymbol ( )
override

Definition at line 94 of file DtmfGen.cpp.

References DTMFTONES_PLUGIN_SYMBOL.

95 {
97 }
#define DTMFTONES_PLUGIN_SYMBOL
Definition: DtmfGen.h:28
EffectType EffectDtmf::GetType ( )
override

Definition at line 111 of file DtmfGen.cpp.

112 {
113  return EffectTypeGenerate;
114 }
bool EffectDtmf::Init ( )
overridevirtual

Reimplemented from Effect.

Definition at line 299 of file DtmfGen.cpp.

References Recalculate().

300 {
301  Recalculate();
302 
303  return true;
304 }
void Recalculate()
Definition: DtmfGen.cpp:403
bool EffectDtmf::MakeDtmfTone ( float *  buffer,
size_t  len,
float  fs,
wxChar  tone,
sampleCount  last,
sampleCount  total,
float  amplitude 
)
private

Definition at line 445 of file DtmfGen.cpp.

References kFadeInOut, and M_PI.

Referenced by ProcessBlock().

446 {
447 /*
448  --------------------------------------------
449  1209 Hz 1336 Hz 1477 Hz 1633 Hz
450 
451  ABC DEF
452  697 Hz 1 2 3 A
453 
454  GHI JKL MNO
455  770 Hz 4 5 6 B
456 
457  PQRS TUV WXYZ
458  852 Hz 7 8 9 C
459 
460  oper
461  941 Hz * 0 # D
462  --------------------------------------------
463  Essentially we need to generate two sin with
464  frequencies according to this table, and sum
465  them up.
466  sin wave is generated by:
467  s(n)=sin(2*pi*n*f/fs)
468 
469  We will precalculate:
470  A= 2*pi*f1/fs
471  B= 2*pi*f2/fs
472 
473  And use two switch statements to select the frequency
474 
475  Note: added support for letters, like those on the keypad
476  This support is only for lowercase letters: uppercase
477  are still considered to be the 'military'/carrier extra
478  tones.
479 */
480 
481  float f1, f2=0.0;
482  double A,B;
483 
484  // select low tone: left column
485  switch (tone) {
486  case '1': case '2': case '3': case 'A':
487  case 'a': case 'b': case 'c':
488  case 'd': case 'e': case 'f':
489  f1=697;
490  break;
491  case '4': case '5': case '6': case 'B':
492  case 'g': case 'h': case 'i':
493  case 'j': case 'k': case 'l':
494  case 'm': case 'n': case 'o':
495  f1=770;
496  break;
497  case '7': case '8': case '9': case 'C':
498  case 'p': case 'q': case 'r': case 's':
499  case 't': case 'u': case 'v':
500  case 'w': case 'x': case 'y': case 'z':
501  f1=852;
502  break;
503  case '*': case '0': case '#': case 'D':
504  f1=941;
505  break;
506  default:
507  f1=0;
508  }
509 
510  // select high tone: top row
511  switch (tone) {
512  case '1': case '4': case '7': case '*':
513  case 'g': case 'h': case 'i':
514  case 'p': case 'q': case 'r': case 's':
515  f2=1209;
516  break;
517  case '2': case '5': case '8': case '0':
518  case 'a': case 'b': case 'c':
519  case 'j': case 'k': case 'l':
520  case 't': case 'u': case 'v':
521  f2=1336;
522  break;
523  case '3': case '6': case '9': case '#':
524  case 'd': case 'e': case 'f':
525  case 'm': case 'n': case 'o':
526  case 'w': case 'x': case 'y': case 'z':
527  f2=1477;
528  break;
529  case 'A': case 'B': case 'C': case 'D':
530  f2=1633;
531  break;
532  default:
533  f2=0;
534  }
535 
536  // precalculations
537  A=B=2*M_PI/fs;
538  A*=f1;
539  B*=f2;
540 
541  // now generate the wave: 'last' is used to avoid phase errors
542  // when inside the inner for loop of the Process() function.
543  for(decltype(len) i = 0; i < len; i++) {
544  buffer[i] = amplitude * 0.5 *
545  (sin( A * (i + last).as_double() ) +
546  sin( B * (i + last).as_double() ));
547  }
548 
549  // generate a fade-in of duration 1/250th of second
550  if (last == 0) {
551  A = (fs / kFadeInOut);
552  for(size_t i = 0; i < A; i++) {
553  buffer[i] *= i/A;
554  }
555  }
556 
557  // generate a fade-out of duration 1/250th of second
558  if (last == total - len) {
559  // we are at the last buffer of 'len' size, so, offset is to
560  // backup 'A' samples, from 'len'
561  A = (fs / kFadeInOut);
562  auto offset = long(len) - long(fs / kFadeInOut);
563  // protect against negative offset, which can occur if too a
564  // small selection is made
565  if (offset >= 0) {
566  for(size_t i = 0; i < A; i++) {
567  buffer[i + offset] *= (1 - (i / A));
568  }
569  }
570  }
571  return true;
572 }
static const double kFadeInOut
Definition: DtmfGen.cpp:51
#define M_PI
Definition: Distortion.cpp:28
wxString EffectDtmf::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 104 of file DtmfGen.cpp.

105 {
106  return wxT("DTMF_Tones");
107 }
void EffectDtmf::OnAmplitude ( wxCommandEvent &  evt)
private

Definition at line 593 of file DtmfGen.cpp.

References mDtmfAmplitudeT, Recalculate(), and UpdateUI().

594 {
595  if (!mDtmfAmplitudeT->GetValidator()->TransferFromWindow())
596  {
597  return;
598  }
599  Recalculate();
600  UpdateUI();
601 }
void Recalculate()
Definition: DtmfGen.cpp:403
void UpdateUI()
Definition: DtmfGen.cpp:574
wxTextCtrl * mDtmfAmplitudeT
Definition: DtmfGen.h:95
void EffectDtmf::OnDuration ( wxCommandEvent &  evt)
private

Definition at line 602 of file DtmfGen.cpp.

References NumericConverter::GetValue(), mDtmfDurationT, Recalculate(), Effect::SetDuration(), and UpdateUI().

603 {
605  Recalculate();
606  UpdateUI();
607 }
void Recalculate()
Definition: DtmfGen.cpp:403
void UpdateUI()
Definition: DtmfGen.cpp:574
void SetDuration(double duration) override
Definition: Effect.cpp:757
NumericTextCtrl * mDtmfDurationT
Definition: DtmfGen.h:97
void EffectDtmf::OnDutyCycle ( wxCommandEvent &  evt)
private

Definition at line 609 of file DtmfGen.cpp.

References dtmfDutyCycle, Recalculate(), and UpdateUI().

610 {
611  dtmfDutyCycle = (double) evt.GetInt() / SCL_DutyCycle;
612  Recalculate();
613  UpdateUI();
614 }
void Recalculate()
Definition: DtmfGen.cpp:403
void UpdateUI()
Definition: DtmfGen.cpp:574
double dtmfDutyCycle
Definition: DtmfGen.h:91
void EffectDtmf::OnSequence ( wxCommandEvent &  evt)
private

Definition at line 586 of file DtmfGen.cpp.

References dtmfSequence, mDtmfSequenceT, Recalculate(), and UpdateUI().

587 {
588  dtmfSequence = mDtmfSequenceT->GetValue();
589  Recalculate();
590  UpdateUI();
591 }
void Recalculate()
Definition: DtmfGen.cpp:403
wxString dtmfSequence
Definition: DtmfGen.h:87
wxTextCtrl * mDtmfSequenceT
Definition: DtmfGen.h:94
void UpdateUI()
Definition: DtmfGen.cpp:574
void EffectDtmf::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 306 of file DtmfGen.cpp.

References _(), ShuttleGuiBase::AddFixedText(), ShuttleGuiBase::AddPrompt(), ShuttleGuiBase::AddSlider(), ShuttleGui::AddSpace(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::AddVariableText(), ShuttleGuiBase::AddWindow(), dtmfAmplitude, dtmfDutyCycle, dtmfSequence, dtmfSilence, dtmfTone, NumericTextCtrl::EnableMenu(), ShuttleGuiBase::EndMultiColumn(), Effect::GetDuration(), Effect::GetDurationFormat(), ShuttleGuiBase::GetParent(), ShuttleGui::Id(), ID_Amplitude, ID_Duration, ID_DutyCycle, ID_Sequence, mDtmfDurationT, mDtmfDutyCycleS, mDtmfDutyT, mDtmfSequenceT, mDtmfSilenceT, mDtmfToneT, Effect::mProjectRate, safenew, ShuttleGui::SetSizeHints(), ShuttleGuiBase::SetStyle(), ShuttleGuiBase::StartMultiColumn(), and NumericConverter::TIME.

307 {
308  // dialog will be passed values from effect
309  // Effect retrieves values from saved config
310  // Dialog will take care of using them to initialize controls
311  // If there is a selection, use that duration, otherwise use
312  // value from saved config: this is useful is user wants to
313  // replace selection with dtmf sequence
314 
315  S.AddSpace(0, 5);
316  S.StartMultiColumn(2, wxCENTER);
317  {
318  wxTextValidator vldDtmf(wxFILTER_INCLUDE_CHAR_LIST, &dtmfSequence);
319  vldDtmf.SetIncludes(wxArrayString(WXSIZEOF(kSymbols), kSymbols));
320  mDtmfSequenceT = S.Id(ID_Sequence).AddTextBox(_("DTMF sequence:"), wxT(""), 10);
321  mDtmfSequenceT->SetValidator(vldDtmf);
322 
323  FloatingPointValidator<double> vldAmp(3, &dtmfAmplitude, NUM_VAL_NO_TRAILING_ZEROES);
324  vldAmp.SetRange(MIN_Amplitude, MAX_Amplitude);
325  S.Id(ID_Amplitude).AddTextBox(_("Amplitude (0-1):"), wxT(""), 10)->SetValidator(vldAmp);
326 
327  S.AddPrompt(_("Duration:"));
330  S.GetParent(),
331  ID_Duration,
333  GetDuration(),
334  mProjectRate,
335  wxDefaultPosition,
336  wxDefaultSize,
337  true);
338  mDtmfDurationT->SetName(_("Duration"));
341 
342  S.AddFixedText(_("Tone/silence ratio:"), false);
343  S.SetStyle(wxSL_HORIZONTAL | wxEXPAND);
345  dtmfDutyCycle * SCL_DutyCycle,
346  MAX_DutyCycle * SCL_DutyCycle,
347  MIN_DutyCycle * SCL_DutyCycle);
348  S.SetSizeHints(-1,-1);
349  }
350  S.EndMultiColumn();
351 
352  S.StartMultiColumn(2, wxCENTER);
353  {
354  S.AddFixedText(_("Duty cycle:"), false);
355  mDtmfDutyT = S.AddVariableText(wxString::Format(wxT("%.1f %%"), dtmfDutyCycle), false);
356 
357  S.AddFixedText(_("Tone duration:"), false);
358  mDtmfSilenceT = S.AddVariableText(wxString::Format(wxString(wxT("%.0f ")) + _("ms"), dtmfTone * 1000.0), false);
359 
360  S.AddFixedText(_("Silence duration:"), false);
361  mDtmfToneT = S.AddVariableText(wxString::Format(wxString(wxT("%0.f ")) + _("ms"), dtmfSilence * 1000.0), false);
362  }
363  S.EndMultiColumn();
364 }
wxStaticText * mDtmfToneT
Definition: DtmfGen.h:98
static const wxChar * kSymbols[]
Definition: DtmfGen.cpp:53
double GetDuration() override
Definition: Effect.cpp:737
wxWindow * AddWindow(wxWindow *pWindow, int Flags=wxALIGN_CENTRE|wxALL)
Definition: ShuttleGui.cpp:257
wxString GetDurationFormat() override
Definition: Effect.cpp:747
wxStaticText * mDtmfDutyT
Definition: DtmfGen.h:100
wxSlider * mDtmfDutyCycleS
Definition: DtmfGen.h:96
void EndMultiColumn()
void EnableMenu(bool enable=true)
#define safenew
Definition: Audacity.h:223
wxString dtmfSequence
Definition: DtmfGen.h:87
wxTextCtrl * mDtmfSequenceT
Definition: DtmfGen.h:94
void AddPrompt(const wxString &Prompt)
Right aligned text string.
Definition: ShuttleGui.cpp:215
void SetSizeHints(int minX=-1, int minY=-1)
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:493
wxWindow * GetParent()
Definition: ShuttleGui.h:259
double dtmfAmplitude
Definition: DtmfGen.h:92
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
ShuttleGui & Id(int id)
void SetStyle(int Style)
Definition: ShuttleGui.h:252
double dtmfSilence
Definition: DtmfGen.h:90
void AddFixedText(const wxString &Str, bool bCenter=false)
Definition: ShuttleGui.cpp:356
wxStaticText * mDtmfSilenceT
Definition: DtmfGen.h:99
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
double mProjectRate
Definition: Effect.h:453
wxStaticText * AddVariableText(const wxString &Str, bool bCenter=false, int PositionFlags=0)
Definition: ShuttleGui.cpp:373
double dtmfDutyCycle
Definition: DtmfGen.h:91
NumericTextCtrl * mDtmfDurationT
Definition: DtmfGen.h:97
wxSizerItem * AddSpace(int width, int height)
double dtmfTone
Definition: DtmfGen.h:89
wxSlider * AddSlider(const wxString &Prompt, int pos, int Max, int Min=0)
Definition: ShuttleGui.cpp:456
size_t EffectDtmf::ProcessBlock ( float **  inBlock,
float **  outBlock,
size_t  blockLen 
)
override

Definition at line 166 of file DtmfGen.cpp.

References curSeqPos, curTonePos, diff, dtmfAmplitude, dtmfSequence, isTone, MakeDtmfTone(), Effect::mSampleRate, numRemaining, numSamplesSilence, and numSamplesTone.

167 {
168  float *buffer = outbuf[0];
169  decltype(size) processed = 0;
170 
171  // for the whole dtmf sequence, we will be generating either tone or silence
172  // according to a bool value, and this might be done in small chunks of size
173  // 'block', as a single tone might sometimes be larger than the block
174  // tone and silence generally have different duration, thus two generation blocks
175  //
176  // Note: to overcome a 'clicking' noise introduced by the abrupt transition from/to
177  // silence, I added a fade in/out of 1/250th of a second (4ms). This can still be
178  // tweaked but gives excellent results at 44.1kHz: I haven't tried other freqs.
179  // A problem might be if the tone duration is very short (<10ms)... (?)
180  //
181  // One more problem is to deal with the approximations done when calculating the duration
182  // of both tone and silence: in some cases the final sum might not be same as the initial
183  // duration. So, to overcome this, we had a redistribution block up, and now we will spread
184  // the remaining samples in every bin in order to achieve the full duration: test case was
185  // to generate an 11 tone DTMF sequence, in 4 seconds, and with DutyCycle=75%: after generation
186  // you ended up with 3.999s or in other units: 3 seconds and 44097 samples.
187  //
188  while (size)
189  {
190  if (numRemaining == 0)
191  {
192  isTone = !isTone;
193 
194  if (isTone)
195  {
196  curSeqPos++;
198  curTonePos = 0;
199  }
200  else
201  {
203  }
204 
205  // the statement takes care of extracting one sample from the diff bin and
206  // adding it into the current block until depletion
207  numRemaining += (diff-- > 0 ? 1 : 0);
208  }
209 
210  const auto len = limitSampleBufferSize( size, numRemaining );
211 
212  if (isTone)
213  {
214  // generate the tone and append
216  curTonePos += len;
217  }
218  else
219  {
220  memset(buffer, 0, sizeof(float) * len);
221  }
222 
223  numRemaining -= len;
224 
225  buffer += len;
226  size -= len;
227  processed += len;
228  }
229 
230  return processed;
231 }
sampleCount numSamplesSilence
Definition: DtmfGen.h:80
double mSampleRate
Definition: Effect.h:455
sampleCount diff
Definition: DtmfGen.h:81
wxString dtmfSequence
Definition: DtmfGen.h:87
int curSeqPos
Definition: DtmfGen.h:85
double dtmfAmplitude
Definition: DtmfGen.h:92
sampleCount numRemaining
Definition: DtmfGen.h:82
bool MakeDtmfTone(float *buffer, size_t len, float fs, wxChar tone, sampleCount last, sampleCount total, float amplitude)
Definition: DtmfGen.cpp:445
sampleCount curTonePos
Definition: DtmfGen.h:83
sampleCount numSamplesTone
Definition: DtmfGen.h:79
bool isTone
Definition: DtmfGen.h:84
bool EffectDtmf::ProcessInitialize ( sampleCount  totalLen,
ChannelNames  chanMap = NULL 
)
override

Definition at line 123 of file DtmfGen.cpp.

References curSeqPos, diff, dtmfNTones, dtmfSilence, dtmfTone, Effect::GetDuration(), isTone, Effect::mSampleRate, Effect::mT0, numRemaining, numSamplesSequence, numSamplesSilence, and numSamplesTone.

124 {
125  double duration = GetDuration();
126 
127  // all dtmf sequence durations in samples from seconds
128  // MJS: Note that mDuration is in seconds but will have been quantised to the units of the TTC.
129  // If this was 'samples' and the project rate was lower than the track rate,
130  // extra samples may get created as mDuration may now be > mT1 - mT0;
131  // However we are making our best efforts at creating what was asked for.
132 
133  auto nT0 = (sampleCount)floor(mT0 * mSampleRate + 0.5);
134  auto nT1 = (sampleCount)floor((mT0 + duration) * mSampleRate + 0.5);
135  numSamplesSequence = nT1 - nT0; // needs to be exact number of samples selected
136 
137  //make under-estimates if anything, and then redistribute the few remaining samples
138  numSamplesTone = sampleCount( floor(dtmfTone * mSampleRate) );
139  numSamplesSilence = sampleCount( floor(dtmfSilence * mSampleRate) );
140 
141  // recalculate the sum, and spread the difference - due to approximations.
142  // Since diff should be in the order of "some" samples, a division (resulting in zero)
143  // is not sufficient, so we add the additional remaining samples in each tone/silence block,
144  // at least until available.
146  while (diff > 2*dtmfNTones - 1) { // more than one per thingToBeGenerated
147  // in this case, both numSamplesTone and numSamplesSilence would change, so it makes sense
148  // to recalculate diff here, otherwise just keep the value we already have
149 
150  // should always be the case that dtmfNTones>1, as if 0, we don't even start processing,
151  // and with 1 there is no difference to spread (no silence slot)...
152  wxASSERT(dtmfNTones > 1);
156  }
157  wxASSERT(diff >= 0); // should never be negative
158 
159  curSeqPos = -1; // pointer to string in dtmfSequence
160  isTone = false;
161  numRemaining = 0;
162 
163  return true;
164 }
double GetDuration() override
Definition: Effect.cpp:737
sampleCount numSamplesSilence
Definition: DtmfGen.h:80
double mSampleRate
Definition: Effect.h:455
sampleCount diff
Definition: DtmfGen.h:81
int curSeqPos
Definition: DtmfGen.h:85
sampleCount numRemaining
Definition: DtmfGen.h:82
sampleCount numSamplesSequence
Definition: DtmfGen.h:78
double dtmfSilence
Definition: DtmfGen.h:90
int dtmfNTones
Definition: DtmfGen.h:88
sampleCount numSamplesTone
Definition: DtmfGen.h:79
double dtmfTone
Definition: DtmfGen.h:89
bool isTone
Definition: DtmfGen.h:84
double mT0
Definition: Effect.h:459
void EffectDtmf::Recalculate ( )
private

Definition at line 403 of file DtmfGen.cpp.

References dtmfDutyCycle, dtmfNTones, dtmfSequence, dtmfSilence, dtmfTone, Effect::GetDuration(), and Effect::SetDuration().

Referenced by Init(), OnAmplitude(), OnDuration(), OnDutyCycle(), OnSequence(), SetAutomationParameters(), TransferDataFromWindow(), and TransferDataToWindow().

404 {
405  // remember that dtmfDutyCycle is in range (0.0-100.0)
406 
407  dtmfNTones = (int) dtmfSequence.Length();
408 
409  if (dtmfNTones==0) {
410  // no tones, all zero: don't do anything
411  // this should take care of the case where user got an empty
412  // dtmf sequence into the generator: track won't be generated
413  SetDuration(0.0);
414  dtmfTone = 0;
415  dtmfSilence = 0;
416  } else {
417  if (dtmfNTones==1) {
418  // single tone, as long as the sequence
419  dtmfTone = GetDuration();
420  dtmfSilence = 0;
421  } else {
422  // Don't be fooled by the fact that you divide the sequence into dtmfNTones:
423  // the last slot will only contain a tone, not ending with silence.
424  // Given this, the right thing to do is to divide the sequence duration
425  // by dtmfNTones tones and (dtmfNTones-1) silences each sized according to the duty
426  // cycle: original division was:
427  // slot=mDuration / (dtmfNTones*(dtmfDutyCycle/MAX_DutyCycle)+(dtmfNTones-1)*(1.0-dtmfDutyCycle/MAX_DutyCycle))
428  // which can be simplified in the one below.
429  // Then just take the part that belongs to tone or silence.
430  //
431  double slot = GetDuration() / ((double)dtmfNTones + (dtmfDutyCycle / 100.0) - 1);
432  dtmfTone = slot * (dtmfDutyCycle / 100.0); // seconds
433  dtmfSilence = slot * (1.0 - (dtmfDutyCycle / 100.0)); // seconds
434 
435  // Note that in the extremes we have:
436  // - dutyCycle=100%, this means no silence, so each tone will measure mDuration/dtmfNTones
437  // - dutyCycle=0%, this means no tones, so each silence slot will measure mDuration/(NTones-1)
438  // But we always count:
439  // - dtmfNTones tones
440  // - dtmfNTones-1 silences
441  }
442  }
443 }
double GetDuration() override
Definition: Effect.cpp:737
wxString dtmfSequence
Definition: DtmfGen.h:87
double dtmfSilence
Definition: DtmfGen.h:90
void SetDuration(double duration) override
Definition: Effect.cpp:757
double dtmfDutyCycle
Definition: DtmfGen.h:91
int dtmfNTones
Definition: DtmfGen.h:88
double dtmfTone
Definition: DtmfGen.h:89
bool EffectDtmf::SetAutomationParameters ( EffectAutomationParameters &  parms)
override

Definition at line 242 of file DtmfGen.cpp.

References dtmfAmplitude, dtmfDutyCycle, dtmfSequence, ReadAndVerifyDouble, ReadAndVerifyString, and Recalculate().

243 {
244  ReadAndVerifyDouble(DutyCycle);
245  ReadAndVerifyDouble(Amplitude);
247 
248  wxString symbols;
249  for (unsigned int i = 0; i < WXSIZEOF(kSymbols); i++)
250  {
251  symbols += kSymbols[i];
252  }
253 
254  if (Sequence.find_first_not_of(symbols) != wxString::npos)
255  {
256  return false;
257  }
258 
259  dtmfDutyCycle = DutyCycle;
260  dtmfAmplitude = Amplitude;
262 
263  Recalculate();
264 
265  return true;
266 }
static const wxChar * kSymbols[]
Definition: DtmfGen.cpp:53
A WaveTrack contains WaveClip(s). A WaveClip contains a Sequence. A Sequence is primarily an interfac...
Definition: Sequence.h:55
void Recalculate()
Definition: DtmfGen.cpp:403
wxString dtmfSequence
Definition: DtmfGen.h:87
double dtmfAmplitude
Definition: DtmfGen.h:92
#define ReadAndVerifyDouble(name)
Definition: Effect.h:787
#define ReadAndVerifyString(name)
Definition: Effect.h:790
double dtmfDutyCycle
Definition: DtmfGen.h:91
bool EffectDtmf::Startup ( )
overridevirtual

Reimplemented from Effect.

Definition at line 270 of file DtmfGen.cpp.

References dtmfAmplitude, dtmfDutyCycle, dtmfSequence, Effect::GetCurrentSettingsGroup(), gPrefs, Effect::SaveUserPreset(), and SHORT_APP_NAME.

271 {
272  wxString base = wxT("/Effects/DtmfGen/");
273 
274  // Migrate settings from 2.1.0 or before
275 
276  // Already migrated, so bail
277  if (gPrefs->Exists(base + wxT("Migrated")))
278  {
279  return true;
280  }
281 
282  // Load the old "current" settings
283  if (gPrefs->Exists(base))
284  {
285  gPrefs->Read(base + wxT("String"), &dtmfSequence, wxT(SHORT_APP_NAME));
286  gPrefs->Read(base + wxT("DutyCycle"), &dtmfDutyCycle, 550L);
287  gPrefs->Read(base + wxT("Amplitude"), &dtmfAmplitude, 0.8f);
288 
290 
291  // Do not migrate again
292  gPrefs->Write(base + wxT("Migrated"), true);
293  gPrefs->Flush();
294  }
295 
296  return true;
297 }
#define SHORT_APP_NAME
Definition: DtmfGen.cpp:41
bool SaveUserPreset(const wxString &name) override
Definition: Effect.cpp:615
wxString GetCurrentSettingsGroup() override
Definition: Effect.cpp:814
wxString dtmfSequence
Definition: DtmfGen.h:87
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
double dtmfAmplitude
Definition: DtmfGen.h:92
double dtmfDutyCycle
Definition: DtmfGen.h:91
bool EffectDtmf::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 384 of file DtmfGen.cpp.

References dtmfDutyCycle, NumericConverter::GetValue(), mDtmfDurationT, mDtmfDutyCycleS, Effect::mUIParent, Recalculate(), and Effect::SetDuration().

385 {
386  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
387  {
388  return false;
389  }
390 
391  dtmfDutyCycle = (double) mDtmfDutyCycleS->GetValue() / SCL_DutyCycle;
393 
394  // recalculate to make sure all values are up-to-date. This is especially
395  // important if the user did not change any values in the dialog
396  Recalculate();
397 
398  return true;
399 }
wxSlider * mDtmfDutyCycleS
Definition: DtmfGen.h:96
void Recalculate()
Definition: DtmfGen.cpp:403
void SetDuration(double duration) override
Definition: Effect.cpp:757
wxWindow * mUIParent
Definition: Effect.h:471
double dtmfDutyCycle
Definition: DtmfGen.h:91
NumericTextCtrl * mDtmfDurationT
Definition: DtmfGen.h:97
bool EffectDtmf::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 366 of file DtmfGen.cpp.

References dtmfDutyCycle, Effect::GetDuration(), mDtmfDurationT, mDtmfDutyCycleS, Effect::mUIParent, Recalculate(), NumericTextCtrl::SetValue(), and UpdateUI().

367 {
368  Recalculate();
369 
370  if (!mUIParent->TransferDataToWindow())
371  {
372  return false;
373  }
374 
375  mDtmfDutyCycleS->SetValue(dtmfDutyCycle * SCL_DutyCycle);
376 
378 
379  UpdateUI();
380 
381  return true;
382 }
double GetDuration() override
Definition: Effect.cpp:737
wxSlider * mDtmfDutyCycleS
Definition: DtmfGen.h:96
void Recalculate()
Definition: DtmfGen.cpp:403
void UpdateUI()
Definition: DtmfGen.cpp:574
void SetValue(double newValue)
wxWindow * mUIParent
Definition: Effect.h:471
double dtmfDutyCycle
Definition: DtmfGen.h:91
NumericTextCtrl * mDtmfDurationT
Definition: DtmfGen.h:97
void EffectDtmf::UpdateUI ( void  )
private

Definition at line 574 of file DtmfGen.cpp.

References _(), dtmfDutyCycle, dtmfSilence, dtmfTone, mDtmfDutyT, mDtmfSilenceT, and mDtmfToneT.

Referenced by OnAmplitude(), OnDuration(), OnDutyCycle(), OnSequence(), and TransferDataToWindow().

575 {
576  mDtmfDutyT->SetLabel(wxString::Format(wxT("%.1f %%"), dtmfDutyCycle));
577  mDtmfDutyT->SetName(mDtmfDutyT->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
578 
579  mDtmfSilenceT->SetLabel(wxString::Format(_("%.0f ms"), dtmfTone * 1000.0));
580  mDtmfSilenceT->SetName(mDtmfSilenceT->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
581 
582  mDtmfToneT->SetLabel(wxString::Format(_("%.0f ms"), dtmfSilence * 1000.0));
583  mDtmfToneT->SetName(mDtmfToneT->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
584 }
wxStaticText * mDtmfToneT
Definition: DtmfGen.h:98
wxStaticText * mDtmfDutyT
Definition: DtmfGen.h:100
double dtmfSilence
Definition: DtmfGen.h:90
wxStaticText * mDtmfSilenceT
Definition: DtmfGen.h:99
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
double dtmfDutyCycle
Definition: DtmfGen.h:91
double dtmfTone
Definition: DtmfGen.h:89

Member Data Documentation

int EffectDtmf::curSeqPos
private

Definition at line 85 of file DtmfGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

sampleCount EffectDtmf::curTonePos
private

Definition at line 83 of file DtmfGen.h.

Referenced by ProcessBlock().

sampleCount EffectDtmf::diff
private

Definition at line 81 of file DtmfGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

double EffectDtmf::dtmfAmplitude
private
double EffectDtmf::dtmfDutyCycle
private
int EffectDtmf::dtmfNTones
private

Definition at line 88 of file DtmfGen.h.

Referenced by ProcessInitialize(), and Recalculate().

wxString EffectDtmf::dtmfSequence
private
double EffectDtmf::dtmfSilence
private

Definition at line 90 of file DtmfGen.h.

Referenced by PopulateOrExchange(), ProcessInitialize(), Recalculate(), and UpdateUI().

double EffectDtmf::dtmfTone
private

Definition at line 89 of file DtmfGen.h.

Referenced by PopulateOrExchange(), ProcessInitialize(), Recalculate(), and UpdateUI().

bool EffectDtmf::isTone
private

Definition at line 84 of file DtmfGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

wxTextCtrl* EffectDtmf::mDtmfAmplitudeT
private

Definition at line 95 of file DtmfGen.h.

Referenced by OnAmplitude().

NumericTextCtrl* EffectDtmf::mDtmfDurationT
private
wxSlider* EffectDtmf::mDtmfDutyCycleS
private

Definition at line 96 of file DtmfGen.h.

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

wxStaticText* EffectDtmf::mDtmfDutyT
private

Definition at line 100 of file DtmfGen.h.

Referenced by PopulateOrExchange(), and UpdateUI().

wxTextCtrl* EffectDtmf::mDtmfSequenceT
private

Definition at line 94 of file DtmfGen.h.

Referenced by OnSequence(), and PopulateOrExchange().

wxStaticText* EffectDtmf::mDtmfSilenceT
private

Definition at line 99 of file DtmfGen.h.

Referenced by PopulateOrExchange(), and UpdateUI().

wxStaticText* EffectDtmf::mDtmfToneT
private

Definition at line 98 of file DtmfGen.h.

Referenced by PopulateOrExchange(), and UpdateUI().

sampleCount EffectDtmf::numRemaining
private

Definition at line 82 of file DtmfGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

sampleCount EffectDtmf::numSamplesSequence
private

Definition at line 78 of file DtmfGen.h.

Referenced by ProcessInitialize().

sampleCount EffectDtmf::numSamplesSilence
private

Definition at line 80 of file DtmfGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().

sampleCount EffectDtmf::numSamplesTone
private

Definition at line 79 of file DtmfGen.h.

Referenced by ProcessBlock(), and ProcessInitialize().


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