From 9bf67c75aa78ed3d53e8f31edb7e31707cc1399f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 24 Nov 2022 22:00:02 -0800 Subject: Use complex floats for convolution reverb FFTs --- common/alcomplex.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'common/alcomplex.cpp') diff --git a/common/alcomplex.cpp b/common/alcomplex.cpp index eae47227..c08ac751 100644 --- a/common/alcomplex.cpp +++ b/common/alcomplex.cpp @@ -91,7 +91,9 @@ constexpr std::array,11> gBitReverses{{ } // namespace -void complex_fft(const al::span> buffer, const double sign) +template +std::enable_if_t::value> +complex_fft(const al::span> buffer, const Real sign) { const size_t fftsize{buffer.size()}; /* Get the number of bits used for indexing. Simplifies bit-reversal and @@ -118,21 +120,21 @@ void complex_fft(const al::span> buffer, const double sign) std::swap(buffer[rev.first], buffer[rev.second]); /* Iterative form of Danielson-Lanczos lemma */ - const double pi{al::numbers::pi * sign}; + const Real pi{al::numbers::pi_v * sign}; size_t step2{1u}; for(size_t i{0};i < log2_size;++i) { - const double arg{pi / static_cast(step2)}; + const Real arg{pi / static_cast(step2)}; /* TODO: Would std::polar(1.0, arg) be any better? */ - const std::complex w{std::cos(arg), std::sin(arg)}; - std::complex u{1.0, 0.0}; + const std::complex w{std::cos(arg), std::sin(arg)}; + std::complex u{1.0, 0.0}; const size_t step{step2 << 1}; for(size_t j{0};j < step2;j++) { for(size_t k{j};k < fftsize;k+=step) { - std::complex temp{buffer[k+step2] * u}; + std::complex temp{buffer[k+step2] * u}; buffer[k+step2] = buffer[k] - temp; buffer[k] += temp; } @@ -163,3 +165,7 @@ void complex_hilbert(const al::span> buffer) forward_fft(buffer); } + + +template void complex_fft<>(const al::span> buffer, const float sign); +template void complex_fft<>(const al::span> buffer, const double sign); -- cgit v1.2.3