kiss_fft.h

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

Generated on Mon Jun 19 22:40:58 2006 for speex by  doxygen 1.4.6