History

Remove kiss fft and add --disable-fftw ./configure option. Kiss fft was removed to allow the Rabbit to be dual licensed.

Erik de Castro Lopo committed 22 years ago

Commit 10c87921 parent d9a49735 files · +29 −626Browse files

Unified · Split

5 files
  1. configure.ac +14 −14
  2. tests/_kiss_fft_guts.h +0 −107
  3. tests/calc_snr.c +15 −46
  4. tests/kiss_fft.c +0 −373
  5. tests/kiss_fft.h +0 −86
configure.ac+14−14
@@ -55,6 +55,10 @@ AC_ARG_ENABLE(gcc-opt, · 54 unmodified lines
5555 [ --disable-gcc-opt disable gcc optimisations ],
5656 ac_arg_gcc_opt="N", ac_arg_gcc_opt="Y")
5757
58+AC_ARG_ENABLE(fftw,
59+ [ --disable-fftw disable usage of FFTW ],
60+ ac_arg_fftw="N", ac_arg_fftw="Y")
61+
5862 AC_ARG_ENABLE(debug,
5963 [ --enable-debug enable debugging ],
6064 ac_arg_debug=yes, ac_arg_debug=no)
@@ -185,14 +189,17 @@ else · 124 unmodified lines
185189 #====================================================================================
186190 # Check for libfftw3 which is required for the test and example programs.
187191
188−PKG_CHECK_MODULES(FFTW3, fftw3 >= 0.15.0, ac_cv_fftw3=1, ac_cv_fftw3=0)
192+if test $ac_arg_fftw = "Y" ; then
193+ PKG_CHECK_MODULES(FFTW3, fftw3 >= 0.15.0, ac_cv_fftw3=1, ac_cv_fftw3=0)
194+ AC_DEFINE_UNQUOTED([HAVE_FFTW3],$ac_cv_fftw3,[Set to 1 if you have libfftw3.])
189195
190−AC_DEFINE_UNQUOTED([HAVE_FFTW3],$ac_cv_fftw3,[Set to 1 if you have libfftw3.])
196+ if test x$ac_cv_fftw3 = x1 ; then
197+ ac_cv_fftw3=yes
198+ HAVE_FFTW3=1
199+ fi
200+ fi
191201
192−if test x$ac_cv_fftw3 = x1 ; then
193− ac_cv_fftw3=yes
194− HAVE_FFTW3=1
195−else
202+if test x$ac_cv_fftw3 != xyes ; then
196203 ac_cv_fftw3=no
197204 HAVE_FFTW3=0
198205 fi
@@ -267,14 +274,7 @@ if test x$ac_cv_c_compiler_gnu = xyes ; then · 68 unmodified lines
267274 AC_MSG_RESULT([
268275 Extra tools required for testing and examples :
269276
270− Have FFTW : ................... ${ac_cv_fftw3}])
271−
272−if test x$ac_cv_fftw3 = xno ; then
273− echo
274− echo " * FFTW is available from http://www.fftw.org/ or if you "
275− echo " * are using Debian : \"apt-get install fftw3 fftw3-dev\""
276− echo
277− fi
277+ Use FFTW : .................... ${ac_cv_fftw3}])
278278
279279 AC_MSG_RESULT([ Have libsndfile : ............. ${ac_cv_sndfile}])
280280 AC_MSG_RESULT([ Have libefence : .............. ${ac_cv_lib_efence_memalign}
tests/_kiss_fft_guts.h+0−107
@@ -1,107 +0,0 @@
1−/*
2−Copyright (c) 2003, Mark Borgerding
3−
4−All rights reserved.
5−
6−Redistribution 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−
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.
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−
21−typedef 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−
73−static inline
74−kiss_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−
87−void 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+15−46
@@ -21,11 +21,15 @@ · 20 unmodified lines
2121 #include "calc_snr.h"
2222 #include "util.h"
2323
24+#if (HAVE_FFTW3 == 1)
25+
2426 #include <stdio.h>
2527 #include <stdlib.h>
2628 #include <string.h>
2729 #include <math.h>
2830
31+#include <fftw3.h>
32+
2933 #define MAX_SPEC_LEN (1<<18)
3034 #define MAX_PEAKS 10
3135
@@ -183,13 +187,6 @@ find_snr (const double *magnitude, int len) · 151 unmodified lines
183187 return snr ;
184188 } /* find_snr */
185189
186−/*==============================================================================
187−*/
188−
189−#if (HAVE_FFTW3 == 1)
190−
191−#include <fftw3.h>
192−
193190 static void
194191 log_mag_spectrum (double *input, int len, double *magnitude)
195192 { fftw_plan plan = NULL ;
@@ -207,6 +204,8 @@ log_mag_spectrum (double *input, int len, double *magnitude) · 11 unmodified lines
207204 } ;
208205
209206 fftw_execute (plan) ;
207+
208+ fftw_destroy_plan (plan) ;
210209
211210 /* (k < N/2 rounded up) */
212211 maxval = 0.0 ;
@@ -229,48 +228,17 @@ log_mag_spectrum (double *input, int len, double *magnitude) · 16 unmodified lines
229228 return ;
230229 } /* log_mag_spectrum */
231230
232−#else /* (! HAVE_FFTW3) */
231+#else /* ! (HAVE_LIBFFTW && HAVE_LIBRFFTW) */
233232
234−#include "kiss_fft.h"
235−
236−static void
237−log_mag_spectrum (double *input, int len, double *magnitude)
238−{ fftw_plan plan = NULL ;
239−
240− double maxval ;
241− int k ;
242−
243− if (input == NULL || magnitude == NULL)
244− return ;
245−
246− plan = fftw_plan_r2r_1d (len, input, magnitude, FFTW_R2HC, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT) ;
247− if (plan == NULL)
248− { printf ("%s : line %d : create plan failed.\n", __FILE__, __LINE__) ;
249− exit (1) ;
250− } ;
251−
252− fftw_execute (plan) ;
253−
254− /* (k < N/2 rounded up) */
255− maxval = 0.0 ;
256− for (k = 1 ; k < len / 2 ; k++)
257− { magnitude [k] = sqrt (magnitude [k] * magnitude [k] + magnitude [len - k - 1] * magnitude [len - k - 1]) ;
258− maxval = (maxval < magnitude [k]) ? magnitude [k] : maxval ;
259− } ;
260−
261− memset (magnitude + len / 2, 0, len / 2 * sizeof (magnitude [0])) ;
262−
263− /* Don't care about DC component. Make it zero. */
264− magnitude [0] = 0.0 ;
233+double
234+calculate_snr (float *data, int len)
235+{ double snr = 200.0 ;
265236
266− /* log magnitude. */
267− for (k = 0 ; k < len ; k++)
268− { magnitude [k] = magnitude [k] / maxval ;
269− magnitude [k] = (magnitude [k] < 1e-15) ? -200.0 : 20.0 * log10 (magnitude [k]) ;
270− } ;
237+ data = data ;
238+ len = len ;
271239
272− return ;
273−} /* log_mag_spectrum */
240+ return snr ;
241+} /* calculate_snr */
274242
275243 #endif
276244
@@ -281,3 +249,4 @@ log_mag_spectrum (double *input, int len, double *magnitude) · 4 unmodified lines
281249 **
282250 ** arch-tag: 7ae937c5-53a5-45d8-8aa2-793de9c35f0a
283251 */
252+
tests/kiss_fft.c+0−373
@@ -1,373 +0,0 @@
1−/*
2−Copyright (c) 2003, Mark Borgerding
3−
4−All rights reserved.
5−
6−Redistribution 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−
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.
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−
27−static 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−
50−static 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−
98−static 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−
144−static 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 */
206−static 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−
243−void 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 */
277−void 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− * */
306−void * 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−
344−void 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−
360−void 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+0−86
@@ -1,86 +0,0 @@
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−
30−typedef 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− * */
57−void* 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− * */
69−void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
70−
71−void 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−

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