ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

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