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