annotate peck_fft.h @ 2:3d08140650d8

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

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.