aboutsummaryrefslogtreecommitdiffstats
path: root/alc/effects/convolution.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-10-11 15:56:11 -0700
committerChris Robinson <[email protected]>2023-10-11 15:56:11 -0700
commit5149cb8c357630dba5253e2568b68d2ed069bcea (patch)
tree7fbf96b5e694e71029441d9db89df083cfb1c8f5 /alc/effects/convolution.cpp
parentce25165944913c12b9b782e40691f3be1d18dadd (diff)
Make and use a separate zconvolve method without scaling
When you're doing hundreds or thousands of separate zconvolve calls into the same buffer, it's more efficient to do the multiply once at the end instead of in each call.
Diffstat (limited to 'alc/effects/convolution.cpp')
-rw-r--r--alc/effects/convolution.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp
index c7a342dc..a98a0616 100644
--- a/alc/effects/convolution.cpp
+++ b/alc/effects/convolution.cpp
@@ -655,11 +655,6 @@ void ConvolutionState::process(const size_t samplesToDo,
const float *RESTRICT filter{mComplexData.get() + mNumConvolveSegs*ConvolveUpdateSize};
for(size_t c{0};c < chans.size();++c)
{
- /* The iFFT'd response is scaled up by the number of bins, so apply
- * the inverse to normalize the output.
- */
- static constexpr float fftscale{1.0f / float{ConvolveUpdateSize}};
-
/* Convolve each input segment with its IR filter counterpart
* (aligned in time).
*/
@@ -667,14 +662,14 @@ void ConvolutionState::process(const size_t samplesToDo,
const float *RESTRICT input{&mComplexData[curseg*ConvolveUpdateSize]};
for(size_t s{curseg};s < mNumConvolveSegs;++s)
{
- pffft_zconvolve_accumulate(mFft.get(), input, filter, mFftBuffer.data(), fftscale);
+ pffft_zconvolve_accumulate(mFft.get(), input, filter, mFftBuffer.data());
input += ConvolveUpdateSize;
filter += ConvolveUpdateSize;
}
input = mComplexData.get();
for(size_t s{0};s < curseg;++s)
{
- pffft_zconvolve_accumulate(mFft.get(), input, filter, mFftBuffer.data(), fftscale);
+ pffft_zconvolve_accumulate(mFft.get(), input, filter, mFftBuffer.data());
input += ConvolveUpdateSize;
filter += ConvolveUpdateSize;
}
@@ -687,8 +682,12 @@ void ConvolutionState::process(const size_t samplesToDo,
pffft_transform(mFft.get(), mFftBuffer.data(), mFftBuffer.data(),
mFftWorkBuffer.data(), PFFFT_BACKWARD);
+ /* The iFFT'd response is scaled up by the number of bins, so apply
+ * the inverse to normalize the output.
+ */
+ static constexpr float fftscale{1.0f / float{ConvolveUpdateSize}};
for(size_t i{0};i < ConvolveUpdateSamples;++i)
- mOutput[c][i] = mFftBuffer[i] + mOutput[c][ConvolveUpdateSamples+i];
+ mOutput[c][i] = (mFftBuffer[i]+mOutput[c][ConvolveUpdateSamples+i]) * fftscale;
for(size_t i{0};i < ConvolveUpdateSamples;++i)
mOutput[c][ConvolveUpdateSamples+i] = mFftBuffer[ConvolveUpdateSamples+i];
}