alcomplex.h 1.7 KB

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