Don't return a large-ish array on the stack
[openal-soft.git] / common / alcomplex.h
blob794c352689fefc87940f0d4f85c0ce743f96278e
1 #ifndef ALCOMPLEX_H
2 #define ALCOMPLEX_H
4 #include <complex>
5 #include <type_traits>
7 #include "alspan.h"
9 /**
10 * Iterative implementation of 2-radix FFT (In-place algorithm). Sign = -1 is
11 * FFT and 1 is inverse FFT. Applies the Discrete Fourier Transform (DFT) to
12 * the data supplied in the buffer, which MUST BE power of two.
14 template<typename Real>
15 std::enable_if_t<std::is_floating_point<Real>::value>
16 complex_fft(const al::span<std::complex<Real>> buffer, const al::type_identity_t<Real> sign);
18 /**
19 * Calculate the frequency-domain response of the time-domain signal in the
20 * provided buffer, which MUST BE power of two.
22 template<typename Real, size_t N>
23 std::enable_if_t<std::is_floating_point<Real>::value>
24 forward_fft(const al::span<std::complex<Real>,N> buffer)
25 { complex_fft(buffer.subspan(0), -1); }
27 /**
28 * Calculate the time-domain signal of the frequency-domain response in the
29 * provided buffer, which MUST BE power of two.
31 template<typename Real, size_t N>
32 std::enable_if_t<std::is_floating_point<Real>::value>
33 inverse_fft(const al::span<std::complex<Real>,N> buffer)
34 { complex_fft(buffer.subspan(0), 1); }
36 /**
37 * Calculate the complex helical sequence (discrete-time analytical signal) of
38 * the given input using the discrete Hilbert transform (In-place algorithm).
39 * Fills the buffer with the discrete-time analytical signal stored in the
40 * buffer. The buffer is an array of complex numbers and MUST BE power of two,
41 * and the imaginary components should be cleared to 0.
43 void complex_hilbert(const al::span<std::complex<double>> buffer);
45 #endif /* ALCOMPLEX_H */