Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
kiss_fft.h
00001 #ifndef KISS_FFT_H 00002 #define KISS_FFT_H 00003 00004 #include <stdlib.h> 00005 #include <stdio.h> 00006 #include <math.h> 00007 #include <string.h> 00008 00009 #ifdef __cplusplus 00010 extern "C" { 00011 #endif 00012 00013 /* 00014 ATTENTION! 00015 If you would like a : 00016 -- a utility that will handle the caching of fft objects 00017 -- real-only (no imaginary time component ) FFT 00018 -- a multi-dimensional FFT 00019 -- a command-line utility to perform ffts 00020 -- a command-line utility to perform fast-convolution filtering 00021 00022 Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c 00023 in the tools/ directory. 00024 */ 00025 00026 #ifdef USE_SIMD 00027 # include <xmmintrin.h> 00028 # define kiss_fft_scalar __m128 00029 #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) 00030 #define KISS_FFT_FREE _mm_free 00031 #else 00032 #define KISS_FFT_MALLOC(X) (void*)(0) /* Patched. */ 00033 #define KISS_FFT_FREE(X) /* Patched. */ 00034 #endif 00035 00036 00037 // Patched automatically by download_dependencies.sh so default is 16 bit. 00038 #ifndef FIXED_POINT 00039 #define FIXED_POINT (16) 00040 #endif 00041 // End patch. 00042 00043 #ifdef FIXED_POINT 00044 #include <sys/types.h> 00045 # if (FIXED_POINT == 32) 00046 # define kiss_fft_scalar int32_t 00047 # else 00048 # define kiss_fft_scalar int16_t 00049 # endif 00050 #else 00051 # ifndef kiss_fft_scalar 00052 /* default is float */ 00053 # define kiss_fft_scalar float 00054 # endif 00055 #endif 00056 00057 typedef struct { 00058 kiss_fft_scalar r; 00059 kiss_fft_scalar i; 00060 }kiss_fft_cpx; 00061 00062 typedef struct kiss_fft_state* kiss_fft_cfg; 00063 00064 /* 00065 * kiss_fft_alloc 00066 * 00067 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 00068 * 00069 * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); 00070 * 00071 * The return value from fft_alloc is a cfg buffer used internally 00072 * by the fft routine or NULL. 00073 * 00074 * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. 00075 * The returned value should be free()d when done to avoid memory leaks. 00076 * 00077 * The state can be placed in a user supplied buffer 'mem': 00078 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 00079 * then the function places the cfg in mem and the size used in *lenmem 00080 * and returns mem. 00081 * 00082 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 00083 * then the function returns NULL and places the minimum cfg 00084 * buffer size in *lenmem. 00085 * */ 00086 00087 kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 00088 00089 /* 00090 * kiss_fft(cfg,in_out_buf) 00091 * 00092 * Perform an FFT on a complex input buffer. 00093 * for a forward FFT, 00094 * fin should be f[0] , f[1] , ... ,f[nfft-1] 00095 * fout will be F[0] , F[1] , ... ,F[nfft-1] 00096 * Note that each element is complex and can be accessed like 00097 f[k].r and f[k].i 00098 * */ 00099 void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); 00100 00101 /* 00102 A more generic version of the above function. It reads its input from every Nth sample. 00103 * */ 00104 void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); 00105 00106 /* If kiss_fft_alloc allocated a buffer, it is one contiguous 00107 buffer and can be simply free()d when no longer needed*/ 00108 #define kiss_fft_free free 00109 00110 /* 00111 Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 00112 your compiler output to call this before you exit. 00113 */ 00114 void kiss_fft_cleanup(void); 00115 00116 00117 /* 00118 * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) 00119 */ 00120 int kiss_fft_next_fast_size(int n); 00121 00122 /* for real ffts, we need an even size */ 00123 #define kiss_fftr_next_fast_size_real(n) \ 00124 (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) 00125 00126 #ifdef __cplusplus 00127 } 00128 #endif 00129 00130 #endif
Generated on Wed Jul 13 2022 16:03:35 by
