Free Electron
alcomplex.h
1 #ifndef ALCOMPLEX_H
2 #define ALCOMPLEX_H
3 
4 #include "AL/al.h"
5 
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 typedef struct ALcomplex {
12  ALdouble Real;
13  ALdouble Imag;
14 } ALcomplex;
15 
16 /** Addition of two complex numbers. */
17 inline ALcomplex complex_add(ALcomplex a, ALcomplex b)
18 {
19  ALcomplex result;
20 
21  result.Real = a.Real + b.Real;
22  result.Imag = a.Imag + b.Imag;
23 
24  return result;
25 }
26 
27 /** Subtraction of two complex numbers. */
28 inline ALcomplex complex_sub(ALcomplex a, ALcomplex b)
29 {
30  ALcomplex result;
31 
32  result.Real = a.Real - b.Real;
33  result.Imag = a.Imag - b.Imag;
34 
35  return result;
36 }
37 
38 /** Multiplication of two complex numbers. */
39 inline ALcomplex complex_mult(ALcomplex a, ALcomplex b)
40 {
41  ALcomplex result;
42 
43  result.Real = a.Real*b.Real - a.Imag*b.Imag;
44  result.Imag = a.Imag*b.Real + a.Real*b.Imag;
45 
46  return result;
47 }
48 
49 /**
50  * Iterative implementation of 2-radix FFT (In-place algorithm). Sign = -1 is
51  * FFT and 1 is iFFT (inverse). Fills FFTBuffer[0...FFTSize-1] with the
52  * Discrete Fourier Transform (DFT) of the time domain data stored in
53  * FFTBuffer[0...FFTSize-1]. FFTBuffer is an array of complex numbers, FFTSize
54  * MUST BE power of two.
55  */
56 void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign);
57 
58 /**
59  * Calculate the complex helical sequence (discrete-time analytical signal) of
60  * the given input using the discrete Hilbert transform (In-place algorithm).
61  * Fills Buffer[0...size-1] with the discrete-time analytical signal stored in
62  * Buffer[0...size-1]. Buffer is an array of complex numbers, size MUST BE
63  * power of two.
64  */
65 void complex_hilbert(ALcomplex *Buffer, ALsizei size);
66 
67 #ifdef __cplusplus
68 } // extern "C"
69 #endif
70 
71 #endif /* ALCOMPLEX_H */