1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/celt/_kiss_fft_guts.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,183 @@ 1.4 +/*Copyright (c) 2003-2004, Mark Borgerding 1.5 + 1.6 + All rights reserved. 1.7 + 1.8 + Redistribution and use in source and binary forms, with or without 1.9 + modification, are permitted provided that the following conditions are met: 1.10 + 1.11 + * Redistributions of source code must retain the above copyright notice, 1.12 + this list of conditions and the following disclaimer. 1.13 + * Redistributions in binary form must reproduce the above copyright notice, 1.14 + this list of conditions and the following disclaimer in the 1.15 + documentation and/or other materials provided with the distribution. 1.16 + 1.17 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.18 + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.19 + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.20 + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 1.21 + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.22 + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.23 + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.24 + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.25 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.26 + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.27 + POSSIBILITY OF SUCH DAMAGE.*/ 1.28 + 1.29 +#ifndef KISS_FFT_GUTS_H 1.30 +#define KISS_FFT_GUTS_H 1.31 + 1.32 +#define MIN(a,b) ((a)<(b) ? (a):(b)) 1.33 +#define MAX(a,b) ((a)>(b) ? (a):(b)) 1.34 + 1.35 +/* kiss_fft.h 1.36 + defines kiss_fft_scalar as either short or a float type 1.37 + and defines 1.38 + typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ 1.39 +#include "kiss_fft.h" 1.40 + 1.41 +/* 1.42 + Explanation of macros dealing with complex math: 1.43 + 1.44 + C_MUL(m,a,b) : m = a*b 1.45 + C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise 1.46 + C_SUB( res, a,b) : res = a - b 1.47 + C_SUBFROM( res , a) : res -= a 1.48 + C_ADDTO( res , a) : res += a 1.49 + * */ 1.50 +#ifdef FIXED_POINT 1.51 +#include "arch.h" 1.52 + 1.53 + 1.54 +#define SAMP_MAX 2147483647 1.55 +#define TWID_MAX 32767 1.56 +#define TRIG_UPSCALE 1 1.57 + 1.58 +#define SAMP_MIN -SAMP_MAX 1.59 + 1.60 + 1.61 +# define S_MUL(a,b) MULT16_32_Q15(b, a) 1.62 + 1.63 +# define C_MUL(m,a,b) \ 1.64 + do{ (m).r = SUB32(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ 1.65 + (m).i = ADD32(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)); }while(0) 1.66 + 1.67 +# define C_MULC(m,a,b) \ 1.68 + do{ (m).r = ADD32(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ 1.69 + (m).i = SUB32(S_MUL((a).i,(b).r) , S_MUL((a).r,(b).i)); }while(0) 1.70 + 1.71 +# define C_MUL4(m,a,b) \ 1.72 + do{ (m).r = SHR32(SUB32(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)),2); \ 1.73 + (m).i = SHR32(ADD32(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)),2); }while(0) 1.74 + 1.75 +# define C_MULBYSCALAR( c, s ) \ 1.76 + do{ (c).r = S_MUL( (c).r , s ) ;\ 1.77 + (c).i = S_MUL( (c).i , s ) ; }while(0) 1.78 + 1.79 +# define DIVSCALAR(x,k) \ 1.80 + (x) = S_MUL( x, (TWID_MAX-((k)>>1))/(k)+1 ) 1.81 + 1.82 +# define C_FIXDIV(c,div) \ 1.83 + do { DIVSCALAR( (c).r , div); \ 1.84 + DIVSCALAR( (c).i , div); }while (0) 1.85 + 1.86 +#define C_ADD( res, a,b)\ 1.87 + do {(res).r=ADD32((a).r,(b).r); (res).i=ADD32((a).i,(b).i); \ 1.88 + }while(0) 1.89 +#define C_SUB( res, a,b)\ 1.90 + do {(res).r=SUB32((a).r,(b).r); (res).i=SUB32((a).i,(b).i); \ 1.91 + }while(0) 1.92 +#define C_ADDTO( res , a)\ 1.93 + do {(res).r = ADD32((res).r, (a).r); (res).i = ADD32((res).i,(a).i);\ 1.94 + }while(0) 1.95 + 1.96 +#define C_SUBFROM( res , a)\ 1.97 + do {(res).r = ADD32((res).r,(a).r); (res).i = SUB32((res).i,(a).i); \ 1.98 + }while(0) 1.99 + 1.100 +#if defined(OPUS_ARM_INLINE_ASM) 1.101 +#include "arm/kiss_fft_armv4.h" 1.102 +#endif 1.103 + 1.104 +#if defined(OPUS_ARM_INLINE_EDSP) 1.105 +#include "arm/kiss_fft_armv5e.h" 1.106 +#endif 1.107 + 1.108 +#else /* not FIXED_POINT*/ 1.109 + 1.110 +# define S_MUL(a,b) ( (a)*(b) ) 1.111 +#define C_MUL(m,a,b) \ 1.112 + do{ (m).r = (a).r*(b).r - (a).i*(b).i;\ 1.113 + (m).i = (a).r*(b).i + (a).i*(b).r; }while(0) 1.114 +#define C_MULC(m,a,b) \ 1.115 + do{ (m).r = (a).r*(b).r + (a).i*(b).i;\ 1.116 + (m).i = (a).i*(b).r - (a).r*(b).i; }while(0) 1.117 + 1.118 +#define C_MUL4(m,a,b) C_MUL(m,a,b) 1.119 + 1.120 +# define C_FIXDIV(c,div) /* NOOP */ 1.121 +# define C_MULBYSCALAR( c, s ) \ 1.122 + do{ (c).r *= (s);\ 1.123 + (c).i *= (s); }while(0) 1.124 +#endif 1.125 + 1.126 +#ifndef CHECK_OVERFLOW_OP 1.127 +# define CHECK_OVERFLOW_OP(a,op,b) /* noop */ 1.128 +#endif 1.129 + 1.130 +#ifndef C_ADD 1.131 +#define C_ADD( res, a,b)\ 1.132 + do { \ 1.133 + CHECK_OVERFLOW_OP((a).r,+,(b).r)\ 1.134 + CHECK_OVERFLOW_OP((a).i,+,(b).i)\ 1.135 + (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \ 1.136 + }while(0) 1.137 +#define C_SUB( res, a,b)\ 1.138 + do { \ 1.139 + CHECK_OVERFLOW_OP((a).r,-,(b).r)\ 1.140 + CHECK_OVERFLOW_OP((a).i,-,(b).i)\ 1.141 + (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \ 1.142 + }while(0) 1.143 +#define C_ADDTO( res , a)\ 1.144 + do { \ 1.145 + CHECK_OVERFLOW_OP((res).r,+,(a).r)\ 1.146 + CHECK_OVERFLOW_OP((res).i,+,(a).i)\ 1.147 + (res).r += (a).r; (res).i += (a).i;\ 1.148 + }while(0) 1.149 + 1.150 +#define C_SUBFROM( res , a)\ 1.151 + do {\ 1.152 + CHECK_OVERFLOW_OP((res).r,-,(a).r)\ 1.153 + CHECK_OVERFLOW_OP((res).i,-,(a).i)\ 1.154 + (res).r -= (a).r; (res).i -= (a).i; \ 1.155 + }while(0) 1.156 +#endif /* C_ADD defined */ 1.157 + 1.158 +#ifdef FIXED_POINT 1.159 +/*# define KISS_FFT_COS(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * cos (phase)))) 1.160 +# define KISS_FFT_SIN(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * sin (phase))))*/ 1.161 +# define KISS_FFT_COS(phase) floor(.5+TWID_MAX*cos (phase)) 1.162 +# define KISS_FFT_SIN(phase) floor(.5+TWID_MAX*sin (phase)) 1.163 +# define HALF_OF(x) ((x)>>1) 1.164 +#elif defined(USE_SIMD) 1.165 +# define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) ) 1.166 +# define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) ) 1.167 +# define HALF_OF(x) ((x)*_mm_set1_ps(.5f)) 1.168 +#else 1.169 +# define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) 1.170 +# define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) 1.171 +# define HALF_OF(x) ((x)*.5f) 1.172 +#endif 1.173 + 1.174 +#define kf_cexp(x,phase) \ 1.175 + do{ \ 1.176 + (x)->r = KISS_FFT_COS(phase);\ 1.177 + (x)->i = KISS_FFT_SIN(phase);\ 1.178 + }while(0) 1.179 + 1.180 +#define kf_cexp2(x,phase) \ 1.181 + do{ \ 1.182 + (x)->r = TRIG_UPSCALE*celt_cos_norm((phase));\ 1.183 + (x)->i = TRIG_UPSCALE*celt_cos_norm((phase)-32768);\ 1.184 +}while(0) 1.185 + 1.186 +#endif /* KISS_FFT_GUTS_H */