History

Update copyright dates on all files. Add kiss_fft files.

Erik de Castro Lopo committed 22 years ago

Commit bd5c8de1 parent 70079c223 files · +586 −20Browse files

Unified · Split

23 files
  1. examples/sndfile-resample.c +1 −1
  2. examples/varispeed-play.c +1 −1
  3. src/fastest_coeffs.h +1 −1
  4. src/high_qual_coeffs.h +1 −1
  5. src/mid_qual_coeffs.h +1 −1
  6. src/samplerate.c +1 −1
  7. src/samplerate.h +1 −1
  8. src/src_linear.c +1 −1
  9. src/src_sinc.c +1 −1
  10. src/src_zoh.c +1 −1
  11. tests/_kiss_fft_guts.h +107 −0
  12. tests/calc_snr.c +1 −1
  13. tests/calc_snr.h +1 −1
  14. tests/kiss_fft.c +373 −0
  15. tests/kiss_fft.h +86 −0
  16. tests/misc_test.c +1 −1
  17. tests/multi_channel_test.c +1 −1
  18. tests/reset_test.c +1 −1
  19. tests/simple_test.c +1 −1
  20. tests/src-evaluate.c +1 −1
  21. tests/termination_test.c +1 −1
  22. tests/util.c +1 −1
  23. tests/util.h +1 −1
examples/sndfile-resample.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
examples/varispeed-play.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
src/fastest_coeffs.h+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
src/high_qual_coeffs.h+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
src/mid_qual_coeffs.h+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
src/samplerate.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
src/samplerate.h+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
src/src_linear.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
src/src_sinc.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
src/src_zoh.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/_kiss_fft_guts.h+107−0
@@ -0,0 +1,107 @@
1/*
2Copyright (c) 2003, Mark Borgerding
3
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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.
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.
11
12THIS 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.
13*/
14
15/* kiss_fft.h
16 defines kiss_fft_scalar as either short or a float type
17 and defines
18 typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
19#include "kiss_fft.h"
20
21typedef struct {
22 int nfft;
23 int inverse;
24 int *factors;
25 kiss_fft_cpx * twiddles;
26 kiss_fft_cpx * tmpbuf;
27 kiss_fft_cpx * scratch;
28}kiss_fft_state;
29
30/*
31 Explanation of macros dealing with complex math:
32
33 C_MUL(m,a,b) : m = a*b
34 C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise
35 C_SUB( res, a,b) : res = a - b
36 C_SUBFROM( res , a) : res -= a
37 C_ADDTO( res , a) : res += a
38 * */
39#ifdef FIXED_POINT
40# define S_MUL(a,b) ( ( (a)*(b) + (1<<14) )>>15 )
41# define C_MUL(m,a,b) \
42 do{ (m).r = ( ( (a).r*(b).r - (a).i*(b).i) + (1<<14) ) >> 15;\
43 (m).i = ( ( (a).r*(b).i + (a).i*(b).r) + (1<<14) ) >> 15;\
44 }while(0)
45# define C_FIXDIV(c,div) \
46 do{ (c).r /= div; (c).i /=div; }while(0)
47
48# define C_MULBYSCALAR( c, s ) \
49 do{ (c).r = ( ( (c).r*(s) ) + (1<<14) ) >> 15;\
50 (c).i = ( ( (c).i*(s) ) + (1<<14) ) >> 15; }while(0)
51
52#else /* not FIXED_POINT*/
53
54# define S_MUL(a,b) ( (a)*(b) )
55#define C_MUL(m,a,b) \
56 do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
57 (m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
58# define C_FIXDIV(c,div) /* NOOP */
59# define C_MULBYSCALAR( c, s ) \
60 do{ (c).r *= (s);\
61 (c).i *= (s); }while(0)
62#endif
63
64#define C_ADD( res, a,b)\
65 do { (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; }while(0)
66#define C_SUB( res, a,b)\
67 do { (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; }while(0)
68#define C_ADDTO( res , a)\
69 do { (res).r += (a).r; (res).i += (a).i; }while(0)
70#define C_SUBFROM( res , a)\
71 do { (res).r -= (a).r; (res).i -= (a).i; }while(0)
72
73static inline
74kiss_fft_cpx kf_cexp(double phase) /* returns e ** (j*phase) */
75{
76 kiss_fft_cpx x;
77#ifdef FIXED_POINT
78 x.r = (kiss_fft_scalar) (32767 * cos (phase));
79 x.i = (kiss_fft_scalar) (32767 * sin (phase));
80#else
81 x.r = cos (phase);
82 x.i = sin (phase);
83#endif
84 return x;
85}
86
87void kf_work(
88 kiss_fft_cpx * Fout,
89 const kiss_fft_cpx * f,
90 int fstride,
91 int in_skip,
92 int * factors,
93 const kiss_fft_state * st
94 );
95
96/* a debugging function */
97#define pcpx(c)\
98 fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) )
99
100/*
101** Do not edit or modify anything in this comment block.
102** The arch-tag line is a file identity tag for the GNU Arch
103** revision control system.
104**
105** arch-tag: 61697948-aa60-4f95-9433-da1f25c536e1
106*/
107
tests/calc_snr.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/calc_snr.h+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/kiss_fft.c+373−0
@@ -0,0 +1,373 @@
1/*
2Copyright (c) 2003, Mark Borgerding
3
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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.
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.
11
12THIS 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.
13*/
14
15
16#include "_kiss_fft_guts.h"
17/* The guts header contains all the multiplication and addition macros that are defined for
18 fixed or floating point complex numbers. It also delares the kf_ internal functions.
19 */
20
21/* the max length of the sequence of factors of nfft ,
22 MAXFACTORS==32 this should be good up to more 1e15 samples
23 ( 2 * 3**31 )
24 */
25#define MAXFACTORS 32
26
27static void kf_bfly2(
28 kiss_fft_cpx * Fout,
29 int fstride,
30 const kiss_fft_state * st,
31 int m
32 )
33{
34 kiss_fft_cpx * Fout2;
35 kiss_fft_cpx * tw1 = st->twiddles;
36 kiss_fft_cpx t;
37 Fout2 = Fout + m;
38 do{
39 C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
40
41 C_MUL (t, *Fout2 , *tw1);
42 tw1 += fstride;
43 C_SUB( *Fout2 , *Fout , t );
44 C_ADDTO( *Fout , t );
45 ++Fout2;
46 ++Fout;
47 }while (--m);
48}
49
50static void kf_bfly4(
51 kiss_fft_cpx * Fout,
52 int fstride,
53 const kiss_fft_state * st,
54 int m
55 )
56{
57 kiss_fft_cpx *Fout1,*Fout2,*Fout3;
58 kiss_fft_cpx *tw1,*tw2,*tw3;
59 kiss_fft_cpx scratch[6];
60
61 Fout1 = Fout + m;
62 Fout2 = Fout + 2*m;
63 Fout3 = Fout + 3*m;
64 tw3 = tw2 = tw1 = st->twiddles;
65
66 do {
67 C_FIXDIV(*Fout,4); C_FIXDIV(*Fout1,4); C_FIXDIV(*Fout2,4); C_FIXDIV(*Fout3,4);
68
69 C_MUL(scratch[0],*Fout1 , *tw1 );
70 C_MUL(scratch[1],*Fout2 , *tw2 );
71 C_MUL(scratch[2],*Fout3 , *tw3 );
72
73 C_SUB( scratch[5] , *Fout, scratch[1] );
74 C_ADDTO(*Fout, scratch[1]);
75 C_ADD( scratch[3] , scratch[0] , scratch[2] );
76 C_SUB( scratch[4] , scratch[0] , scratch[2] );
77 C_SUB( *Fout2, *Fout, scratch[3] );
78 tw1 += fstride;
79 tw2 += fstride*2;
80 tw3 += fstride*3;
81 C_ADDTO( *Fout , scratch[3] );
82
83 if(st->inverse) {
84 Fout1->r = scratch[5].r - scratch[4].i;
85 Fout1->i = scratch[5].i + scratch[4].r;
86 Fout3->r = scratch[5].r + scratch[4].i;
87 Fout3->i = scratch[5].i - scratch[4].r;
88 }else{
89 Fout1->r = scratch[5].r + scratch[4].i;
90 Fout1->i = scratch[5].i - scratch[4].r;
91 Fout3->r = scratch[5].r - scratch[4].i;
92 Fout3->i = scratch[5].i + scratch[4].r;
93 }
94 ++Fout; ++Fout1; ++Fout2; ++Fout3;
95 }while(--m);
96}
97
98static void kf_bfly3(
99 kiss_fft_cpx * Fout,
100 int fstride,
101 const kiss_fft_state * st,
102 int m
103 )
104{
105 kiss_fft_cpx *Fout0,*Fout1,*Fout2;
106 kiss_fft_cpx *tw1,*tw2;
107 kiss_fft_cpx scratch[5];
108 kiss_fft_cpx epi3;
109 epi3 = st->twiddles[fstride*m];
110
111 Fout0=Fout;
112 Fout1=Fout0+m;
113 Fout2=Fout0+2*m;
114 tw1=tw2=st->twiddles;
115
116 do{
117 C_FIXDIV(*Fout0,3); C_FIXDIV(*Fout1,3); C_FIXDIV(*Fout2,3);
118
119 C_MUL(scratch[1],*Fout1 , *tw1);
120 C_MUL(scratch[2],*Fout2 , *tw2);
121
122 C_ADD(scratch[3],scratch[1],scratch[2]);
123 C_SUB(scratch[0],scratch[1],scratch[2]);
124
125 Fout1->r = Fout0->r - scratch[3].r/2;
126 Fout1->i = Fout0->i - scratch[3].i/2;
127
128 C_MULBYSCALAR( scratch[0] , epi3.i );
129
130 C_ADDTO(*Fout0,scratch[3]);
131
132 Fout2->r = Fout1->r + scratch[0].i;
133 Fout2->i = Fout1->i - scratch[0].r;
134
135 Fout1->r -= scratch[0].i;
136 Fout1->i += scratch[0].r;
137
138 ++Fout0;++Fout1;++Fout2;
139 tw1 += fstride;
140 tw2 += fstride*2;
141 }while(--m);
142}
143
144static void kf_bfly5(
145 kiss_fft_cpx * Fout,
146 int fstride,
147 const kiss_fft_state * st,
148 int m
149 )
150{
151 kiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4;
152 int u;
153 kiss_fft_cpx scratch[13];
154 kiss_fft_cpx * twiddles = st->twiddles;
155 kiss_fft_cpx *tw;
156 kiss_fft_cpx y1,y2;
157 y1 = twiddles[fstride*m];
158 y2 = twiddles[fstride*2*m];
159
160 Fout0=Fout;
161 Fout1=Fout0+m;
162 Fout2=Fout0+2*m;
163 Fout3=Fout0+3*m;
164 Fout4=Fout0+4*m;
165
166 tw=st->twiddles;
167 for ( u=0; u<m; ++u ) {
168 C_FIXDIV( *Fout0,5); C_FIXDIV( *Fout1,5); C_FIXDIV( *Fout2,5); C_FIXDIV( *Fout3,5); C_FIXDIV( *Fout4,5);
169 scratch[0] = *Fout0;
170
171 C_MUL(scratch[1] ,*Fout1, tw[u*fstride]);
172 C_MUL(scratch[2] ,*Fout2, tw[2*u*fstride]);
173 C_MUL(scratch[3] ,*Fout3, tw[3*u*fstride]);
174 C_MUL(scratch[4] ,*Fout4, tw[4*u*fstride]);
175
176 C_ADD( scratch[7],scratch[1],scratch[4]);
177 C_SUB( scratch[10],scratch[1],scratch[4]);
178 C_ADD( scratch[8],scratch[2],scratch[3]);
179 C_SUB( scratch[9],scratch[2],scratch[3]);
180
181 Fout0->r += scratch[7].r + scratch[8].r;
182 Fout0->i += scratch[7].i + scratch[8].i;
183
184 scratch[5].r = scratch[0].r + S_MUL(scratch[7].r,y1.r) + S_MUL(scratch[8].r,y2.r);
185 scratch[5].i = scratch[0].i + S_MUL(scratch[7].i,y1.r) + S_MUL(scratch[8].i,y2.r);
186
187 scratch[6].r = S_MUL(scratch[10].i,y1.i) + S_MUL(scratch[9].i,y2.i);
188 scratch[6].i = -S_MUL(scratch[10].r,y1.i) - S_MUL(scratch[9].r,y2.i);
189
190 C_SUB(*Fout1,scratch[5],scratch[6]);
191 C_ADD(*Fout4,scratch[5],scratch[6]);
192
193 scratch[11].r = scratch[0].r + S_MUL(scratch[7].r,y2.r) + S_MUL(scratch[8].r,y1.r);
194 scratch[11].i = scratch[0].i + S_MUL(scratch[7].i,y2.r) + S_MUL(scratch[8].i,y1.r);
195 scratch[12].r = - S_MUL(scratch[10].i,y2.i) + S_MUL(scratch[9].i,y1.i);
196 scratch[12].i = S_MUL(scratch[10].r,y2.i) - S_MUL(scratch[9].r,y1.i);
197
198 C_ADD(*Fout2,scratch[11],scratch[12]);
199 C_SUB(*Fout3,scratch[11],scratch[12]);
200
201 ++Fout0;++Fout1;++Fout2;++Fout3;++Fout4;
202 }
203}
204
205/* perform the butterfly for one stage of a mixed radix FFT */
206static void kf_bfly_generic(
207 kiss_fft_cpx * Fout,
208 int fstride,
209 const kiss_fft_state * st,
210 int m,
211 int p
212 )
213{
214 int u,k,q1,q;
215 kiss_fft_cpx * scratch = st->scratch;
216 kiss_fft_cpx * twiddles = st->twiddles;
217 kiss_fft_cpx t;
218 int Norig = st->nfft;
219
220 for ( u=0; u<m; ++u ) {
221 k=u;
222 for ( q1=0 ; q1<p ; ++q1 ) {
223 scratch[q1] = Fout[ k ];
224 C_FIXDIV(scratch[q1],p);
225 k += m;
226 }
227
228 k=u;
229 for ( q1=0 ; q1<p ; ++q1 ) {
230 int twidx=0;
231 Fout[ k ] = scratch[0];
232 for (q=1;q<p;++q ) {
233 twidx += fstride * k;
234 if (twidx>=Norig) twidx-=Norig;
235 C_MUL(t,scratch[q] , twiddles[twidx] );
236 C_ADDTO( Fout[ k ] ,t);
237 }
238 k += m;
239 }
240 }
241}
242
243void kf_work(
244 kiss_fft_cpx * Fout,
245 const kiss_fft_cpx * f,
246 int fstride,
247 int in_stride,
248 int * factors,
249 const kiss_fft_state * st
250 )
251{
252 int m,p,q;
253 p=*factors++;
254 m=*factors++;
255
256 for (q=0;q<p;++q) {
257 if (m==1)
258 Fout[q] = *f;
259 else
260 kf_work( Fout + m*q, f, fstride*p, in_stride, factors,st);
261 f += fstride*in_stride;
262 }
263
264 switch (p) {
265 case 2: kf_bfly2(Fout,fstride,st,m); break;
266 case 3: kf_bfly3(Fout,fstride,st,m); break;
267 case 4: kf_bfly4(Fout,fstride,st,m); break;
268 case 5: kf_bfly5(Fout,fstride,st,m); break;
269 default: kf_bfly_generic(Fout,fstride,st,m,p); break;
270 }
271}
272
273/* facbuf is populated by p1,m1,p2,m2, ...
274 where
275 p[i] * m[i] = m[i-1]
276 m0 = n */
277void kf_factor(int n,int * facbuf)
278{
279 int p=4;
280 int floor_sqrt = floor (sqrt (n));
281
282 /*factor out powers of 4, powers of 2, then any remaining primes */
283 do {
284 while (n % p) {
285 switch (p) {
286 case 4: p = 2; break;
287 case 2: p = 3; break;
288 default: p += 2; break;
289 }
290 if (p > floor_sqrt)
291 p = n; /* no more factors, skip to end */
292 }
293 n /= p;
294 *facbuf++ = p;
295 *facbuf++ = n;
296 } while (n > 1);
297}
298
299/*
300 *
301 * User-callable function to allocate all necessary scratch space for the fft.
302 *
303 * The return value is a contiguous block of memory, allocated with malloc. As such,
304 * It can be freed with free(), rather than a kiss_fft-specific function.
305 * */
306void * kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem )
307{
308 kiss_fft_state * st=NULL;
309 size_t memneeded = sizeof(kiss_fft_state)
310 + sizeof(kiss_fft_cpx)*nfft /* twiddle factors*/
311 + sizeof(kiss_fft_cpx)*nfft /* tmpbuf*/
312 + sizeof(int)*2*MAXFACTORS /* factors*/
313 + sizeof(kiss_fft_cpx)*nfft; /* scratch*/
314
315 if ( lenmem==NULL ) {
316 st = ( kiss_fft_state *)malloc( memneeded );
317 }else{
318 if (*lenmem >= memneeded)
319 st = ( kiss_fft_state *)mem;
320 *lenmem = memneeded;
321 }
322 if (st){
323 int i;
324 st->nfft=nfft;
325 st->inverse = inverse_fft;
326 st->twiddles = (kiss_fft_cpx*)(st+1); /* just beyond struct*/
327 st->tmpbuf = (kiss_fft_cpx*)(st->twiddles + nfft);/* just after twiddles*/
328 st->scratch = (kiss_fft_cpx*)(st->tmpbuf + nfft);
329 st->factors = (int*)(st->scratch + nfft);
330
331 for (i=0;i<nfft;++i) {
332 const double pi=3.14159265358979323846264338327;
333 double phase = ( -2*pi /nfft ) * i;
334 if (st->inverse)
335 phase *= -1;
336 st->twiddles[i] = kf_cexp( phase );
337 }
338
339 kf_factor(nfft,st->factors);
340 }
341 return st;
342}
343
344void kiss_fft_stride(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
345{
346 const kiss_fft_state * st = cfg;
347 if (st->nfft < 0) {
348 fprintf(stderr,"usage error: invalid kiss_fft_state. make sure the correct kiss_fft_alloc routine was used.\n");
349 exit(1);
350 }
351
352 if (fin == fout) {
353 kf_work(st->tmpbuf,fin,1,in_stride, st->factors,st);
354 memcpy(fout,st->tmpbuf,sizeof(kiss_fft_cpx)*st->nfft);
355 }else{
356 kf_work( fout, fin, 1,in_stride, st->factors,st );
357 }
358}
359
360void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
361{
362 kiss_fft_stride(cfg,fin,fout,1);
363}
364
365
366/*
367** Do not edit or modify anything in this comment block.
368** The arch-tag line is a file identity tag for the GNU Arch
369** revision control system.
370**
371** arch-tag: 90159a40-9424-4c9a-9e8c-dcb050bc8bb1
372*/
373
tests/kiss_fft.h+86−0
@@ -0,0 +1,86 @@
1#ifndef KISS_FFT_H
2#define KISS_FFT_H
3
4#include <stdlib.h>
5#include <stdio.h>
6#include <math.h>
7#include <memory.h>
8
9/*
10 ATTENTION!
11 If you would like a :
12 -- a utility that will handle the caching of fft objects
13 -- real-only FFT
14 -- a multi-dimensional FFT
15 -- a command-line utility to perform ffts
16 -- a command-line utility to perform fast-convolution filtering
17
18 then see tools/
19 */
20
21#ifdef FIXED_POINT
22# define kiss_fft_scalar short
23#else
24# ifndef kiss_fft_scalar
25/* default is float */
26# define kiss_fft_scalar float
27# endif
28#endif
29
30typedef struct {
31 kiss_fft_scalar r;
32 kiss_fft_scalar i;
33}kiss_fft_cpx;
34
35/*
36 * kiss_fft_alloc
37 *
38 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
39 *
40 * typical usage: void * mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
41 *
42 * The return value from fft_alloc is a cfg buffer used internally
43 * by the fft routine or NULL.
44 *
45 * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
46 * The returned value should be free()d when done to avoid memory leaks.
47 *
48 * The state can be placed in a user supplied buffer 'mem':
49 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
50 * then the function places the cfg in mem and the size used in *lenmem
51 * and returns mem.
52 *
53 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
54 * then the function returns NULL and places the minimum cfg
55 * buffer size in *lenmem.
56 * */
57void* kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
58
59/*
60 * kiss_fft(cfg,in_out_buf)
61 *
62 * Perform an FFT on a complex input buffer.
63 * for a forward FFT,
64 * fin should be f[0] , f[1] , ... ,f[nfft-1]
65 * fout will be F[0] , F[1] , ... ,F[nfft-1]
66 * Note that each element is complex and can be accessed like
67 f[k].r and f[k].i
68 * */
69void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
70
71void kiss_fft_stride(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
72
73/* If kiss_fft_alloc allocated a buffer, it is one contiguous
74 buffer and can be simply free()d when no longer needed*/
75#define kiss_fft_free free
76
77#endif
78
79/*
80** Do not edit or modify anything in this comment block.
81** The arch-tag line is a file identity tag for the GNU Arch
82** revision control system.
83**
84** arch-tag: 2bab07d5-bee1-4724-b5a1-f867d467b7c5
85*/
86
tests/misc_test.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/multi_channel_test.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/reset_test.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/simple_test.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/src-evaluate.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/termination_test.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/util.c+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by
tests/util.h+1−1
@@ -1,5 +1,5 @@
1/*1/*
2** Copyright (C) 2002,2003 Erik de Castro Lopo <erikd@mega-nerd.com>2** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
3**3**
4** This program is free software; you can redistribute it and/or modify4** This program is free software; you can redistribute it and/or modify
5** it under the terms of the GNU General Public License as published by5** it under the terms of the GNU General Public License as published by

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t