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 12 13 #pragma once 14 15 #include "openmpt/all/BuildSettings.hpp" 16 #include <complex> 17 18 OPENMPT_NAMESPACE_BEGIN 19 20 class TinyFFT 21 { 22 static constexpr std::complex<double> I{0.0, 1.0}; 23 std::vector<std::complex<double>> w; // Pre-computed twiddle factors 24 const uint32 k; // log2 of FFT size 25 26 void GenerateTwiddleFactors(uint32 i, uint32 b, std::complex<double> z); 27 28 public: 29 TinyFFT(const uint32 fftSize); 30 31 uint32 Size() const noexcept; 32 33 // Computes in-place FFT of size 2^k of A, result is in bit-reversed order. 34 void FFT(std::vector<std::complex<double>> &A) const; 35 36 // Computes in-place IFFT of size 2^k of A, input is expected to be in bit-reversed order. 37 void IFFT(std::vector<std::complex<double>> &A) const; 38 39 static void Normalize(std::vector<std::complex<double>> &data); 40 }; 41 42 OPENMPT_NAMESPACE_END 43