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