From c550e30479dbe6b21f96e3297623940da29e68fb Mon Sep 17 00:00:00 2001 From: Michael Bloom Date: Tue, 5 Sep 2023 19:46:02 -0400 Subject: [PATCH] Cleanup naive trig functions and check they still work (with lower accuracy) --- include/sdsp/fft.h | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/include/sdsp/fft.h b/include/sdsp/fft.h index 974f9b3..0f19923 100644 --- a/include/sdsp/fft.h +++ b/include/sdsp/fft.h @@ -51,30 +51,17 @@ namespace sdsp template using complex_array = std::array, N>; - template - constexpr trig_array calc_cosines_naive() - { - trig_array cosines {0}; - for (size_t i {0}; i < cosines.size(); i++) { - uint pow2 {1u << i + 1u}; - for (size_t j {0}; j < cosines.at(i).size(); j++) { - cosines.at(i).at(j) = std::cos(2 * M_PI * j / pow2); - } - } - return cosines; - } - - template - constexpr trig_array calc_sines_naive() + template + constexpr trig_array calc_trigs_naive() { - trig_array sines {0}; - for (size_t i {0}; i < sines.size(); i++) { - uint pow2 {1u << i + 1u}; - for (size_t j {0}; j < sines.at(i).size(); j++) { - sines.at(i).at(j) = -std::sin(2 * M_PI * j / pow2); + trig_array trigs {0}; + for (size_t i {0}; i < trigs.size(); i++) { + uint pow2 {1u << (i + 1u)}; + for (size_t j {0}; j < trigs.at(i).size(); j++) { + trigs.at(i).at(j) = T::Value(2 * M_PI * j / pow2); } } - return sines; + return trigs; } class sine_calculator @@ -176,10 +163,10 @@ namespace sdsp template constexpr coeff_array calc_wCoeffs() { - //auto cosines = calc_cosines_naive(); + //auto cosines {calc_trigs_naive()}; auto cosines {calc_trigs()}; - //auto sines = calc_sines_naive(); + //auto sines = calc_trigs_naive(); auto sines {calc_trigs()}; coeff_array wCoeffs {0};