Skip to content

Commit

Permalink
Merge pull request #3 from mike919192/cleanupNaive
Browse files Browse the repository at this point in the history
Cleanup naive trig functions and check they still work (with lower accuracy)
  • Loading branch information
mike919192 authored Sep 5, 2023
2 parents 8e73507 + c550e30 commit 40e2b7a
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions include/sdsp/fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,17 @@ namespace sdsp
template <size_t N>
using complex_array = std::array<std::complex<double>, N>;

template <size_t N>
constexpr trig_array<N> calc_cosines_naive()
{
trig_array<N> 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 <size_t N>
constexpr trig_array<N> calc_sines_naive()
template <size_t N, class T>
constexpr trig_array<N> calc_trigs_naive()
{
trig_array<N> 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<N> 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
Expand Down Expand Up @@ -176,10 +163,10 @@ namespace sdsp
template<size_t N, class T>
constexpr coeff_array<N> calc_wCoeffs()
{
//auto cosines = calc_cosines_naive<N>();
//auto cosines {calc_trigs_naive<N, cosine_calculator>()};
auto cosines {calc_trigs<N, cosine_calculator>()};

//auto sines = calc_sines_naive<N>();
//auto sines = calc_trigs_naive<N, sine_calculator>();
auto sines {calc_trigs<N, sine_calculator>()};

coeff_array<N> wCoeffs {0};
Expand Down

0 comments on commit 40e2b7a

Please sign in to comment.