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