annotate src/opus-1.3/celt/_kiss_fft_guts.h @ 77:4edcd14160a5 pa_catalina

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