vrshoot
diff libs/kissfft/kiss_fft.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/kissfft/kiss_fft.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,124 @@ 1.4 +#ifndef KISS_FFT_H 1.5 +#define KISS_FFT_H 1.6 + 1.7 +#include <stdlib.h> 1.8 +#include <stdio.h> 1.9 +#include <math.h> 1.10 +#include <string.h> 1.11 + 1.12 +#ifdef __cplusplus 1.13 +extern "C" { 1.14 +#endif 1.15 + 1.16 +/* 1.17 + ATTENTION! 1.18 + If you would like a : 1.19 + -- a utility that will handle the caching of fft objects 1.20 + -- real-only (no imaginary time component ) FFT 1.21 + -- a multi-dimensional FFT 1.22 + -- a command-line utility to perform ffts 1.23 + -- a command-line utility to perform fast-convolution filtering 1.24 + 1.25 + Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c 1.26 + in the tools/ directory. 1.27 +*/ 1.28 + 1.29 +#ifdef USE_SIMD 1.30 +# include <xmmintrin.h> 1.31 +# define kiss_fft_scalar __m128 1.32 +#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) 1.33 +#define KISS_FFT_FREE _mm_free 1.34 +#else 1.35 +#define KISS_FFT_MALLOC malloc 1.36 +#define KISS_FFT_FREE free 1.37 +#endif 1.38 + 1.39 + 1.40 +#ifdef FIXED_POINT 1.41 +#include <sys/types.h> 1.42 +# if (FIXED_POINT == 32) 1.43 +# define kiss_fft_scalar int32_t 1.44 +# else 1.45 +# define kiss_fft_scalar int16_t 1.46 +# endif 1.47 +#else 1.48 +# ifndef kiss_fft_scalar 1.49 +/* default is float */ 1.50 +# define kiss_fft_scalar float 1.51 +# endif 1.52 +#endif 1.53 + 1.54 +typedef struct { 1.55 + kiss_fft_scalar r; 1.56 + kiss_fft_scalar i; 1.57 +}kiss_fft_cpx; 1.58 + 1.59 +typedef struct kiss_fft_state* kiss_fft_cfg; 1.60 + 1.61 +/* 1.62 + * kiss_fft_alloc 1.63 + * 1.64 + * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 1.65 + * 1.66 + * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); 1.67 + * 1.68 + * The return value from fft_alloc is a cfg buffer used internally 1.69 + * by the fft routine or NULL. 1.70 + * 1.71 + * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. 1.72 + * The returned value should be free()d when done to avoid memory leaks. 1.73 + * 1.74 + * The state can be placed in a user supplied buffer 'mem': 1.75 + * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 1.76 + * then the function places the cfg in mem and the size used in *lenmem 1.77 + * and returns mem. 1.78 + * 1.79 + * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 1.80 + * then the function returns NULL and places the minimum cfg 1.81 + * buffer size in *lenmem. 1.82 + * */ 1.83 + 1.84 +kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 1.85 + 1.86 +/* 1.87 + * kiss_fft(cfg,in_out_buf) 1.88 + * 1.89 + * Perform an FFT on a complex input buffer. 1.90 + * for a forward FFT, 1.91 + * fin should be f[0] , f[1] , ... ,f[nfft-1] 1.92 + * fout will be F[0] , F[1] , ... ,F[nfft-1] 1.93 + * Note that each element is complex and can be accessed like 1.94 + f[k].r and f[k].i 1.95 + * */ 1.96 +void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); 1.97 + 1.98 +/* 1.99 + A more generic version of the above function. It reads its input from every Nth sample. 1.100 + * */ 1.101 +void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); 1.102 + 1.103 +/* If kiss_fft_alloc allocated a buffer, it is one contiguous 1.104 + buffer and can be simply free()d when no longer needed*/ 1.105 +#define kiss_fft_free free 1.106 + 1.107 +/* 1.108 + Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 1.109 + your compiler output to call this before you exit. 1.110 +*/ 1.111 +void kiss_fft_cleanup(void); 1.112 + 1.113 + 1.114 +/* 1.115 + * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) 1.116 + */ 1.117 +int kiss_fft_next_fast_size(int n); 1.118 + 1.119 +/* for real ffts, we need an even size */ 1.120 +#define kiss_fftr_next_fast_size_real(n) \ 1.121 + (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) 1.122 + 1.123 +#ifdef __cplusplus 1.124 +} 1.125 +#endif 1.126 + 1.127 +#endif