Mercurial > hg > peckfft
annotate peck_fft.h @ 13:3e85a9101f02 default tip
readme
author | Peter Meerwald <p.meerwald@bct-electronic.com> |
---|---|
date | Thu, 09 Feb 2012 09:44:39 +0100 |
parents | 2d6c49fcafcb |
children |
rev | line source |
---|---|
0 | 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 | |
4
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
13 #define SIMD_SSE2 1 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
14 #define SIMD_NEON4 2 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
15 #define SIMD_NEON2 3 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
16 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
17 #if USE_SIMD == SIMD_SSE2 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
18 #include <xmmintrin.h> |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
19 #define peck_fft_scalar __m128 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
20 #define PECK_FFT_MALLOC(nbytes) _mm_malloc(nbytes, 16) |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
21 #define PECK_FFT_FREE _mm_free |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
22 #elif USE_SIMD == SIMD_NEON4 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
23 #include <arm_neon.h> |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
24 #define peck_fft_scalar float32x4_t |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
25 #define PECK_FFT_MALLOC malloc |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
26 #define PECK_FFT_FREE free |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
27 #elif USE_SIMD == SIMD_NEON2 |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
28 #include <arm_neon.h> |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
29 #define peck_fft_scalar float32x2_t |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
30 #define PECK_FFT_MALLOC malloc |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
31 #define PECK_FFT_FREE free |
0 | 32 #else |
4
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
33 #define PECK_FFT_MALLOC malloc |
2d6c49fcafcb
neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
3
diff
changeset
|
34 #define PECK_FFT_FREE free |
0 | 35 #endif |
36 | |
37 | |
38 #ifdef FIXED_POINT | |
39 #include <sys/types.h> | |
40 # if (FIXED_POINT == 32) | |
41 # define peck_fft_scalar int32_t | |
42 # else | |
43 # define peck_fft_scalar int16_t | |
44 # endif | |
45 #else | |
46 # ifndef peck_fft_scalar | |
47 /* default is float */ | |
48 # define peck_fft_scalar float | |
49 # endif | |
50 #endif | |
51 | |
52 typedef struct { | |
53 peck_fft_scalar r; | |
54 peck_fft_scalar i; | |
2 | 55 } peck_fft_cpx; |
0 | 56 |
57 typedef struct peck_fft_state* peck_fft_cfg; | |
58 | |
59 /* | |
3 | 60 * peck_fft_alloc() |
0 | 61 * |
3 | 62 * Initialize a FFT (or IFFT) algorithm's cfg buffer. |
0 | 63 * |
3 | 64 * typical usage: peck_fft_cfg mycfg = peck_fft_alloc(1024, 0, NULL, NULL); |
0 | 65 * |
3 | 66 * The return value from fft_alloc() is a cfg buffer used internally |
67 * by the FFT routine or NULL. | |
0 | 68 * |
3 | 69 * If lenmem is NULL, then peck_fft_alloc() will allocate a cfg buffer using malloc. |
0 | 70 * The returned value should be free()d when done to avoid memory leaks. |
71 * | |
72 * The state can be placed in a user supplied buffer 'mem': | |
73 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, | |
74 * then the function places the cfg in mem and the size used in *lenmem | |
75 * and returns mem. | |
76 * | |
77 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), | |
78 * then the function returns NULL and places the minimum cfg | |
79 * buffer size in *lenmem. | |
3 | 80 */ |
0 | 81 |
82 peck_fft_cfg peck_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); | |
83 | |
84 /* | |
3 | 85 * peck_fft(cfg, in_buf, out_buf) |
0 | 86 * |
87 * Perform an FFT on a complex input buffer. | |
3 | 88 * For a forward FFT, |
89 * fin should be f[0], f[1], ... , f[nfft-1] | |
90 * fout will be F[0], F[1], ... , F[nfft-1] | |
0 | 91 * Note that each element is complex and can be accessed like |
3 | 92 * f[k].r and f[k].i |
93 */ | |
94 void peck_fft(peck_fft_cfg cfg, const peck_fft_cpx *fin, peck_fft_cpx *fout); | |
0 | 95 |
96 /* If peck_fft_alloc allocated a buffer, it is one contiguous | |
3 | 97 * buffer and can be simply free()d when no longer needed |
98 */ | |
0 | 99 #define peck_fft_free free |
100 | |
101 /* | |
3 | 102 * Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up |
103 * your compiler output to call this before you exit. | |
104 */ | |
0 | 105 void peck_fft_cleanup(void); |
106 | |
107 /* | |
3 | 108 * Returns the smallest integer k, such that k>=n and k has only 'fast' factors (2,3,5) |
0 | 109 */ |
110 int peck_fft_next_fast_size(int n); | |
111 | |
112 /* for real ffts, we need an even size */ | |
113 #define peck_fftr_next_fast_size_real(n) \ | |
3 | 114 (peck_fft_next_fast_size(((n)+1) >> 1) << 1) |
0 | 115 |
116 #ifdef __cplusplus | |
117 } | |
118 #endif | |
119 | |
120 #endif |