Audacity 3.2.0
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Attributes | Static Private Member Functions | List of all members
DtmfBase Class Reference

#include <DtmfBase.h>

Inheritance diagram for DtmfBase:
[legend]
Collaboration diagram for DtmfBase:
[legend]

Classes

struct  Instance
 Temporary state of the computation. More...
 

Public Member Functions

 DtmfBase ()
 
virtual ~DtmfBase ()
 
ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
ManualPageID ManualPage () const override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectWithSettings< DtmfSettings, PerTrackEffect >
EffectSettings MakeSettings () const override
 
bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const override
 
- Public Member Functions inherited from PerTrackEffect
 ~PerTrackEffect () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatID GetSelectionFormat ()
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings, InstanceFinder finder={})
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
bool IsLinearEffect () const
 
bool PreviewsFullSelection () const
 
void SetTracks (TrackList *pTracks)
 
double GetDefaultDuration ()
 
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void CountWaveTracks ()
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("DTMF Tones") }
 
static constexpr std::array< char, 6 *7 > kSymbols
 
- Static Public Attributes inherited from EffectPlugin
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

const EffectParameterMethodsParameters () const override
 
- Protected Member Functions inherited from PerTrackEffect
bool DoPass1 () const
 
bool DoPass2 () const
 
bool Process (EffectInstance &instance, EffectSettings &settings) const
 
std::shared_ptr< EffectOutputTracksMakeOutputTracks ()
 
void DestroyOutputTracks () const
 
- Protected Member Functions inherited from Effect
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, sampleCount *start, sampleCount *len)
 
- Protected Member Functions inherited from EffectBase
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 

Static Protected Attributes

static constexpr EffectParameter Sequence
 
static constexpr EffectParameter DutyCycle
 
static constexpr EffectParameter Amplitude
 

Static Private Member Functions

static bool MakeDtmfTone (float *buffer, size_t len, float fs, wxChar tone, sampleCount last, sampleCount total, float amplitude)
 

Additional Inherited Members

- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Static Public Member Functions inherited from EffectWithSettings< DtmfSettings, PerTrackEffect >
static DtmfSettingsGetSettings (EffectSettings &settings)
 Assume settings originated from MakeSettings() and copies thereof. More...
 
static const DtmfSettingsGetSettings (const EffectSettings &settings)
 Assume settings originated from MakeSettings() and copies thereof. More...
 
static DtmfSettingsFetchParameters (PerTrackEffect &, EffectSettings &s)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
- Static Public Member Functions inherited from EffectBase
static std::optional< InstancePointerFindInstance (EffectPlugin &plugin)
 
static InstanceFinder DefaultInstanceFinder (EffectPlugin &plugin)
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Public Attributes inherited from EffectBase
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 
- Protected Attributes inherited from PerTrackEffect
sampleCount mSampleCnt {}
 
- Protected Attributes inherited from EffectBase
double mF0 {}
 
double mF1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

Detailed Description

Definition at line 28 of file DtmfBase.h.

Constructor & Destructor Documentation

◆ DtmfBase()

DtmfBase::DtmfBase ( )

Definition at line 27 of file DtmfBase.cpp.

28{
29}

◆ ~DtmfBase()

DtmfBase::~DtmfBase ( )
virtual

Definition at line 31 of file DtmfBase.cpp.

32{
33}

Member Function Documentation

◆ GetDescription()

TranslatableString DtmfBase::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 61 of file DtmfBase.cpp.

62{
63 return XO(
64 "Generates dual-tone multi-frequency (DTMF) tones like those produced by the keypad on telephones");
65}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol DtmfBase::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 56 of file DtmfBase.cpp.

57{
58 return Symbol;
59}
static const ComponentInterfaceSymbol Symbol
Definition: DtmfBase.h:32

References Symbol.

◆ GetType()

EffectType DtmfBase::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 74 of file DtmfBase.cpp.

75{
76 return EffectTypeGenerate;
77}
@ EffectTypeGenerate

References EffectTypeGenerate.

◆ MakeDtmfTone()

bool DtmfBase::MakeDtmfTone ( float *  buffer,
size_t  len,
float  fs,
wxChar  tone,
sampleCount  last,
sampleCount  total,
float  amplitude 
)
staticprivate

Definition at line 282 of file DtmfBase.cpp.

285{
286 /*
287 --------------------------------------------
288 1209 Hz 1336 Hz 1477 Hz 1633 Hz
289
290 ABC DEF
291 697 Hz 1 2 3 A
292
293 GHI JKL MNO
294 770 Hz 4 5 6 B
295
296 PQRS TUV WXYZ
297 852 Hz 7 8 9 C
298
299 oper
300 941 Hz * 0 # D
301 --------------------------------------------
302 Essentially we need to generate two sin with
303 frequencies according to this table, and sum
304 them up.
305 sin wave is generated by:
306 s(n)=sin(2*pi*n*f/fs)
307
308 We will precalculate:
309 A= 2*pi*f1/fs
310 B= 2*pi*f2/fs
311
312 And use two switch statements to select the frequency
313
314 Note: added support for letters, like those on the keypad
315 This support is only for lowercase letters: uppercase
316 are still considered to be the 'military'/carrier extra
317 tones.
318 */
319
320 float f1, f2 = 0.0;
321 double A, B;
322
323 // select low tone: left column
324 switch (tone)
325 {
326 case '1':
327 case '2':
328 case '3':
329 case 'A':
330 case 'a':
331 case 'b':
332 case 'c':
333 case 'd':
334 case 'e':
335 case 'f':
336 f1 = 697;
337 break;
338 case '4':
339 case '5':
340 case '6':
341 case 'B':
342 case 'g':
343 case 'h':
344 case 'i':
345 case 'j':
346 case 'k':
347 case 'l':
348 case 'm':
349 case 'n':
350 case 'o':
351 f1 = 770;
352 break;
353 case '7':
354 case '8':
355 case '9':
356 case 'C':
357 case 'p':
358 case 'q':
359 case 'r':
360 case 's':
361 case 't':
362 case 'u':
363 case 'v':
364 case 'w':
365 case 'x':
366 case 'y':
367 case 'z':
368 f1 = 852;
369 break;
370 case '*':
371 case '0':
372 case '#':
373 case 'D':
374 f1 = 941;
375 break;
376 default:
377 f1 = 0;
378 }
379
380 // select high tone: top row
381 switch (tone)
382 {
383 case '1':
384 case '4':
385 case '7':
386 case '*':
387 case 'g':
388 case 'h':
389 case 'i':
390 case 'p':
391 case 'q':
392 case 'r':
393 case 's':
394 f2 = 1209;
395 break;
396 case '2':
397 case '5':
398 case '8':
399 case '0':
400 case 'a':
401 case 'b':
402 case 'c':
403 case 'j':
404 case 'k':
405 case 'l':
406 case 't':
407 case 'u':
408 case 'v':
409 f2 = 1336;
410 break;
411 case '3':
412 case '6':
413 case '9':
414 case '#':
415 case 'd':
416 case 'e':
417 case 'f':
418 case 'm':
419 case 'n':
420 case 'o':
421 case 'w':
422 case 'x':
423 case 'y':
424 case 'z':
425 f2 = 1477;
426 break;
427 case 'A':
428 case 'B':
429 case 'C':
430 case 'D':
431 f2 = 1633;
432 break;
433 default:
434 f2 = 0;
435 }
436
437 // precalculations
438 A = B = 2 * M_PI / fs;
439 A *= f1;
440 B *= f2;
441
442 // now generate the wave: 'last' is used to avoid phase errors
443 // when inside the inner for loop of the Process() function.
444 for (decltype(len) i = 0; i < len; i++)
445 {
446 buffer[i] =
447 amplitude * 0.5 *
448 (sin(A * (i + last).as_double()) + sin(B * (i + last).as_double()));
449 }
450
451 // generate a fade-in of duration 1/250th of second
452 if (last == 0)
453 {
454 A = std::min<double>(len, (fs / kFadeInOut));
455 for (size_t i = 0; i < A; i++)
456 {
457 buffer[i] *= i / A;
458 }
459 }
460
461 // generate a fade-out of duration 1/250th of second
462 if (last >= total - len)
463 {
464 // we are at the last buffer of 'len' size, so, offset is to
465 // backup 'A' samples, from 'len'
466 A = std::min<double>(len, (fs / kFadeInOut));
467 size_t offset = len - A;
468 wxASSERT(offset >= 0);
469 for (size_t i = 0; i < A; i++)
470 {
471 buffer[i + offset] *= (1 - (i / A));
472 }
473 }
474 return true;
475}
#define M_PI
Definition: Distortion.cpp:22
static const double kFadeInOut
Definition: DtmfBase.cpp:11
#define A(N)
Definition: ToChars.cpp:62

References A, kFadeInOut, and M_PI.

Referenced by DtmfBase::Instance::ProcessBlock().

Here is the caller graph for this function:

◆ MakeInstance()

std::shared_ptr< EffectInstance > DtmfBase::MakeInstance ( ) const
overridevirtual

Make an object maintaining short-term state of an Effect.

One effect may have multiple instances extant simultaneously. Instances have state, may be implemented in foreign code, and are temporary, whereas EffectSettings represents persistent effect state that can be saved and reloaded from files.

Parameters
settingsmay be assumed to have a lifetime enclosing the instance's
Postcondition
true (no promises that the result isn't null)

Implements EffectInstanceFactory.

Definition at line 477 of file DtmfBase.cpp.

478{
479 // TODO: don't use Effect::mT0 and Effect::mSampleRate, but use an
480 // EffectContext (that class is not yet defined)
481 return std::make_shared<Instance>(*this, mT0);
482}
double mT0
Definition: EffectBase.h:122

References EffectBase::mT0.

◆ ManualPage()

ManualPageID DtmfBase::ManualPage ( ) const
overridevirtual

Name of a page in the Audacity alpha manual, default is empty.

Reimplemented from EffectDefinitionInterface.

Definition at line 67 of file DtmfBase.cpp.

68{
69 return L"DTMF_Tones";
70}

◆ Parameters()

const EffectParameterMethods & DtmfBase::Parameters ( ) const
overrideprotectedvirtual

Reimplemented from Effect.

Definition at line 35 of file DtmfBase.cpp.

36{
38 parameters {
39 [](DtmfBase&, EffectSettings& es, DtmfSettings& s, bool updating) {
40 if (updating)
41 {
42 if (
43 s.dtmfSequence.find_first_not_of(AllSymbols()) !=
45 return false;
46 s.Recalculate(es);
47 }
48 return true;
49 },
50 };
51 return parameters;
52}
Generates EffectParameterMethods overrides from variadic template arguments.
constexpr size_t npos(-1)
Externalized state of a plug-in.

References anonymous_namespace{DtmfBase.cpp}::AllSymbols(), and Tuple::detail::npos().

Here is the call graph for this function:

Member Data Documentation

◆ Amplitude

constexpr EffectParameter DtmfBase::Amplitude
staticconstexprprotected
Initial value:
L"Amplitude",
0.001,
1.0,
1 }
static constexpr double DefaultAmplitude
Definition: DtmfBase.h:11
double dtmfAmplitude
Definition: DtmfBase.h:21

Definition at line 117 of file DtmfBase.h.

Referenced by EffectDtmf::Editor::PopulateOrExchange().

◆ DutyCycle

constexpr EffectParameter DtmfBase::DutyCycle
staticconstexprprotected
Initial value:
L"Duty Cycle",
0.0,
100.0,
10.0 }
static constexpr double DefaultDutyCycle
Definition: DtmfBase.h:10
double dtmfDutyCycle
Definition: DtmfBase.h:18

Definition at line 111 of file DtmfBase.h.

Referenced by EffectDtmf::Editor::OnDutyCycle(), EffectDtmf::Editor::PopulateOrExchange(), EffectDtmf::Editor::UpdateUI(), and EffectDtmf::Editor::ValidateUI().

◆ kSymbols

constexpr std::array<char, 6 * 7> DtmfBase::kSymbols
staticconstexpr
Initial value:
{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '#', 'A', 'B',
'C', 'D', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
}

Definition at line 34 of file DtmfBase.h.

Referenced by anonymous_namespace{DtmfBase.cpp}::AllSymbols(), and EffectDtmf::Editor::PopulateOrExchange().

◆ Sequence

constexpr EffectParameter DtmfBase::Sequence
staticconstexprprotected
Initial value:
L"Sequence",
L"",
L"",
L"" }
wxString dtmfSequence
Definition: DtmfBase.h:13
static constexpr wchar_t DefaultSequence[]
Definition: DtmfBase.h:9

Definition at line 105 of file DtmfBase.h.

◆ Symbol

const ComponentInterfaceSymbol DtmfBase::Symbol { XO("DTMF Tones") }
static

Definition at line 32 of file DtmfBase.h.

Referenced by GetSymbol().


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