Chris@69: /*Copyright (c) 2003-2004, Mark Borgerding Chris@69: Chris@69: All rights reserved. Chris@69: Chris@69: Redistribution and use in source and binary forms, with or without Chris@69: modification, are permitted provided that the following conditions are met: Chris@69: Chris@69: * Redistributions of source code must retain the above copyright notice, Chris@69: this list of conditions and the following disclaimer. Chris@69: * Redistributions in binary form must reproduce the above copyright notice, Chris@69: this list of conditions and the following disclaimer in the Chris@69: documentation and/or other materials provided with the distribution. Chris@69: Chris@69: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" Chris@69: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE Chris@69: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE Chris@69: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE Chris@69: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR Chris@69: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF Chris@69: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS Chris@69: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN Chris@69: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) Chris@69: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE Chris@69: POSSIBILITY OF SUCH DAMAGE.*/ Chris@69: Chris@69: #ifndef KISS_FFT_GUTS_H Chris@69: #define KISS_FFT_GUTS_H Chris@69: Chris@69: #define MIN(a,b) ((a)<(b) ? (a):(b)) Chris@69: #define MAX(a,b) ((a)>(b) ? (a):(b)) Chris@69: Chris@69: /* kiss_fft.h Chris@69: defines kiss_fft_scalar as either short or a float type Chris@69: and defines Chris@69: typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ Chris@69: #include "kiss_fft.h" Chris@69: Chris@69: /* Chris@69: Explanation of macros dealing with complex math: Chris@69: Chris@69: C_MUL(m,a,b) : m = a*b Chris@69: C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise Chris@69: C_SUB( res, a,b) : res = a - b Chris@69: C_SUBFROM( res , a) : res -= a Chris@69: C_ADDTO( res , a) : res += a Chris@69: * */ Chris@69: #ifdef FIXED_POINT Chris@69: #include "arch.h" Chris@69: Chris@69: Chris@69: #define SAMP_MAX 2147483647 Chris@69: #define TWID_MAX 32767 Chris@69: #define TRIG_UPSCALE 1 Chris@69: Chris@69: #define SAMP_MIN -SAMP_MAX Chris@69: Chris@69: Chris@69: # define S_MUL(a,b) MULT16_32_Q15(b, a) Chris@69: Chris@69: # define C_MUL(m,a,b) \ Chris@69: do{ (m).r = SUB32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ Chris@69: (m).i = ADD32_ovflw(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)); }while(0) Chris@69: Chris@69: # define C_MULC(m,a,b) \ Chris@69: do{ (m).r = ADD32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ Chris@69: (m).i = SUB32_ovflw(S_MUL((a).i,(b).r) , S_MUL((a).r,(b).i)); }while(0) Chris@69: Chris@69: # define C_MULBYSCALAR( c, s ) \ Chris@69: do{ (c).r = S_MUL( (c).r , s ) ;\ Chris@69: (c).i = S_MUL( (c).i , s ) ; }while(0) Chris@69: Chris@69: # define DIVSCALAR(x,k) \ Chris@69: (x) = S_MUL( x, (TWID_MAX-((k)>>1))/(k)+1 ) Chris@69: Chris@69: # define C_FIXDIV(c,div) \ Chris@69: do { DIVSCALAR( (c).r , div); \ Chris@69: DIVSCALAR( (c).i , div); }while (0) Chris@69: Chris@69: #define C_ADD( res, a,b)\ Chris@69: do {(res).r=ADD32_ovflw((a).r,(b).r); (res).i=ADD32_ovflw((a).i,(b).i); \ Chris@69: }while(0) Chris@69: #define C_SUB( res, a,b)\ Chris@69: do {(res).r=SUB32_ovflw((a).r,(b).r); (res).i=SUB32_ovflw((a).i,(b).i); \ Chris@69: }while(0) Chris@69: #define C_ADDTO( res , a)\ Chris@69: do {(res).r = ADD32_ovflw((res).r, (a).r); (res).i = ADD32_ovflw((res).i,(a).i);\ Chris@69: }while(0) Chris@69: Chris@69: #define C_SUBFROM( res , a)\ Chris@69: do {(res).r = ADD32_ovflw((res).r,(a).r); (res).i = SUB32_ovflw((res).i,(a).i); \ Chris@69: }while(0) Chris@69: Chris@69: #if defined(OPUS_ARM_INLINE_ASM) Chris@69: #include "arm/kiss_fft_armv4.h" Chris@69: #endif Chris@69: Chris@69: #if defined(OPUS_ARM_INLINE_EDSP) Chris@69: #include "arm/kiss_fft_armv5e.h" Chris@69: #endif Chris@69: #if defined(MIPSr1_ASM) Chris@69: #include "mips/kiss_fft_mipsr1.h" Chris@69: #endif Chris@69: Chris@69: #else /* not FIXED_POINT*/ Chris@69: Chris@69: # define S_MUL(a,b) ( (a)*(b) ) Chris@69: #define C_MUL(m,a,b) \ Chris@69: do{ (m).r = (a).r*(b).r - (a).i*(b).i;\ Chris@69: (m).i = (a).r*(b).i + (a).i*(b).r; }while(0) Chris@69: #define C_MULC(m,a,b) \ Chris@69: do{ (m).r = (a).r*(b).r + (a).i*(b).i;\ Chris@69: (m).i = (a).i*(b).r - (a).r*(b).i; }while(0) Chris@69: Chris@69: #define C_MUL4(m,a,b) C_MUL(m,a,b) Chris@69: Chris@69: # define C_FIXDIV(c,div) /* NOOP */ Chris@69: # define C_MULBYSCALAR( c, s ) \ Chris@69: do{ (c).r *= (s);\ Chris@69: (c).i *= (s); }while(0) Chris@69: #endif Chris@69: Chris@69: #ifndef CHECK_OVERFLOW_OP Chris@69: # define CHECK_OVERFLOW_OP(a,op,b) /* noop */ Chris@69: #endif Chris@69: Chris@69: #ifndef C_ADD Chris@69: #define C_ADD( res, a,b)\ Chris@69: do { \ Chris@69: CHECK_OVERFLOW_OP((a).r,+,(b).r)\ Chris@69: CHECK_OVERFLOW_OP((a).i,+,(b).i)\ Chris@69: (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \ Chris@69: }while(0) Chris@69: #define C_SUB( res, a,b)\ Chris@69: do { \ Chris@69: CHECK_OVERFLOW_OP((a).r,-,(b).r)\ Chris@69: CHECK_OVERFLOW_OP((a).i,-,(b).i)\ Chris@69: (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \ Chris@69: }while(0) Chris@69: #define C_ADDTO( res , a)\ Chris@69: do { \ Chris@69: CHECK_OVERFLOW_OP((res).r,+,(a).r)\ Chris@69: CHECK_OVERFLOW_OP((res).i,+,(a).i)\ Chris@69: (res).r += (a).r; (res).i += (a).i;\ Chris@69: }while(0) Chris@69: Chris@69: #define C_SUBFROM( res , a)\ Chris@69: do {\ Chris@69: CHECK_OVERFLOW_OP((res).r,-,(a).r)\ Chris@69: CHECK_OVERFLOW_OP((res).i,-,(a).i)\ Chris@69: (res).r -= (a).r; (res).i -= (a).i; \ Chris@69: }while(0) Chris@69: #endif /* C_ADD defined */ Chris@69: Chris@69: #ifdef FIXED_POINT Chris@69: /*# define KISS_FFT_COS(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * cos (phase)))) Chris@69: # define KISS_FFT_SIN(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * sin (phase))))*/ Chris@69: # define KISS_FFT_COS(phase) floor(.5+TWID_MAX*cos (phase)) Chris@69: # define KISS_FFT_SIN(phase) floor(.5+TWID_MAX*sin (phase)) Chris@69: # define HALF_OF(x) ((x)>>1) Chris@69: #elif defined(USE_SIMD) Chris@69: # define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) ) Chris@69: # define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) ) Chris@69: # define HALF_OF(x) ((x)*_mm_set1_ps(.5f)) Chris@69: #else Chris@69: # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) Chris@69: # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) Chris@69: # define HALF_OF(x) ((x)*.5f) Chris@69: #endif Chris@69: Chris@69: #define kf_cexp(x,phase) \ Chris@69: do{ \ Chris@69: (x)->r = KISS_FFT_COS(phase);\ Chris@69: (x)->i = KISS_FFT_SIN(phase);\ Chris@69: }while(0) Chris@69: Chris@69: #define kf_cexp2(x,phase) \ Chris@69: do{ \ Chris@69: (x)->r = TRIG_UPSCALE*celt_cos_norm((phase));\ Chris@69: (x)->i = TRIG_UPSCALE*celt_cos_norm((phase)-32768);\ Chris@69: }while(0) Chris@69: Chris@69: #endif /* KISS_FFT_GUTS_H */