]> git.tdb.fi Git - ext/openal.git/blob - common/alcomplex.h
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / common / alcomplex.h
1 #ifndef ALCOMPLEX_H
2 #define ALCOMPLEX_H
3
4 #include <complex>
5 #include <type_traits>
6
7 #include "alspan.h"
8
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.
13  */
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);
17
18 /**
19  * Calculate the frequency-domain response of the time-domain signal in the
20  * provided buffer, which MUST BE power of two.
21  */
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); }
26
27 /**
28  * Calculate the time-domain signal of the frequency-domain response in the
29  * provided buffer, which MUST BE power of two.
30  */
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); }
35
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.
42  */
43 void complex_hilbert(const al::span<std::complex<double>> buffer);
44
45 #endif /* ALCOMPLEX_H */