Audacity  2.2.2
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 #include "../Audacity.h"
23 #include "Echo.h"
24 
25 #include <float.h>
26 
27 #include <wx/intl.h>
28 
29 #include "../ShuttleGui.h"
30 #include "../widgets/ErrorDialog.h"
31 #include "../widgets/valnum.h"
32 #include "../SampleFormat.h"
33 
34 // Define keys, defaults, minimums, and maximums for the effect parameters
35 //
36 // Name Type Key Def Min Max Scale
37 Param( Delay, float, wxT("Delay"), 1.0f, 0.001f, FLT_MAX, 1.0f );
38 Param( Decay, float, wxT("Decay"), 0.5f, 0.0f, FLT_MAX, 1.0f );
39 
41 {
42  delay = DEF_Delay;
43  decay = DEF_Decay;
44 
45  SetLinearEffectFlag(true);
46 }
47 
49 {
50 }
51 
52 // IdentInterface implementation
53 
55 {
56  return ECHO_PLUGIN_SYMBOL;
57 }
58 
60 {
61  return _("Repeats the selected audio again and again");
62 }
63 
65 {
66  return wxT("Echo");
67 }
68 
69 // EffectIdentInterface implementation
70 
71 EffectType EffectEcho::GetType()
72 {
73  return EffectTypeProcess;
74 }
75 
76 // EffectClientInterface implementation
77 
79 {
80  return 1;
81 }
82 
84 {
85  return 1;
86 }
87 
88 bool EffectEcho::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelNames WXUNUSED(chanMap))
89 {
90  if (delay == 0.0)
91  {
92  return false;
93  }
94 
95  histPos = 0;
96  auto requestedHistLen = (sampleCount) (mSampleRate * delay);
97 
98  // Guard against extreme delay values input by the user
99  try {
100  // Guard against huge delay values from the user.
101  // Don't violate the assertion in as_size_t
102  if (requestedHistLen !=
103  (histLen = static_cast<size_t>(requestedHistLen.as_long_long())))
104  throw std::bad_alloc{};
105  history.reinit(histLen, true);
106  }
107  catch ( const std::bad_alloc& ) {
108  Effect::MessageBox(_("Requested value exceeds memory capacity."));
109  return false;
110  }
111 
112  return history != NULL;
113 }
114 
116 {
117  history.reset();
118  return true;
119 }
120 
121 size_t EffectEcho::ProcessBlock(float **inBlock, float **outBlock, size_t blockLen)
122 {
123  float *ibuf = inBlock[0];
124  float *obuf = outBlock[0];
125 
126  for (decltype(blockLen) i = 0; i < blockLen; i++, histPos++)
127  {
128  if (histPos == histLen)
129  {
130  histPos = 0;
131  }
132  history[histPos] = obuf[i] = ibuf[i] + history[histPos] * decay;
133  }
134 
135  return blockLen;
136 }
137 
138 bool EffectEcho::GetAutomationParameters(EffectAutomationParameters & parms)
139 {
140  parms.WriteFloat(KEY_Delay, delay);
141  parms.WriteFloat(KEY_Decay, decay);
142 
143  return true;
144 }
145 
146 bool EffectEcho::SetAutomationParameters(EffectAutomationParameters & parms)
147 {
148  ReadAndVerifyFloat(Delay);
149  ReadAndVerifyFloat(Decay);
150 
151  delay = Delay;
152  decay = Decay;
153 
154  return true;
155 }
156 
158 {
159  S.AddSpace(0, 5);
160 
161  S.StartMultiColumn(2, wxALIGN_CENTER);
162  {
163  FloatingPointValidator<double> vldDelay(3, &delay, NUM_VAL_NO_TRAILING_ZEROES);
164  vldDelay.SetRange(MIN_Delay, MAX_Delay);
165  S.AddTextBox(_("Delay time (seconds):"), wxT(""), 10)->SetValidator(vldDelay);
166 
167  FloatingPointValidator<double> vldDecay(3, &decay, NUM_VAL_NO_TRAILING_ZEROES);
168  vldDecay.SetRange(MIN_Decay, MAX_Decay);
169  S.AddTextBox(_("Decay factor:"), wxT(""), 10)->SetValidator(vldDecay);
170  }
171  S.EndMultiColumn();
172 }
173 
175 {
176  if (!mUIParent->TransferDataToWindow())
177  {
178  return false;
179  }
180 
181  return true;
182 }
183 
185 {
186  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
187  {
188  return false;
189  }
190 
191  return true;
192 }
193 
wxString GetSymbol() override
Definition: Echo.cpp:54
bool TransferDataFromWindow() override
Definition: Echo.cpp:184
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2655
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
#define ReadAndVerifyFloat(name)
Definition: Effect.h:788
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1954
EffectEcho()
Definition: Echo.cpp:40
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:499
Floats history
Definition: Echo.h:63
void EndMultiColumn()
size_t histLen
Definition: Echo.h:65
unsigned GetAudioOutCount() override
Definition: Echo.cpp:83
double mSampleRate
Definition: Effect.h:455
bool GetAutomationParameters(EffectAutomationParameters &parms) override
Definition: Echo.cpp:138
virtual ~EffectEcho()
Definition: Echo.cpp:48
bool SetAutomationParameters(EffectAutomationParameters &parms) override
Definition: Echo.cpp:146
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:493
double delay
Definition: Echo.h:61
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
size_t ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) override
Definition: Echo.cpp:121
#define ECHO_PLUGIN_SYMBOL
Definition: Echo.h:24
EffectType GetType() override
Definition: Echo.cpp:71
wxWindow * mUIParent
Definition: Effect.h:471
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
wxString GetDescription() override
Definition: Echo.cpp:59
bool ProcessFinalize() override
Definition: Echo.cpp:115
Param(Delay, float, wxT("Delay"), 1.0f, 0.001f, FLT_MAX, 1.0f)
wxString ManualPage() override
Definition: Echo.cpp:64
size_t histPos
Definition: Echo.h:64
void PopulateOrExchange(ShuttleGui &S) override
Definition: Echo.cpp:157
bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap=NULL) override
Definition: Echo.cpp:88
wxSizerItem * AddSpace(int width, int height)
double decay
Definition: Echo.h:62
unsigned GetAudioInCount() override
Definition: Echo.cpp:78
bool TransferDataToWindow() override
Definition: Echo.cpp:174