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