aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-05-09 16:42:43 -0700
committerChris Robinson <[email protected]>2020-05-09 16:42:43 -0700
commit52a5dc23a301e49f82139de9ff699662572523ab (patch)
tree39aaa43dce034ad255d4fff62cb6b996f6b4f9ae /alc
parent73569dfecad08b6c2fb5634242b537af73f0c8ab (diff)
Fix the UHJ filter generator
The half point needs to be included in the frequency response.
Diffstat (limited to 'alc')
-rw-r--r--alc/uhjfilter.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/alc/uhjfilter.cpp b/alc/uhjfilter.cpp
index 99737cc9..c9e35914 100644
--- a/alc/uhjfilter.cpp
+++ b/alc/uhjfilter.cpp
@@ -47,7 +47,7 @@ std::array<float,Uhj2Encoder::sFilterSize> GenerateFilter()
constexpr size_t half_size{32768};
/* Generate a frequency domain impulse with a +90 degree phase offset. Keep
- * the latter half clear for converting to the time domain.
+ * the mirrored frequencies clear for converting to the time domain.
*/
auto fftBuffer = std::vector<complex_d>(half_size*2, complex_d{});
for(size_t i{0};i < half_size;i += 2)
@@ -55,6 +55,7 @@ std::array<float,Uhj2Encoder::sFilterSize> GenerateFilter()
fftBuffer[i ] = c0;
fftBuffer[i+1] = c1;
}
+ fftBuffer[half_size] = c0;
complex_fft(fftBuffer, 1.0);
/* Reverse and truncate the filter to a usable size, and store only the
@@ -64,7 +65,7 @@ std::array<float,Uhj2Encoder::sFilterSize> GenerateFilter()
auto fftiter = fftBuffer.data() + half_size + (Uhj2Encoder::sFilterSize-1);
for(float &coeff : ret)
{
- coeff = static_cast<float>(fftiter->real() / half_size);
+ coeff = static_cast<float>(fftiter->real() / (half_size+1));
fftiter -= 2;
}
return ret;
@@ -82,6 +83,9 @@ void allpass_process(al::span<float> dst, const float *RESTRICT src)
for(size_t i{0};i < todo;i+=4)
{
const __m128 coeffs{_mm_load_ps(&PShiftCoeffs[i])};
+ /* NOTE: This could alternatively be done with two unaligned loads
+ * and a shuffle. Which would be better?
+ */
const __m128 s{_mm_setr_ps(src[i*2], src[i*2 + 2], src[i*2 + 4], src[i*2 + 6])};
r4 = _mm_add_ps(r4, _mm_mul_ps(s, coeffs));
}