Mercurial > hg > peckfft
comparison peck_fft.h @ 0:723f588b82ac
import
author | Peter Meerwald <p.meerwald@bct-electronic.com> |
---|---|
date | Fri, 16 Sep 2011 12:53:08 +0200 |
parents | |
children | 3d08140650d8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:723f588b82ac |
---|---|
1 #ifndef PECK_FFT_H | |
2 #define PECK_FFT_H | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <math.h> | |
7 #include <string.h> | |
8 | |
9 #ifdef __cplusplus | |
10 extern "C" { | |
11 #endif | |
12 | |
13 #ifdef USE_SIMD | |
14 # include <xmmintrin.h> | |
15 # define peck_fft_scalar __m128 | |
16 #define PECK_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) | |
17 #define PECK_FFT_FREE _mm_free | |
18 #else | |
19 #define PECK_FFT_MALLOC malloc | |
20 #define PECK_FFT_FREE free | |
21 #endif | |
22 | |
23 | |
24 #ifdef FIXED_POINT | |
25 #include <sys/types.h> | |
26 # if (FIXED_POINT == 32) | |
27 # define peck_fft_scalar int32_t | |
28 # else | |
29 # define peck_fft_scalar int16_t | |
30 # endif | |
31 #else | |
32 # ifndef peck_fft_scalar | |
33 /* default is float */ | |
34 # define peck_fft_scalar float | |
35 # endif | |
36 #endif | |
37 | |
38 typedef struct { | |
39 peck_fft_scalar r; | |
40 peck_fft_scalar i; | |
41 }peck_fft_cpx; | |
42 | |
43 typedef struct peck_fft_state* peck_fft_cfg; | |
44 | |
45 /* | |
46 * peck_fft_alloc | |
47 * | |
48 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. | |
49 * | |
50 * typical usage: peck_fft_cfg mycfg=peck_fft_alloc(1024,0,NULL,NULL); | |
51 * | |
52 * The return value from fft_alloc is a cfg buffer used internally | |
53 * by the fft routine or NULL. | |
54 * | |
55 * If lenmem is NULL, then peck_fft_alloc will allocate a cfg buffer using malloc. | |
56 * The returned value should be free()d when done to avoid memory leaks. | |
57 * | |
58 * The state can be placed in a user supplied buffer 'mem': | |
59 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, | |
60 * then the function places the cfg in mem and the size used in *lenmem | |
61 * and returns mem. | |
62 * | |
63 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), | |
64 * then the function returns NULL and places the minimum cfg | |
65 * buffer size in *lenmem. | |
66 * */ | |
67 | |
68 peck_fft_cfg peck_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); | |
69 | |
70 /* | |
71 * peck_fft(cfg,in_out_buf) | |
72 * | |
73 * Perform an FFT on a complex input buffer. | |
74 * for a forward FFT, | |
75 * fin should be f[0] , f[1] , ... ,f[nfft-1] | |
76 * fout will be F[0] , F[1] , ... ,F[nfft-1] | |
77 * Note that each element is complex and can be accessed like | |
78 f[k].r and f[k].i | |
79 * */ | |
80 void peck_fft(peck_fft_cfg cfg,const peck_fft_cpx *fin,peck_fft_cpx *fout); | |
81 | |
82 /* | |
83 A more generic version of the above function. It reads its input from every Nth sample. | |
84 * */ | |
85 void peck_fft_stride(peck_fft_cfg cfg,const peck_fft_cpx *fin,peck_fft_cpx *fout,int fin_stride); | |
86 | |
87 /* If peck_fft_alloc allocated a buffer, it is one contiguous | |
88 buffer and can be simply free()d when no longer needed*/ | |
89 #define peck_fft_free free | |
90 | |
91 /* | |
92 Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up | |
93 your compiler output to call this before you exit. | |
94 */ | |
95 void peck_fft_cleanup(void); | |
96 | |
97 | |
98 /* | |
99 * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) | |
100 */ | |
101 int peck_fft_next_fast_size(int n); | |
102 | |
103 /* for real ffts, we need an even size */ | |
104 #define peck_fftr_next_fast_size_real(n) \ | |
105 (peck_fft_next_fast_size( ((n)+1)>>1)<<1) | |
106 | |
107 #ifdef __cplusplus | |
108 } | |
109 #endif | |
110 | |
111 #endif |