aboutsummaryrefslogtreecommitdiffstats
path: root/alc/effects/autowah.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alc/effects/autowah.cpp')
-rw-r--r--alc/effects/autowah.cpp49
1 files changed, 25 insertions, 24 deletions
diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp
index 4f874ef2..6d66f99f 100644
--- a/alc/effects/autowah.cpp
+++ b/alc/effects/autowah.cpp
@@ -59,12 +59,13 @@ struct AutowahState final : public EffectState {
float mEnvDelay;
/* Filter components derived from the envelope. */
- struct {
+ struct FilterParam {
float cos_w0;
float alpha;
- } mEnv[BufferLineSize];
+ };
+ std::array<FilterParam,BufferLineSize> mEnv;
- struct {
+ struct ChannelData {
uint mTargetChannel{InvalidChannelIndex};
/* Effect filters' history. */
@@ -75,10 +76,11 @@ struct AutowahState final : public EffectState {
/* Effect gains for each output channel */
float mCurrentGain;
float mTargetGain;
- } mChans[MaxAmbiChannels];
+ };
+ std::array<ChannelData,MaxAmbiChannels> mChans;
/* Effects buffers */
- alignas(16) float mBufferOut[BufferLineSize];
+ alignas(16) FloatBufferLine mBufferOut;
void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override;
@@ -155,17 +157,16 @@ void AutowahState::process(const size_t samplesToDo,
float env_delay{mEnvDelay};
for(size_t i{0u};i < samplesToDo;i++)
{
- float w0, sample, a;
-
/* Envelope follower described on the book: Audio Effects, Theory,
* Implementation and Application.
*/
- sample = peak_gain * std::fabs(samplesIn[0][i]);
- a = (sample > env_delay) ? attack_rate : release_rate;
+ const float sample{peak_gain * std::fabs(samplesIn[0][i])};
+ const float a{(sample > env_delay) ? attack_rate : release_rate};
env_delay = lerpf(sample, env_delay, a);
/* Calculate the cos and alpha components for this sample's filter. */
- w0 = minf((bandwidth*env_delay + freq_min), 0.46f) * (al::numbers::pi_v<float>*2.0f);
+ const float w0{minf((bandwidth*env_delay + freq_min), 0.46f) *
+ (al::numbers::pi_v<float>*2.0f)};
mEnv[i].cos_w0 = std::cos(w0);
mEnv[i].alpha = std::sin(w0)/(2.0f * QFactor);
}
@@ -194,18 +195,18 @@ void AutowahState::process(const size_t samplesToDo,
{
const float alpha{mEnv[i].alpha};
const float cos_w0{mEnv[i].cos_w0};
- float input, output;
- float a[3], b[3];
-
- b[0] = 1.0f + alpha*res_gain;
- b[1] = -2.0f * cos_w0;
- b[2] = 1.0f - alpha*res_gain;
- a[0] = 1.0f + alpha/res_gain;
- a[1] = -2.0f * cos_w0;
- a[2] = 1.0f - alpha/res_gain;
-
- input = insamples[i];
- output = input*(b[0]/a[0]) + z1;
+
+ const std::array b{
+ 1.0f + alpha*res_gain,
+ -2.0f * cos_w0,
+ 1.0f - alpha*res_gain};
+ const std::array a{
+ 1.0f + alpha/res_gain,
+ -2.0f * cos_w0,
+ 1.0f - alpha/res_gain};
+
+ const float input{insamples[i]};
+ const float output{input*(b[0]/a[0]) + z1};
z1 = input*(b[1]/a[0]) - output*(a[1]/a[0]) + z2;
z2 = input*(b[2]/a[0]) - output*(a[2]/a[0]);
mBufferOut[i] = output;
@@ -214,8 +215,8 @@ void AutowahState::process(const size_t samplesToDo,
chandata->mFilter.z2 = z2;
/* Now, mix the processed sound data to the output. */
- MixSamples({mBufferOut, samplesToDo}, samplesOut[outidx].data(), chandata->mCurrentGain,
- chandata->mTargetGain, samplesToDo);
+ MixSamples({mBufferOut.data(), samplesToDo}, samplesOut[outidx].data(),
+ chandata->mCurrentGain, chandata->mTargetGain, samplesToDo);
++chandata;
}
}