kodi
kiss_fft.h
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 
34 #ifdef USE_SIMD
35 # include <xmmintrin.h>
36 # define kiss_fft_scalar __m128
37 #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16)
38 #define KISS_FFT_FREE _mm_free
39 #else
40 #define KISS_FFT_MALLOC malloc
41 #define KISS_FFT_FREE free
42 #endif
43 
44 
45 #ifdef FIXED_POINT
46 #include <sys/types.h>
47 # if (FIXED_POINT == 32)
48 # define kiss_fft_scalar int32_t
49 # else
50 # define kiss_fft_scalar int16_t
51 # endif
52 #else
53 # ifndef kiss_fft_scalar
54 /* default is float */
55 # define kiss_fft_scalar float
56 # endif
57 #endif
58 
59 typedef struct {
60  kiss_fft_scalar r;
61  kiss_fft_scalar i;
63 
64 typedef struct kiss_fft_state* kiss_fft_cfg;
65 
66 /*
67  * kiss_fft_alloc
68  *
69  * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
70  *
71  * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
72  *
73  * The return value from fft_alloc is a cfg buffer used internally
74  * by the fft routine or NULL.
75  *
76  * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
77  * The returned value should be free()d when done to avoid memory leaks.
78  *
79  * The state can be placed in a user supplied buffer 'mem':
80  * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
81  * then the function places the cfg in mem and the size used in *lenmem
82  * and returns mem.
83  *
84  * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
85  * then the function returns NULL and places the minimum cfg
86  * buffer size in *lenmem.
87  * */
88 
89 kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
90 
91 /*
92  * kiss_fft(cfg,in_out_buf)
93  *
94  * Perform an FFT on a complex input buffer.
95  * for a forward FFT,
96  * fin should be f[0] , f[1] , ... ,f[nfft-1]
97  * fout will be F[0] , F[1] , ... ,F[nfft-1]
98  * Note that each element is complex and can be accessed like
99  f[k].r and f[k].i
100  * */
101 void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
102 
103 /*
104  A more generic version of the above function. It reads its input from every Nth sample.
105  * */
106 void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
107 
108 /* If kiss_fft_alloc allocated a buffer, it is one contiguous
109  buffer and can be simply free()d when no longer needed*/
110 #define kiss_fft_free free
111 
112 /*
113  Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
114  your compiler output to call this before you exit.
115 */
116 void kiss_fft_cleanup(void);
117 
118 
119 /*
120  * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
121  */
122 int kiss_fft_next_fast_size(int n);
123 
124 /* for real ffts, we need an even size */
125 #define kiss_fftr_next_fast_size_real(n) \
126  (kiss_fft_next_fast_size( ((n)+1)>>1)<<1)
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif
Definition: _kiss_fft_guts.h:22
Definition: kiss_fft.h:59