/src/speex/libspeex/math_approx.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2002 Jean-Marc Valin */ |
2 | | /** |
3 | | @file math_approx.h |
4 | | @brief Various math approximation functions for Speex |
5 | | */ |
6 | | /* |
7 | | Redistribution and use in source and binary forms, with or without |
8 | | modification, are permitted provided that the following conditions |
9 | | are met: |
10 | | |
11 | | - Redistributions of source code must retain the above copyright |
12 | | notice, this list of conditions and the following disclaimer. |
13 | | |
14 | | - Redistributions in binary form must reproduce the above copyright |
15 | | notice, this list of conditions and the following disclaimer in the |
16 | | documentation and/or other materials provided with the distribution. |
17 | | |
18 | | - Neither the name of the Xiph.org Foundation nor the names of its |
19 | | contributors may be used to endorse or promote products derived from |
20 | | this software without specific prior written permission. |
21 | | |
22 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
23 | | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
24 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
25 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
26 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
27 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
28 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
29 | | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
30 | | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
31 | | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
32 | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | | */ |
34 | | |
35 | | #ifndef MATH_APPROX_H |
36 | | #define MATH_APPROX_H |
37 | | |
38 | | #include "arch.h" |
39 | | |
40 | | #ifndef FIXED_POINT |
41 | | |
42 | 58.3k | #define spx_sqrt sqrt |
43 | | #define spx_acos acos |
44 | 5.90k | #define spx_exp exp |
45 | | #define spx_cos_norm(x) (cos((.5f*M_PI)*(x))) |
46 | | #define spx_atan atan |
47 | | |
48 | | /** Generate a pseudo-random number */ |
49 | | static inline spx_word16_t speex_rand(spx_word16_t std, spx_uint32_t *seed) |
50 | 4.60M | { |
51 | 4.60M | const unsigned int jflone = 0x3f800000; |
52 | 4.60M | const unsigned int jflmsk = 0x007fffff; |
53 | 4.60M | union {int i; float f;} ran; |
54 | 4.60M | *seed = 1664525 * *seed + 1013904223; |
55 | 4.60M | ran.i = jflone | (jflmsk & *seed); |
56 | 4.60M | ran.f -= 1.5; |
57 | 4.60M | return 3.4642*std*ran.f; |
58 | 4.60M | } Unexecuted instantiation: stereo.c:speex_rand Line | Count | Source | 50 | 3.60M | { | 51 | 3.60M | const unsigned int jflone = 0x3f800000; | 52 | 3.60M | const unsigned int jflmsk = 0x007fffff; | 53 | 3.60M | union {int i; float f;} ran; | 54 | 3.60M | *seed = 1664525 * *seed + 1013904223; | 55 | 3.60M | ran.i = jflone | (jflmsk & *seed); | 56 | 3.60M | ran.f -= 1.5; | 57 | 3.60M | return 3.4642*std*ran.f; | 58 | 3.60M | } |
Line | Count | Source | 50 | 382k | { | 51 | 382k | const unsigned int jflone = 0x3f800000; | 52 | 382k | const unsigned int jflmsk = 0x007fffff; | 53 | 382k | union {int i; float f;} ran; | 54 | 382k | *seed = 1664525 * *seed + 1013904223; | 55 | 382k | ran.i = jflone | (jflmsk & *seed); | 56 | 382k | ran.f -= 1.5; | 57 | 382k | return 3.4642*std*ran.f; | 58 | 382k | } |
Line | Count | Source | 50 | 611k | { | 51 | 611k | const unsigned int jflone = 0x3f800000; | 52 | 611k | const unsigned int jflmsk = 0x007fffff; | 53 | 611k | union {int i; float f;} ran; | 54 | 611k | *seed = 1664525 * *seed + 1013904223; | 55 | 611k | ran.i = jflone | (jflmsk & *seed); | 56 | 611k | ran.f -= 1.5; | 57 | 611k | return 3.4642*std*ran.f; | 58 | 611k | } |
Unexecuted instantiation: filters.c:speex_rand Unexecuted instantiation: lsp.c:speex_rand Unexecuted instantiation: ltp.c:speex_rand |
59 | | |
60 | | |
61 | | #endif |
62 | | |
63 | | |
64 | | static inline spx_int16_t spx_ilog2(spx_uint32_t x) |
65 | 6.83k | { |
66 | 6.83k | int r=0; |
67 | 6.83k | if (x>=(spx_int32_t)65536) |
68 | 1.98k | { |
69 | 1.98k | x >>= 16; |
70 | 1.98k | r += 16; |
71 | 1.98k | } |
72 | 6.83k | if (x>=256) |
73 | 1.91k | { |
74 | 1.91k | x >>= 8; |
75 | 1.91k | r += 8; |
76 | 1.91k | } |
77 | 6.83k | if (x>=16) |
78 | 1.57k | { |
79 | 1.57k | x >>= 4; |
80 | 1.57k | r += 4; |
81 | 1.57k | } |
82 | 6.83k | if (x>=4) |
83 | 1.62k | { |
84 | 1.62k | x >>= 2; |
85 | 1.62k | r += 2; |
86 | 1.62k | } |
87 | 6.83k | if (x>=2) |
88 | 1.75k | { |
89 | 1.75k | r += 1; |
90 | 1.75k | } |
91 | 6.83k | return r; |
92 | 6.83k | } Unexecuted instantiation: nb_celp.c:spx_ilog2 Unexecuted instantiation: sb_celp.c:spx_ilog2 Unexecuted instantiation: cb_search.c:spx_ilog2 Unexecuted instantiation: filters.c:spx_ilog2 Unexecuted instantiation: lsp.c:spx_ilog2 Unexecuted instantiation: ltp.c:spx_ilog2 Line | Count | Source | 65 | 6.83k | { | 66 | 6.83k | int r=0; | 67 | 6.83k | if (x>=(spx_int32_t)65536) | 68 | 1.98k | { | 69 | 1.98k | x >>= 16; | 70 | 1.98k | r += 16; | 71 | 1.98k | } | 72 | 6.83k | if (x>=256) | 73 | 1.91k | { | 74 | 1.91k | x >>= 8; | 75 | 1.91k | r += 8; | 76 | 1.91k | } | 77 | 6.83k | if (x>=16) | 78 | 1.57k | { | 79 | 1.57k | x >>= 4; | 80 | 1.57k | r += 4; | 81 | 1.57k | } | 82 | 6.83k | if (x>=4) | 83 | 1.62k | { | 84 | 1.62k | x >>= 2; | 85 | 1.62k | r += 2; | 86 | 1.62k | } | 87 | 6.83k | if (x>=2) | 88 | 1.75k | { | 89 | 1.75k | r += 1; | 90 | 1.75k | } | 91 | 6.83k | return r; | 92 | 6.83k | } |
|
93 | | |
94 | | static inline spx_int16_t spx_ilog4(spx_uint32_t x) |
95 | 839k | { |
96 | 839k | int r=0; |
97 | 839k | if (x>=(spx_int32_t)65536) |
98 | 502k | { |
99 | 502k | x >>= 16; |
100 | 502k | r += 8; |
101 | 502k | } |
102 | 839k | if (x>=256) |
103 | 386k | { |
104 | 386k | x >>= 8; |
105 | 386k | r += 4; |
106 | 386k | } |
107 | 839k | if (x>=16) |
108 | 228k | { |
109 | 228k | x >>= 4; |
110 | 228k | r += 2; |
111 | 228k | } |
112 | 839k | if (x>=4) |
113 | 353k | { |
114 | 353k | r += 1; |
115 | 353k | } |
116 | 839k | return r; |
117 | 839k | } Unexecuted instantiation: cb_search.c:spx_ilog4 Line | Count | Source | 95 | 13.4k | { | 96 | 13.4k | int r=0; | 97 | 13.4k | if (x>=(spx_int32_t)65536) | 98 | 11.7k | { | 99 | 11.7k | x >>= 16; | 100 | 11.7k | r += 8; | 101 | 11.7k | } | 102 | 13.4k | if (x>=256) | 103 | 1.85k | { | 104 | 1.85k | x >>= 8; | 105 | 1.85k | r += 4; | 106 | 1.85k | } | 107 | 13.4k | if (x>=16) | 108 | 1.53k | { | 109 | 1.53k | x >>= 4; | 110 | 1.53k | r += 2; | 111 | 1.53k | } | 112 | 13.4k | if (x>=4) | 113 | 1.91k | { | 114 | 1.91k | r += 1; | 115 | 1.91k | } | 116 | 13.4k | return r; | 117 | 13.4k | } |
Line | Count | Source | 95 | 17.4k | { | 96 | 17.4k | int r=0; | 97 | 17.4k | if (x>=(spx_int32_t)65536) | 98 | 9.01k | { | 99 | 9.01k | x >>= 16; | 100 | 9.01k | r += 8; | 101 | 9.01k | } | 102 | 17.4k | if (x>=256) | 103 | 9.54k | { | 104 | 9.54k | x >>= 8; | 105 | 9.54k | r += 4; | 106 | 9.54k | } | 107 | 17.4k | if (x>=16) | 108 | 13.0k | { | 109 | 13.0k | x >>= 4; | 110 | 13.0k | r += 2; | 111 | 13.0k | } | 112 | 17.4k | if (x>=4) | 113 | 5.68k | { | 114 | 5.68k | r += 1; | 115 | 5.68k | } | 116 | 17.4k | return r; | 117 | 17.4k | } |
Line | Count | Source | 95 | 3.78k | { | 96 | 3.78k | int r=0; | 97 | 3.78k | if (x>=(spx_int32_t)65536) | 98 | 810 | { | 99 | 810 | x >>= 16; | 100 | 810 | r += 8; | 101 | 810 | } | 102 | 3.78k | if (x>=256) | 103 | 731 | { | 104 | 731 | x >>= 8; | 105 | 731 | r += 4; | 106 | 731 | } | 107 | 3.78k | if (x>=16) | 108 | 599 | { | 109 | 599 | x >>= 4; | 110 | 599 | r += 2; | 111 | 599 | } | 112 | 3.78k | if (x>=4) | 113 | 937 | { | 114 | 937 | r += 1; | 115 | 937 | } | 116 | 3.78k | return r; | 117 | 3.78k | } |
Line | Count | Source | 95 | 330k | { | 96 | 330k | int r=0; | 97 | 330k | if (x>=(spx_int32_t)65536) | 98 | 114k | { | 99 | 114k | x >>= 16; | 100 | 114k | r += 8; | 101 | 114k | } | 102 | 330k | if (x>=256) | 103 | 97.0k | { | 104 | 97.0k | x >>= 8; | 105 | 97.0k | r += 4; | 106 | 97.0k | } | 107 | 330k | if (x>=16) | 108 | 71.3k | { | 109 | 71.3k | x >>= 4; | 110 | 71.3k | r += 2; | 111 | 71.3k | } | 112 | 330k | if (x>=4) | 113 | 100k | { | 114 | 100k | r += 1; | 115 | 100k | } | 116 | 330k | return r; | 117 | 330k | } |
Line | Count | Source | 95 | 254k | { | 96 | 254k | int r=0; | 97 | 254k | if (x>=(spx_int32_t)65536) | 98 | 254k | { | 99 | 254k | x >>= 16; | 100 | 254k | r += 8; | 101 | 254k | } | 102 | 254k | if (x>=256) | 103 | 196k | { | 104 | 196k | x >>= 8; | 105 | 196k | r += 4; | 106 | 196k | } | 107 | 254k | if (x>=16) | 108 | 55.7k | { | 109 | 55.7k | x >>= 4; | 110 | 55.7k | r += 2; | 111 | 55.7k | } | 112 | 254k | if (x>=4) | 113 | 156k | { | 114 | 156k | r += 1; | 115 | 156k | } | 116 | 254k | return r; | 117 | 254k | } |
Line | Count | Source | 95 | 220k | { | 96 | 220k | int r=0; | 97 | 220k | if (x>=(spx_int32_t)65536) | 98 | 112k | { | 99 | 112k | x >>= 16; | 100 | 112k | r += 8; | 101 | 112k | } | 102 | 220k | if (x>=256) | 103 | 80.7k | { | 104 | 80.7k | x >>= 8; | 105 | 80.7k | r += 4; | 106 | 80.7k | } | 107 | 220k | if (x>=16) | 108 | 86.2k | { | 109 | 86.2k | x >>= 4; | 110 | 86.2k | r += 2; | 111 | 86.2k | } | 112 | 220k | if (x>=4) | 113 | 87.2k | { | 114 | 87.2k | r += 1; | 115 | 87.2k | } | 116 | 220k | return r; | 117 | 220k | } |
|
118 | | |
119 | | #ifdef FIXED_POINT |
120 | | |
121 | | /** Generate a pseudo-random number */ |
122 | | static inline spx_word16_t speex_rand(spx_word16_t std, spx_uint32_t *seed) |
123 | 4.60M | { |
124 | 4.60M | spx_word32_t res; |
125 | 4.60M | *seed = 1664525 * *seed + 1013904223; |
126 | 4.60M | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); |
127 | 4.60M | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); |
128 | 4.60M | } Line | Count | Source | 123 | 3.60M | { | 124 | 3.60M | spx_word32_t res; | 125 | 3.60M | *seed = 1664525 * *seed + 1013904223; | 126 | 3.60M | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); | 127 | 3.60M | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); | 128 | 3.60M | } |
Line | Count | Source | 123 | 382k | { | 124 | 382k | spx_word32_t res; | 125 | 382k | *seed = 1664525 * *seed + 1013904223; | 126 | 382k | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); | 127 | 382k | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); | 128 | 382k | } |
Line | Count | Source | 123 | 611k | { | 124 | 611k | spx_word32_t res; | 125 | 611k | *seed = 1664525 * *seed + 1013904223; | 126 | 611k | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); | 127 | 611k | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); | 128 | 611k | } |
|
129 | | |
130 | | /* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25723*x^3 (for .25 < x < 1) */ |
131 | | /*#define C0 3634 |
132 | | #define C1 21173 |
133 | | #define C2 -12627 |
134 | | #define C3 4215*/ |
135 | | |
136 | | /* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25659*x^3 (for .25 < x < 1) */ |
137 | | #define C0 3634 |
138 | | #define C1 21173 |
139 | | #define C2 -12627 |
140 | | #define C3 4204 |
141 | | |
142 | | static inline spx_word16_t spx_sqrt(spx_word32_t x) |
143 | 839k | { |
144 | 839k | int k; |
145 | 839k | spx_word32_t rt; |
146 | 839k | k = spx_ilog4(x)-6; |
147 | 839k | x = VSHR32(x, (int)((unsigned)k<<1)); |
148 | 839k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); |
149 | 839k | rt = VSHR32(rt,7-k); |
150 | 839k | return rt; |
151 | 839k | } Line | Count | Source | 143 | 13.4k | { | 144 | 13.4k | int k; | 145 | 13.4k | spx_word32_t rt; | 146 | 13.4k | k = spx_ilog4(x)-6; | 147 | 13.4k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 13.4k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 13.4k | rt = VSHR32(rt,7-k); | 150 | 13.4k | return rt; | 151 | 13.4k | } |
Line | Count | Source | 143 | 17.4k | { | 144 | 17.4k | int k; | 145 | 17.4k | spx_word32_t rt; | 146 | 17.4k | k = spx_ilog4(x)-6; | 147 | 17.4k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 17.4k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 17.4k | rt = VSHR32(rt,7-k); | 150 | 17.4k | return rt; | 151 | 17.4k | } |
Line | Count | Source | 143 | 3.78k | { | 144 | 3.78k | int k; | 145 | 3.78k | spx_word32_t rt; | 146 | 3.78k | k = spx_ilog4(x)-6; | 147 | 3.78k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 3.78k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 3.78k | rt = VSHR32(rt,7-k); | 150 | 3.78k | return rt; | 151 | 3.78k | } |
Unexecuted instantiation: cb_search.c:spx_sqrt Line | Count | Source | 143 | 330k | { | 144 | 330k | int k; | 145 | 330k | spx_word32_t rt; | 146 | 330k | k = spx_ilog4(x)-6; | 147 | 330k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 330k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 330k | rt = VSHR32(rt,7-k); | 150 | 330k | return rt; | 151 | 330k | } |
Line | Count | Source | 143 | 254k | { | 144 | 254k | int k; | 145 | 254k | spx_word32_t rt; | 146 | 254k | k = spx_ilog4(x)-6; | 147 | 254k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 254k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 254k | rt = VSHR32(rt,7-k); | 150 | 254k | return rt; | 151 | 254k | } |
Line | Count | Source | 143 | 220k | { | 144 | 220k | int k; | 145 | 220k | spx_word32_t rt; | 146 | 220k | k = spx_ilog4(x)-6; | 147 | 220k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 220k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 220k | rt = VSHR32(rt,7-k); | 150 | 220k | return rt; | 151 | 220k | } |
|
152 | | |
153 | | /* log(x) ~= -2.18151 + 4.20592*x - 2.88938*x^2 + 0.86535*x^3 (for .5 < x < 1) */ |
154 | | |
155 | | |
156 | | #define A1 16469 |
157 | | #define A2 2242 |
158 | | #define A3 1486 |
159 | | |
160 | | static inline spx_word16_t spx_acos(spx_word16_t x) |
161 | 254k | { |
162 | 254k | int s=0; |
163 | 254k | spx_word16_t ret; |
164 | 254k | spx_word16_t sq; |
165 | 254k | if (x<0) |
166 | 127k | { |
167 | 127k | s=1; |
168 | 127k | x = NEG16(x); |
169 | 127k | } |
170 | 254k | x = SUB16(16384,x); |
171 | | |
172 | 254k | x = x >> 1; |
173 | 254k | sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3)))))); |
174 | 254k | ret = spx_sqrt(SHL32(EXTEND32(sq),13)); |
175 | | |
176 | | /*ret = spx_sqrt(67108864*(-1.6129e-04 + 2.0104e+00*f + 2.7373e-01*f*f + 1.8136e-01*f*f*f));*/ |
177 | 254k | if (s) |
178 | 127k | ret = SUB16(25736,ret); |
179 | 254k | return ret; |
180 | 254k | } Unexecuted instantiation: stereo.c:spx_acos Unexecuted instantiation: nb_celp.c:spx_acos Unexecuted instantiation: sb_celp.c:spx_acos Unexecuted instantiation: cb_search.c:spx_acos Unexecuted instantiation: filters.c:spx_acos Line | Count | Source | 161 | 254k | { | 162 | 254k | int s=0; | 163 | 254k | spx_word16_t ret; | 164 | 254k | spx_word16_t sq; | 165 | 254k | if (x<0) | 166 | 127k | { | 167 | 127k | s=1; | 168 | 127k | x = NEG16(x); | 169 | 127k | } | 170 | 254k | x = SUB16(16384,x); | 171 | | | 172 | 254k | x = x >> 1; | 173 | 254k | sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3)))))); | 174 | 254k | ret = spx_sqrt(SHL32(EXTEND32(sq),13)); | 175 | | | 176 | | /*ret = spx_sqrt(67108864*(-1.6129e-04 + 2.0104e+00*f + 2.7373e-01*f*f + 1.8136e-01*f*f*f));*/ | 177 | 254k | if (s) | 178 | 127k | ret = SUB16(25736,ret); | 179 | 254k | return ret; | 180 | 254k | } |
Unexecuted instantiation: ltp.c:spx_acos |
181 | | |
182 | | |
183 | | #define K1 8192 |
184 | | #define K2 -4096 |
185 | | #define K3 340 |
186 | | #define K4 -10 |
187 | | |
188 | | static inline spx_word16_t spx_cos(spx_word16_t x) |
189 | 4.16M | { |
190 | 4.16M | spx_word16_t x2; |
191 | | |
192 | 4.16M | if (x<12868) |
193 | 2.09M | { |
194 | 2.09M | x2 = MULT16_16_P13(x,x); |
195 | 2.09M | return ADD32(K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2)))))); |
196 | 2.09M | } else { |
197 | 2.07M | x = SUB16(25736,x); |
198 | 2.07M | x2 = MULT16_16_P13(x,x); |
199 | 2.07M | return SUB32(-K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2)))))); |
200 | 2.07M | } |
201 | 4.16M | } |
202 | | |
203 | | #define L1 32767 |
204 | | #define L2 -7651 |
205 | | #define L3 8277 |
206 | | #define L4 -626 |
207 | | |
208 | | static inline spx_word16_t _spx_cos_pi_2(spx_word16_t x) |
209 | 0 | { |
210 | 0 | spx_word16_t x2; |
211 | 0 |
|
212 | 0 | x2 = MULT16_16_P15(x,x); |
213 | 0 | return ADD16(1,MIN16(32766,ADD32(SUB16(L1,x2), MULT16_16_P15(x2, ADD32(L2, MULT16_16_P15(x2, ADD32(L3, MULT16_16_P15(L4, x2)))))))); |
214 | 0 | } Unexecuted instantiation: stereo.c:_spx_cos_pi_2 Unexecuted instantiation: nb_celp.c:_spx_cos_pi_2 Unexecuted instantiation: sb_celp.c:_spx_cos_pi_2 Unexecuted instantiation: cb_search.c:_spx_cos_pi_2 Unexecuted instantiation: filters.c:_spx_cos_pi_2 Unexecuted instantiation: lsp.c:_spx_cos_pi_2 Unexecuted instantiation: ltp.c:_spx_cos_pi_2 |
215 | | |
216 | | static inline spx_word16_t spx_cos_norm(spx_word32_t x) |
217 | 0 | { |
218 | 0 | x = x&0x0001ffff; |
219 | 0 | if (x>SHL32(EXTEND32(1), 16)) |
220 | 0 | x = SUB32(SHL32(EXTEND32(1), 17),x); |
221 | 0 | if (x&0x00007fff) |
222 | 0 | { |
223 | 0 | if (x<SHL32(EXTEND32(1), 15)) |
224 | 0 | { |
225 | 0 | return _spx_cos_pi_2(EXTRACT16(x)); |
226 | 0 | } else { |
227 | 0 | return NEG32(_spx_cos_pi_2(EXTRACT16(65536-x))); |
228 | 0 | } |
229 | 0 | } else { |
230 | 0 | if (x&0x0000ffff) |
231 | 0 | return 0; |
232 | 0 | else if (x&0x0001ffff) |
233 | 0 | return -32767; |
234 | 0 | else |
235 | 0 | return 32767; |
236 | 0 | } |
237 | 0 | } Unexecuted instantiation: stereo.c:spx_cos_norm Unexecuted instantiation: nb_celp.c:spx_cos_norm Unexecuted instantiation: sb_celp.c:spx_cos_norm Unexecuted instantiation: cb_search.c:spx_cos_norm Unexecuted instantiation: filters.c:spx_cos_norm Unexecuted instantiation: lsp.c:spx_cos_norm Unexecuted instantiation: ltp.c:spx_cos_norm |
238 | | |
239 | | /* |
240 | | K0 = 1 |
241 | | K1 = log(2) |
242 | | K2 = 3-4*log(2) |
243 | | K3 = 3*log(2) - 2 |
244 | | */ |
245 | | #define D0 16384 |
246 | | #define D1 11356 |
247 | | #define D2 3726 |
248 | | #define D3 1301 |
249 | | /* Input in Q11 format, output in Q16 */ |
250 | | static inline spx_word32_t spx_exp2(spx_word16_t x) |
251 | 5.63k | { |
252 | 5.63k | int integer; |
253 | 5.63k | spx_word16_t frac; |
254 | 5.63k | integer = SHR16(x,11); |
255 | 5.63k | if (integer>14) |
256 | 0 | return 0x7fffffff; |
257 | 5.63k | else if (integer < -15) |
258 | 0 | return 0; |
259 | 5.63k | frac = SHL16(x-SHL16(integer,11),3); |
260 | 5.63k | frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac)))))); |
261 | 5.63k | return VSHR32(EXTEND32(frac), -integer-2); |
262 | 5.63k | } Line | Count | Source | 251 | 542 | { | 252 | 542 | int integer; | 253 | 542 | spx_word16_t frac; | 254 | 542 | integer = SHR16(x,11); | 255 | 542 | if (integer>14) | 256 | 0 | return 0x7fffffff; | 257 | 542 | else if (integer < -15) | 258 | 0 | return 0; | 259 | 542 | frac = SHL16(x-SHL16(integer,11),3); | 260 | 542 | frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac)))))); | 261 | 542 | return VSHR32(EXTEND32(frac), -integer-2); | 262 | 542 | } |
Unexecuted instantiation: nb_celp.c:spx_exp2 Line | Count | Source | 251 | 5.09k | { | 252 | 5.09k | int integer; | 253 | 5.09k | spx_word16_t frac; | 254 | 5.09k | integer = SHR16(x,11); | 255 | 5.09k | if (integer>14) | 256 | 0 | return 0x7fffffff; | 257 | 5.09k | else if (integer < -15) | 258 | 0 | return 0; | 259 | 5.09k | frac = SHL16(x-SHL16(integer,11),3); | 260 | 5.09k | frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac)))))); | 261 | 5.09k | return VSHR32(EXTEND32(frac), -integer-2); | 262 | 5.09k | } |
Unexecuted instantiation: cb_search.c:spx_exp2 Unexecuted instantiation: filters.c:spx_exp2 Unexecuted instantiation: lsp.c:spx_exp2 Unexecuted instantiation: ltp.c:spx_exp2 |
263 | | |
264 | | /* Input in Q11 format, output in Q16 */ |
265 | | static inline spx_word32_t spx_exp(spx_word16_t x) |
266 | 5.63k | { |
267 | 5.63k | if (x>21290) |
268 | 0 | return 0x7fffffff; |
269 | 5.63k | else if (x<-21290) |
270 | 0 | return 0; |
271 | 5.63k | else |
272 | 5.63k | return spx_exp2(MULT16_16_P14(23637,x)); |
273 | 5.63k | } Line | Count | Source | 266 | 542 | { | 267 | 542 | if (x>21290) | 268 | 0 | return 0x7fffffff; | 269 | 542 | else if (x<-21290) | 270 | 0 | return 0; | 271 | 542 | else | 272 | 542 | return spx_exp2(MULT16_16_P14(23637,x)); | 273 | 542 | } |
Unexecuted instantiation: nb_celp.c:spx_exp Line | Count | Source | 266 | 5.09k | { | 267 | 5.09k | if (x>21290) | 268 | 0 | return 0x7fffffff; | 269 | 5.09k | else if (x<-21290) | 270 | 0 | return 0; | 271 | 5.09k | else | 272 | 5.09k | return spx_exp2(MULT16_16_P14(23637,x)); | 273 | 5.09k | } |
Unexecuted instantiation: cb_search.c:spx_exp Unexecuted instantiation: filters.c:spx_exp Unexecuted instantiation: lsp.c:spx_exp Unexecuted instantiation: ltp.c:spx_exp |
274 | | #define M1 32767 |
275 | | #define M2 -21 |
276 | | #define M3 -11943 |
277 | | #define M4 4936 |
278 | | |
279 | | static inline spx_word16_t spx_atan01(spx_word16_t x) |
280 | 0 | { |
281 | 0 | return MULT16_16_P15(x, ADD32(M1, MULT16_16_P15(x, ADD32(M2, MULT16_16_P15(x, ADD32(M3, MULT16_16_P15(M4, x))))))); |
282 | 0 | } Unexecuted instantiation: stereo.c:spx_atan01 Unexecuted instantiation: nb_celp.c:spx_atan01 Unexecuted instantiation: sb_celp.c:spx_atan01 Unexecuted instantiation: cb_search.c:spx_atan01 Unexecuted instantiation: filters.c:spx_atan01 Unexecuted instantiation: lsp.c:spx_atan01 Unexecuted instantiation: ltp.c:spx_atan01 |
283 | | |
284 | | #undef M1 |
285 | | #undef M2 |
286 | | #undef M3 |
287 | | #undef M4 |
288 | | |
289 | | /* Input in Q15, output in Q14 */ |
290 | | static inline spx_word16_t spx_atan(spx_word32_t x) |
291 | 0 | { |
292 | 0 | if (x <= 32767) |
293 | 0 | { |
294 | 0 | return SHR16(spx_atan01(x),1); |
295 | 0 | } else { |
296 | 0 | int e = spx_ilog2(x); |
297 | 0 | if (e>=29) |
298 | 0 | return 25736; |
299 | 0 | x = DIV32_16(SHL32(EXTEND32(32767),29-e), EXTRACT16(SHR32(x, e-14))); |
300 | 0 | return SUB16(25736, SHR16(spx_atan01(x),1)); |
301 | 0 | } |
302 | 0 | } Unexecuted instantiation: stereo.c:spx_atan Unexecuted instantiation: nb_celp.c:spx_atan Unexecuted instantiation: sb_celp.c:spx_atan Unexecuted instantiation: cb_search.c:spx_atan Unexecuted instantiation: filters.c:spx_atan Unexecuted instantiation: lsp.c:spx_atan Unexecuted instantiation: ltp.c:spx_atan |
303 | | #else |
304 | | |
305 | | #ifndef M_PI |
306 | | #define M_PI 3.14159265358979323846 /* pi */ |
307 | | #endif |
308 | | |
309 | 2.09M | #define C1 0.9999932946f |
310 | 2.09M | #define C2 -0.4999124376f |
311 | 2.09M | #define C3 0.0414877472f |
312 | 2.09M | #define C4 -0.0012712095f |
313 | | |
314 | | |
315 | 4.16M | #define SPX_PI_2 1.5707963268 |
316 | | static inline spx_word16_t spx_cos(spx_word16_t x) |
317 | 4.16M | { |
318 | 4.16M | if (x<SPX_PI_2) |
319 | 2.09M | { |
320 | 2.09M | x *= x; |
321 | 2.09M | return C1 + x*(C2+x*(C3+C4*x)); |
322 | 2.09M | } else { |
323 | 2.07M | x = M_PI-x; |
324 | 2.07M | x *= x; |
325 | 2.07M | return NEG16(C1 + x*(C2+x*(C3+C4*x))); |
326 | 2.07M | } |
327 | 4.16M | } Unexecuted instantiation: stereo.c:spx_cos Unexecuted instantiation: nb_celp.c:spx_cos Unexecuted instantiation: sb_celp.c:spx_cos Unexecuted instantiation: cb_search.c:spx_cos Unexecuted instantiation: filters.c:spx_cos Line | Count | Source | 317 | 4.16M | { | 318 | 4.16M | if (x<SPX_PI_2) | 319 | 2.09M | { | 320 | 2.09M | x *= x; | 321 | 2.09M | return C1 + x*(C2+x*(C3+C4*x)); | 322 | 2.09M | } else { | 323 | 2.07M | x = M_PI-x; | 324 | 2.07M | x *= x; | 325 | 2.07M | return NEG16(C1 + x*(C2+x*(C3+C4*x))); | 326 | 2.07M | } | 327 | 4.16M | } |
Unexecuted instantiation: ltp.c:spx_cos |
328 | | |
329 | | #endif |
330 | | |
331 | | |
332 | | #endif |