Audacity 3.2.0
EchoBase.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 EchoBase.cpp
6
7 Dominic Mazzoni
8 Vaughan Johnson (dialog)
9
10***********************************************************************/
11#include "EchoBase.h"
12#include "BasicUI.h"
13#include "ShuttleAutomation.h"
14
16{
18 return parameters;
19}
20
22
24{
26}
27
29{
30}
31
32// ComponentInterface implementation
33
35{
36 return Symbol;
37}
38
40{
41 return XO("Repeats the selected audio again and again");
42}
43
45{
46 return L"Echo";
47}
48
49// EffectDefinitionInterface implementation
50
52{
53 return EffectTypeProcess;
54}
55
58{
59 auto& echoSettings = GetSettings(settings);
60 if (echoSettings.delay == 0.0)
61 return false;
62
63 histPos = 0;
64 auto requestedHistLen = (sampleCount)(sampleRate * echoSettings.delay);
65
66 // Guard against extreme delay values input by the user
67 try
68 {
69 // Guard against huge delay values from the user.
70 // Don't violate the assertion in as_size_t
71 if (
72 requestedHistLen !=
73 (histLen = static_cast<size_t>(requestedHistLen.as_long_long())))
74 throw std::bad_alloc {};
75 history.reinit(histLen, true);
76 }
77 catch (const std::bad_alloc&)
78 {
79 BasicUI::ShowMessageBox(XO("Requested value exceeds memory capacity."));
80 return false;
81 }
82
83 return history != NULL;
84}
85
87{
88 return true;
89}
90
92 EffectSettings& settings, const float* const* inBlock,
93 float* const* outBlock, size_t blockLen)
94{
95 auto& echoSettings = GetSettings(settings);
96
97 const float* ibuf = inBlock[0];
98 float* obuf = outBlock[0];
99
100 for (decltype(blockLen) i = 0; i < blockLen; i++, histPos++)
101 {
102 if (histPos == histLen)
103 {
104 histPos = 0;
105 }
106 history[histPos] = obuf[i] =
107 ibuf[i] + history[histPos] * echoSettings.decay;
108 }
109
110 return blockLen;
111}
Toolkit-neutral facade for basic user interface services.
EffectType
@ EffectTypeProcess
ChannelName
XO("Cut/Copy/Paste")
static Settings & settings()
Definition: TrackInfo.cpp:51
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:59
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
EffectType GetType() const override
Type determines how it behaves.
Definition: EchoBase.cpp:51
EchoBase()
Definition: EchoBase.cpp:23
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: EchoBase.cpp:44
virtual ~EchoBase()
Definition: EchoBase.cpp:28
ComponentInterfaceSymbol GetSymbol() const override
Definition: EchoBase.cpp:34
TranslatableString GetDescription() const override
Definition: EchoBase.cpp:39
const EffectParameterMethods & Parameters() const override
Definition: EchoBase.cpp:15
static const ComponentInterfaceSymbol Symbol
Definition: EchoBase.h:33
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:210
Interface for manipulations of an Effect's settings.
static EchoSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:166
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
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:287
size_t ProcessBlock(EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
Called for destructive effect computation.
Definition: EchoBase.cpp:91
bool ProcessFinalize() noexcept override
Definition: EchoBase.cpp:86
bool ProcessInitialize(EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
Definition: EchoBase.cpp:56
Externalized state of a plug-in.