1
0

TinyFFT.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * TinyFFT.h
  3. * ---------
  4. * Purpose: A simple FFT implementation for power-of-two FFTs
  5. * Notes : This is a C++ adaption of Ryuhei Mori's BSD 2-clause licensed TinyFFT
  6. * available from https://github.com/ryuhei-mori/tinyfft
  7. * Authors: Ryuhei Mori
  8. * OpenMPT Devs
  9. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  10. */
  11. #pragma once
  12. #include "openmpt/all/BuildSettings.hpp"
  13. #include <complex>
  14. OPENMPT_NAMESPACE_BEGIN
  15. class TinyFFT
  16. {
  17. static constexpr std::complex<double> I{0.0, 1.0};
  18. std::vector<std::complex<double>> w; // Pre-computed twiddle factors
  19. const uint32 k; // log2 of FFT size
  20. void GenerateTwiddleFactors(uint32 i, uint32 b, std::complex<double> z);
  21. public:
  22. TinyFFT(const uint32 fftSize);
  23. uint32 Size() const noexcept;
  24. // Computes in-place FFT of size 2^k of A, result is in bit-reversed order.
  25. void FFT(std::vector<std::complex<double>> &A) const;
  26. // Computes in-place IFFT of size 2^k of A, input is expected to be in bit-reversed order.
  27. void IFFT(std::vector<std::complex<double>> &A) const;
  28. static void Normalize(std::vector<std::complex<double>> &data);
  29. };
  30. OPENMPT_NAMESPACE_END