From f4a55cc8c2e8093e1156686292a38ae10a738a08 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 8 Sep 2020 22:56:30 -0700 Subject: Don't leave the negative frequencies as 0 for inverse FFT --- alc/effects/convolution.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'alc/effects/convolution.cpp') diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp index 102bed59..bbf8cb3f 100644 --- a/alc/effects/convolution.cpp +++ b/alc/effects/convolution.cpp @@ -266,8 +266,7 @@ void ConvolutionState::update(const ALCcontext *context, const ALeffectslot *slo /* The iFFT'd response is scaled up by the number of bins, so apply the * inverse to the output mixing gain. */ - constexpr size_t m{ConvolveUpdateSize/2 + 1}; - const float gain{slot->Params.Gain * (1.0f/m)}; + const float gain{slot->Params.Gain * (1.0f/float{ConvolveUpdateSize})}; auto &chans = *mChans; if(mChannels == FmtBFormat3D || mChannels == FmtBFormat2D) { @@ -386,6 +385,12 @@ void ConvolutionState::process(const size_t samplesToDo, mFftBuffer[i] += *input * *filter; } + /* Reconstruct the mirrored/negative frequencies to do a proper + * inverse FFT. + */ + for(size_t i{m};i < ConvolveUpdateSize;++i) + mFftBuffer[i] = std::conj(mFftBuffer[ConvolveUpdateSize-i]); + /* Apply iFFT to get the 1024 (really 1023) samples for output. The * 512 output samples are combined with the last output's 511 * second-half samples (and this output's second half is -- cgit v1.2.3