Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | #ifndef KISS_FFT_H |
michael@0 | 2 | #define KISS_FFT_H |
michael@0 | 3 | |
michael@0 | 4 | #include <stdlib.h> |
michael@0 | 5 | #include <stdio.h> |
michael@0 | 6 | #include <math.h> |
michael@0 | 7 | #include <string.h> |
michael@0 | 8 | |
michael@0 | 9 | #ifdef __cplusplus |
michael@0 | 10 | extern "C" { |
michael@0 | 11 | #endif |
michael@0 | 12 | |
michael@0 | 13 | /* |
michael@0 | 14 | ATTENTION! |
michael@0 | 15 | If you would like a : |
michael@0 | 16 | -- a utility that will handle the caching of fft objects |
michael@0 | 17 | -- real-only (no imaginary time component ) FFT |
michael@0 | 18 | -- a multi-dimensional FFT |
michael@0 | 19 | -- a command-line utility to perform ffts |
michael@0 | 20 | -- a command-line utility to perform fast-convolution filtering |
michael@0 | 21 | |
michael@0 | 22 | Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c |
michael@0 | 23 | in the tools/ directory. |
michael@0 | 24 | */ |
michael@0 | 25 | |
michael@0 | 26 | #ifdef USE_SIMD |
michael@0 | 27 | # include <xmmintrin.h> |
michael@0 | 28 | # define kiss_fft_scalar __m128 |
michael@0 | 29 | #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) |
michael@0 | 30 | #define KISS_FFT_FREE _mm_free |
michael@0 | 31 | #else |
michael@0 | 32 | #define KISS_FFT_MALLOC malloc |
michael@0 | 33 | #define KISS_FFT_FREE free |
michael@0 | 34 | #endif |
michael@0 | 35 | |
michael@0 | 36 | |
michael@0 | 37 | #ifdef FIXED_POINT |
michael@0 | 38 | #include <sys/types.h> |
michael@0 | 39 | # if (FIXED_POINT == 32) |
michael@0 | 40 | # define kiss_fft_scalar int32_t |
michael@0 | 41 | # else |
michael@0 | 42 | # define kiss_fft_scalar int16_t |
michael@0 | 43 | # endif |
michael@0 | 44 | #else |
michael@0 | 45 | # ifndef kiss_fft_scalar |
michael@0 | 46 | /* default is float */ |
michael@0 | 47 | # define kiss_fft_scalar float |
michael@0 | 48 | # endif |
michael@0 | 49 | #endif |
michael@0 | 50 | |
michael@0 | 51 | typedef struct { |
michael@0 | 52 | kiss_fft_scalar r; |
michael@0 | 53 | kiss_fft_scalar i; |
michael@0 | 54 | }kiss_fft_cpx; |
michael@0 | 55 | |
michael@0 | 56 | typedef struct kiss_fft_state* kiss_fft_cfg; |
michael@0 | 57 | |
michael@0 | 58 | /* |
michael@0 | 59 | * kiss_fft_alloc |
michael@0 | 60 | * |
michael@0 | 61 | * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. |
michael@0 | 62 | * |
michael@0 | 63 | * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); |
michael@0 | 64 | * |
michael@0 | 65 | * The return value from fft_alloc is a cfg buffer used internally |
michael@0 | 66 | * by the fft routine or NULL. |
michael@0 | 67 | * |
michael@0 | 68 | * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. |
michael@0 | 69 | * The returned value should be free()d when done to avoid memory leaks. |
michael@0 | 70 | * |
michael@0 | 71 | * The state can be placed in a user supplied buffer 'mem': |
michael@0 | 72 | * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, |
michael@0 | 73 | * then the function places the cfg in mem and the size used in *lenmem |
michael@0 | 74 | * and returns mem. |
michael@0 | 75 | * |
michael@0 | 76 | * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), |
michael@0 | 77 | * then the function returns NULL and places the minimum cfg |
michael@0 | 78 | * buffer size in *lenmem. |
michael@0 | 79 | * */ |
michael@0 | 80 | |
michael@0 | 81 | kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); |
michael@0 | 82 | |
michael@0 | 83 | /* |
michael@0 | 84 | * kiss_fft(cfg,in_out_buf) |
michael@0 | 85 | * |
michael@0 | 86 | * Perform an FFT on a complex input buffer. |
michael@0 | 87 | * for a forward FFT, |
michael@0 | 88 | * fin should be f[0] , f[1] , ... ,f[nfft-1] |
michael@0 | 89 | * fout will be F[0] , F[1] , ... ,F[nfft-1] |
michael@0 | 90 | * Note that each element is complex and can be accessed like |
michael@0 | 91 | f[k].r and f[k].i |
michael@0 | 92 | * */ |
michael@0 | 93 | void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); |
michael@0 | 94 | |
michael@0 | 95 | /* |
michael@0 | 96 | A more generic version of the above function. It reads its input from every Nth sample. |
michael@0 | 97 | * */ |
michael@0 | 98 | void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); |
michael@0 | 99 | |
michael@0 | 100 | /* If kiss_fft_alloc allocated a buffer, it is one contiguous |
michael@0 | 101 | buffer and can be simply free()d when no longer needed*/ |
michael@0 | 102 | #define kiss_fft_free free |
michael@0 | 103 | |
michael@0 | 104 | /* |
michael@0 | 105 | Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up |
michael@0 | 106 | your compiler output to call this before you exit. |
michael@0 | 107 | */ |
michael@0 | 108 | void kiss_fft_cleanup(void); |
michael@0 | 109 | |
michael@0 | 110 | |
michael@0 | 111 | /* |
michael@0 | 112 | * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) |
michael@0 | 113 | */ |
michael@0 | 114 | int kiss_fft_next_fast_size(int n); |
michael@0 | 115 | |
michael@0 | 116 | /* for real ffts, we need an even size */ |
michael@0 | 117 | #define kiss_fftr_next_fast_size_real(n) \ |
michael@0 | 118 | (kiss_fft_next_fast_size( ((n)+1)>>1)<<1) |
michael@0 | 119 | |
michael@0 | 120 | #ifdef __cplusplus |
michael@0 | 121 | } |
michael@0 | 122 | #endif |
michael@0 | 123 | |
michael@0 | 124 | #endif |