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