| OLD | NEW |
| (Empty) | |
| 1 /*Copyright (c) 2003-2004, Mark Borgerding |
| 2 |
| 3 All rights reserved. |
| 4 |
| 5 Redistribution and use in source and binary forms, with or without |
| 6 modification, are permitted provided that the following conditions are met: |
| 7 |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 this list of conditions and the following disclaimer. |
| 10 * Redistributions in binary form must reproduce the above copyright notice, |
| 11 this list of conditions and the following disclaimer in the |
| 12 documentation and/or other materials provided with the distribution. |
| 13 |
| 14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 18 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 24 POSSIBILITY OF SUCH DAMAGE.*/ |
| 25 |
| 26 #ifndef KISS_FFT_GUTS_H |
| 27 #define KISS_FFT_GUTS_H |
| 28 |
| 29 #define MIN(a,b) ((a)<(b) ? (a):(b)) |
| 30 #define MAX(a,b) ((a)>(b) ? (a):(b)) |
| 31 |
| 32 /* kiss_fft.h |
| 33 defines kiss_fft_scalar as either short or a float type |
| 34 and defines |
| 35 typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ |
| 36 #include "kiss_fft.h" |
| 37 |
| 38 /* |
| 39 Explanation of macros dealing with complex math: |
| 40 |
| 41 C_MUL(m,a,b) : m = a*b |
| 42 C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise |
| 43 C_SUB( res, a,b) : res = a - b |
| 44 C_SUBFROM( res , a) : res -= a |
| 45 C_ADDTO( res , a) : res += a |
| 46 * */ |
| 47 #ifdef FIXED_POINT |
| 48 #include "arch.h" |
| 49 |
| 50 |
| 51 #define SAMP_MAX 2147483647 |
| 52 #define TWID_MAX 32767 |
| 53 #define TRIG_UPSCALE 1 |
| 54 |
| 55 #define SAMP_MIN -SAMP_MAX |
| 56 |
| 57 |
| 58 # define S_MUL(a,b) MULT16_32_Q15(b, a) |
| 59 |
| 60 # define C_MUL(m,a,b) \ |
| 61 do{ (m).r = SUB32(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ |
| 62 (m).i = ADD32(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)); }while(0) |
| 63 |
| 64 # define C_MULC(m,a,b) \ |
| 65 do{ (m).r = ADD32(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ |
| 66 (m).i = SUB32(S_MUL((a).i,(b).r) , S_MUL((a).r,(b).i)); }while(0) |
| 67 |
| 68 # define C_MUL4(m,a,b) \ |
| 69 do{ (m).r = SHR32(SUB32(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)),2); \ |
| 70 (m).i = SHR32(ADD32(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)),2); }whil
e(0) |
| 71 |
| 72 # define C_MULBYSCALAR( c, s ) \ |
| 73 do{ (c).r = S_MUL( (c).r , s ) ;\ |
| 74 (c).i = S_MUL( (c).i , s ) ; }while(0) |
| 75 |
| 76 # define DIVSCALAR(x,k) \ |
| 77 (x) = S_MUL( x, (TWID_MAX-((k)>>1))/(k)+1 ) |
| 78 |
| 79 # define C_FIXDIV(c,div) \ |
| 80 do { DIVSCALAR( (c).r , div); \ |
| 81 DIVSCALAR( (c).i , div); }while (0) |
| 82 |
| 83 #define C_ADD( res, a,b)\ |
| 84 do {(res).r=ADD32((a).r,(b).r); (res).i=ADD32((a).i,(b).i); \ |
| 85 }while(0) |
| 86 #define C_SUB( res, a,b)\ |
| 87 do {(res).r=SUB32((a).r,(b).r); (res).i=SUB32((a).i,(b).i); \ |
| 88 }while(0) |
| 89 #define C_ADDTO( res , a)\ |
| 90 do {(res).r = ADD32((res).r, (a).r); (res).i = ADD32((res).i,(a).i);\ |
| 91 }while(0) |
| 92 |
| 93 #define C_SUBFROM( res , a)\ |
| 94 do {(res).r = ADD32((res).r,(a).r); (res).i = SUB32((res).i,(a).i); \ |
| 95 }while(0) |
| 96 |
| 97 #else /* not FIXED_POINT*/ |
| 98 |
| 99 # define S_MUL(a,b) ( (a)*(b) ) |
| 100 #define C_MUL(m,a,b) \ |
| 101 do{ (m).r = (a).r*(b).r - (a).i*(b).i;\ |
| 102 (m).i = (a).r*(b).i + (a).i*(b).r; }while(0) |
| 103 #define C_MULC(m,a,b) \ |
| 104 do{ (m).r = (a).r*(b).r + (a).i*(b).i;\ |
| 105 (m).i = (a).i*(b).r - (a).r*(b).i; }while(0) |
| 106 |
| 107 #define C_MUL4(m,a,b) C_MUL(m,a,b) |
| 108 |
| 109 # define C_FIXDIV(c,div) /* NOOP */ |
| 110 # define C_MULBYSCALAR( c, s ) \ |
| 111 do{ (c).r *= (s);\ |
| 112 (c).i *= (s); }while(0) |
| 113 #endif |
| 114 |
| 115 #ifndef CHECK_OVERFLOW_OP |
| 116 # define CHECK_OVERFLOW_OP(a,op,b) /* noop */ |
| 117 #endif |
| 118 |
| 119 #ifndef C_ADD |
| 120 #define C_ADD( res, a,b)\ |
| 121 do { \ |
| 122 CHECK_OVERFLOW_OP((a).r,+,(b).r)\ |
| 123 CHECK_OVERFLOW_OP((a).i,+,(b).i)\ |
| 124 (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \ |
| 125 }while(0) |
| 126 #define C_SUB( res, a,b)\ |
| 127 do { \ |
| 128 CHECK_OVERFLOW_OP((a).r,-,(b).r)\ |
| 129 CHECK_OVERFLOW_OP((a).i,-,(b).i)\ |
| 130 (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \ |
| 131 }while(0) |
| 132 #define C_ADDTO( res , a)\ |
| 133 do { \ |
| 134 CHECK_OVERFLOW_OP((res).r,+,(a).r)\ |
| 135 CHECK_OVERFLOW_OP((res).i,+,(a).i)\ |
| 136 (res).r += (a).r; (res).i += (a).i;\ |
| 137 }while(0) |
| 138 |
| 139 #define C_SUBFROM( res , a)\ |
| 140 do {\ |
| 141 CHECK_OVERFLOW_OP((res).r,-,(a).r)\ |
| 142 CHECK_OVERFLOW_OP((res).i,-,(a).i)\ |
| 143 (res).r -= (a).r; (res).i -= (a).i; \ |
| 144 }while(0) |
| 145 #endif /* C_ADD defined */ |
| 146 |
| 147 #ifdef FIXED_POINT |
| 148 /*# define KISS_FFT_COS(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+3276
8 * cos (phase)))) |
| 149 # define KISS_FFT_SIN(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768
* sin (phase))))*/ |
| 150 # define KISS_FFT_COS(phase) floor(.5+TWID_MAX*cos (phase)) |
| 151 # define KISS_FFT_SIN(phase) floor(.5+TWID_MAX*sin (phase)) |
| 152 # define HALF_OF(x) ((x)>>1) |
| 153 #elif defined(USE_SIMD) |
| 154 # define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) ) |
| 155 # define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) ) |
| 156 # define HALF_OF(x) ((x)*_mm_set1_ps(.5f)) |
| 157 #else |
| 158 # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) |
| 159 # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) |
| 160 # define HALF_OF(x) ((x)*.5f) |
| 161 #endif |
| 162 |
| 163 #define kf_cexp(x,phase) \ |
| 164 do{ \ |
| 165 (x)->r = KISS_FFT_COS(phase);\ |
| 166 (x)->i = KISS_FFT_SIN(phase);\ |
| 167 }while(0) |
| 168 |
| 169 #define kf_cexp2(x,phase) \ |
| 170 do{ \ |
| 171 (x)->r = TRIG_UPSCALE*celt_cos_norm((phase));\ |
| 172 (x)->i = TRIG_UPSCALE*celt_cos_norm((phase)-32768);\ |
| 173 }while(0) |
| 174 |
| 175 #endif /* KISS_FFT_GUTS_H */ |
| OLD | NEW |