aboutsummaryrefslogtreecommitdiffstats
path: root/common/alcomplex.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-09-13 00:58:05 -0700
committerChris Robinson <[email protected]>2020-09-13 03:33:52 -0700
commit9a883f50462f22474601204b0052ca9ef4fce676 (patch)
tree574dde5838dc595f4a8629f36fece640b45f7aa1 /common/alcomplex.cpp
parent1d4b355622cf6ad97e242e422dc6244edbaf2b55 (diff)
Partly simplify FFT bit-reversal
This can almost certainly be improved further, as less than half of the indices really need their reversed bit-pattern calculated and elements swapped (any symetrical bit pattern would just swap with itself, and indices whose reversed bit-pattern has already been traversed is already swapped). It may also prove beneficial to provide the base-2 log of the fft buffer size (number of bits to represent the indices), as that could help make the reversal more efficient with a known bit/loop count.
Diffstat (limited to 'common/alcomplex.cpp')
-rw-r--r--common/alcomplex.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/common/alcomplex.cpp b/common/alcomplex.cpp
index e5cbe8a0..0af9fc98 100644
--- a/common/alcomplex.cpp
+++ b/common/alcomplex.cpp
@@ -18,12 +18,8 @@ void complex_fft(const al::span<std::complex<double>> buffer, const double sign)
for(size_t i{1u};i < fftsize-1;i++)
{
size_t j{0u};
- for(size_t mask{1u};mask < fftsize;mask <<= 1)
- {
- if((i&mask) != 0)
- j++;
- j <<= 1;
- }
+ for(size_t imask{i + fftsize};imask;imask >>= 1)
+ j = (j<<1) + (imask&1);
j >>= 1;
if(i < j)
@@ -35,9 +31,9 @@ void complex_fft(const al::span<std::complex<double>> buffer, const double sign)
for(size_t i{1u};i < fftsize;i<<=1, step<<=1)
{
const size_t step2{step >> 1};
- double arg{al::MathDefs<double>::Pi() / static_cast<double>(step2)};
+ const double arg{al::MathDefs<double>::Pi() / static_cast<double>(step2)};
- std::complex<double> w{std::cos(arg), std::sin(arg)*sign};
+ const std::complex<double> w{std::cos(arg), std::sin(arg)*sign};
std::complex<double> u{1.0, 0.0};
for(size_t j{0};j < step2;j++)
{