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