Audacity  3.0.3
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 <float.h>
27 
28 #include <wx/intl.h>
29 
30 #include "../ShuttleGui.h"
31 #include "../Shuttle.h"
32 #include "../widgets/AudacityMessageBox.h"
33 #include "../widgets/valnum.h"
34 
35 // Define keys, defaults, minimums, and maximums for the effect parameters
36 //
37 // Name Type Key Def Min Max Scale
38 Param( Delay, float, wxT("Delay"), 1.0f, 0.001f, FLT_MAX, 1.0f );
39 Param( Decay, float, wxT("Decay"), 0.5f, 0.0f, FLT_MAX, 1.0f );
40 
42 { XO("Echo") };
43 
45 
47 {
48  delay = DEF_Delay;
49  decay = DEF_Decay;
50 
51  SetLinearEffectFlag(true);
52 }
53 
55 {
56 }
57 
58 // ComponentInterface implementation
59 
61 {
62  return Symbol;
63 }
64 
66 {
67  return XO("Repeats the selected audio again and again");
68 }
69 
71 {
72  return wxT("Echo");
73 }
74 
75 // EffectDefinitionInterface implementation
76 
78 {
79  return EffectTypeProcess;
80 }
81 
82 // EffectClientInterface implementation
83 
85 {
86  return 1;
87 }
88 
90 {
91  return 1;
92 }
93 
94 bool EffectEcho::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelNames WXUNUSED(chanMap))
95 {
96  if (delay == 0.0)
97  {
98  return false;
99  }
100 
101  histPos = 0;
102  auto requestedHistLen = (sampleCount) (mSampleRate * delay);
103 
104  // Guard against extreme delay values input by the user
105  try {
106  // Guard against huge delay values from the user.
107  // Don't violate the assertion in as_size_t
108  if (requestedHistLen !=
109  (histLen = static_cast<size_t>(requestedHistLen.as_long_long())))
110  throw std::bad_alloc{};
111  history.reinit(histLen, true);
112  }
113  catch ( const std::bad_alloc& ) {
114  Effect::MessageBox( XO("Requested value exceeds memory capacity.") );
115  return false;
116  }
117 
118  return history != NULL;
119 }
120 
122 {
123  history.reset();
124  return true;
125 }
126 
127 size_t EffectEcho::ProcessBlock(float **inBlock, float **outBlock, size_t blockLen)
128 {
129  float *ibuf = inBlock[0];
130  float *obuf = outBlock[0];
131 
132  for (decltype(blockLen) i = 0; i < blockLen; i++, histPos++)
133  {
134  if (histPos == histLen)
135  {
136  histPos = 0;
137  }
138  history[histPos] = obuf[i] = ibuf[i] + history[histPos] * decay;
139  }
140 
141  return blockLen;
142 }
143 
145  S.SHUTTLE_PARAM( delay, Delay );
146  S.SHUTTLE_PARAM( decay, Decay );
147  return true;
148 }
149 
150 
152 {
153  parms.WriteFloat(KEY_Delay, delay);
154  parms.WriteFloat(KEY_Decay, decay);
155 
156  return true;
157 }
158 
160 {
161  ReadAndVerifyFloat(Delay);
162  ReadAndVerifyFloat(Decay);
163 
164  delay = Delay;
165  decay = Decay;
166 
167  return true;
168 }
169 
171 {
172  S.AddSpace(0, 5);
173 
174  S.StartMultiColumn(2, wxALIGN_CENTER);
175  {
176  S.Validator<FloatingPointValidator<double>>(
177  3, &delay, NumValidatorStyle::NO_TRAILING_ZEROES,
178  MIN_Delay, MAX_Delay
179  )
180  .AddTextBox(XXO("&Delay time (seconds):"), wxT(""), 10);
181 
182  S.Validator<FloatingPointValidator<double>>(
183  3, &decay, NumValidatorStyle::NO_TRAILING_ZEROES,
184  MIN_Decay, MAX_Decay)
185  .AddTextBox(XXO("D&ecay factor:"), wxT(""), 10);
186  }
187  S.EndMultiColumn();
188 }
189 
191 {
192  if (!mUIParent->TransferDataToWindow())
193  {
194  return false;
195  }
196 
197  return true;
198 }
199 
201 {
202  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
203  {
204  return false;
205  }
206 
207  return true;
208 }
209 
EffectEcho::TransferDataFromWindow
bool TransferDataFromWindow() override
Definition: Echo.cpp:200
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
CommandParameters
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
Definition: EffectAutomationParameters.h:67
EffectEcho::GetAudioOutCount
unsigned GetAudioOutCount() override
Definition: Echo.cpp:89
EffectEcho::TransferDataToWindow
bool TransferDataToWindow() override
Definition: Echo.cpp:190
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:59
Effect::SetLinearEffectFlag
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:2000
EffectEcho::GetAudioInCount
unsigned GetAudioInCount() override
Definition: Echo.cpp:84
EffectEcho::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: Echo.h:22
Effect::MessageBox
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
Definition: Effect.cpp:2478
EffectEcho::histLen
size_t histLen
Definition: Echo.h:61
EffectEcho::decay
double decay
Definition: Echo.h:58
ArrayOf::reinit
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:56
EffectEcho::history
Floats history
Definition: Echo.h:59
EffectEcho::GetType
EffectType GetType() override
Definition: Echo.cpp:77
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2421
EffectEcho::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: Echo.cpp:170
XO
#define XO(s)
Definition: Internat.h:31
EffectEcho::SetAutomationParameters
bool SetAutomationParameters(CommandParameters &parms) override
Definition: Echo.cpp:159
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:61
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1212
CommandParameters::WriteFloat
bool WriteFloat(const wxString &key, float f)
Definition: EffectAutomationParameters.h:157
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:61
Echo.h
XXO
#define XXO(s)
Definition: Internat.h:44
EffectEcho::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: Echo.cpp:144
EffectEcho::GetAutomationParameters
bool GetAutomationParameters(CommandParameters &parms) override
Definition: Echo.cpp:151
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1203
ChannelNames
enum ChannelName * ChannelNames
ShuttleGui::Validator
ShuttleGui & Validator(const Factory &f)
Definition: ShuttleGui.h:672
anonymous_namespace{Echo.cpp}::reg
BuiltinEffectsModule::Registration< EffectEcho > reg
Definition: Echo.cpp:44
EffectEcho::GetDescription
TranslatableString GetDescription() override
Definition: Echo.cpp:65
LoadEffects.h
EffectEcho::EffectEcho
EffectEcho()
Definition: Echo.cpp:46
EffectEcho::ProcessFinalize
bool ProcessFinalize() override
Definition: Echo.cpp:121
Effect::mSampleRate
double mSampleRate
Definition: Effect.h:458
BuiltinEffectsModule::Registration
Definition: LoadEffects.h:40
EffectEcho::~EffectEcho
virtual ~EffectEcho()
Definition: Echo.cpp:54
Effect::mUIParent
wxWindow * mUIParent
Definition: Effect.h:476
sampleCount
Definition: Types.h:66
EffectEcho::ManualPage
wxString ManualPage() override
Definition: Echo.cpp:70
EffectEcho::histPos
size_t histPos
Definition: Echo.h:60
EffectEcho::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: Echo.cpp:60
EffectEcho::ProcessBlock
size_t ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) override
Definition: Echo.cpp:127
EffectType
EffectType
Definition: EffectInterface.h:55
Param
Param(Delay, float, wxT("Delay"), 1.0f, 0.001f, FLT_MAX, 1.0f)
EffectEcho::delay
double delay
Definition: Echo.h:57
EffectEcho::ProcessInitialize
bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap=NULL) override
Definition: Echo.cpp:94
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
ReadAndVerifyFloat
#define ReadAndVerifyFloat(name)
Definition: Effect.h:632