0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
1 /*
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
2 Copyright (c) 2003-2010, Mark Borgerding
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
3
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
4 All rights reserved.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
5
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
7
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
8 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
9 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
10 * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
11
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
12 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
13 */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
14
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
15
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
16 #include "_peck_fft_guts.h"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
17 /* The guts header contains all the multiplication and addition macros that are defined for
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
18 fixed or floating point complex numbers. It also delares the kf_ internal functions.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
19 */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
20
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
21 static void kf_bfly2(
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
22 peck_fft_cpx * Fout,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
23 const size_t fstride,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
24 const peck_fft_cfg st,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
25 int m
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
26 )
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
27 {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
28
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
29 //printf("kf_bfly2\n");
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
30
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
31 peck_fft_cpx * Fout2;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
32 peck_fft_cpx * tw1 = st->twiddles;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
33 peck_fft_cpx t;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
34 Fout2 = Fout + m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
35 do{
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
36 C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
37
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
38 C_MUL (t, *Fout2 , *tw1);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
39 tw1 += fstride;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
40 C_SUB( *Fout2 , *Fout , t );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
41 C_ADDTO( *Fout , t );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
42 ++Fout2;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
43 ++Fout;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
44 }while (--m);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
45 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
46
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
47 static void kf_bfly4(
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
48 peck_fft_cpx * Fout,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
49 const size_t fstride,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
50 const peck_fft_cfg st,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
51 const size_t m
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
52 )
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
53 {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
54 peck_fft_cpx *tw1,*tw2,*tw3;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
55 peck_fft_cpx scratch[6];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
56 size_t k=m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
57 const size_t m2=2*m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
58 const size_t m3=3*m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
59
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
60 //printf("kf_bfly4\n");
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
61
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
62
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
63 tw3 = tw2 = tw1 = st->twiddles;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
64
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
65 do {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
66 C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
67
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
68 C_MUL(scratch[0],Fout[m] , *tw1 );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
69 C_MUL(scratch[1],Fout[m2] , *tw2 );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
70 C_MUL(scratch[2],Fout[m3] , *tw3 );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
71
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
72 C_SUB( scratch[5] , *Fout, scratch[1] );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
73 C_ADDTO(*Fout, scratch[1]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
74 C_ADD( scratch[3] , scratch[0] , scratch[2] );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
75 C_SUB( scratch[4] , scratch[0] , scratch[2] );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
76 C_SUB( Fout[m2], *Fout, scratch[3] );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
77 tw1 += fstride;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
78 tw2 += fstride*2;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
79 tw3 += fstride*3;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
80 C_ADDTO( *Fout , scratch[3] );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
81
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
82 if(st->inverse) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
83 Fout[m].r = scratch[5].r - scratch[4].i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
84 Fout[m].i = scratch[5].i + scratch[4].r;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
85 Fout[m3].r = scratch[5].r + scratch[4].i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
86 Fout[m3].i = scratch[5].i - scratch[4].r;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
87 }else{
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
88 Fout[m].r = scratch[5].r + scratch[4].i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
89 Fout[m].i = scratch[5].i - scratch[4].r;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
90 Fout[m3].r = scratch[5].r - scratch[4].i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
91 Fout[m3].i = scratch[5].i + scratch[4].r;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
92 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
93 ++Fout;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
94 }while(--k);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
95 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
96
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
97 static void kf_bfly3(
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
98 peck_fft_cpx * Fout,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
99 const size_t fstride,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
100 const peck_fft_cfg st,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
101 size_t m
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
102 )
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
103 {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
104 size_t k=m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
105 const size_t m2 = 2*m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
106 peck_fft_cpx *tw1,*tw2;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
107 peck_fft_cpx scratch[5];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
108 peck_fft_cpx epi3;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
109 epi3 = st->twiddles[fstride*m];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
110
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
111 printf("kf_bfly3\n");
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
112
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
113
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
114 tw1=tw2=st->twiddles;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
115
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
116 do{
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
117 C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
118
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
119 C_MUL(scratch[1],Fout[m] , *tw1);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
120 C_MUL(scratch[2],Fout[m2] , *tw2);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
121
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
122 C_ADD(scratch[3],scratch[1],scratch[2]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
123 C_SUB(scratch[0],scratch[1],scratch[2]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
124 tw1 += fstride;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
125 tw2 += fstride*2;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
126
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
127 Fout[m].r = Fout->r - HALF_OF(scratch[3].r);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
128 Fout[m].i = Fout->i - HALF_OF(scratch[3].i);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
129
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
130 C_MULBYSCALAR( scratch[0] , epi3.i );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
131
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
132 C_ADDTO(*Fout,scratch[3]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
133
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
134 Fout[m2].r = Fout[m].r + scratch[0].i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
135 Fout[m2].i = Fout[m].i - scratch[0].r;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
136
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
137 Fout[m].r -= scratch[0].i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
138 Fout[m].i += scratch[0].r;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
139
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
140 ++Fout;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
141 }while(--k);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
142 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
143
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
144 static void kf_bfly5(
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
145 peck_fft_cpx * Fout,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
146 const size_t fstride,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
147 const peck_fft_cfg st,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
148 int m
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
149 )
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
150 {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
151 peck_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
152 int u;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
153 peck_fft_cpx scratch[13];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
154 peck_fft_cpx * twiddles = st->twiddles;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
155 peck_fft_cpx *tw;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
156 peck_fft_cpx ya,yb;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
157 ya = twiddles[fstride*m];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
158 yb = twiddles[fstride*2*m];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
159
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
160 printf("kf_bfly5\n");
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
161
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
162
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
163 Fout0=Fout;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
164 Fout1=Fout0+m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
165 Fout2=Fout0+2*m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
166 Fout3=Fout0+3*m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
167 Fout4=Fout0+4*m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
168
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
169 tw=st->twiddles;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
170 for ( u=0; u<m; ++u ) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
171 C_FIXDIV( *Fout0,5); C_FIXDIV( *Fout1,5); C_FIXDIV( *Fout2,5); C_FIXDIV( *Fout3,5); C_FIXDIV( *Fout4,5);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
172 scratch[0] = *Fout0;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
173
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
174 C_MUL(scratch[1] ,*Fout1, tw[u*fstride]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
175 C_MUL(scratch[2] ,*Fout2, tw[2*u*fstride]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
176 C_MUL(scratch[3] ,*Fout3, tw[3*u*fstride]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
177 C_MUL(scratch[4] ,*Fout4, tw[4*u*fstride]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
178
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
179 C_ADD( scratch[7],scratch[1],scratch[4]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
180 C_SUB( scratch[10],scratch[1],scratch[4]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
181 C_ADD( scratch[8],scratch[2],scratch[3]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
182 C_SUB( scratch[9],scratch[2],scratch[3]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
183
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
184 Fout0->r += scratch[7].r + scratch[8].r;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
185 Fout0->i += scratch[7].i + scratch[8].i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
186
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
187 scratch[5].r = scratch[0].r + S_MUL(scratch[7].r,ya.r) + S_MUL(scratch[8].r,yb.r);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
188 scratch[5].i = scratch[0].i + S_MUL(scratch[7].i,ya.r) + S_MUL(scratch[8].i,yb.r);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
189
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
190 scratch[6].r = S_MUL(scratch[10].i,ya.i) + S_MUL(scratch[9].i,yb.i);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
191 scratch[6].i = -S_MUL(scratch[10].r,ya.i) - S_MUL(scratch[9].r,yb.i);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
192
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
193 C_SUB(*Fout1,scratch[5],scratch[6]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
194 C_ADD(*Fout4,scratch[5],scratch[6]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
195
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
196 scratch[11].r = scratch[0].r + S_MUL(scratch[7].r,yb.r) + S_MUL(scratch[8].r,ya.r);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
197 scratch[11].i = scratch[0].i + S_MUL(scratch[7].i,yb.r) + S_MUL(scratch[8].i,ya.r);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
198 scratch[12].r = - S_MUL(scratch[10].i,yb.i) + S_MUL(scratch[9].i,ya.i);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
199 scratch[12].i = S_MUL(scratch[10].r,yb.i) - S_MUL(scratch[9].r,ya.i);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
200
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
201 C_ADD(*Fout2,scratch[11],scratch[12]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
202 C_SUB(*Fout3,scratch[11],scratch[12]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
203
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
204 ++Fout0;++Fout1;++Fout2;++Fout3;++Fout4;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
205 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
206 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
207
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
208 /* perform the butterfly for one stage of a mixed radix FFT */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
209 static void kf_bfly_generic(
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
210 peck_fft_cpx * Fout,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
211 const size_t fstride,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
212 const peck_fft_cfg st,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
213 int m,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
214 int p
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
215 )
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
216 {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
217 int u,k,q1,q;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
218 peck_fft_cpx * twiddles = st->twiddles;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
219 peck_fft_cpx t;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
220 int Norig = st->nfft;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
221
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
222 printf("kf_bfly_generic\n");
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
223
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
224
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
225 peck_fft_cpx * scratch = (peck_fft_cpx*)PECK_FFT_TMP_ALLOC(sizeof(peck_fft_cpx)*p);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
226
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
227 for ( u=0; u<m; ++u ) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
228 k=u;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
229 for (q1 = 0; q1 < p; ++q1) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
230 scratch[q1] = Fout[k];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
231 C_FIXDIV(scratch[q1], p);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
232 k += m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
233 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
234
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
235 k=u;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
236 for ( q1=0 ; q1<p ; ++q1 ) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
237 int twidx=0;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
238 Fout[ k ] = scratch[0];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
239 for (q=1;q<p;++q ) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
240 twidx += fstride * k;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
241 if (twidx>=Norig) twidx-=Norig;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
242 C_MUL(t,scratch[q] , twiddles[twidx] );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
243 C_ADDTO( Fout[ k ] ,t);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
244 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
245 k += m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
246 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
247 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
248 PECK_FFT_TMP_FREE(scratch);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
249 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
250
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
251 static void kf_work(
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
252 peck_fft_cpx * Fout,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
253 const peck_fft_cpx * f,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
254 const size_t fstride,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
255 int *factors,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
256 const peck_fft_cfg st) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
257 peck_fft_cpx *Fout_beg = Fout;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
258 const int p = *factors++; /* the radix */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
259 const int m = *factors++; /* stage's FFT length / p */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
260 const peck_fft_cpx *Fout_end = Fout + p*m;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
261
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
262 // printf("kf_work\n");
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
263
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
264 if (m == 1) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
265 do {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
266 *Fout = *f;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
267 f += fstride;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
268 } while (++Fout != Fout_end);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
269 } else {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
270 do {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
271 // recursive call:
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
272 // DFT of size m*p performed by doing
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
273 // p instances of smaller DFTs of size m,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
274 // each one takes a decimated version of the input
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
275 kf_work(Fout, f, fstride*p, factors, st);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
276 f += fstride;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
277 } while ((Fout += m) != Fout_end);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
278 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
279
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
280 Fout=Fout_beg;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
281
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
282 // recombine the p smaller DFTs
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
283 switch (p) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
284 case 2: kf_bfly2(Fout, fstride, st, m); break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
285 case 3: kf_bfly3(Fout, fstride, st, m); break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
286 case 4: kf_bfly4(Fout, fstride, st, m); break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
287 case 5: kf_bfly5(Fout, fstride, st, m); break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
288 default: kf_bfly_generic(Fout, fstride, st, m, p); break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
289 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
290 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
291
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
292 /*
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
293 * facbuf is populated by p1, m1, p2, m2, ...
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
294 * where
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
295 * p[i] * m[i] = m[i-1]
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
296 * m0 = n
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
297 */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
298 static void kf_factor(int n, int * facbuf) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
299 int p = 4;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
300 float floor_sqrt;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
301 floor_sqrt = floorf(sqrtf(n));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
302
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
303 /* factor out powers of 4, powers of 2, then any remaining primes */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
304 do {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
305 while (n % p) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
306 switch (p) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
307 case 4: p = 2; break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
308 case 2: p = 3; break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
309 default: p += 2; break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
310 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
311 if (p > floor_sqrt)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
312 p = n; /* no more factors, skip to end */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
313 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
314 n /= p;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
315 *facbuf++ = p;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
316 *facbuf++ = n;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
317 } while (n > 1);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
318 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
319
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
320 /*
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
321 * User-callable function to allocate all necessary storage space for the fft.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
322 * The return value is a contiguous block of memory, allocated with malloc. As such,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
323 * it can be freed with free(), rather than a peck_fft-specific function.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
324 */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
325 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
|
326 peck_fft_cfg st = NULL;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
327 size_t memneeded = sizeof(struct peck_fft_state)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
328 + sizeof(peck_fft_cpx)*(nfft-1); /* twiddle factors */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
329
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
330 if (lenmem == NULL) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
331 st = ( peck_fft_cfg)PECK_FFT_MALLOC(memneeded);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
332 } else {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
333 if (mem != NULL && *lenmem >= memneeded)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
334 st = (peck_fft_cfg)mem;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
335 *lenmem = memneeded;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
336 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
337
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
338 if (st) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
339 int i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
340 st->nfft=nfft;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
341 st->inverse = inverse_fft;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
342
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
343 for (i = 0; i < nfft; ++i) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
344 const float pi = 3.14159265359f;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
345 float phase = -2*pi*i / nfft;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
346 if (st->inverse)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
347 phase *= -1;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
348 kf_cexp(st->twiddles+i, phase);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
349 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
350
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
351 kf_factor(nfft, st->factors);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
352 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
353 return st;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
354 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
355
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
356 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
|
357 kf_work(fout, fin, 1, cfg->factors, cfg);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
358 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
359
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
360 void peck_fft_cleanup(void) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
361 /* nothing needed any more */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
362 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
363
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
364 int peck_fft_next_fast_size(int n) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
365 while (1) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
366 int m = n;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
367 while ((m % 2) == 0) m /= 2;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
368 while ((m % 3) == 0) m /= 3;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
369 while ((m % 5) == 0) m /= 5;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
370 if (m <= 1)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
371 break; /* n is completely factorable by twos, threes, and fives */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
372 n++;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
373 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
374 return n;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
375 }
|