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