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 "../Shuttle.h"
31 #include "../widgets/ErrorDialog.h"
32 #include "../widgets/valnum.h"
33 #include "../SampleFormat.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 {
43  delay = DEF_Delay;
44  decay = DEF_Decay;
45 
46  SetLinearEffectFlag(true);
47 }
48 
50 {
51 }
52 
53 // IdentInterface implementation
54 
56 {
57  return ECHO_PLUGIN_SYMBOL;
58 }
59 
61 {
62  return _("Repeats the selected audio again and again");
63 }
64 
66 {
67  return wxT("Echo");
68 }
69 
70 // EffectDefinitionInterface implementation
71 
73 {
74  return EffectTypeProcess;
75 }
76 
77 // EffectClientInterface implementation
78 
80 {
81  return 1;
82 }
83 
85 {
86  return 1;
87 }
88 
89 bool EffectEcho::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelNames WXUNUSED(chanMap))
90 {
91  if (delay == 0.0)
92  {
93  return false;
94  }
95 
96  histPos = 0;
97  auto requestedHistLen = (sampleCount) (mSampleRate * delay);
98 
99  // Guard against extreme delay values input by the user
100  try {
101  // Guard against huge delay values from the user.
102  // Don't violate the assertion in as_size_t
103  if (requestedHistLen !=
104  (histLen = static_cast<size_t>(requestedHistLen.as_long_long())))
105  throw std::bad_alloc{};
106  history.reinit(histLen, true);
107  }
108  catch ( const std::bad_alloc& ) {
109  Effect::MessageBox(_("Requested value exceeds memory capacity."));
110  return false;
111  }
112 
113  return history != NULL;
114 }
115 
117 {
118  history.reset();
119  return true;
120 }
121 
122 size_t EffectEcho::ProcessBlock(float **inBlock, float **outBlock, size_t blockLen)
123 {
124  float *ibuf = inBlock[0];
125  float *obuf = outBlock[0];
126 
127  for (decltype(blockLen) i = 0; i < blockLen; i++, histPos++)
128  {
129  if (histPos == histLen)
130  {
131  histPos = 0;
132  }
133  history[histPos] = obuf[i] = ibuf[i] + history[histPos] * decay;
134  }
135 
136  return blockLen;
137 }
138 
140  S.SHUTTLE_PARAM( delay, Delay );
141  S.SHUTTLE_PARAM( decay, Decay );
142  return true;
143 }
144 
145 
147 {
148  parms.WriteFloat(KEY_Delay, delay);
149  parms.WriteFloat(KEY_Decay, decay);
150 
151  return true;
152 }
153 
155 {
156  ReadAndVerifyFloat(Delay);
157  ReadAndVerifyFloat(Decay);
158 
159  delay = Delay;
160  decay = Decay;
161 
162  return true;
163 }
164 
166 {
167  S.AddSpace(0, 5);
168 
169  S.StartMultiColumn(2, wxALIGN_CENTER);
170  {
171  FloatingPointValidator<double> vldDelay(3, &delay, NumValidatorStyle::NO_TRAILING_ZEROES);
172  vldDelay.SetRange(MIN_Delay, MAX_Delay);
173  S.AddTextBox(_("Delay time (seconds):"), wxT(""), 10)->SetValidator(vldDelay);
174 
175  FloatingPointValidator<double> vldDecay(3, &decay, NumValidatorStyle::NO_TRAILING_ZEROES);
176  vldDecay.SetRange(MIN_Decay, MAX_Decay);
177  S.AddTextBox(_("Decay factor:"), wxT(""), 10)->SetValidator(vldDecay);
178  }
179  S.EndMultiColumn();
180 }
181 
183 {
184  if (!mUIParent->TransferDataToWindow())
185  {
186  return false;
187  }
188 
189  return true;
190 }
191 
193 {
194  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
195  {
196  return false;
197  }
198 
199  return true;
200 }
201 
bool TransferDataFromWindow() override
Definition: Echo.cpp:192
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2664
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
#define ReadAndVerifyFloat(name)
Definition: Effect.h:799
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1963
EffectEcho()
Definition: Echo.cpp:41
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:519
Floats history
Definition: Echo.h:64
void EndMultiColumn()
size_t histLen
Definition: Echo.h:66
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
unsigned GetAudioOutCount() override
Definition: Echo.cpp:84
double mSampleRate
Definition: Effect.h:455
virtual ~EffectEcho()
Definition: Echo.cpp:49
bool WriteFloat(const wxString &key, float f)
IdentInterfaceSymbol GetSymbol() override
Definition: Echo.cpp:55
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
double delay
Definition: Echo.h:62
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
size_t ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) override
Definition: Echo.cpp:122
bool DefineParams(ShuttleParams &S) override
Definition: Echo.cpp:139
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
enum ChannelName * ChannelNames
#define ECHO_PLUGIN_SYMBOL
Definition: Echo.h:24
EffectType GetType() override
Definition: Echo.cpp:72
wxWindow * mUIParent
Definition: Effect.h:472
wxString GetDescription() override
Definition: Echo.cpp:60
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
EffectType
bool ProcessFinalize() override
Definition: Echo.cpp:116
Param(Delay, float, wxT("Delay"), 1.0f, 0.001f, FLT_MAX, 1.0f)
wxString ManualPage() override
Definition: Echo.cpp:65
bool GetAutomationParameters(CommandParameters &parms) override
Definition: Echo.cpp:146
size_t histPos
Definition: Echo.h:65
void PopulateOrExchange(ShuttleGui &S) override
Definition: Echo.cpp:165
bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap=NULL) override
Definition: Echo.cpp:89
wxSizerItem * AddSpace(int width, int height)
double decay
Definition: Echo.h:63
unsigned GetAudioInCount() override
Definition: Echo.cpp:79
bool SetAutomationParameters(CommandParameters &parms) override
Definition: Echo.cpp:154
bool TransferDataToWindow() override
Definition: Echo.cpp:182