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