kiss_fft.h 3.2 KB

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