fastsa/fft.cpp

24 lines
755 B
C++
Raw Normal View History

2023-09-13 10:40:07 +08:00
#include <vector>
#include <complex>
#define POCKETFFT_CACHE_SIZE (16*1024*1024)
#define POCKETFFT_NO_MULTITHREADING // MT doesn't seem to help at small sizes
#include <pocketfft_hdronly.h>
void fft_mag(std::complex<float>* in, float* out, size_t len)
{
pocketfft::shape_t shape{len};
pocketfft::stride_t stride(1);
stride[0] = sizeof(std::complex<float>);
pocketfft::shape_t axes;
axes.push_back(0);
std::vector<std::complex<float>> out_rev(len);
pocketfft::c2c(shape, stride, stride, axes, pocketfft::FORWARD, in, out_rev.data(), 1.0f);
// negative frequencies first
for(size_t i=0;i<len/2;i++)
out[i] = abs(out_rev[i + len/2]);
for(size_t i=0;i<len/2;i++)
out[i + len/2] = abs(out_rev[i]);
}