Audacity 3.2.0
DtmfBase.h
Go to the documentation of this file.
1#pragma once
2
3#include "PerTrackEffect.h"
4#include "ShuttleAutomation.h"
5#include <array>
6
7struct BUILTIN_EFFECTS_API DtmfSettings
8{
9 static constexpr wchar_t DefaultSequence[] = L"audacity";
10 static constexpr double DefaultDutyCycle = 55.0;
11 static constexpr double DefaultAmplitude = 0.8;
12
13 wxString dtmfSequence { DefaultSequence }; // dtmf tone string
14 size_t dtmfNTones =
15 dtmfSequence.length(); // total number of tones to generate
16 double dtmfTone {}; // duration of a single tone in ms
17 double dtmfSilence {}; // duration of silence between tones in ms
18 double dtmfDutyCycle {
19 DefaultDutyCycle
20 }; // ratio of dtmfTone/(dtmfTone+dtmfSilence)
21 double dtmfAmplitude {
22 DefaultAmplitude
23 }; // amplitude of dtmf tone sequence, restricted to (0-1)
24
25 void Recalculate(EffectSettings& settings);
26};
27
28class BUILTIN_EFFECTS_API DtmfBase :
29 public EffectWithSettings<DtmfSettings, PerTrackEffect>
30{
31public:
33
34 static constexpr std::array<char, 6 * 7> kSymbols {
35 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '#', 'A', 'B',
36 'C', 'D', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
37 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
38 };
39
40 DtmfBase();
41 virtual ~DtmfBase();
42
43 // ComponentInterface implementation
44
45 ComponentInterfaceSymbol GetSymbol() const override;
46 TranslatableString GetDescription() const override;
47 ManualPageID ManualPage() const override;
48
49 // EffectDefinitionInterface implementation
50
51 EffectType GetType() const override;
52
55 {
56 Instance(const PerTrackEffect& effect, double t0)
57 : PerTrackEffect::Instance { effect }
58 , mT0 { t0 }
59 {
60 }
61
62 bool ProcessInitialize(
64 ChannelNames chanMap) override;
65 size_t ProcessBlock(
66 EffectSettings& settings, const float* const* inBlock,
67 float* const* outBlock, size_t blockLen) override;
68
69 unsigned GetAudioInCount() const override
70 {
71 return 0;
72 }
73
74 unsigned GetAudioOutCount() const override
75 {
76 return 1;
77 }
78
79 const double mT0;
80 double mSampleRate {};
81
82 sampleCount numSamplesSequence; // total number of samples to generate
83 sampleCount numSamplesTone; // number of samples in a tone block
84 sampleCount numSamplesSilence; // number of samples in a silence block
85 sampleCount diff; // number of extra samples to redistribute
87 numRemaining; // number of samples left to produce in the current block
88 sampleCount curTonePos; // position in tone to start the wave
89 bool isTone; // true if block is tone, otherwise silence
90 int curSeqPos; // index into dtmf tone string
91 };
92
93 std::shared_ptr<EffectInstance> MakeInstance() const override;
94
95private:
96 // DtmfBase implementation
97
98 static bool MakeDtmfTone(
99 float* buffer, size_t len, float fs, wxChar tone, sampleCount last,
100 sampleCount total, float amplitude);
101
102protected:
103 const EffectParameterMethods& Parameters() const override;
104
106 L"Sequence",
108 L"",
109 L"",
110 L"" };
111 static constexpr EffectParameter DutyCycle { &DtmfSettings::dtmfDutyCycle,
112 L"Duty Cycle",
114 0.0,
115 100.0,
116 10.0 };
117 static constexpr EffectParameter Amplitude { &DtmfSettings::dtmfAmplitude,
118 L"Amplitude",
120 0.001,
121 1.0,
122 1 };
123};
EffectType
ChannelName
static Settings & settings()
Definition: TrackInfo.cpp:51
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static const ComponentInterfaceSymbol Symbol
Definition: DtmfBase.h:32
Inherit to add a state variable to an EffectInstance subclass.
Interface for manipulations of an Effect's settings.
Base class for many of the effects in Audacity.
A WaveTrack contains WaveClip(s). A WaveClip contains a Sequence. A Sequence is primarily an interfac...
Definition: Sequence.h:53
Holds a msgid for the translation catalog; may also bind format arguments.
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
Temporary state of the computation.
Definition: DtmfBase.h:55
unsigned GetAudioOutCount() const override
How many output buffers to allocate at once.
Definition: DtmfBase.h:74
sampleCount diff
Definition: DtmfBase.h:85
sampleCount numSamplesSilence
Definition: DtmfBase.h:84
sampleCount curTonePos
Definition: DtmfBase.h:88
sampleCount numSamplesSequence
Definition: DtmfBase.h:82
sampleCount numSamplesTone
Definition: DtmfBase.h:83
Instance(const PerTrackEffect &effect, double t0)
Definition: DtmfBase.h:56
const double mT0
Definition: DtmfBase.h:79
unsigned GetAudioInCount() const override
How many input buffers to allocate at once.
Definition: DtmfBase.h:69
sampleCount numRemaining
Definition: DtmfBase.h:87
static constexpr double DefaultDutyCycle
Definition: DtmfBase.h:10
static constexpr double DefaultAmplitude
Definition: DtmfBase.h:11
wxString dtmfSequence
Definition: DtmfBase.h:13
double dtmfDutyCycle
Definition: DtmfBase.h:18
double dtmfAmplitude
Definition: DtmfBase.h:21
static constexpr wchar_t DefaultSequence[]
Definition: DtmfBase.h:9
Externalized state of a plug-in.