aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-01-01 02:41:27 -0800
committerChris Robinson <[email protected]>2019-01-01 02:41:27 -0800
commitc36798fd0759331caac80bb16cebe6c19a646090 (patch)
tree88fc8d0a6af898571316b59cdcc2d3ced5e5562d
parente930c70eaab7946a716d641beb7c4b026fee5d4d (diff)
Avoid unnecessary extra buffers for filter chains
-rw-r--r--Alc/effects/equalizer.cpp22
-rw-r--r--Alc/effects/reverb.cpp7
-rw-r--r--Alc/uhjfilter.cpp61
3 files changed, 46 insertions, 44 deletions
diff --git a/Alc/effects/equalizer.cpp b/Alc/effects/equalizer.cpp
index cb421914..94c760ea 100644
--- a/Alc/effects/equalizer.cpp
+++ b/Alc/effects/equalizer.cpp
@@ -35,6 +35,8 @@
#include "vecmat.h"
+namespace {
+
/* The document "Effects Extension Guide.pdf" says that low and high *
* frequencies are cutoff frequencies. This is not fully correct, they *
* are corner frequencies for low and high shelf filters. If they were *
@@ -87,7 +89,7 @@ struct ALequalizerState final : public EffectState {
ALfloat TargetGains[MAX_OUTPUT_CHANNELS]{};
} mChans[MAX_EFFECT_CHANNELS];
- ALfloat mSampleBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE]{};
+ ALfloat mSampleBuffer[BUFFERSIZE]{};
ALboolean deviceUpdate(const ALCdevice *device) override;
@@ -161,21 +163,19 @@ void ALequalizerState::update(const ALCcontext *context, const ALeffectslot *slo
void ALequalizerState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
{
- ALfloat (*RESTRICT temps)[BUFFERSIZE] = mSampleBuffer;
- ALsizei c;
-
- for(c = 0;c < MAX_EFFECT_CHANNELS;c++)
+ for(ALsizei c{0};c < MAX_EFFECT_CHANNELS;c++)
{
- mChans[c].filter[0].process(temps[0], SamplesIn[c], SamplesToDo);
- mChans[c].filter[1].process(temps[1], temps[0], SamplesToDo);
- mChans[c].filter[2].process(temps[2], temps[1], SamplesToDo);
- mChans[c].filter[3].process(temps[3], temps[2], SamplesToDo);
+ mChans[c].filter[0].process(mSampleBuffer, SamplesIn[c], SamplesToDo);
+ mChans[c].filter[1].process(mSampleBuffer, mSampleBuffer, SamplesToDo);
+ mChans[c].filter[2].process(mSampleBuffer, mSampleBuffer, SamplesToDo);
+ mChans[c].filter[3].process(mSampleBuffer, mSampleBuffer, SamplesToDo);
- MixSamples(temps[3], NumChannels, SamplesOut, mChans[c].CurrentGains,
- mChans[c].TargetGains, SamplesToDo, 0, SamplesToDo);
+ MixSamples(mSampleBuffer, NumChannels, SamplesOut, mChans[c].CurrentGains,
+ mChans[c].TargetGains, SamplesToDo, 0, SamplesToDo);
}
}
+} // namespace
struct EqualizerStateFactory final : public EffectStateFactory {
EffectState *create() override;
diff --git a/Alc/effects/reverb.cpp b/Alc/effects/reverb.cpp
index d984ceab..9bc4f8f2 100644
--- a/Alc/effects/reverb.cpp
+++ b/Alc/effects/reverb.cpp
@@ -1183,11 +1183,10 @@ void EarlyReflection_Faded(ReverbState *State, ALsizei offset, const ALsizei tod
}
/* Applies the two T60 damping filter sections. */
-static inline void LateT60Filter(ALfloat *RESTRICT samples, const ALsizei todo, T60Filter *filter)
+inline void LateT60Filter(ALfloat *samples, const ALsizei todo, T60Filter *filter)
{
- ALfloat temp[MAX_UPDATE_SAMPLES];
- filter->HFFilter.process(temp, samples, todo);
- filter->LFFilter.process(samples, temp, todo);
+ filter->HFFilter.process(samples, samples, todo);
+ filter->LFFilter.process(samples, samples, todo);
}
/* This generates the reverb tail using a modified feed-back delay network
diff --git a/Alc/uhjfilter.cpp b/Alc/uhjfilter.cpp
index 1c5c836c..64d5f76c 100644
--- a/Alc/uhjfilter.cpp
+++ b/Alc/uhjfilter.cpp
@@ -1,9 +1,12 @@
#include "config.h"
-#include "alu.h"
#include "uhjfilter.h"
+#include <algorithm>
+
+#include "alu.h"
+
namespace {
/* This is the maximum number of samples processed for each inner loop
@@ -18,17 +21,17 @@ constexpr ALfloat Filter2CoeffSqr[4] = {
0.161758498368f, 0.733028932341f, 0.945349700329f, 0.990599156685f
};
-void allpass_process(AllPassState *state, ALfloat *RESTRICT dst, const ALfloat *RESTRICT src, const ALfloat aa, ALsizei todo)
+void allpass_process(AllPassState *state, ALfloat *dst, const ALfloat *src, const ALfloat aa, ALsizei todo)
{
- ALfloat z1 = state->z[0];
- ALfloat z2 = state->z[1];
- for(ALsizei i{0};i < todo;i++)
+ ALfloat z1{state->z[0]};
+ ALfloat z2{state->z[1]};
+ auto proc_sample = [aa,&z1,&z2](ALfloat input) noexcept -> ALfloat
{
- ALfloat input = src[i];
ALfloat output = input*aa + z1;
z1 = z2; z2 = output*aa - input;
- dst[i] = output;
- }
+ return output;
+ };
+ std::transform(src, src+todo, dst, proc_sample);
state->z[0] = z1;
state->z[1] = z2;
}
@@ -59,7 +62,7 @@ void allpass_process(AllPassState *state, ALfloat *RESTRICT dst, const ALfloat *
void Uhj2Encoder::encode(ALfloat *LeftOut, ALfloat *RightOut, ALfloat (*InSamples)[BUFFERSIZE], const ALsizei SamplesToDo)
{
alignas(16) ALfloat D[MAX_UPDATE_SAMPLES], S[MAX_UPDATE_SAMPLES];
- alignas(16) ALfloat temp[2][MAX_UPDATE_SAMPLES];
+ alignas(16) ALfloat temp[MAX_UPDATE_SAMPLES];
ASSUME(SamplesToDo > 0);
@@ -71,43 +74,43 @@ void Uhj2Encoder::encode(ALfloat *LeftOut, ALfloat *RightOut, ALfloat (*InSample
/* D = 0.6554516*Y */
const ALfloat *RESTRICT input{al::assume_aligned<16>(InSamples[2]+base)};
for(ALsizei i{0};i < todo;i++)
- temp[0][i] = 0.6554516f*input[i];
- allpass_process(&mFilter1_Y[0], temp[1], temp[0], Filter1CoeffSqr[0], todo);
- allpass_process(&mFilter1_Y[1], temp[0], temp[1], Filter1CoeffSqr[1], todo);
- allpass_process(&mFilter1_Y[2], temp[1], temp[0], Filter1CoeffSqr[2], todo);
- allpass_process(&mFilter1_Y[3], temp[0], temp[1], Filter1CoeffSqr[3], todo);
+ temp[i] = 0.6554516f*input[i];
+ allpass_process(&mFilter1_Y[0], temp, temp, Filter1CoeffSqr[0], todo);
+ allpass_process(&mFilter1_Y[1], temp, temp, Filter1CoeffSqr[1], todo);
+ allpass_process(&mFilter1_Y[2], temp, temp, Filter1CoeffSqr[2], todo);
+ allpass_process(&mFilter1_Y[3], temp, temp, Filter1CoeffSqr[3], todo);
/* NOTE: Filter1 requires a 1 sample delay for the final output, so
* take the last processed sample from the previous run as the first
* output sample.
*/
D[0] = mLastY;
for(ALsizei i{1};i < todo;i++)
- D[i] = temp[0][i-1];
- mLastY = temp[0][todo-1];
+ D[i] = temp[i-1];
+ mLastY = temp[todo-1];
/* D += j(-0.3420201*W + 0.5098604*X) */
const ALfloat *RESTRICT input0{al::assume_aligned<16>(InSamples[0]+base)};
const ALfloat *RESTRICT input1{al::assume_aligned<16>(InSamples[1]+base)};
for(ALsizei i{0};i < todo;i++)
- temp[0][i] = -0.3420201f*input0[i] + 0.5098604f*input1[i];
- allpass_process(&mFilter2_WX[0], temp[1], temp[0], Filter2CoeffSqr[0], todo);
- allpass_process(&mFilter2_WX[1], temp[0], temp[1], Filter2CoeffSqr[1], todo);
- allpass_process(&mFilter2_WX[2], temp[1], temp[0], Filter2CoeffSqr[2], todo);
- allpass_process(&mFilter2_WX[3], temp[0], temp[1], Filter2CoeffSqr[3], todo);
+ temp[i] = -0.3420201f*input0[i] + 0.5098604f*input1[i];
+ allpass_process(&mFilter2_WX[0], temp, temp, Filter2CoeffSqr[0], todo);
+ allpass_process(&mFilter2_WX[1], temp, temp, Filter2CoeffSqr[1], todo);
+ allpass_process(&mFilter2_WX[2], temp, temp, Filter2CoeffSqr[2], todo);
+ allpass_process(&mFilter2_WX[3], temp, temp, Filter2CoeffSqr[3], todo);
for(ALsizei i{0};i < todo;i++)
- D[i] += temp[0][i];
+ D[i] += temp[i];
/* S = 0.9396926*W + 0.1855740*X */
for(ALsizei i{0};i < todo;i++)
- temp[0][i] = 0.9396926f*input0[i] + 0.1855740f*input1[i];
- allpass_process(&mFilter1_WX[0], temp[1], temp[0], Filter1CoeffSqr[0], todo);
- allpass_process(&mFilter1_WX[1], temp[0], temp[1], Filter1CoeffSqr[1], todo);
- allpass_process(&mFilter1_WX[2], temp[1], temp[0], Filter1CoeffSqr[2], todo);
- allpass_process(&mFilter1_WX[3], temp[0], temp[1], Filter1CoeffSqr[3], todo);
+ temp[i] = 0.9396926f*input0[i] + 0.1855740f*input1[i];
+ allpass_process(&mFilter1_WX[0], temp, temp, Filter1CoeffSqr[0], todo);
+ allpass_process(&mFilter1_WX[1], temp, temp, Filter1CoeffSqr[1], todo);
+ allpass_process(&mFilter1_WX[2], temp, temp, Filter1CoeffSqr[2], todo);
+ allpass_process(&mFilter1_WX[3], temp, temp, Filter1CoeffSqr[3], todo);
S[0] = mLastWX;
for(ALsizei i{1};i < todo;i++)
- S[i] = temp[0][i-1];
- mLastWX = temp[0][todo-1];
+ S[i] = temp[i-1];
+ mLastWX = temp[todo-1];
/* Left = (S + D)/2.0 */
ALfloat *RESTRICT left = al::assume_aligned<16>(LeftOut+base);