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