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