You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.1KB

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