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