Mercurial > hg > vamp-plugin-sdk
comparison src/vamp-sdk/ext/_kiss_fft_guts.h @ 434:e979a9c4ffb6 vampipe
Switch from Cross FFT with option of FFTW build, to KissFFT only (code bundled). This is much faster than the default build and simpler than managing two options.
author | Chris Cannam |
---|---|
date | Tue, 16 Aug 2016 16:04:09 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
432:8dea61e4a7be | 434:e979a9c4ffb6 |
---|---|
1 #ifndef KISS_FFT__GUTS_H | |
2 #define KISS_FFT__GUTS_H | |
3 /* | |
4 Copyright (c) 2003-2010, Mark Borgerding | |
5 | |
6 All rights reserved. | |
7 | |
8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | |
9 | |
10 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | |
11 * 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. | |
12 * 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. | |
13 | |
14 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. | |
15 */ | |
16 | |
17 /* kiss_fft.h | |
18 defines kiss_fft_scalar as either short or a float type | |
19 and defines | |
20 typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ | |
21 #include "kiss_fft.h" | |
22 #include <limits.h> | |
23 | |
24 #define MAXFACTORS 32 | |
25 /* e.g. an fft of length 128 has 4 factors | |
26 as far as kissfft is concerned | |
27 4*4*4*2 | |
28 */ | |
29 | |
30 struct kiss_fft_state{ | |
31 int nfft; | |
32 int inverse; | |
33 int factors[2*MAXFACTORS]; | |
34 kiss_fft_cpx twiddles[1]; | |
35 }; | |
36 | |
37 /* | |
38 Explanation of macros dealing with complex math: | |
39 | |
40 C_MUL(m,a,b) : m = a*b | |
41 C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise | |
42 C_SUB( res, a,b) : res = a - b | |
43 C_SUBFROM( res , a) : res -= a | |
44 C_ADDTO( res , a) : res += a | |
45 * */ | |
46 #ifdef FIXED_POINT | |
47 #if (FIXED_POINT==32) | |
48 # define FRACBITS 31 | |
49 # define SAMPPROD int64_t | |
50 #define SAMP_MAX 2147483647 | |
51 #else | |
52 # define FRACBITS 15 | |
53 # define SAMPPROD int32_t | |
54 #define SAMP_MAX 32767 | |
55 #endif | |
56 | |
57 #define SAMP_MIN -SAMP_MAX | |
58 | |
59 #if defined(CHECK_OVERFLOW) | |
60 # define CHECK_OVERFLOW_OP(a,op,b) \ | |
61 if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \ | |
62 fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) ); } | |
63 #endif | |
64 | |
65 | |
66 # define smul(a,b) ( (SAMPPROD)(a)*(b) ) | |
67 # define sround( x ) (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS ) | |
68 | |
69 # define S_MUL(a,b) sround( smul(a,b) ) | |
70 | |
71 # define C_MUL(m,a,b) \ | |
72 do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \ | |
73 (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0) | |
74 | |
75 # define DIVSCALAR(x,k) \ | |
76 (x) = sround( smul( x, SAMP_MAX/k ) ) | |
77 | |
78 # define C_FIXDIV(c,div) \ | |
79 do { DIVSCALAR( (c).r , div); \ | |
80 DIVSCALAR( (c).i , div); }while (0) | |
81 | |
82 # define C_MULBYSCALAR( c, s ) \ | |
83 do{ (c).r = sround( smul( (c).r , s ) ) ;\ | |
84 (c).i = sround( smul( (c).i , s ) ) ; }while(0) | |
85 | |
86 #else /* not FIXED_POINT*/ | |
87 | |
88 # define S_MUL(a,b) ( (a)*(b) ) | |
89 #define C_MUL(m,a,b) \ | |
90 do{ (m).r = (a).r*(b).r - (a).i*(b).i;\ | |
91 (m).i = (a).r*(b).i + (a).i*(b).r; }while(0) | |
92 # define C_FIXDIV(c,div) /* NOOP */ | |
93 # define C_MULBYSCALAR( c, s ) \ | |
94 do{ (c).r *= (s);\ | |
95 (c).i *= (s); }while(0) | |
96 #endif | |
97 | |
98 #ifndef CHECK_OVERFLOW_OP | |
99 # define CHECK_OVERFLOW_OP(a,op,b) /* noop */ | |
100 #endif | |
101 | |
102 #define C_ADD( res, a,b)\ | |
103 do { \ | |
104 CHECK_OVERFLOW_OP((a).r,+,(b).r)\ | |
105 CHECK_OVERFLOW_OP((a).i,+,(b).i)\ | |
106 (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \ | |
107 }while(0) | |
108 #define C_SUB( res, a,b)\ | |
109 do { \ | |
110 CHECK_OVERFLOW_OP((a).r,-,(b).r)\ | |
111 CHECK_OVERFLOW_OP((a).i,-,(b).i)\ | |
112 (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \ | |
113 }while(0) | |
114 #define C_ADDTO( res , a)\ | |
115 do { \ | |
116 CHECK_OVERFLOW_OP((res).r,+,(a).r)\ | |
117 CHECK_OVERFLOW_OP((res).i,+,(a).i)\ | |
118 (res).r += (a).r; (res).i += (a).i;\ | |
119 }while(0) | |
120 | |
121 #define C_SUBFROM( res , a)\ | |
122 do {\ | |
123 CHECK_OVERFLOW_OP((res).r,-,(a).r)\ | |
124 CHECK_OVERFLOW_OP((res).i,-,(a).i)\ | |
125 (res).r -= (a).r; (res).i -= (a).i; \ | |
126 }while(0) | |
127 | |
128 | |
129 #ifdef FIXED_POINT | |
130 # define KISS_FFT_COS(phase) floor(.5+SAMP_MAX * cos (phase)) | |
131 # define KISS_FFT_SIN(phase) floor(.5+SAMP_MAX * sin (phase)) | |
132 # define HALF_OF(x) ((x)>>1) | |
133 #elif defined(USE_SIMD) | |
134 # define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) ) | |
135 # define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) ) | |
136 # define HALF_OF(x) ((x)*_mm_set1_ps(.5)) | |
137 #else | |
138 # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) | |
139 # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) | |
140 # define HALF_OF(x) ((x)*.5) | |
141 #endif | |
142 | |
143 #define kf_cexp(x,phase) \ | |
144 do{ \ | |
145 (x)->r = KISS_FFT_COS(phase);\ | |
146 (x)->i = KISS_FFT_SIN(phase);\ | |
147 }while(0) | |
148 | |
149 | |
150 /* a debugging function */ | |
151 #define pcpx(c)\ | |
152 fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) ) | |
153 | |
154 | |
155 #ifdef KISS_FFT_USE_ALLOCA | |
156 // define this to allow use of alloca instead of malloc for temporary buffers | |
157 // Temporary buffers are used in two case: | |
158 // 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5 | |
159 // 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform. | |
160 #include <alloca.h> | |
161 #define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes) | |
162 #define KISS_FFT_TMP_FREE(ptr) | |
163 #else | |
164 #define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) | |
165 #define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) | |
166 #endif | |
167 | |
168 #endif |