Coverage Report

Created: 2026-01-17 06:57

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
53.1k
#define spx_sqrt sqrt
43
#define spx_acos acos
44
6.56k
#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.58M
{
51
4.58M
   const unsigned int jflone = 0x3f800000;
52
4.58M
   const unsigned int jflmsk = 0x007fffff;
53
4.58M
   union {int i; float f;} ran;
54
4.58M
   *seed = 1664525 * *seed + 1013904223;
55
4.58M
   ran.i = jflone | (jflmsk & *seed);
56
4.58M
   ran.f -= 1.5;
57
4.58M
   return 3.4642*std*ran.f;
58
4.58M
}
Unexecuted instantiation: stereo.c:speex_rand
nb_celp.c:speex_rand
Line
Count
Source
50
3.43M
{
51
3.43M
   const unsigned int jflone = 0x3f800000;
52
3.43M
   const unsigned int jflmsk = 0x007fffff;
53
3.43M
   union {int i; float f;} ran;
54
3.43M
   *seed = 1664525 * *seed + 1013904223;
55
3.43M
   ran.i = jflone | (jflmsk & *seed);
56
3.43M
   ran.f -= 1.5;
57
3.43M
   return 3.4642*std*ran.f;
58
3.43M
}
sb_celp.c:speex_rand
Line
Count
Source
50
438k
{
51
438k
   const unsigned int jflone = 0x3f800000;
52
438k
   const unsigned int jflmsk = 0x007fffff;
53
438k
   union {int i; float f;} ran;
54
438k
   *seed = 1664525 * *seed + 1013904223;
55
438k
   ran.i = jflone | (jflmsk & *seed);
56
438k
   ran.f -= 1.5;
57
438k
   return 3.4642*std*ran.f;
58
438k
}
cb_search.c:speex_rand
Line
Count
Source
50
712k
{
51
712k
   const unsigned int jflone = 0x3f800000;
52
712k
   const unsigned int jflmsk = 0x007fffff;
53
712k
   union {int i; float f;} ran;
54
712k
   *seed = 1664525 * *seed + 1013904223;
55
712k
   ran.i = jflone | (jflmsk & *seed);
56
712k
   ran.f -= 1.5;
57
712k
   return 3.4642*std*ran.f;
58
712k
}
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.54k
{
66
6.54k
   int r=0;
67
6.54k
   if (x>=(spx_int32_t)65536)
68
1.64k
   {
69
1.64k
      x >>= 16;
70
1.64k
      r += 16;
71
1.64k
   }
72
6.54k
   if (x>=256)
73
1.68k
   {
74
1.68k
      x >>= 8;
75
1.68k
      r += 8;
76
1.68k
   }
77
6.54k
   if (x>=16)
78
1.48k
   {
79
1.48k
      x >>= 4;
80
1.48k
      r += 4;
81
1.48k
   }
82
6.54k
   if (x>=4)
83
1.55k
   {
84
1.55k
      x >>= 2;
85
1.55k
      r += 2;
86
1.55k
   }
87
6.54k
   if (x>=2)
88
1.61k
   {
89
1.61k
      r += 1;
90
1.61k
   }
91
6.54k
   return r;
92
6.54k
}
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
6.54k
{
66
6.54k
   int r=0;
67
6.54k
   if (x>=(spx_int32_t)65536)
68
1.64k
   {
69
1.64k
      x >>= 16;
70
1.64k
      r += 16;
71
1.64k
   }
72
6.54k
   if (x>=256)
73
1.68k
   {
74
1.68k
      x >>= 8;
75
1.68k
      r += 8;
76
1.68k
   }
77
6.54k
   if (x>=16)
78
1.48k
   {
79
1.48k
      x >>= 4;
80
1.48k
      r += 4;
81
1.48k
   }
82
6.54k
   if (x>=4)
83
1.55k
   {
84
1.55k
      x >>= 2;
85
1.55k
      r += 2;
86
1.55k
   }
87
6.54k
   if (x>=2)
88
1.61k
   {
89
1.61k
      r += 1;
90
1.61k
   }
91
6.54k
   return r;
92
6.54k
}
93
94
static inline spx_int16_t spx_ilog4(spx_uint32_t x)
95
785k
{
96
785k
   int r=0;
97
785k
   if (x>=(spx_int32_t)65536)
98
476k
   {
99
476k
      x >>= 16;
100
476k
      r += 8;
101
476k
   }
102
785k
   if (x>=256)
103
357k
   {
104
357k
      x >>= 8;
105
357k
      r += 4;
106
357k
   }
107
785k
   if (x>=16)
108
221k
   {
109
221k
      x >>= 4;
110
221k
      r += 2;
111
221k
   }
112
785k
   if (x>=4)
113
331k
   {
114
331k
      r += 1;
115
331k
   }
116
785k
   return r;
117
785k
}
Unexecuted instantiation: cb_search.c:spx_ilog4
stereo.c:spx_ilog4
Line
Count
Source
95
10.5k
{
96
10.5k
   int r=0;
97
10.5k
   if (x>=(spx_int32_t)65536)
98
9.74k
   {
99
9.74k
      x >>= 16;
100
9.74k
      r += 8;
101
9.74k
   }
102
10.5k
   if (x>=256)
103
1.50k
   {
104
1.50k
      x >>= 8;
105
1.50k
      r += 4;
106
1.50k
   }
107
10.5k
   if (x>=16)
108
768
   {
109
768
      x >>= 4;
110
768
      r += 2;
111
768
   }
112
10.5k
   if (x>=4)
113
1.30k
   {
114
1.30k
      r += 1;
115
1.30k
   }
116
10.5k
   return r;
117
10.5k
}
nb_celp.c:spx_ilog4
Line
Count
Source
95
23.9k
{
96
23.9k
   int r=0;
97
23.9k
   if (x>=(spx_int32_t)65536)
98
8.44k
   {
99
8.44k
      x >>= 16;
100
8.44k
      r += 8;
101
8.44k
   }
102
23.9k
   if (x>=256)
103
8.85k
   {
104
8.85k
      x >>= 8;
105
8.85k
      r += 4;
106
8.85k
   }
107
23.9k
   if (x>=16)
108
19.7k
   {
109
19.7k
      x >>= 4;
110
19.7k
      r += 2;
111
19.7k
   }
112
23.9k
   if (x>=4)
113
5.67k
   {
114
5.67k
      r += 1;
115
5.67k
   }
116
23.9k
   return r;
117
23.9k
}
sb_celp.c:spx_ilog4
Line
Count
Source
95
3.40k
{
96
3.40k
   int r=0;
97
3.40k
   if (x>=(spx_int32_t)65536)
98
775
   {
99
775
      x >>= 16;
100
775
      r += 8;
101
775
   }
102
3.40k
   if (x>=256)
103
533
   {
104
533
      x >>= 8;
105
533
      r += 4;
106
533
   }
107
3.40k
   if (x>=16)
108
519
   {
109
519
      x >>= 4;
110
519
      r += 2;
111
519
   }
112
3.40k
   if (x>=4)
113
855
   {
114
855
      r += 1;
115
855
   }
116
3.40k
   return r;
117
3.40k
}
filters.c:spx_ilog4
Line
Count
Source
95
308k
{
96
308k
   int r=0;
97
308k
   if (x>=(spx_int32_t)65536)
98
109k
   {
99
109k
      x >>= 16;
100
109k
      r += 8;
101
109k
   }
102
308k
   if (x>=256)
103
92.1k
   {
104
92.1k
      x >>= 8;
105
92.1k
      r += 4;
106
92.1k
   }
107
308k
   if (x>=16)
108
69.7k
   {
109
69.7k
      x >>= 4;
110
69.7k
      r += 2;
111
69.7k
   }
112
308k
   if (x>=4)
113
95.5k
   {
114
95.5k
      r += 1;
115
95.5k
   }
116
308k
   return r;
117
308k
}
lsp.c:spx_ilog4
Line
Count
Source
95
235k
{
96
235k
   int r=0;
97
235k
   if (x>=(spx_int32_t)65536)
98
235k
   {
99
235k
      x >>= 16;
100
235k
      r += 8;
101
235k
   }
102
235k
   if (x>=256)
103
182k
   {
104
182k
      x >>= 8;
105
182k
      r += 4;
106
182k
   }
107
235k
   if (x>=16)
108
51.6k
   {
109
51.6k
      x >>= 4;
110
51.6k
      r += 2;
111
51.6k
   }
112
235k
   if (x>=4)
113
144k
   {
114
144k
      r += 1;
115
144k
   }
116
235k
   return r;
117
235k
}
ltp.c:spx_ilog4
Line
Count
Source
95
203k
{
96
203k
   int r=0;
97
203k
   if (x>=(spx_int32_t)65536)
98
112k
   {
99
112k
      x >>= 16;
100
112k
      r += 8;
101
112k
   }
102
203k
   if (x>=256)
103
72.2k
   {
104
72.2k
      x >>= 8;
105
72.2k
      r += 4;
106
72.2k
   }
107
203k
   if (x>=16)
108
79.2k
   {
109
79.2k
      x >>= 4;
110
79.2k
      r += 2;
111
79.2k
   }
112
203k
   if (x>=4)
113
83.0k
   {
114
83.0k
      r += 1;
115
83.0k
   }
116
203k
   return r;
117
203k
}
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.58M
{
124
4.58M
   spx_word32_t res;
125
4.58M
   *seed = 1664525 * *seed + 1013904223;
126
4.58M
   res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
127
4.58M
   return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
128
4.58M
}
nb_celp.c:speex_rand
Line
Count
Source
123
3.43M
{
124
3.43M
   spx_word32_t res;
125
3.43M
   *seed = 1664525 * *seed + 1013904223;
126
3.43M
   res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
127
3.43M
   return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
128
3.43M
}
sb_celp.c:speex_rand
Line
Count
Source
123
438k
{
124
438k
   spx_word32_t res;
125
438k
   *seed = 1664525 * *seed + 1013904223;
126
438k
   res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
127
438k
   return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
128
438k
}
cb_search.c:speex_rand
Line
Count
Source
123
712k
{
124
712k
   spx_word32_t res;
125
712k
   *seed = 1664525 * *seed + 1013904223;
126
712k
   res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std);
127
712k
   return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14));
128
712k
}
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
785k
{
144
785k
   int k;
145
785k
   spx_word32_t rt;
146
785k
   k = spx_ilog4(x)-6;
147
785k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
785k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
785k
   rt = VSHR32(rt,7-k);
150
785k
   return rt;
151
785k
}
stereo.c:spx_sqrt
Line
Count
Source
143
10.5k
{
144
10.5k
   int k;
145
10.5k
   spx_word32_t rt;
146
10.5k
   k = spx_ilog4(x)-6;
147
10.5k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
10.5k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
10.5k
   rt = VSHR32(rt,7-k);
150
10.5k
   return rt;
151
10.5k
}
nb_celp.c:spx_sqrt
Line
Count
Source
143
23.9k
{
144
23.9k
   int k;
145
23.9k
   spx_word32_t rt;
146
23.9k
   k = spx_ilog4(x)-6;
147
23.9k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
23.9k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
23.9k
   rt = VSHR32(rt,7-k);
150
23.9k
   return rt;
151
23.9k
}
sb_celp.c:spx_sqrt
Line
Count
Source
143
3.40k
{
144
3.40k
   int k;
145
3.40k
   spx_word32_t rt;
146
3.40k
   k = spx_ilog4(x)-6;
147
3.40k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
3.40k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
3.40k
   rt = VSHR32(rt,7-k);
150
3.40k
   return rt;
151
3.40k
}
Unexecuted instantiation: cb_search.c:spx_sqrt
filters.c:spx_sqrt
Line
Count
Source
143
308k
{
144
308k
   int k;
145
308k
   spx_word32_t rt;
146
308k
   k = spx_ilog4(x)-6;
147
308k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
308k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
308k
   rt = VSHR32(rt,7-k);
150
308k
   return rt;
151
308k
}
lsp.c:spx_sqrt
Line
Count
Source
143
235k
{
144
235k
   int k;
145
235k
   spx_word32_t rt;
146
235k
   k = spx_ilog4(x)-6;
147
235k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
235k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
235k
   rt = VSHR32(rt,7-k);
150
235k
   return rt;
151
235k
}
ltp.c:spx_sqrt
Line
Count
Source
143
203k
{
144
203k
   int k;
145
203k
   spx_word32_t rt;
146
203k
   k = spx_ilog4(x)-6;
147
203k
   x = VSHR32(x, (int)((unsigned)k<<1));
148
203k
   rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
149
203k
   rt = VSHR32(rt,7-k);
150
203k
   return rt;
151
203k
}
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
235k
{
162
235k
   int s=0;
163
235k
   spx_word16_t ret;
164
235k
   spx_word16_t sq;
165
235k
   if (x<0)
166
117k
   {
167
117k
      s=1;
168
117k
      x = NEG16(x);
169
117k
   }
170
235k
   x = SUB16(16384,x);
171
172
235k
   x = x >> 1;
173
235k
   sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3))))));
174
235k
   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
235k
   if (s)
178
117k
      ret = SUB16(25736,ret);
179
235k
   return ret;
180
235k
}
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
235k
{
162
235k
   int s=0;
163
235k
   spx_word16_t ret;
164
235k
   spx_word16_t sq;
165
235k
   if (x<0)
166
117k
   {
167
117k
      s=1;
168
117k
      x = NEG16(x);
169
117k
   }
170
235k
   x = SUB16(16384,x);
171
172
235k
   x = x >> 1;
173
235k
   sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3))))));
174
235k
   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
235k
   if (s)
178
117k
      ret = SUB16(25736,ret);
179
235k
   return ret;
180
235k
}
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.93M
{
190
3.93M
   spx_word16_t x2;
191
192
3.93M
   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.96M
      x = SUB16(25736,x);
198
1.96M
      x2 = MULT16_16_P13(x,x);
199
1.96M
      return SUB32(-K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
200
1.96M
   }
201
3.93M
}
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.63k
{
252
4.63k
   int integer;
253
4.63k
   spx_word16_t frac;
254
4.63k
   integer = SHR16(x,11);
255
4.63k
   if (integer>14)
256
0
      return 0x7fffffff;
257
4.63k
   else if (integer < -15)
258
0
      return 0;
259
4.63k
   frac = SHL16(x-SHL16(integer,11),3);
260
4.63k
   frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
261
4.63k
   return VSHR32(EXTEND32(frac), -integer-2);
262
4.63k
}
stereo.c:spx_exp2
Line
Count
Source
251
515
{
252
515
   int integer;
253
515
   spx_word16_t frac;
254
515
   integer = SHR16(x,11);
255
515
   if (integer>14)
256
0
      return 0x7fffffff;
257
515
   else if (integer < -15)
258
0
      return 0;
259
515
   frac = SHL16(x-SHL16(integer,11),3);
260
515
   frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
261
515
   return VSHR32(EXTEND32(frac), -integer-2);
262
515
}
Unexecuted instantiation: nb_celp.c:spx_exp2
sb_celp.c:spx_exp2
Line
Count
Source
251
4.12k
{
252
4.12k
   int integer;
253
4.12k
   spx_word16_t frac;
254
4.12k
   integer = SHR16(x,11);
255
4.12k
   if (integer>14)
256
0
      return 0x7fffffff;
257
4.12k
   else if (integer < -15)
258
0
      return 0;
259
4.12k
   frac = SHL16(x-SHL16(integer,11),3);
260
4.12k
   frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac))))));
261
4.12k
   return VSHR32(EXTEND32(frac), -integer-2);
262
4.12k
}
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.63k
{
267
4.63k
   if (x>21290)
268
0
      return 0x7fffffff;
269
4.63k
   else if (x<-21290)
270
0
      return 0;
271
4.63k
   else
272
4.63k
      return spx_exp2(MULT16_16_P14(23637,x));
273
4.63k
}
stereo.c:spx_exp
Line
Count
Source
266
515
{
267
515
   if (x>21290)
268
0
      return 0x7fffffff;
269
515
   else if (x<-21290)
270
0
      return 0;
271
515
   else
272
515
      return spx_exp2(MULT16_16_P14(23637,x));
273
515
}
Unexecuted instantiation: nb_celp.c:spx_exp
sb_celp.c:spx_exp
Line
Count
Source
266
4.12k
{
267
4.12k
   if (x>21290)
268
0
      return 0x7fffffff;
269
4.12k
   else if (x<-21290)
270
0
      return 0;
271
4.12k
   else
272
4.12k
      return spx_exp2(MULT16_16_P14(23637,x));
273
4.12k
}
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.93M
#define SPX_PI_2 1.5707963268
316
static inline spx_word16_t spx_cos(spx_word16_t x)
317
3.93M
{
318
3.93M
   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.96M
      x = M_PI-x;
324
1.96M
      x *= x;
325
1.96M
      return NEG16(C1 + x*(C2+x*(C3+C4*x)));
326
1.96M
   }
327
3.93M
}
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.93M
{
318
3.93M
   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.96M
      x = M_PI-x;
324
1.96M
      x *= x;
325
1.96M
      return NEG16(C1 + x*(C2+x*(C3+C4*x)));
326
1.96M
   }
327
3.93M
}
Unexecuted instantiation: ltp.c:spx_cos
328
329
#endif
330
331
332
#endif