GNU Radio 3.5.3.2 C++ API
|
00001 #ifndef KISS_FFT_H 00002 #define KISS_FFT_H 00003 00004 #include <stdlib.h> 00005 #include <stdio.h> 00006 #include <math.h> 00007 #include <string.h> 00008 00009 #ifdef __cplusplus 00010 extern "C" { 00011 #endif 00012 00013 /* 00014 ATTENTION! 00015 If you would like a : 00016 -- a utility that will handle the caching of fft objects 00017 -- real-only (no imaginary time component ) FFT 00018 -- a multi-dimensional FFT 00019 -- a command-line utility to perform ffts 00020 -- a command-line utility to perform fast-convolution filtering 00021 00022 Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c 00023 in the tools/ directory. 00024 */ 00025 00026 #ifdef USE_SIMD 00027 # include <xmmintrin.h> 00028 # define kiss_fft_scalar __m128 00029 #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) 00030 #define KISS_FFT_FREE _mm_free 00031 #else 00032 #define KISS_FFT_MALLOC malloc 00033 #define KISS_FFT_FREE free 00034 #endif 00035 00036 00037 #ifdef FIXED_POINT 00038 #include <sys/types.h> 00039 # if (FIXED_POINT == 32) 00040 # define kiss_fft_scalar int32_t 00041 # else 00042 # define kiss_fft_scalar int16_t 00043 # endif 00044 #else 00045 # ifndef kiss_fft_scalar 00046 /* default is float */ 00047 # define kiss_fft_scalar float 00048 # endif 00049 #endif 00050 00051 typedef struct { 00052 kiss_fft_scalar r; 00053 kiss_fft_scalar i; 00054 }kiss_fft_cpx; 00055 00056 typedef struct kiss_fft_state* kiss_fft_cfg; 00057 00058 /* 00059 * kiss_fft_alloc 00060 * 00061 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 00062 * 00063 * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); 00064 * 00065 * The return value from fft_alloc is a cfg buffer used internally 00066 * by the fft routine or NULL. 00067 * 00068 * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. 00069 * The returned value should be free()d when done to avoid memory leaks. 00070 * 00071 * The state can be placed in a user supplied buffer 'mem': 00072 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 00073 * then the function places the cfg in mem and the size used in *lenmem 00074 * and returns mem. 00075 * 00076 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 00077 * then the function returns NULL and places the minimum cfg 00078 * buffer size in *lenmem. 00079 * */ 00080 00081 kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 00082 00083 /* 00084 * kiss_fft(cfg,in_out_buf) 00085 * 00086 * Perform an FFT on a complex input buffer. 00087 * for a forward FFT, 00088 * fin should be f[0] , f[1] , ... ,f[nfft-1] 00089 * fout will be F[0] , F[1] , ... ,F[nfft-1] 00090 * Note that each element is complex and can be accessed like 00091 f[k].r and f[k].i 00092 * */ 00093 void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); 00094 00095 /* 00096 A more generic version of the above function. It reads its input from every Nth sample. 00097 * */ 00098 void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); 00099 00100 /* If kiss_fft_alloc allocated a buffer, it is one contiguous 00101 buffer and can be simply free()d when no longer needed*/ 00102 #define kiss_fft_free free 00103 00104 /* 00105 Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 00106 your compiler output to call this before you exit. 00107 */ 00108 void kiss_fft_cleanup(void); 00109 00110 00111 /* 00112 * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) 00113 */ 00114 int kiss_fft_next_fast_size(int n); 00115 00116 /* for real ffts, we need an even size */ 00117 #define kiss_fftr_next_fast_size_real(n) \ 00118 (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) 00119 00120 #ifdef __cplusplus 00121 } 00122 #endif 00123 00124 #endif