kiss_fft.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef KISS_FFT_H
  2. #define KISS_FFT_H
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include "arch.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /*
  10. ATTENTION!
  11. If you would like a :
  12. -- a utility that will handle the caching of fft objects
  13. -- real-only (no imaginary time component ) FFT
  14. -- a multi-dimensional FFT
  15. -- a command-line utility to perform ffts
  16. -- a command-line utility to perform fast-convolution filtering
  17. Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c
  18. in the tools/ directory.
  19. */
  20. #ifdef USE_SIMD
  21. # include <xmmintrin.h>
  22. # define kiss_fft_scalar __m128
  23. #define KISS_FFT_MALLOC(nbytes) memalign(16,nbytes)
  24. #else
  25. #define KISS_FFT_MALLOC speex_alloc
  26. #endif
  27. #ifdef FIXED_POINT
  28. #include "arch.h"
  29. # define kiss_fft_scalar spx_int16_t
  30. #else
  31. # ifndef kiss_fft_scalar
  32. /* default is float */
  33. # define kiss_fft_scalar float
  34. # endif
  35. #endif
  36. typedef struct {
  37. kiss_fft_scalar r;
  38. kiss_fft_scalar i;
  39. }kiss_fft_cpx;
  40. typedef struct kiss_fft_state* kiss_fft_cfg;
  41. /*
  42. * kiss_fft_alloc
  43. *
  44. * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
  45. *
  46. * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
  47. *
  48. * The return value from fft_alloc is a cfg buffer used internally
  49. * by the fft routine or NULL.
  50. *
  51. * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
  52. * The returned value should be free()d when done to avoid memory leaks.
  53. *
  54. * The state can be placed in a user supplied buffer 'mem':
  55. * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
  56. * then the function places the cfg in mem and the size used in *lenmem
  57. * and returns mem.
  58. *
  59. * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
  60. * then the function returns NULL and places the minimum cfg
  61. * buffer size in *lenmem.
  62. * */
  63. kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
  64. /*
  65. * kiss_fft(cfg,in_out_buf)
  66. *
  67. * Perform an FFT on a complex input buffer.
  68. * for a forward FFT,
  69. * fin should be f[0] , f[1] , ... ,f[nfft-1]
  70. * fout will be F[0] , F[1] , ... ,F[nfft-1]
  71. * Note that each element is complex and can be accessed like
  72. f[k].r and f[k].i
  73. * */
  74. void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
  75. /*
  76. A more generic version of the above function. It reads its input from every Nth sample.
  77. * */
  78. void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
  79. /* If kiss_fft_alloc allocated a buffer, it is one contiguous
  80. buffer and can be simply free()d when no longer needed*/
  81. #define kiss_fft_free speex_free
  82. /*
  83. Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
  84. your compiler output to call this before you exit.
  85. */
  86. void kiss_fft_cleanup(void);
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif