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