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 // Define KISS_FFT_SHARED macro to properly export symbols
18 #ifdef KISS_FFT_SHARED
19 #ifdef _WIN32
20 #ifdef KISS_FFT_BUILD
21 #define KISS_FFT_API __declspec(dllexport)
22 #else
23 #define KISS_FFT_API __declspec(dllimport)
24 #endif
25 #else
26 #define KISS_FFT_API __attribute__((visibility("default")))
27 #endif
28 #else
29 #define KISS_FFT_API
30 #endif
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  ATTENTION!
38  If you would like a :
39  -- a utility that will handle the caching of fft objects
40  -- real-only (no imaginary time component ) FFT
41  -- a multi-dimensional FFT
42  -- a command-line utility to perform ffts
43  -- a command-line utility to perform fast-convolution filtering
44 
45  Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c
46  in the tools/ directory.
47 */
48 
49 /* User may override KISS_FFT_MALLOC and/or KISS_FFT_FREE. */
50 #ifdef USE_SIMD
51 #include <xmmintrin.h>
52 #define kiss_fft_scalar __m128
53 #ifndef KISS_FFT_MALLOC
54 #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes, 16)
55 #define KISS_FFT_ALIGN_CHECK(ptr)
56 #define KISS_FFT_ALIGN_SIZE_UP(size) ((size + 15UL) & ~0xFUL)
57 #endif
58 #ifndef KISS_FFT_FREE
59 #define KISS_FFT_FREE _mm_free
60 #endif
61 #else
62 #define KISS_FFT_ALIGN_CHECK(ptr)
63 #define KISS_FFT_ALIGN_SIZE_UP(size) (size)
64 #ifndef KISS_FFT_MALLOC
65 #define KISS_FFT_MALLOC malloc
66 #endif
67 #ifndef KISS_FFT_FREE
68 #define KISS_FFT_FREE free
69 #endif
70 #endif
71 
72 #ifdef FIXED_POINT
73 #include <stdint.h>
74 #if (FIXED_POINT == 32)
75 #define kiss_fft_scalar int32_t
76 #else
77 #define kiss_fft_scalar int16_t
78 #endif
79 #else
80 #ifndef kiss_fft_scalar
81 /* default is float */
82 #define kiss_fft_scalar float
83 #endif
84 #endif
85 
86 typedef struct
87 {
90 } kiss_fft_cpx;
91 
92 typedef struct kiss_fft_state* kiss_fft_cfg;
93 
94 /*
95  * kiss_fft_alloc
96  *
97  * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
98  *
99  * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
100  *
101  * The return value from fft_alloc is a cfg buffer used internally
102  * by the fft routine or NULL.
103  *
104  * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
105  * The returned value should be free()d when done to avoid memory leaks.
106  *
107  * The state can be placed in a user supplied buffer 'mem':
108  * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
109  * then the function places the cfg in mem and the size used in *lenmem
110  * and returns mem.
111  *
112  * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
113  * then the function returns NULL and places the minimum cfg
114  * buffer size in *lenmem.
115  * */
116 
117 kiss_fft_cfg KISS_FFT_API kiss_fft_alloc(int nfft, int inverse_fft, void* mem,
118  size_t* lenmem);
119 
120 /*
121  * kiss_fft(cfg,in_out_buf)
122  *
123  * Perform an FFT on a complex input buffer.
124  * for a forward FFT,
125  * fin should be f[0] , f[1] , ... ,f[nfft-1]
126  * fout will be F[0] , F[1] , ... ,F[nfft-1]
127  * Note that each element is complex and can be accessed like
128  f[k].r and f[k].i
129  * */
130 void KISS_FFT_API kiss_fft(kiss_fft_cfg cfg, const kiss_fft_cpx* fin, kiss_fft_cpx* fout);
131 
132 /*
133  A more generic version of the above function. It reads its input from every Nth sample.
134  * */
136  kiss_fft_cpx* fout, int fin_stride);
137 
138 /* If kiss_fft_alloc allocated a buffer, it is one contiguous
139  buffer and can be simply free()d when no longer needed*/
140 #define kiss_fft_free KISS_FFT_FREE
141 
142 /*
143  Cleans up some memory that gets managed internally. Not necessary to call, but it might
144  clean up your compiler output to call this before you exit.
145 */
146 void KISS_FFT_API kiss_fft_cleanup(void);
147 
148 /*
149  * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
150  */
152 
153 /* for real ffts, we need an even size */
154 #define kiss_fftr_next_fast_size_real(n) (kiss_fft_next_fast_size(((n) + 1) >> 1) << 1)
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif
kiss_fft_cpx::r
kiss_fft_scalar r
Definition: kiss_fft.h:88
kiss_fft_cfg
struct kiss_fft_state * kiss_fft_cfg
Definition: kiss_fft.h:92
kiss_fft_alloc
kiss_fft_cfg KISS_FFT_API kiss_fft_alloc(int nfft, int inverse_fft, void *mem, size_t *lenmem)
Definition: kiss_fft.c:337
kiss_fft_scalar
#define kiss_fft_scalar
Definition: kiss_fft.h:82
kiss_fft_next_fast_size
int KISS_FFT_API kiss_fft_next_fast_size(int n)
Definition: kiss_fft.c:408
kiss_fft_cpx::i
kiss_fft_scalar i
Definition: kiss_fft.h:89
kiss_fft
void KISS_FFT_API kiss_fft(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout)
Definition: kiss_fft.c:397
kiss_fft_state
Definition: _kiss_fft_guts.h:27
kiss_fft_cleanup
void KISS_FFT_API kiss_fft_cleanup(void)
Definition: kiss_fft.c:403
kiss_fft_stride
void KISS_FFT_API kiss_fft_stride(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout, int fin_stride)
Definition: kiss_fft.c:371
kiss_fft_state::nfft
int nfft
Definition: _kiss_fft_guts.h:29
kiss_fft_cpx
Definition: kiss_fft.h:86
KISS_FFT_API
#define KISS_FFT_API
Definition: kiss_fft.h:29


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:23