Coverage Report

Created: 2026-12-01 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/speex/libspeex/math_approx.h
Line
Count
Source
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
47.9k
#define spx_sqrt sqrt
43
#define spx_acos acos
44
5.38k
#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.18M
{
51
4.18M
   const unsigned int jflone = 0x3f800000;
52
4.18M
   const unsigned int jflmsk = 0x007fffff;
53
4.18M
   union {int i; float f;} ran;
54
4.18M
   *seed = 1664525 * *seed + 1013904223;
55
4.18M
   ran.i = jflone | (jflmsk & *seed);
56
4.18M
   ran.f -= 1.5;
57
4.18M
   return 3.4642*std*ran.f;
58
4.18M
}
Unexecuted instantiation: stereo.c:speex_rand
nb_celp.c:speex_rand
Line
Count
Source
50
3.09M
{
51
3.09M
   const unsigned int jflone = 0x3f800000;
52
3.09M
   const unsigned int jflmsk = 0x007fffff;
53
3.09M
   union {int i; float f;} ran;
54
3.09M
   *seed = 1664525 * *seed + 1013904223;
55
3.09M
   ran.i = jflone | (jflmsk & *seed);
56
3.09M
   ran.f -= 1.5;
57
3.09M
   return 3.4642*std*ran.f;
58
3.09M
}
sb_celp.c:speex_rand
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
}
cb_search.c:speex_rand
Line
Count
Source
50
651k
{
51
651k
   const unsigned int jflone = 0x3f800000;
52
651k
   const unsigned int jflmsk = 0x007fffff;
53
651k
   union {int i; float f;} ran;
54
651k
   *seed = 1664525 * *seed + 1013904223;
55
651k
   ran.i = jflone | (jflmsk & *seed);
56
651k
   ran.f -= 1.5;
57
651k
   return 3.4642*std*ran.f;
58
651k
}
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
7.68k
{
66
7.68k
   int r=0;
67
7.68k
   if (x>=(spx_int32_t)65536)
68
2.01k
   {
69
2.01k
      x >>= 16;
70
2.01k
      r += 16;
71
2.01k
   }
72
7.68k
   if (x>=256)
73
2.13k
   {
74
2.13k
      x >>= 8;
75
2.13k
      r += 8;
76
2.13k
   }
77
7.68k
   if (x>=16)
78
1.83k
   {
79
1.83k
      x >>= 4;
80
1.83k
      r += 4;
81
1.83k
   }
82
7.68k
   if (x>=4)
83
1.92k
   {
84
1.92k
      x >>= 2;
85
1.92k
      r += 2;
86
1.92k
   }
87
7.68k
   if (x>=2)
88
1.90k
   {
89
1.90k
      r += 1;
90
1.90k
   }
91
7.68k
   return r;
92
7.68k
}
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
stereo.c:spx_ilog2
Line
Count
Source
65
7.68k
{
66
7.68k
   int r=0;
67
7.68k
   if (x>=(spx_int32_t)65536)
68
2.01k
   {
69
2.01k
      x >>= 16;
70
2.01k
      r += 16;
71
2.01k
   }
72
7.68k
   if (x>=256)
73
2.13k
   {
74
2.13k
      x >>= 8;
75
2.13k
      r += 8;
76
2.13k
   }
77
7.68k
   if (x>=16)
78
1.83k
   {
79
1.83k
      x >>= 4;
80
1.83k
      r += 4;
81
1.83k
   }
82
7.68k
   if (x>=4)
83
1.92k
   {
84
1.92k
      x >>= 2;
85
1.92k
      r += 2;
86
1.92k
   }
87
7.68k
   if (x>=2)
88
1.90k
   {
89
1.90k
      r += 1;
90
1.90k
   }
91
7.68k
   return r;
92
7.68k
}
93
94
static inline spx_int16_t spx_ilog4(spx_uint32_t x)
95
793k
{
96
793k
   int r=0;
97
793k
   if (x>=(spx_int32_t)65536)
98
468k
   {
99
468k
      x >>= 16;
100
468k
      r += 8;
101
468k
   }
102
793k
   if (x>=256)
103
358k
   {
104
358k
      x >>= 8;
105
358k
      r += 4;
106
358k
   }
107
793k
   if (x>=16)
108
213k
   {
109
213k
      x >>= 4;
110
213k
      r += 2;
111
213k
   }
112
793k
   if (x>=4)
113
332k
   {
114
332k
      r += 1;
115
332k
   }
116
793k
   return r;
117
793k
}
Unexecuted instantiation: cb_search.c:spx_ilog4
stereo.c:spx_ilog4
Line
Count
Source
95
9.28k
{
96
9.28k
   int r=0;
97
9.28k
   if (x>=(spx_int32_t)65536)
98
8.57k
   {
99
8.57k
      x >>= 16;
100
8.57k
      r += 8;
101
8.57k
   }
102
9.28k
   if (x>=256)
103
1.14k
   {
104
1.14k
      x >>= 8;
105
1.14k
      r += 4;
106
1.14k
   }
107
9.28k
   if (x>=16)
108
866
   {
109
866
      x >>= 4;
110
866
      r += 2;
111
866
   }
112
9.28k
   if (x>=4)
113
1.08k
   {
114
1.08k
      r += 1;
115
1.08k
   }
116
9.28k
   return r;
117
9.28k
}
nb_celp.c:spx_ilog4
Line
Count
Source
95
22.7k
{
96
22.7k
   int r=0;
97
22.7k
   if (x>=(spx_int32_t)65536)
98
8.32k
   {
99
8.32k
      x >>= 16;
100
8.32k
      r += 8;
101
8.32k
   }
102
22.7k
   if (x>=256)
103
8.77k
   {
104
8.77k
      x >>= 8;
105
8.77k
      r += 4;
106
8.77k
   }
107
22.7k
   if (x>=16)
108
18.4k
   {
109
18.4k
      x >>= 4;
110
18.4k
      r += 2;
111
18.4k
   }
112
22.7k
   if (x>=4)
113
5.30k
   {
114
5.30k
      r += 1;
115
5.30k
   }
116
22.7k
   return r;
117
22.7k
}
sb_celp.c:spx_ilog4
Line
Count
Source
95
3.66k
{
96
3.66k
   int r=0;
97
3.66k
   if (x>=(spx_int32_t)65536)
98
709
   {
99
709
      x >>= 16;
100
709
      r += 8;
101
709
   }
102
3.66k
   if (x>=256)
103
654
   {
104
654
      x >>= 8;
105
654
      r += 4;
106
654
   }
107
3.66k
   if (x>=16)
108
441
   {
109
441
      x >>= 4;
110
441
      r += 2;
111
441
   }
112
3.66k
   if (x>=4)
113
682
   {
114
682
      r += 1;
115
682
   }
116
3.66k
   return r;
117
3.66k
}
filters.c:spx_ilog4
Line
Count
Source
95
313k
{
96
313k
   int r=0;
97
313k
   if (x>=(spx_int32_t)65536)
98
106k
   {
99
106k
      x >>= 16;
100
106k
      r += 8;
101
106k
   }
102
313k
   if (x>=256)
103
88.2k
   {
104
88.2k
      x >>= 8;
105
88.2k
      r += 4;
106
88.2k
   }
107
313k
   if (x>=16)
108
63.0k
   {
109
63.0k
      x >>= 4;
110
63.0k
      r += 2;
111
63.0k
   }
112
313k
   if (x>=4)
113
94.9k
   {
114
94.9k
      r += 1;
115
94.9k
   }
116
313k
   return r;
117
313k
}
lsp.c:spx_ilog4
Line
Count
Source
95
238k
{
96
238k
   int r=0;
97
238k
   if (x>=(spx_int32_t)65536)
98
238k
   {
99
238k
      x >>= 16;
100
238k
      r += 8;
101
238k
   }
102
238k
   if (x>=256)
103
185k
   {
104
185k
      x >>= 8;
105
185k
      r += 4;
106
185k
   }
107
238k
   if (x>=16)
108
51.7k
   {
109
51.7k
      x >>= 4;
110
51.7k
      r += 2;
111
51.7k
   }
112
238k
   if (x>=4)
113
146k
   {
114
146k
      r += 1;
115
146k
   }
116
238k
   return r;
117
238k
}
ltp.c:spx_ilog4
Line
Count
Source
95
205k
{
96
205k
   int r=0;
97
205k
   if (x>=(spx_int32_t)65536)
98
106k
   {
99
106k
      x >>= 16;
100
106k
      r += 8;
101
106k
   }
102
205k
   if (x>=256)
103
74.2k
   {
104
74.2k
      x >>= 8;
105
74.2k
      r += 4;
106
74.2k
   }
107
205k
   if (x>=16)
108
78.4k
   {
109
78.4k
      x >>= 4;
110
78.4k
      r += 2;
111
78.4k
   }
112
205k
   if (x>=4)
113
83.0k
   {
114
83.0k
      r += 1;
115
83.0k
   }
116
205k
   return r;
117
205k
}
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.18M
{
124
4.18M
   spx_word32_t res;
125
4.18M
   *seed = 1664525 * *seed + 1013904223;
126
4.18M
   res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
127
4.18M
   return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
128
4.18M
}
nb_celp.c:speex_rand
Line
Count
Source
123
3.09M
{
124
3.09M
   spx_word32_t res;
125
3.09M
   *seed = 1664525 * *seed + 1013904223;
126
3.09M
   res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
127
3.09M
   return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
128
3.09M
}
sb_celp.c:speex_rand
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
}
cb_search.c:speex_rand
Line
Count
Source
123
651k
{
124
651k
   spx_word32_t res;
125
651k
   *seed = 1664525 * *seed + 1013904223;
126
651k
   res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
127
651k
   return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
128
651k
}
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
793k
{
144
793k
   int k;
145
793k
   spx_word32_t rt;
146
793k
   k = spx_ilog4(x)-6;
147
793k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
793k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
793k
   rt = VSHR32(rt,7-k);
150
793k
   return rt;
151
793k
}
stereo.c:spx_sqrt
Line
Count
Source
143
9.28k
{
144
9.28k
   int k;
145
9.28k
   spx_word32_t rt;
146
9.28k
   k = spx_ilog4(x)-6;
147
9.28k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
9.28k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
9.28k
   rt = VSHR32(rt,7-k);
150
9.28k
   return rt;
151
9.28k
}
nb_celp.c:spx_sqrt
Line
Count
Source
143
22.7k
{
144
22.7k
   int k;
145
22.7k
   spx_word32_t rt;
146
22.7k
   k = spx_ilog4(x)-6;
147
22.7k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
22.7k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
22.7k
   rt = VSHR32(rt,7-k);
150
22.7k
   return rt;
151
22.7k
}
sb_celp.c:spx_sqrt
Line
Count
Source
143
3.66k
{
144
3.66k
   int k;
145
3.66k
   spx_word32_t rt;
146
3.66k
   k = spx_ilog4(x)-6;
147
3.66k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
3.66k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
3.66k
   rt = VSHR32(rt,7-k);
150
3.66k
   return rt;
151
3.66k
}
Unexecuted instantiation: cb_search.c:spx_sqrt
filters.c:spx_sqrt
Line
Count
Source
143
313k
{
144
313k
   int k;
145
313k
   spx_word32_t rt;
146
313k
   k = spx_ilog4(x)-6;
147
313k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
313k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
313k
   rt = VSHR32(rt,7-k);
150
313k
   return rt;
151
313k
}
lsp.c:spx_sqrt
Line
Count
Source
143
238k
{
144
238k
   int k;
145
238k
   spx_word32_t rt;
146
238k
   k = spx_ilog4(x)-6;
147
238k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
238k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
238k
   rt = VSHR32(rt,7-k);
150
238k
   return rt;
151
238k
}
ltp.c:spx_sqrt
Line
Count
Source
143
205k
{
144
205k
   int k;
145
205k
   spx_word32_t rt;
146
205k
   k = spx_ilog4(x)-6;
147
205k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
205k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
205k
   rt = VSHR32(rt,7-k);
150
205k
   return rt;
151
205k
}
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
238k
{
162
238k
   int s=0;
163
238k
   spx_word16_t ret;
164
238k
   spx_word16_t sq;
165
238k
   if (x<0)
166
118k
   {
167
118k
      s=1;
168
118k
      x = NEG16(x);
169
118k
   }
170
238k
   x = SUB16(16384,x);
171
172
238k
   x = x >> 1;
173
238k
   sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3))))));
174
238k
   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
238k
   if (s)
178
118k
      ret = SUB16(25736,ret);
179
238k
   return ret;
180
238k
}
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
lsp.c:spx_acos
Line
Count
Source
161
238k
{
162
238k
   int s=0;
163
238k
   spx_word16_t ret;
164
238k
   spx_word16_t sq;
165
238k
   if (x<0)
166
118k
   {
167
118k
      s=1;
168
118k
      x = NEG16(x);
169
118k
   }
170
238k
   x = SUB16(16384,x);
171
172
238k
   x = x >> 1;
173
238k
   sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3))))));
174
238k
   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
238k
   if (s)
178
118k
      ret = SUB16(25736,ret);
179
238k
   return ret;
180
238k
}
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.94M
{
190
3.94M
   spx_word16_t x2;
191
192
3.94M
   if (x<12868)
193
1.97M
   {
194
1.97M
      x2 = MULT16_16_P13(x,x);
195
1.97M
      return ADD32(K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
196
1.97M
   } else {
197
1.97M
      x = SUB16(25736,x);
198
1.97M
      x2 = MULT16_16_P13(x,x);
199
1.97M
      return SUB32(-K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
200
1.97M
   }
201
3.94M
}
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.70k
{
252
4.70k
   int integer;
253
4.70k
   spx_word16_t frac;
254
4.70k
   integer = SHR16(x,11);
255
4.70k
   if (integer>14)
256
0
      return 0x7fffffff;
257
4.70k
   else if (integer < -15)
258
0
      return 0;
259
4.70k
   frac = SHL16(x-SHL16(integer,11),3);
260
4.70k
   frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
261
4.70k
   return VSHR32(EXTEND32(frac), -integer-2);
262
4.70k
}
stereo.c:spx_exp2
Line
Count
Source
251
494
{
252
494
   int integer;
253
494
   spx_word16_t frac;
254
494
   integer = SHR16(x,11);
255
494
   if (integer>14)
256
0
      return 0x7fffffff;
257
494
   else if (integer < -15)
258
0
      return 0;
259
494
   frac = SHL16(x-SHL16(integer,11),3);
260
494
   frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
261
494
   return VSHR32(EXTEND32(frac), -integer-2);
262
494
}
Unexecuted instantiation: nb_celp.c:spx_exp2
sb_celp.c:spx_exp2
Line
Count
Source
251
4.21k
{
252
4.21k
   int integer;
253
4.21k
   spx_word16_t frac;
254
4.21k
   integer = SHR16(x,11);
255
4.21k
   if (integer>14)
256
0
      return 0x7fffffff;
257
4.21k
   else if (integer < -15)
258
0
      return 0;
259
4.21k
   frac = SHL16(x-SHL16(integer,11),3);
260
4.21k
   frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
261
4.21k
   return VSHR32(EXTEND32(frac), -integer-2);
262
4.21k
}
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.70k
{
267
4.70k
   if (x>21290)
268
0
      return 0x7fffffff;
269
4.70k
   else if (x<-21290)
270
0
      return 0;
271
4.70k
   else
272
4.70k
      return spx_exp2(MULT16_16_P14(23637,x));
273
4.70k
}
stereo.c:spx_exp
Line
Count
Source
266
494
{
267
494
   if (x>21290)
268
0
      return 0x7fffffff;
269
494
   else if (x<-21290)
270
0
      return 0;
271
494
   else
272
494
      return spx_exp2(MULT16_16_P14(23637,x));
273
494
}
Unexecuted instantiation: nb_celp.c:spx_exp
sb_celp.c:spx_exp
Line
Count
Source
266
4.21k
{
267
4.21k
   if (x>21290)
268
0
      return 0x7fffffff;
269
4.21k
   else if (x<-21290)
270
0
      return 0;
271
4.21k
   else
272
4.21k
      return spx_exp2(MULT16_16_P14(23637,x));
273
4.21k
}
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.97M
#define C1 0.9999932946f
310
1.97M
#define C2 -0.4999124376f
311
1.97M
#define C3 0.0414877472f
312
1.97M
#define C4 -0.0012712095f
313
314
315
3.94M
#define SPX_PI_2 1.5707963268
316
static inline spx_word16_t spx_cos(spx_word16_t x)
317
3.94M
{
318
3.94M
   if (x<SPX_PI_2)
319
1.97M
   {
320
1.97M
      x *= x;
321
1.97M
      return C1 + x*(C2+x*(C3+C4*x));
322
1.97M
   } else {
323
1.97M
      x = M_PI-x;
324
1.97M
      x *= x;
325
1.97M
      return NEG16(C1 + x*(C2+x*(C3+C4*x)));
326
1.97M
   }
327
3.94M
}
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
lsp.c:spx_cos
Line
Count
Source
317
3.94M
{
318
3.94M
   if (x<SPX_PI_2)
319
1.97M
   {
320
1.97M
      x *= x;
321
1.97M
      return C1 + x*(C2+x*(C3+C4*x));
322
1.97M
   } else {
323
1.97M
      x = M_PI-x;
324
1.97M
      x *= x;
325
1.97M
      return NEG16(C1 + x*(C2+x*(C3+C4*x)));
326
1.97M
   }
327
3.94M
}
Unexecuted instantiation: ltp.c:spx_cos
328
329
#endif
330
331
332
#endif