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 "EffectEditor.h"
25#include "LoadEffects.h"
26
27#include "ShuttleGui.h"
28#include "AudacityMessageBox.h"
29#include "../widgets/valnum.h"
30
32{
35 > parameters;
36 return parameters;
37}
38
40{ XO("Echo") };
41
43
44
48{
49 Instance(const PerTrackEffect& effect)
50 : PerTrackEffect::Instance{ effect }
51 {}
52
53 bool ProcessInitialize(EffectSettings& settings, double sampleRate,
54 ChannelNames chanMap) override;
55
57 const float* const* inBlock, float* const* outBlock, size_t blockLen) override;
58
59 bool ProcessFinalize() noexcept override;
60
61 unsigned GetAudioOutCount() const override
62 {
63 return 1;
64 }
65
66 unsigned GetAudioInCount() const override
67 {
68 return 1;
69 }
70
72 size_t histPos;
73 size_t histLen;
74};
75
76
77
78std::shared_ptr<EffectInstance> EffectEcho::MakeInstance() const
79{
80 return std::make_shared<Instance>(*this);
81}
82
83
84
85
87{
89}
90
92{
93}
94
95// ComponentInterface implementation
96
98{
99 return Symbol;
100}
101
103{
104 return XO("Repeats the selected audio again and again");
105}
106
108{
109 return L"Echo";
110}
111
112// EffectDefinitionInterface implementation
113
115{
116 return EffectTypeProcess;
117}
118
120 EffectSettings& settings, double sampleRate, ChannelNames)
121{
122 auto& echoSettings = GetSettings(settings);
123 if (echoSettings.delay == 0.0)
124 return false;
125
126 histPos = 0;
127 auto requestedHistLen = (sampleCount) (sampleRate * echoSettings.delay);
128
129 // Guard against extreme delay values input by the user
130 try {
131 // Guard against huge delay values from the user.
132 // Don't violate the assertion in as_size_t
133 if (requestedHistLen !=
134 (histLen = static_cast<size_t>(requestedHistLen.as_long_long())))
135 throw std::bad_alloc{};
136 history.reinit(histLen, true);
137 }
138 catch ( const std::bad_alloc& ) {
140 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{
177 Editor(const EffectUIServices& services,
179 ) : EffectEditor{ services, access }
181 {}
182 virtual ~Editor() = default;
183
184 bool ValidateUI() override;
185 bool UpdateUI() override;
186
188
190};
191
192
193
194std::unique_ptr<EffectEditor> EffectEcho::MakeEditor(
196 const EffectOutputs *) const
197{
198 auto& settings = access.Get();
199 auto& myEffSettings = GetSettings(settings);
200 auto result = std::make_unique<Editor>(*this, access, myEffSettings);
201 result->PopulateOrExchange(S);
202 return result;
203}
204
205
207{
208 auto& echoSettings = mSettings;
209
210 S.AddSpace(0, 5);
211
212 S.StartMultiColumn(2, wxALIGN_CENTER);
213 {
214 S.Validator<FloatingPointValidator<double>>(
215 3, &echoSettings.delay, NumValidatorStyle::NO_TRAILING_ZEROES,
216 Delay.min, Delay.max )
217 .AddTextBox(XXO("&Delay time (seconds):"), L"", 10);
218
219 S.Validator<FloatingPointValidator<double>>(
220 3, &echoSettings.decay, NumValidatorStyle::NO_TRAILING_ZEROES,
222 .AddTextBox(XXO("D&ecay factor:"), L"", 10);
223 }
224 S.EndMultiColumn();
225}
226
227
229{
230 mAccess.ModifySettings
231 (
232 [this](EffectSettings& settings)
233 {
234 // pass back the modified settings to the MessageBuffer
235
237 return nullptr;
238 }
239 );
240
241 return true;
242}
243
244
246{
247 // get the settings from the MessageBuffer and write them to our local copy
248 const auto& settings = mAccess.Get();
249
250 mSettings = GetSettings(settings);
251
252 return true;
253}
254
EffectType
@ EffectTypeProcess
ChannelName
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#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:214
EffectEcho()
Definition: Echo.cpp:86
static const ComponentInterfaceSymbol Symbol
Definition: Echo.h:39
TranslatableString GetDescription() const override
Definition: Echo.cpp:102
ComponentInterfaceSymbol GetSymbol() const override
Definition: Echo.cpp:97
std::shared_ptr< EffectInstance > MakeInstance() const override
Make an object maintaining short-term state of an Effect.
Definition: Echo.cpp:78
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: Echo.cpp:107
static constexpr EffectParameter Decay
Definition: Echo.h:84
const EffectParameterMethods & Parameters() const override
Definition: Echo.cpp:31
EffectType GetType() const override
Type determines how it behaves.
Definition: Echo.cpp:114
static constexpr EffectParameter Delay
Definition: Echo.h:82
virtual ~EffectEcho()
Definition: Echo.cpp:91
std::unique_ptr< EffectEditor > MakeEditor(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
Called only from PopulateUI, to add controls to effect panel.
Definition: Echo.cpp:194
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
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
static EffectEchoSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:177
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:625
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:42
EffectEchoSettings mSettings
Definition: Echo.cpp:189
void PopulateOrExchange(ShuttleGui &S)
Definition: Echo.cpp:206
bool UpdateUI() override
Update appearance of the panel for changes in settings.
Definition: Echo.cpp:245
bool ValidateUI() override
Get settings data from the panel; may make error dialogs and return false.
Definition: Echo.cpp:228
virtual ~Editor()=default
Editor(const EffectUIServices &services, EffectSettingsAccess &access, const EffectEchoSettings &settings)
Definition: Echo.cpp:177
unsigned GetAudioInCount() const override
How many input buffers to allocate at once.
Definition: Echo.cpp:66
bool ProcessInitialize(EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
Definition: Echo.cpp:119
unsigned GetAudioOutCount() const override
How many output buffers to allocate at once.
Definition: Echo.cpp:61
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:49
const Type min
Minimum value.
const Type max
Maximum value.
Externalized state of a plug-in.