forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcho.cpp
More file actions
209 lines (159 loc) · 4.38 KB
/
Copy pathEcho.cpp
File metadata and controls
209 lines (159 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**********************************************************************
Audacity: A Digital Audio Editor
Echo.cpp
Dominic Mazzoni
Vaughan Johnson (dialog)
*******************************************************************//**
\class EffectEcho
\brief An Effect that causes an echo, variable delay and volume.
*//****************************************************************//**
\class EchoDialog
\brief EchoDialog used with EffectEcho
*//*******************************************************************/
#include "../Audacity.h"
#include "Echo.h"
#include "LoadEffects.h"
#include <float.h>
#include <wx/intl.h>
#include "../ShuttleGui.h"
#include "../Shuttle.h"
#include "../widgets/AudacityMessageBox.h"
#include "../widgets/valnum.h"
// Define keys, defaults, minimums, and maximums for the effect parameters
//
// Name Type Key Def Min Max Scale
Param( Delay, float, wxT("Delay"), 1.0f, 0.001f, FLT_MAX, 1.0f );
Param( Decay, float, wxT("Decay"), 0.5f, 0.0f, FLT_MAX, 1.0f );
const ComponentInterfaceSymbol EffectEcho::Symbol
{ XO("Echo") };
namespace{ BuiltinEffectsModule::Registration< EffectEcho > reg; }
EffectEcho::EffectEcho()
{
delay = DEF_Delay;
decay = DEF_Decay;
SetLinearEffectFlag(true);
}
EffectEcho::~EffectEcho()
{
}
// ComponentInterface implementation
ComponentInterfaceSymbol EffectEcho::GetSymbol()
{
return Symbol;
}
TranslatableString EffectEcho::GetDescription()
{
return XO("Repeats the selected audio again and again");
}
wxString EffectEcho::ManualPage()
{
return wxT("Echo");
}
// EffectDefinitionInterface implementation
EffectType EffectEcho::GetType()
{
return EffectTypeProcess;
}
// EffectClientInterface implementation
unsigned EffectEcho::GetAudioInCount()
{
return 1;
}
unsigned EffectEcho::GetAudioOutCount()
{
return 1;
}
bool EffectEcho::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelNames WXUNUSED(chanMap))
{
if (delay == 0.0)
{
return false;
}
histPos = 0;
auto requestedHistLen = (sampleCount) (mSampleRate * delay);
// Guard against extreme delay values input by the user
try {
// Guard against huge delay values from the user.
// Don't violate the assertion in as_size_t
if (requestedHistLen !=
(histLen = static_cast<size_t>(requestedHistLen.as_long_long())))
throw std::bad_alloc{};
history.reinit(histLen, true);
}
catch ( const std::bad_alloc& ) {
Effect::MessageBox( XO("Requested value exceeds memory capacity.") );
return false;
}
return history != NULL;
}
bool EffectEcho::ProcessFinalize()
{
history.reset();
return true;
}
size_t EffectEcho::ProcessBlock(float **inBlock, float **outBlock, size_t blockLen)
{
float *ibuf = inBlock[0];
float *obuf = outBlock[0];
for (decltype(blockLen) i = 0; i < blockLen; i++, histPos++)
{
if (histPos == histLen)
{
histPos = 0;
}
history[histPos] = obuf[i] = ibuf[i] + history[histPos] * decay;
}
return blockLen;
}
bool EffectEcho::DefineParams( ShuttleParams & S ){
S.SHUTTLE_PARAM( delay, Delay );
S.SHUTTLE_PARAM( decay, Decay );
return true;
}
bool EffectEcho::GetAutomationParameters(CommandParameters & parms)
{
parms.WriteFloat(KEY_Delay, delay);
parms.WriteFloat(KEY_Decay, decay);
return true;
}
bool EffectEcho::SetAutomationParameters(CommandParameters & parms)
{
ReadAndVerifyFloat(Delay);
ReadAndVerifyFloat(Decay);
delay = Delay;
decay = Decay;
return true;
}
void EffectEcho::PopulateOrExchange(ShuttleGui & S)
{
S.AddSpace(0, 5);
S.StartMultiColumn(2, wxALIGN_CENTER);
{
S.Validator<FloatingPointValidator<double>>(
3, &delay, NumValidatorStyle::NO_TRAILING_ZEROES,
MIN_Delay, MAX_Delay
)
.AddTextBox(XXO("&Delay time (seconds):"), wxT(""), 10);
S.Validator<FloatingPointValidator<double>>(
3, &decay, NumValidatorStyle::NO_TRAILING_ZEROES,
MIN_Decay, MAX_Decay)
.AddTextBox(XXO("D&ecay factor:"), wxT(""), 10);
}
S.EndMultiColumn();
}
bool EffectEcho::TransferDataToWindow()
{
if (!mUIParent->TransferDataToWindow())
{
return false;
}
return true;
}
bool EffectEcho::TransferDataFromWindow()
{
if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
{
return false;
}
return true;
}