Audacity 3.2.0
Echo.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Echo.cpp
6
7 Dominic Mazzoni
8 Vaughan Johnson (dialog)
9
10*******************************************************************//****************************************************************//*******************************************************************/
21
22
23#include "Echo.h"
24#include "LoadEffects.h"
25
26#include <wx/intl.h>
27
28#include "../ShuttleGui.h"
29#include "../widgets/AudacityMessageBox.h"
30#include "../widgets/valnum.h"
31
33{
36 > parameters;
37 return parameters;
38}
39
41{ XO("Echo") };
42
44
45
50
51{
52 Instance(const PerTrackEffect& effect)
53 : PerTrackEffect::Instance{ effect }
54 {}
55
57 sampleCount totalLen, ChannelNames chanMap) override;
58
60 const float* const* inBlock, float* const* outBlock, size_t blockLen) override;
61
62 bool ProcessFinalize(void) override;
63
65 size_t histPos;
66 size_t histLen;
67};
68
69
70
71std::shared_ptr<EffectInstance> EffectEcho::MakeInstance() const
72{
73 return std::make_shared<Instance>(*this);
74}
75
76
77
78
80{
82}
83
85{
86}
87
88// ComponentInterface implementation
89
91{
92 return Symbol;
93}
94
96{
97 return XO("Repeats the selected audio again and again");
98}
99
101{
102 return L"Echo";
103}
104
105// EffectDefinitionInterface implementation
106
108{
109 return EffectTypeProcess;
110}
111
113{
114 return 1;
115}
116
118{
119 return 1;
120}
121
124{
125 auto& echoSettings = GetSettings(settings);
126
127 if (echoSettings.delay == 0.0)
128 {
129 return false;
130 }
131
132 histPos = 0;
133 auto requestedHistLen = (sampleCount) (mSampleRate * echoSettings.delay);
134
135 // Guard against extreme delay values input by the user
136 try {
137 // Guard against huge delay values from the user.
138 // Don't violate the assertion in as_size_t
139 if (requestedHistLen !=
140 (histLen = static_cast<size_t>(requestedHistLen.as_long_long())))
141 throw std::bad_alloc{};
142 history.reinit(histLen, true);
143 }
144 catch ( const std::bad_alloc& ) {
145 mProcessor.MessageBox( XO("Requested value exceeds memory capacity.") );
146 return false;
147 }
148
149 return history != NULL;
150}
151
153{
154 return true;
155}
156
158 const float *const *inBlock, float *const *outBlock, size_t blockLen)
159{
160 auto& echoSettings = GetSettings(settings);
161
162 const float *ibuf = inBlock[0];
163 float *obuf = outBlock[0];
164
165 for (decltype(blockLen) i = 0; i < blockLen; i++, histPos++)
166 {
167 if (histPos == histLen)
168 {
169 histPos = 0;
170 }
171 history[histPos] = obuf[i] = ibuf[i] + history[histPos] * echoSettings.decay;
172 }
173
174 return blockLen;
175}
176
177
178
181{
184 : DefaultEffectUIValidator{ effect, access }
186 {}
187 virtual ~Validator() = default;
188
189 Effect& GetEffect() const { return static_cast<Effect&>(mEffect); }
190
191 bool ValidateUI() override;
192 bool UpdateUI() override;
193
195
197};
198
199
200
201std::unique_ptr<EffectUIValidator> EffectEcho::PopulateOrExchange(
203{
204 auto& settings = access.Get();
205 auto& myEffSettings = GetSettings(settings);
206 auto result = std::make_unique<Validator>(*this, access, myEffSettings);
207 result->PopulateOrExchange(S);
208 return result;
209}
210
211
213{
214 auto& echoSettings = mSettings;
215
216 S.AddSpace(0, 5);
217
218 S.StartMultiColumn(2, wxALIGN_CENTER);
219 {
220 S.Validator<FloatingPointValidator<double>>(
221 3, &echoSettings.delay, NumValidatorStyle::NO_TRAILING_ZEROES,
222 Delay.min, Delay.max )
223 .AddTextBox(XXO("&Delay time (seconds):"), L"", 10);
224
225 S.Validator<FloatingPointValidator<double>>(
226 3, &echoSettings.decay, NumValidatorStyle::NO_TRAILING_ZEROES,
228 .AddTextBox(XXO("D&ecay factor:"), L"", 10);
229 }
230 S.EndMultiColumn();
231}
232
233
235{
236 mAccess.ModifySettings
237 (
238 [this](EffectSettings& settings)
239 {
240 // pass back the modified settings to the MessageBuffer
241
243 }
244 );
245
246 return true;
247}
248
249
251{
252 // get the settings from the MessageBuffer and write them to our local copy
253 const auto& settings = mAccess.Get();
254
255 mSettings = GetSettings(settings);
256
257 return true;
258}
259
EffectType
@ EffectTypeProcess
enum ChannelName * ChannelNames
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:87
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:57
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Default implementation of EffectUIValidator invokes ValidateUI method of an EffectUIClientInterface.
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:206
EffectEcho()
Definition: Echo.cpp:79
static const ComponentInterfaceSymbol Symbol
Definition: Echo.h:37
TranslatableString GetDescription() const override
Definition: Echo.cpp:95
ComponentInterfaceSymbol GetSymbol() const override
Definition: Echo.cpp:90
std::shared_ptr< EffectInstance > MakeInstance() const override
Make an object maintaining short-term state of an Effect.
Definition: Echo.cpp:71
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: Echo.cpp:100
unsigned GetAudioOutCount() const override
How many output buffers to allocate at once.
Definition: Echo.cpp:117
static constexpr EffectParameter Decay
Definition: Echo.h:84
const EffectParameterMethods & Parameters() const override
Definition: Echo.cpp:32
EffectType GetType() const override
Type determines how it behaves.
Definition: Echo.cpp:107
static constexpr EffectParameter Delay
Definition: Echo.h:82
virtual ~EffectEcho()
Definition: Echo.cpp:84
unsigned GetAudioInCount() const override
How many input buffers to allocate at once.
Definition: Echo.cpp:112
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
Add controls to effect panel; always succeeds.
Definition: Echo.cpp:201
Base class for many of the effects in Audacity.
Definition: Effect.h:148
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
Definition: Effect.cpp:869
Performs effect computation.
Inherit to add a state variable to an EffectInstance subclass.
Inherit to add a state variable to an EffectInstance subclass.
Interface for manipulations of an Effect's settings.
virtual const EffectSettings & Get()=0
EffectUIClientInterface is an abstract base class to populate a UI and validate UI values....
EffectUIClientInterface & mEffect
static EffectEchoSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:415
const PerTrackEffect & mProcessor
Base class for many of the effects in Audacity.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
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:18
BuiltinEffectsModule::Registration< EffectEcho > reg
Definition: Echo.cpp:43
bool ProcessFinalize(void) override
Definition: Echo.cpp:152
bool ProcessInitialize(EffectSettings &settings, sampleCount totalLen, ChannelNames chanMap) override
Definition: Echo.cpp:122
size_t ProcessBlock(EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
Called for destructive effect computation.
Definition: Echo.cpp:157
Instance(const PerTrackEffect &effect)
Definition: Echo.cpp:52
EffectEchoSettings mSettings
Definition: Echo.cpp:196
bool UpdateUI() override
Update appearance of the panel for changes in settings.
Definition: Echo.cpp:250
virtual ~Validator()=default
void PopulateOrExchange(ShuttleGui &S)
Definition: Echo.cpp:212
Validator(EffectUIClientInterface &effect, EffectSettingsAccess &access, const EffectEchoSettings &settings)
Definition: Echo.cpp:182
bool ValidateUI() override
Get settings data from the panel; may make error dialogs and return false.
Definition: Echo.cpp:234
Effect & GetEffect() const
Definition: Echo.cpp:189
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31
Externalized state of a plug-in.