Audacity 3.2.0
WahWahBase.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 WahwahBase.cpp
6
7 Nasca Octavian Paul (Paul Nasca)
8
9*******************************************************************//*******************************************************************/
15#include "WahWahBase.h"
16
18{
19 static CapturedParameters<
21 parameters;
22 return parameters;
23}
24
25// How many samples are processed before recomputing the lfo value again
26#define lfoskipsamples 30
27
28//
29// WahWahBase
30//
31
33
34std::shared_ptr<EffectInstance> WahWahBase::MakeInstance() const
35{
36 return std::make_shared<Instance>(*this);
37}
38
40{
42}
43
45{
46}
47
48// ComponentInterface implementation
49
51{
52 return Symbol;
53}
54
56{
57 return XO(
58 "Rapid tone quality variations, like that guitar sound so popular in the 1970's");
59}
60
62{
63 return L"Wahwah";
64}
65
66// EffectDefinitionInterface implementation
67
69{
70 return EffectTypeProcess;
71}
72
74{
76}
77
80{
82 if (chanMap[0] == ChannelNameFrontRight)
83 mState.phase += M_PI;
84 return true;
85}
86
88 EffectSettings& settings, const float* const* inBlock,
89 float* const* outBlock, size_t blockLen)
90{
91 return InstanceProcess(settings, mState, inBlock, outBlock, blockLen);
92}
93
95{
96 SetBlockSize(512);
97 mSlaves.clear();
98 return true;
99}
100
103{
104 WahWahBase::Instance slave(mProcessor);
105
106 InstanceInit(settings, slave.mState, sampleRate);
107
108 mSlaves.push_back(slave);
109
110 return true;
111}
112
114{
115 mSlaves.clear();
116
117 return true;
118}
119
121 size_t group, EffectSettings& settings, const float* const* inbuf,
122 float* const* outbuf, size_t numSamples)
123{
124 if (group >= mSlaves.size())
125 return 0;
126 return InstanceProcess(
127 settings, mSlaves[group].mState, inbuf, outbuf, numSamples);
128}
129
130// WahWahBase implementation
131
134{
135 auto& ms = GetSettings(settings);
136
137 data.samplerate = sampleRate;
138 data.lfoskip = ms.mFreq * 2 * M_PI / sampleRate;
139 data.skipcount = 0;
140 data.xn1 = 0;
141 data.xn2 = 0;
142 data.yn1 = 0;
143 data.yn2 = 0;
144 data.b0 = 0;
145 data.b1 = 0;
146 data.b2 = 0;
147 data.a0 = 0;
148 data.a1 = 0;
149 data.a2 = 0;
150
151 data.depth = ms.mDepth / 100.0;
152 data.freqofs = ms.mFreqOfs / 100.0;
153 data.phase = ms.mPhase * M_PI / 180.0;
154 data.outgain = DB_TO_LINEAR(ms.mOutGain);
155}
156
159 const float* const* inBlock, float* const* outBlock, size_t blockLen)
160{
161 auto& ms = GetSettings(settings);
162
163 const float* ibuf = inBlock[0];
164 float* obuf = outBlock[0];
165 double frequency, omega, sn, cs, alpha;
166 double in, out;
167
168 data.lfoskip = ms.mFreq * 2 * M_PI / data.samplerate;
169 data.depth = ms.mDepth / 100.0;
170 data.freqofs = ms.mFreqOfs / 100.0;
171
172 data.phase = ms.mPhase * M_PI / 180.0;
173 data.outgain = DB_TO_LINEAR(ms.mOutGain);
174
175 for (decltype(blockLen) i = 0; i < blockLen; i++)
176 {
177 in = (double)ibuf[i];
178
179 if ((data.skipcount++) % lfoskipsamples == 0)
180 {
181 frequency = (1 + cos(data.skipcount * data.lfoskip + data.phase)) / 2;
182 frequency = frequency * data.depth * (1 - data.freqofs) + data.freqofs;
183 frequency = exp((frequency - 1) * 6);
184 omega = M_PI * frequency;
185 sn = sin(omega);
186 cs = cos(omega);
187 alpha = sn / (2 * ms.mRes);
188 data.b0 = (1 - cs) / 2;
189 data.b1 = 1 - cs;
190 data.b2 = (1 - cs) / 2;
191 data.a0 = 1 + alpha;
192 data.a1 = -2 * cs;
193 data.a2 = 1 - alpha;
194 };
195 out = (data.b0 * in + data.b1 * data.xn1 + data.b2 * data.xn2 -
196 data.a1 * data.yn1 - data.a2 * data.yn2) /
197 data.a0;
198 data.xn2 = data.xn1;
199 data.xn1 = in;
200 data.yn2 = data.yn1;
201 data.yn1 = out;
202 out *= data.outgain;
203
204 obuf[i] = (float)out;
205 }
206
207 return blockLen;
208}
209
211{
212 return 1;
213}
214
216{
217 return 1;
218}
#define M_PI
Definition: Distortion.cpp:22
struct State mState
EffectType
@ EffectTypeProcess
ChannelName
@ ChannelNameFrontRight
XO("Cut/Copy/Paste")
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:338
static Settings & settings()
Definition: TrackInfo.cpp:51
#define lfoskipsamples
Definition: WahWahBase.cpp:26
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:210
RealtimeSince
In which versions of Audacity was an effect realtime capable?
Hold values to send to effect output meters.
Interface for manipulations of an Effect's settings.
unsigned long skipcount
Definition: WahWahBase.h:24
static EffectWahwahSettings & 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.
EffectType GetType() const override
Type determines how it behaves.
Definition: WahWahBase.cpp:68
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: WahWahBase.cpp:61
static constexpr EffectParameter OutGain
Definition: WahWahBase.h:166
virtual ~WahWahBase()
Definition: WahWahBase.cpp:44
static constexpr EffectParameter FreqOfs
Definition: WahWahBase.h:158
static constexpr EffectParameter Phase
Definition: WahWahBase.h:138
static constexpr EffectParameter Freq
Definition: WahWahBase.h:132
RealtimeSince RealtimeSupport() const override
Since which version of Audacity has the effect supported realtime?
Definition: WahWahBase.cpp:73
static constexpr EffectParameter Depth
Definition: WahWahBase.h:144
std::shared_ptr< EffectInstance > MakeInstance() const override
Make an object maintaining short-term state of an Effect.
Definition: WahWahBase.cpp:34
static const ComponentInterfaceSymbol Symbol
Definition: WahWahBase.h:62
TranslatableString GetDescription() const override
Definition: WahWahBase.cpp:55
const EffectParameterMethods & Parameters() const override
Definition: WahWahBase.cpp:17
static constexpr EffectParameter Res
Definition: WahWahBase.h:152
ComponentInterfaceSymbol GetSymbol() const override
Definition: WahWahBase.cpp:50
Externalized state of a plug-in.
bool RealtimeAddProcessor(EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate) override
Definition: WahWahBase.cpp:101
bool RealtimeFinalize(EffectSettings &settings) noexcept override
Definition: WahWahBase.cpp:113
size_t RealtimeProcess(size_t group, EffectSettings &settings, const float *const *inbuf, float *const *outbuf, size_t numSamples) override
Definition: WahWahBase.cpp:120
EffectWahwahState mState
Definition: WahWahBase.h:121
unsigned GetAudioInCount() const override
How many input buffers to allocate at once.
Definition: WahWahBase.cpp:215
void InstanceInit(EffectSettings &settings, EffectWahwahState &data, float sampleRate)
Definition: WahWahBase.cpp:132
size_t InstanceProcess(EffectSettings &settings, EffectWahwahState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
Definition: WahWahBase.cpp:157
size_t ProcessBlock(EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
Called for destructive effect computation.
Definition: WahWahBase.cpp:87
bool ProcessInitialize(EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
Definition: WahWahBase.cpp:78
unsigned GetAudioOutCount() const override
How many output buffers to allocate at once.
Definition: WahWahBase.cpp:210
bool RealtimeInitialize(EffectSettings &settings, double) override
Definition: WahWahBase.cpp:94