comparison peck_fft.h @ 3:3b31bd44a09f

cleanup
author Peter Meerwald <p.meerwald@bct-electronic.com>
date Fri, 16 Sep 2011 13:08:20 +0200
parents 3d08140650d8
children 2d6c49fcafcb
comparison
equal deleted inserted replaced
2:3d08140650d8 3:3b31bd44a09f
41 } peck_fft_cpx; 41 } peck_fft_cpx;
42 42
43 typedef struct peck_fft_state* peck_fft_cfg; 43 typedef struct peck_fft_state* peck_fft_cfg;
44 44
45 /* 45 /*
46 * peck_fft_alloc 46 * peck_fft_alloc()
47 * 47 *
48 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 48 * Initialize a FFT (or IFFT) algorithm's cfg buffer.
49 * 49 *
50 * typical usage: peck_fft_cfg mycfg=peck_fft_alloc(1024,0,NULL,NULL); 50 * typical usage: peck_fft_cfg mycfg = peck_fft_alloc(1024, 0, NULL, NULL);
51 * 51 *
52 * The return value from fft_alloc is a cfg buffer used internally 52 * The return value from fft_alloc() is a cfg buffer used internally
53 * by the fft routine or NULL. 53 * by the FFT routine or NULL.
54 * 54 *
55 * If lenmem is NULL, then peck_fft_alloc will allocate a cfg buffer using malloc. 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. 56 * The returned value should be free()d when done to avoid memory leaks.
57 * 57 *
58 * The state can be placed in a user supplied buffer 'mem': 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, 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 60 * then the function places the cfg in mem and the size used in *lenmem
61 * and returns mem. 61 * and returns mem.
62 * 62 *
63 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 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 64 * then the function returns NULL and places the minimum cfg
65 * buffer size in *lenmem. 65 * buffer size in *lenmem.
66 * */ 66 */
67 67
68 peck_fft_cfg peck_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 68 peck_fft_cfg peck_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
69 69
70 /* 70 /*
71 * peck_fft(cfg,in_out_buf) 71 * peck_fft(cfg, in_buf, out_buf)
72 * 72 *
73 * Perform an FFT on a complex input buffer. 73 * Perform an FFT on a complex input buffer.
74 * for a forward FFT, 74 * For a forward FFT,
75 * fin should be f[0] , f[1] , ... ,f[nfft-1] 75 * fin should be f[0], f[1], ... , f[nfft-1]
76 * fout will 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 77 * Note that each element is complex and can be accessed like
78 f[k].r and f[k].i 78 * f[k].r and f[k].i
79 * */ 79 */
80 void peck_fft(peck_fft_cfg cfg,const peck_fft_cpx *fin,peck_fft_cpx *fout); 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 81
87 /* If peck_fft_alloc allocated a buffer, it is one contiguous 82 /* If peck_fft_alloc allocated a buffer, it is one contiguous
88 buffer and can be simply free()d when no longer needed*/ 83 * buffer and can be simply free()d when no longer needed
84 */
89 #define peck_fft_free free 85 #define peck_fft_free free
90 86
91 /* 87 /*
92 Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 88 * 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. 89 * your compiler output to call this before you exit.
94 */ 90 */
95 void peck_fft_cleanup(void); 91 void peck_fft_cleanup(void);
96
97 92
98 /* 93 /*
99 * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) 94 * Returns the smallest integer k, such that k>=n and k has only 'fast' factors (2,3,5)
100 */ 95 */
101 int peck_fft_next_fast_size(int n); 96 int peck_fft_next_fast_size(int n);
102 97
103 /* for real ffts, we need an even size */ 98 /* for real ffts, we need an even size */
104 #define peck_fftr_next_fast_size_real(n) \ 99 #define peck_fftr_next_fast_size_real(n) \
105 (peck_fft_next_fast_size( ((n)+1)>>1)<<1) 100 (peck_fft_next_fast_size(((n)+1) >> 1) << 1)
106 101
107 #ifdef __cplusplus 102 #ifdef __cplusplus
108 } 103 }
109 #endif 104 #endif
110 105

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