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
49{
50 Instance(const PerTrackEffect& effect)
51 : PerTrackEffect::Instance{ effect }
52 {}
53
54 bool ProcessInitialize(EffectSettings& settings, double sampleRate,
55 ChannelNames chanMap) override;
56
58 const float* const* inBlock, float* const* outBlock, size_t blockLen) override;
59
60 bool ProcessFinalize() noexcept override;
61
62 unsigned GetAudioOutCount() const override
63 {
64 return 1;
65 }
66
67 unsigned GetAudioInCount() const override
68 {
69 return 1;
70 }
71
73 size_t histPos;
74 size_t histLen;
75};
76
77
78
79std::shared_ptr<EffectInstance> EffectEcho::MakeInstance() const
80{
81 return std::make_shared<Instance>(*this);
82}
83
84
85
86
88{
90}
91
93{
94}
95
96// ComponentInterface implementation
97
99{
100 return Symbol;
101}
102
104{
105 return XO("Repeats the selected audio again and again");
106}
107
109{
110 return L"Echo";
111}
112
113// EffectDefinitionInterface implementation
114
116{
117 return EffectTypeProcess;
118}
119
121 EffectSettings& settings, double sampleRate, ChannelNames)
122{
123 auto& echoSettings = GetSettings(settings);
124 if (echoSettings.delay == 0.0)
125 return false;
126
127 histPos = 0;
128 auto requestedHistLen = (sampleCount) (sampleRate * echoSettings.delay);
129
130 // Guard against extreme delay values input by the user
131 try {
132 // Guard against huge delay values from the user.
133 // Don't violate the assertion in as_size_t
134 if (requestedHistLen !=
135 (histLen = static_cast<size_t>(requestedHistLen.as_long_long())))
136 throw std::bad_alloc{};
137 history.reinit(histLen, true);
138 }
139 catch ( const std::bad_alloc& ) {
140 mProcessor.MessageBox( XO("Requested value exceeds memory capacity.") );
141 return false;
142 }
143
144 return history != NULL;
145}
146
148{
149 return true;
150}
151
153 const float *const *inBlock, float *const *outBlock, size_t blockLen)
154{
155 auto& echoSettings = GetSettings(settings);
156
157 const float *ibuf = inBlock[0];
158 float *obuf = outBlock[0];
159
160 for (decltype(blockLen) i = 0; i < blockLen; i++, histPos++)
161 {
162 if (histPos == histLen)
163 {
164 histPos = 0;
165 }
166 history[histPos] = obuf[i] = ibuf[i] + history[histPos] * echoSettings.decay;
167 }
168
169 return blockLen;
170}
171
172
173
176{
179 : EffectUIValidator{ effect, access }
181 {}
182 virtual ~Validator() = default;
183
184 Effect& GetEffect() const { return static_cast<Effect&>(mEffect); }
185
186 bool ValidateUI() override;
187 bool UpdateUI() override;
188
190
192};
193
194
195
196std::unique_ptr<EffectUIValidator> EffectEcho::PopulateOrExchange(
198 const EffectOutputs *)
199{
200 auto& settings = access.Get();
201 auto& myEffSettings = GetSettings(settings);
202 auto result = std::make_unique<Validator>(*this, access, myEffSettings);
203 result->PopulateOrExchange(S);
204 return result;
205}
206
207
209{
210 auto& echoSettings = mSettings;
211
212 S.AddSpace(0, 5);
213
214 S.StartMultiColumn(2, wxALIGN_CENTER);
215 {
216 S.Validator<FloatingPointValidator<double>>(
217 3, &echoSettings.delay, NumValidatorStyle::NO_TRAILING_ZEROES,
218 Delay.min, Delay.max )
219 .AddTextBox(XXO("&Delay time (seconds):"), L"", 10);
220
221 S.Validator<FloatingPointValidator<double>>(
222 3, &echoSettings.decay, NumValidatorStyle::NO_TRAILING_ZEROES,
224 .AddTextBox(XXO("D&ecay factor:"), L"", 10);
225 }
226 S.EndMultiColumn();
227}
228
229
231{
232 mAccess.ModifySettings
233 (
234 [this](EffectSettings& settings)
235 {
236 // pass back the modified settings to the MessageBuffer
237
239 return nullptr;
240 }
241 );
242
243 return true;
244}
245
246
248{
249 // get the settings from the MessageBuffer and write them to our local copy
250 const auto& settings = mAccess.Get();
251
252 mSettings = GetSettings(settings);
253
254 return true;
255}
256
EffectType
@ EffectTypeProcess
ChannelName
#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,...
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:222
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
Definition: Echo.cpp:196
EffectEcho()
Definition: Echo.cpp:87
static const ComponentInterfaceSymbol Symbol
Definition: Echo.h:37
TranslatableString GetDescription() const override
Definition: Echo.cpp:103
ComponentInterfaceSymbol GetSymbol() const override
Definition: Echo.cpp:98
std::shared_ptr< EffectInstance > MakeInstance() const override
Make an object maintaining short-term state of an Effect.
Definition: Echo.cpp:79
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: Echo.cpp:108
static constexpr EffectParameter Decay
Definition: Echo.h:81
const EffectParameterMethods & Parameters() const override
Definition: Echo.cpp:32
EffectType GetType() const override
Type determines how it behaves.
Definition: Echo.cpp:115
static constexpr EffectParameter Delay
Definition: Echo.h:79
virtual ~EffectEcho()
Definition: Echo.cpp:92
Base class for many of the effects in Audacity.
Definition: Effect.h:63
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
Definition: Effect.cpp:863
Performs effect computation.
Inherit to add a state variable to an EffectInstance subclass.
Hold values to send to effect output meters.
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....
Interface for transferring values from a panel of effect controls.
EffectUIClientInterface & mEffect
static EffectEchoSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:333
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:628
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
BuiltinEffectsModule::Registration< EffectEcho > reg
Definition: Echo.cpp:43
unsigned GetAudioInCount() const override
How many input buffers to allocate at once.
Definition: Echo.cpp:67
bool ProcessInitialize(EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
Definition: Echo.cpp:120
unsigned GetAudioOutCount() const override
How many output buffers to allocate at once.
Definition: Echo.cpp:62
bool ProcessFinalize() noexcept override
Definition: Echo.cpp:147
size_t ProcessBlock(EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
Called for destructive effect computation.
Definition: Echo.cpp:152
Instance(const PerTrackEffect &effect)
Definition: Echo.cpp:50
EffectEchoSettings mSettings
Definition: Echo.cpp:191
bool UpdateUI() override
Update appearance of the panel for changes in settings.
Definition: Echo.cpp:247
virtual ~Validator()=default
void PopulateOrExchange(ShuttleGui &S)
Definition: Echo.cpp:208
Validator(EffectUIClientInterface &effect, EffectSettingsAccess &access, const EffectEchoSettings &settings)
Definition: Echo.cpp:177
bool ValidateUI() override
Get settings data from the panel; may make error dialogs and return false.
Definition: Echo.cpp:230
Effect & GetEffect() const
Definition: Echo.cpp:184
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31
Externalized state of a plug-in.