Smart Remote 3 nRF52 v1.2
_kiss_fft_guts.h
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 /* kiss_fft.h
30  defines kiss_fft_scalar as either short or a float type
31  and defines
32  typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
33 #include "kiss_fft.h"
34 
35 /*
36  Explanation of macros dealing with complex math:
37 
38  C_MUL(m,a,b) : m = a*b
39  C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise
40  C_SUB( res, a,b) : res = a - b
41  C_SUBFROM( res , a) : res -= a
42  C_ADDTO( res , a) : res += a
43  * */
44 #ifdef FIXED_POINT
45 #include "arch.h"
46 
47 
48 #define SAMP_MAX 2147483647
49 #define TWID_MAX 32767
50 #define TRIG_UPSCALE 1
51 
52 #define SAMP_MIN -SAMP_MAX
53 
54 
55 # define S_MUL(a,b) MULT16_32_Q15(b, a)
56 
57 # define C_MUL(m,a,b) \
58  do{ (m).r = SUB32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \
59  (m).i = ADD32_ovflw(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)); }while(0)
60 
61 # define C_MULC(m,a,b) \
62  do{ (m).r = ADD32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \
63  (m).i = SUB32_ovflw(S_MUL((a).i,(b).r) , S_MUL((a).r,(b).i)); }while(0)
64 
65 # define C_MULBYSCALAR( c, s ) \
66  do{ (c).r = S_MUL( (c).r , s ) ;\
67  (c).i = S_MUL( (c).i , s ) ; }while(0)
68 
69 # define DIVSCALAR(x,k) \
70  (x) = S_MUL( x, (TWID_MAX-((k)>>1))/(k)+1 )
71 
72 # define C_FIXDIV(c,div) \
73  do { DIVSCALAR( (c).r , div); \
74  DIVSCALAR( (c).i , div); }while (0)
75 
76 #define C_ADD( res, a,b)\
77  do {(res).r=ADD32_ovflw((a).r,(b).r); (res).i=ADD32_ovflw((a).i,(b).i); \
78  }while(0)
79 #define C_SUB( res, a,b)\
80  do {(res).r=SUB32_ovflw((a).r,(b).r); (res).i=SUB32_ovflw((a).i,(b).i); \
81  }while(0)
82 #define C_ADDTO( res , a)\
83  do {(res).r = ADD32_ovflw((res).r, (a).r); (res).i = ADD32_ovflw((res).i,(a).i);\
84  }while(0)
85 
86 #define C_SUBFROM( res , a)\
87  do {(res).r = ADD32_ovflw((res).r,(a).r); (res).i = SUB32_ovflw((res).i,(a).i); \
88  }while(0)
89 
90 #if defined(OPUS_ARM_INLINE_ASM)
91 #include "arm/kiss_fft_armv4.h"
92 #endif
93 
94 #if defined(OPUS_ARM_INLINE_EDSP)
95 #include "arm/kiss_fft_armv5e.h"
96 #endif
97 #if defined(MIPSr1_ASM)
98 #include "mips/kiss_fft_mipsr1.h"
99 #endif
100 
101 #else /* not FIXED_POINT*/
102 
103 # define S_MUL(a,b) ( (a)*(b) )
104 #define C_MUL(m,a,b) \
105  do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
106  (m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
107 #define C_MULC(m,a,b) \
108  do{ (m).r = (a).r*(b).r + (a).i*(b).i;\
109  (m).i = (a).i*(b).r - (a).r*(b).i; }while(0)
110 
111 #define C_MUL4(m,a,b) C_MUL(m,a,b)
112 
113 # define C_FIXDIV(c,div) /* NOOP */
114 # define C_MULBYSCALAR( c, s ) \
115  do{ (c).r *= (s);\
116  (c).i *= (s); }while(0)
117 #endif
118 
119 #ifndef CHECK_OVERFLOW_OP
120 # define CHECK_OVERFLOW_OP(a,op,b) /* noop */
121 #endif
122 
123 #ifndef C_ADD
124 #define C_ADD( res, a,b)\
125  do { \
126  CHECK_OVERFLOW_OP((a).r,+,(b).r)\
127  CHECK_OVERFLOW_OP((a).i,+,(b).i)\
128  (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
129  }while(0)
130 #define C_SUB( res, a,b)\
131  do { \
132  CHECK_OVERFLOW_OP((a).r,-,(b).r)\
133  CHECK_OVERFLOW_OP((a).i,-,(b).i)\
134  (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
135  }while(0)
136 #define C_ADDTO( res , a)\
137  do { \
138  CHECK_OVERFLOW_OP((res).r,+,(a).r)\
139  CHECK_OVERFLOW_OP((res).i,+,(a).i)\
140  (res).r += (a).r; (res).i += (a).i;\
141  }while(0)
142 
143 #define C_SUBFROM( res , a)\
144  do {\
145  CHECK_OVERFLOW_OP((res).r,-,(a).r)\
146  CHECK_OVERFLOW_OP((res).i,-,(a).i)\
147  (res).r -= (a).r; (res).i -= (a).i; \
148  }while(0)
149 #endif /* C_ADD defined */
150 
151 #ifdef FIXED_POINT
152 /*# define KISS_FFT_COS(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * cos (phase))))
153 # define KISS_FFT_SIN(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * sin (phase))))*/
154 # define KISS_FFT_COS(phase) floor(.5+TWID_MAX*cos (phase))
155 # define KISS_FFT_SIN(phase) floor(.5+TWID_MAX*sin (phase))
156 # define HALF_OF(x) ((x)>>1)
157 #elif defined(USE_SIMD)
158 # define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) )
159 # define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) )
160 # define HALF_OF(x) ((x)*_mm_set1_ps(.5f))
161 #else
162 # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase)
163 # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase)
164 # define HALF_OF(x) ((x)*.5f)
165 #endif
166 
167 #define kf_cexp(x,phase) \
168  do{ \
169  (x)->r = KISS_FFT_COS(phase);\
170  (x)->i = KISS_FFT_SIN(phase);\
171  }while(0)
172 
173 #define kf_cexp2(x,phase) \
174  do{ \
175  (x)->r = TRIG_UPSCALE*celt_cos_norm((phase));\
176  (x)->i = TRIG_UPSCALE*celt_cos_norm((phase)-32768);\
177 }while(0)
178 
179 #endif /* KISS_FFT_GUTS_H */

Documentation feedback | Developer Zone | Subscribe | Updated