/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 | 54.5k | #define spx_sqrt sqrt |
43 | | #define spx_acos acos |
44 | 4.70k | #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.40M | { |
51 | 4.40M | const unsigned int jflone = 0x3f800000; |
52 | 4.40M | const unsigned int jflmsk = 0x007fffff; |
53 | 4.40M | union {int i; float f;} ran; |
54 | 4.40M | *seed = 1664525 * *seed + 1013904223; |
55 | 4.40M | ran.i = jflone | (jflmsk & *seed); |
56 | 4.40M | ran.f -= 1.5; |
57 | 4.40M | return 3.4642*std*ran.f; |
58 | 4.40M | } Unexecuted instantiation: stereo.c:speex_rand Line | Count | Source | 50 | 3.34M | { | 51 | 3.34M | const unsigned int jflone = 0x3f800000; | 52 | 3.34M | const unsigned int jflmsk = 0x007fffff; | 53 | 3.34M | union {int i; float f;} ran; | 54 | 3.34M | *seed = 1664525 * *seed + 1013904223; | 55 | 3.34M | ran.i = jflone | (jflmsk & *seed); | 56 | 3.34M | ran.f -= 1.5; | 57 | 3.34M | return 3.4642*std*ran.f; | 58 | 3.34M | } |
Line | Count | Source | 50 | 435k | { | 51 | 435k | const unsigned int jflone = 0x3f800000; | 52 | 435k | const unsigned int jflmsk = 0x007fffff; | 53 | 435k | union {int i; float f;} ran; | 54 | 435k | *seed = 1664525 * *seed + 1013904223; | 55 | 435k | ran.i = jflone | (jflmsk & *seed); | 56 | 435k | ran.f -= 1.5; | 57 | 435k | return 3.4642*std*ran.f; | 58 | 435k | } |
Line | Count | Source | 50 | 619k | { | 51 | 619k | const unsigned int jflone = 0x3f800000; | 52 | 619k | const unsigned int jflmsk = 0x007fffff; | 53 | 619k | union {int i; float f;} ran; | 54 | 619k | *seed = 1664525 * *seed + 1013904223; | 55 | 619k | ran.i = jflone | (jflmsk & *seed); | 56 | 619k | ran.f -= 1.5; | 57 | 619k | return 3.4642*std*ran.f; | 58 | 619k | } |
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.18k | { |
66 | 6.18k | int r=0; |
67 | 6.18k | if (x>=(spx_int32_t)65536) |
68 | 1.98k | { |
69 | 1.98k | x >>= 16; |
70 | 1.98k | r += 16; |
71 | 1.98k | } |
72 | 6.18k | if (x>=256) |
73 | 2.05k | { |
74 | 2.05k | x >>= 8; |
75 | 2.05k | r += 8; |
76 | 2.05k | } |
77 | 6.18k | if (x>=16) |
78 | 1.36k | { |
79 | 1.36k | x >>= 4; |
80 | 1.36k | r += 4; |
81 | 1.36k | } |
82 | 6.18k | if (x>=4) |
83 | 1.53k | { |
84 | 1.53k | x >>= 2; |
85 | 1.53k | r += 2; |
86 | 1.53k | } |
87 | 6.18k | if (x>=2) |
88 | 1.63k | { |
89 | 1.63k | r += 1; |
90 | 1.63k | } |
91 | 6.18k | return r; |
92 | 6.18k | } 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.18k | { | 66 | 6.18k | int r=0; | 67 | 6.18k | if (x>=(spx_int32_t)65536) | 68 | 1.98k | { | 69 | 1.98k | x >>= 16; | 70 | 1.98k | r += 16; | 71 | 1.98k | } | 72 | 6.18k | if (x>=256) | 73 | 2.05k | { | 74 | 2.05k | x >>= 8; | 75 | 2.05k | r += 8; | 76 | 2.05k | } | 77 | 6.18k | if (x>=16) | 78 | 1.36k | { | 79 | 1.36k | x >>= 4; | 80 | 1.36k | r += 4; | 81 | 1.36k | } | 82 | 6.18k | if (x>=4) | 83 | 1.53k | { | 84 | 1.53k | x >>= 2; | 85 | 1.53k | r += 2; | 86 | 1.53k | } | 87 | 6.18k | if (x>=2) | 88 | 1.63k | { | 89 | 1.63k | r += 1; | 90 | 1.63k | } | 91 | 6.18k | return r; | 92 | 6.18k | } |
|
93 | | |
94 | | static inline spx_int16_t spx_ilog4(spx_uint32_t x) |
95 | 698k | { |
96 | 698k | int r=0; |
97 | 698k | if (x>=(spx_int32_t)65536) |
98 | 425k | { |
99 | 425k | x >>= 16; |
100 | 425k | r += 8; |
101 | 425k | } |
102 | 698k | if (x>=256) |
103 | 321k | { |
104 | 321k | x >>= 8; |
105 | 321k | r += 4; |
106 | 321k | } |
107 | 698k | if (x>=16) |
108 | 186k | { |
109 | 186k | x >>= 4; |
110 | 186k | r += 2; |
111 | 186k | } |
112 | 698k | if (x>=4) |
113 | 289k | { |
114 | 289k | r += 1; |
115 | 289k | } |
116 | 698k | return r; |
117 | 698k | } Unexecuted instantiation: cb_search.c:spx_ilog4 Line | Count | Source | 95 | 11.2k | { | 96 | 11.2k | int r=0; | 97 | 11.2k | if (x>=(spx_int32_t)65536) | 98 | 10.7k | { | 99 | 10.7k | x >>= 16; | 100 | 10.7k | r += 8; | 101 | 10.7k | } | 102 | 11.2k | if (x>=256) | 103 | 998 | { | 104 | 998 | x >>= 8; | 105 | 998 | r += 4; | 106 | 998 | } | 107 | 11.2k | if (x>=16) | 108 | 638 | { | 109 | 638 | x >>= 4; | 110 | 638 | r += 2; | 111 | 638 | } | 112 | 11.2k | if (x>=4) | 113 | 932 | { | 114 | 932 | r += 1; | 115 | 932 | } | 116 | 11.2k | return r; | 117 | 11.2k | } |
Line | Count | Source | 95 | 15.8k | { | 96 | 15.8k | int r=0; | 97 | 15.8k | if (x>=(spx_int32_t)65536) | 98 | 7.30k | { | 99 | 7.30k | x >>= 16; | 100 | 7.30k | r += 8; | 101 | 7.30k | } | 102 | 15.8k | if (x>=256) | 103 | 7.76k | { | 104 | 7.76k | x >>= 8; | 105 | 7.76k | r += 4; | 106 | 7.76k | } | 107 | 15.8k | if (x>=16) | 108 | 11.9k | { | 109 | 11.9k | x >>= 4; | 110 | 11.9k | r += 2; | 111 | 11.9k | } | 112 | 15.8k | if (x>=4) | 113 | 5.51k | { | 114 | 5.51k | r += 1; | 115 | 5.51k | } | 116 | 15.8k | return r; | 117 | 15.8k | } |
Line | Count | Source | 95 | 3.38k | { | 96 | 3.38k | int r=0; | 97 | 3.38k | if (x>=(spx_int32_t)65536) | 98 | 670 | { | 99 | 670 | x >>= 16; | 100 | 670 | r += 8; | 101 | 670 | } | 102 | 3.38k | if (x>=256) | 103 | 537 | { | 104 | 537 | x >>= 8; | 105 | 537 | r += 4; | 106 | 537 | } | 107 | 3.38k | if (x>=16) | 108 | 420 | { | 109 | 420 | x >>= 4; | 110 | 420 | r += 2; | 111 | 420 | } | 112 | 3.38k | if (x>=4) | 113 | 682 | { | 114 | 682 | r += 1; | 115 | 682 | } | 116 | 3.38k | return r; | 117 | 3.38k | } |
Line | Count | Source | 95 | 289k | { | 96 | 289k | int r=0; | 97 | 289k | if (x>=(spx_int32_t)65536) | 98 | 101k | { | 99 | 101k | x >>= 16; | 100 | 101k | r += 8; | 101 | 101k | } | 102 | 289k | if (x>=256) | 103 | 87.4k | { | 104 | 87.4k | x >>= 8; | 105 | 87.4k | r += 4; | 106 | 87.4k | } | 107 | 289k | if (x>=16) | 108 | 60.2k | { | 109 | 60.2k | x >>= 4; | 110 | 60.2k | r += 2; | 111 | 60.2k | } | 112 | 289k | if (x>=4) | 113 | 86.7k | { | 114 | 86.7k | r += 1; | 115 | 86.7k | } | 116 | 289k | return r; | 117 | 289k | } |
Line | Count | Source | 95 | 201k | { | 96 | 201k | int r=0; | 97 | 201k | if (x>=(spx_int32_t)65536) | 98 | 201k | { | 99 | 201k | x >>= 16; | 100 | 201k | r += 8; | 101 | 201k | } | 102 | 201k | if (x>=256) | 103 | 155k | { | 104 | 155k | x >>= 8; | 105 | 155k | r += 4; | 106 | 155k | } | 107 | 201k | if (x>=16) | 108 | 44.3k | { | 109 | 44.3k | x >>= 4; | 110 | 44.3k | r += 2; | 111 | 44.3k | } | 112 | 201k | if (x>=4) | 113 | 123k | { | 114 | 123k | r += 1; | 115 | 123k | } | 116 | 201k | return r; | 117 | 201k | } |
Line | Count | Source | 95 | 176k | { | 96 | 176k | int r=0; | 97 | 176k | if (x>=(spx_int32_t)65536) | 98 | 103k | { | 99 | 103k | x >>= 16; | 100 | 103k | r += 8; | 101 | 103k | } | 102 | 176k | if (x>=256) | 103 | 69.4k | { | 104 | 69.4k | x >>= 8; | 105 | 69.4k | r += 4; | 106 | 69.4k | } | 107 | 176k | if (x>=16) | 108 | 69.0k | { | 109 | 69.0k | x >>= 4; | 110 | 69.0k | r += 2; | 111 | 69.0k | } | 112 | 176k | if (x>=4) | 113 | 71.8k | { | 114 | 71.8k | r += 1; | 115 | 71.8k | } | 116 | 176k | return r; | 117 | 176k | } |
|
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.40M | { |
124 | 4.40M | spx_word32_t res; |
125 | 4.40M | *seed = 1664525 * *seed + 1013904223; |
126 | 4.40M | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); |
127 | 4.40M | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); |
128 | 4.40M | } Line | Count | Source | 123 | 3.34M | { | 124 | 3.34M | spx_word32_t res; | 125 | 3.34M | *seed = 1664525 * *seed + 1013904223; | 126 | 3.34M | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); | 127 | 3.34M | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); | 128 | 3.34M | } |
Line | Count | Source | 123 | 435k | { | 124 | 435k | spx_word32_t res; | 125 | 435k | *seed = 1664525 * *seed + 1013904223; | 126 | 435k | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); | 127 | 435k | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); | 128 | 435k | } |
Line | Count | Source | 123 | 619k | { | 124 | 619k | spx_word32_t res; | 125 | 619k | *seed = 1664525 * *seed + 1013904223; | 126 | 619k | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); | 127 | 619k | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); | 128 | 619k | } |
|
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 | 698k | { |
144 | 698k | int k; |
145 | 698k | spx_word32_t rt; |
146 | 698k | k = spx_ilog4(x)-6; |
147 | 698k | x = VSHR32(x, (int)((unsigned)k<<1)); |
148 | 698k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); |
149 | 698k | rt = VSHR32(rt,7-k); |
150 | 698k | return rt; |
151 | 698k | } Line | Count | Source | 143 | 11.2k | { | 144 | 11.2k | int k; | 145 | 11.2k | spx_word32_t rt; | 146 | 11.2k | k = spx_ilog4(x)-6; | 147 | 11.2k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 11.2k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 11.2k | rt = VSHR32(rt,7-k); | 150 | 11.2k | return rt; | 151 | 11.2k | } |
Line | Count | Source | 143 | 15.8k | { | 144 | 15.8k | int k; | 145 | 15.8k | spx_word32_t rt; | 146 | 15.8k | k = spx_ilog4(x)-6; | 147 | 15.8k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 15.8k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 15.8k | rt = VSHR32(rt,7-k); | 150 | 15.8k | return rt; | 151 | 15.8k | } |
Line | Count | Source | 143 | 3.38k | { | 144 | 3.38k | int k; | 145 | 3.38k | spx_word32_t rt; | 146 | 3.38k | k = spx_ilog4(x)-6; | 147 | 3.38k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 3.38k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 3.38k | rt = VSHR32(rt,7-k); | 150 | 3.38k | return rt; | 151 | 3.38k | } |
Unexecuted instantiation: cb_search.c:spx_sqrt Line | Count | Source | 143 | 289k | { | 144 | 289k | int k; | 145 | 289k | spx_word32_t rt; | 146 | 289k | k = spx_ilog4(x)-6; | 147 | 289k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 289k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 289k | rt = VSHR32(rt,7-k); | 150 | 289k | return rt; | 151 | 289k | } |
Line | Count | Source | 143 | 201k | { | 144 | 201k | int k; | 145 | 201k | spx_word32_t rt; | 146 | 201k | k = spx_ilog4(x)-6; | 147 | 201k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 201k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 201k | rt = VSHR32(rt,7-k); | 150 | 201k | return rt; | 151 | 201k | } |
Line | Count | Source | 143 | 176k | { | 144 | 176k | int k; | 145 | 176k | spx_word32_t rt; | 146 | 176k | k = spx_ilog4(x)-6; | 147 | 176k | x = VSHR32(x, (int)((unsigned)k<<1)); | 148 | 176k | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); | 149 | 176k | rt = VSHR32(rt,7-k); | 150 | 176k | return rt; | 151 | 176k | } |
|
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 | 201k | { |
162 | 201k | int s=0; |
163 | 201k | spx_word16_t ret; |
164 | 201k | spx_word16_t sq; |
165 | 201k | if (x<0) |
166 | 100k | { |
167 | 100k | s=1; |
168 | 100k | x = NEG16(x); |
169 | 100k | } |
170 | 201k | x = SUB16(16384,x); |
171 | | |
172 | 201k | x = x >> 1; |
173 | 201k | sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3)))))); |
174 | 201k | 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 | 201k | if (s) |
178 | 100k | ret = SUB16(25736,ret); |
179 | 201k | return ret; |
180 | 201k | } 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 | 201k | { | 162 | 201k | int s=0; | 163 | 201k | spx_word16_t ret; | 164 | 201k | spx_word16_t sq; | 165 | 201k | if (x<0) | 166 | 100k | { | 167 | 100k | s=1; | 168 | 100k | x = NEG16(x); | 169 | 100k | } | 170 | 201k | x = SUB16(16384,x); | 171 | | | 172 | 201k | x = x >> 1; | 173 | 201k | sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3)))))); | 174 | 201k | 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 | 201k | if (s) | 178 | 100k | ret = SUB16(25736,ret); | 179 | 201k | return ret; | 180 | 201k | } |
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 | 3.35M | { |
190 | 3.35M | spx_word16_t x2; |
191 | | |
192 | 3.35M | if (x<12868) |
193 | 1.68M | { |
194 | 1.68M | x2 = MULT16_16_P13(x,x); |
195 | 1.68M | return ADD32(K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2)))))); |
196 | 1.68M | } else { |
197 | 1.67M | x = SUB16(25736,x); |
198 | 1.67M | x2 = MULT16_16_P13(x,x); |
199 | 1.67M | return SUB32(-K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2)))))); |
200 | 1.67M | } |
201 | 3.35M | } |
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 | 4.86k | { |
252 | 4.86k | int integer; |
253 | 4.86k | spx_word16_t frac; |
254 | 4.86k | integer = SHR16(x,11); |
255 | 4.86k | if (integer>14) |
256 | 0 | return 0x7fffffff; |
257 | 4.86k | else if (integer < -15) |
258 | 0 | return 0; |
259 | 4.86k | frac = SHL16(x-SHL16(integer,11),3); |
260 | 4.86k | frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac)))))); |
261 | 4.86k | return VSHR32(EXTEND32(frac), -integer-2); |
262 | 4.86k | } Line | Count | Source | 251 | 502 | { | 252 | 502 | int integer; | 253 | 502 | spx_word16_t frac; | 254 | 502 | integer = SHR16(x,11); | 255 | 502 | if (integer>14) | 256 | 0 | return 0x7fffffff; | 257 | 502 | else if (integer < -15) | 258 | 0 | return 0; | 259 | 502 | frac = SHL16(x-SHL16(integer,11),3); | 260 | 502 | frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac)))))); | 261 | 502 | return VSHR32(EXTEND32(frac), -integer-2); | 262 | 502 | } |
Unexecuted instantiation: nb_celp.c:spx_exp2 Line | Count | Source | 251 | 4.36k | { | 252 | 4.36k | int integer; | 253 | 4.36k | spx_word16_t frac; | 254 | 4.36k | integer = SHR16(x,11); | 255 | 4.36k | if (integer>14) | 256 | 0 | return 0x7fffffff; | 257 | 4.36k | else if (integer < -15) | 258 | 0 | return 0; | 259 | 4.36k | frac = SHL16(x-SHL16(integer,11),3); | 260 | 4.36k | frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac)))))); | 261 | 4.36k | return VSHR32(EXTEND32(frac), -integer-2); | 262 | 4.36k | } |
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 | 4.86k | { |
267 | 4.86k | if (x>21290) |
268 | 0 | return 0x7fffffff; |
269 | 4.86k | else if (x<-21290) |
270 | 0 | return 0; |
271 | 4.86k | else |
272 | 4.86k | return spx_exp2(MULT16_16_P14(23637,x)); |
273 | 4.86k | } Line | Count | Source | 266 | 502 | { | 267 | 502 | if (x>21290) | 268 | 0 | return 0x7fffffff; | 269 | 502 | else if (x<-21290) | 270 | 0 | return 0; | 271 | 502 | else | 272 | 502 | return spx_exp2(MULT16_16_P14(23637,x)); | 273 | 502 | } |
Unexecuted instantiation: nb_celp.c:spx_exp Line | Count | Source | 266 | 4.36k | { | 267 | 4.36k | if (x>21290) | 268 | 0 | return 0x7fffffff; | 269 | 4.36k | else if (x<-21290) | 270 | 0 | return 0; | 271 | 4.36k | else | 272 | 4.36k | return spx_exp2(MULT16_16_P14(23637,x)); | 273 | 4.36k | } |
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 | 1.68M | #define C1 0.9999932946f |
310 | 1.68M | #define C2 -0.4999124376f |
311 | 1.68M | #define C3 0.0414877472f |
312 | 1.68M | #define C4 -0.0012712095f |
313 | | |
314 | | |
315 | 3.35M | #define SPX_PI_2 1.5707963268 |
316 | | static inline spx_word16_t spx_cos(spx_word16_t x) |
317 | 3.35M | { |
318 | 3.35M | if (x<SPX_PI_2) |
319 | 1.68M | { |
320 | 1.68M | x *= x; |
321 | 1.68M | return C1 + x*(C2+x*(C3+C4*x)); |
322 | 1.68M | } else { |
323 | 1.67M | x = M_PI-x; |
324 | 1.67M | x *= x; |
325 | 1.67M | return NEG16(C1 + x*(C2+x*(C3+C4*x))); |
326 | 1.67M | } |
327 | 3.35M | } 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 | 3.35M | { | 318 | 3.35M | if (x<SPX_PI_2) | 319 | 1.68M | { | 320 | 1.68M | x *= x; | 321 | 1.68M | return C1 + x*(C2+x*(C3+C4*x)); | 322 | 1.68M | } else { | 323 | 1.67M | x = M_PI-x; | 324 | 1.67M | x *= x; | 325 | 1.67M | return NEG16(C1 + x*(C2+x*(C3+C4*x))); | 326 | 1.67M | } | 327 | 3.35M | } |
Unexecuted instantiation: ltp.c:spx_cos |
328 | | |
329 | | #endif |
330 | | |
331 | | |
332 | | #endif |