Coverage Report

Created: 2025-12-14 06:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/speex/libspeex/quant_lsp.c
Line
Count
Source
1
/* Copyright (C) 2002 Jean-Marc Valin
2
   File: quant_lsp.c
3
   LSP vector quantization
4
5
   Redistribution and use in source and binary forms, with or without
6
   modification, are permitted provided that the following conditions
7
   are met:
8
9
   - Redistributions of source code must retain the above copyright
10
   notice, this list of conditions and the following disclaimer.
11
12
   - Redistributions in binary form must reproduce the above copyright
13
   notice, this list of conditions and the following disclaimer in the
14
   documentation and/or other materials provided with the distribution.
15
16
   - Neither the name of the Xiph.org Foundation nor the names of its
17
   contributors may be used to endorse or promote products derived from
18
   this software without specific prior written permission.
19
20
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
24
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
#ifdef HAVE_CONFIG_H
34
#include "config.h"
35
#endif
36
37
#include "quant_lsp.h"
38
#include "os_support.h"
39
#include <math.h>
40
#ifndef M_PI
41
#define M_PI 3.14159265358979323846
42
#endif
43
44
#include "arch.h"
45
46
#ifdef BFIN_ASM
47
#include "quant_lsp_bfin.h"
48
#endif
49
50
#ifdef FIXED_POINT
51
52
229k
#define LSP_LINEAR(i) (SHL16(i+1,11))
53
49.1k
#define LSP_LINEAR_HIGH(i) (ADD16(MULT16_16_16(i,2560),6144))
54
229k
#define LSP_DIV_256(x) (SHL16((spx_word16_t)x, 5))
55
229k
#define LSP_DIV_512(x) (SHL16((spx_word16_t)x, 4))
56
#define LSP_DIV_1024(x) (SHL16((spx_word16_t)x, 3))
57
31.8k
#define LSP_PI 25736
58
59
#else
60
61
229k
#define LSP_LINEAR(i) (.25*(i)+.25)
62
49.1k
#define LSP_LINEAR_HIGH(i) (.3125*(i)+.75)
63
95.3k
#define LSP_SCALE 256.
64
229k
#define LSP_DIV_256(x) (0.0039062*(x))
65
229k
#define LSP_DIV_512(x) (0.0019531*(x))
66
#define LSP_DIV_1024(x) (0.00097656*(x))
67
31.8k
#define LSP_PI M_PI
68
69
#endif
70
71
#ifndef DISABLE_ENCODER
72
static void compute_quant_weights(spx_lsp_t *qlsp, spx_word16_t *quant_weight, int order)
73
63.6k
{
74
63.6k
   int i;
75
63.6k
   spx_word16_t tmp1, tmp2;
76
666k
   for (i=0;i<order;i++)
77
602k
   {
78
602k
      if (i==0)
79
63.6k
         tmp1 = qlsp[i];
80
539k
      else
81
539k
         tmp1 = qlsp[i]-qlsp[i-1];
82
602k
      if (i==order-1)
83
63.6k
         tmp2 = LSP_PI-qlsp[i];
84
539k
      else
85
539k
         tmp2 = qlsp[i+1]-qlsp[i];
86
602k
      if (tmp2<tmp1)
87
314k
         tmp1 = tmp2;
88
#ifdef FIXED_POINT
89
301k
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
      quant_weight[i] = 10/(.04+tmp1);
92
#endif
93
602k
   }
94
95
63.6k
}
quant_lsp.c:compute_quant_weights
Line
Count
Source
73
31.8k
{
74
31.8k
   int i;
75
31.8k
   spx_word16_t tmp1, tmp2;
76
333k
   for (i=0;i<order;i++)
77
301k
   {
78
301k
      if (i==0)
79
31.8k
         tmp1 = qlsp[i];
80
269k
      else
81
269k
         tmp1 = qlsp[i]-qlsp[i-1];
82
301k
      if (i==order-1)
83
31.8k
         tmp2 = LSP_PI-qlsp[i];
84
269k
      else
85
269k
         tmp2 = qlsp[i+1]-qlsp[i];
86
301k
      if (tmp2<tmp1)
87
157k
         tmp1 = tmp2;
88
#ifdef FIXED_POINT
89
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
301k
      quant_weight[i] = 10/(.04+tmp1);
92
301k
#endif
93
301k
   }
94
95
31.8k
}
quant_lsp.c:compute_quant_weights
Line
Count
Source
73
31.8k
{
74
31.8k
   int i;
75
31.8k
   spx_word16_t tmp1, tmp2;
76
333k
   for (i=0;i<order;i++)
77
301k
   {
78
301k
      if (i==0)
79
31.8k
         tmp1 = qlsp[i];
80
269k
      else
81
269k
         tmp1 = qlsp[i]-qlsp[i-1];
82
301k
      if (i==order-1)
83
31.8k
         tmp2 = LSP_PI-qlsp[i];
84
269k
      else
85
269k
         tmp2 = qlsp[i+1]-qlsp[i];
86
301k
      if (tmp2<tmp1)
87
157k
         tmp1 = tmp2;
88
301k
#ifdef FIXED_POINT
89
301k
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
      quant_weight[i] = 10/(.04+tmp1);
92
#endif
93
301k
   }
94
95
31.8k
}
96
97
/* Note: x is modified*/
98
#ifndef OVERRIDE_LSP_QUANT
99
static int lsp_quant(spx_word16_t *x, const signed char *cdbk, int nbVec, int nbDim)
100
63.6k
{
101
63.6k
   int i,j;
102
63.6k
   spx_word32_t dist;
103
63.6k
   spx_word16_t tmp;
104
63.6k
   spx_word32_t best_dist=VERY_LARGE32;
105
63.6k
   int best_id=0;
106
63.6k
   const signed char *ptr=cdbk;
107
4.13M
   for (i=0;i<nbVec;i++)
108
4.07M
   {
109
4.07M
      dist=0;
110
42.6M
      for (j=0;j<nbDim;j++)
111
38.5M
      {
112
38.5M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
38.5M
         dist=MAC16_16(dist,tmp,tmp);
114
38.5M
      }
115
4.07M
      if (dist<best_dist)
116
217k
      {
117
217k
         best_dist=dist;
118
217k
         best_id=i;
119
217k
      }
120
4.07M
   }
121
122
666k
   for (j=0;j<nbDim;j++)
123
602k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
63.6k
   return best_id;
126
63.6k
}
quant_lsp.c:lsp_quant
Line
Count
Source
100
31.8k
{
101
31.8k
   int i,j;
102
31.8k
   spx_word32_t dist;
103
31.8k
   spx_word16_t tmp;
104
31.8k
   spx_word32_t best_dist=VERY_LARGE32;
105
31.8k
   int best_id=0;
106
31.8k
   const signed char *ptr=cdbk;
107
2.06M
   for (i=0;i<nbVec;i++)
108
2.03M
   {
109
2.03M
      dist=0;
110
21.3M
      for (j=0;j<nbDim;j++)
111
19.2M
      {
112
19.2M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
19.2M
         dist=MAC16_16(dist,tmp,tmp);
114
19.2M
      }
115
2.03M
      if (dist<best_dist)
116
108k
      {
117
108k
         best_dist=dist;
118
108k
         best_id=i;
119
108k
      }
120
2.03M
   }
121
122
333k
   for (j=0;j<nbDim;j++)
123
301k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
31.8k
   return best_id;
126
31.8k
}
quant_lsp.c:lsp_quant
Line
Count
Source
100
31.8k
{
101
31.8k
   int i,j;
102
31.8k
   spx_word32_t dist;
103
31.8k
   spx_word16_t tmp;
104
31.8k
   spx_word32_t best_dist=VERY_LARGE32;
105
31.8k
   int best_id=0;
106
31.8k
   const signed char *ptr=cdbk;
107
2.06M
   for (i=0;i<nbVec;i++)
108
2.03M
   {
109
2.03M
      dist=0;
110
21.3M
      for (j=0;j<nbDim;j++)
111
19.2M
      {
112
19.2M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
19.2M
         dist=MAC16_16(dist,tmp,tmp);
114
19.2M
      }
115
2.03M
      if (dist<best_dist)
116
108k
      {
117
108k
         best_dist=dist;
118
108k
         best_id=i;
119
108k
      }
120
2.03M
   }
121
122
333k
   for (j=0;j<nbDim;j++)
123
301k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
31.8k
   return best_id;
126
31.8k
}
127
#endif
128
129
/* Note: x is modified*/
130
#ifndef OVERRIDE_LSP_WEIGHT_QUANT
131
static int lsp_weight_quant(spx_word16_t *x, spx_word16_t *weight, const signed char *cdbk, int nbVec, int nbDim)
132
129k
{
133
129k
   int i,j;
134
129k
   spx_word32_t dist;
135
129k
   spx_word16_t tmp;
136
129k
   spx_word32_t best_dist=VERY_LARGE32;
137
129k
   int best_id=0;
138
129k
   const signed char *ptr=cdbk;
139
8.43M
   for (i=0;i<nbVec;i++)
140
8.30M
   {
141
8.30M
      dist=0;
142
53.0M
      for (j=0;j<nbDim;j++)
143
44.7M
      {
144
44.7M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
44.7M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
44.7M
      }
147
8.30M
      if (dist<best_dist)
148
658k
      {
149
658k
         best_dist=dist;
150
658k
         best_id=i;
151
658k
      }
152
8.30M
   }
153
154
828k
   for (j=0;j<nbDim;j++)
155
699k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
129k
   return best_id;
157
129k
}
quant_lsp.c:lsp_weight_quant
Line
Count
Source
132
64.8k
{
133
64.8k
   int i,j;
134
64.8k
   spx_word32_t dist;
135
64.8k
   spx_word16_t tmp;
136
64.8k
   spx_word32_t best_dist=VERY_LARGE32;
137
64.8k
   int best_id=0;
138
64.8k
   const signed char *ptr=cdbk;
139
4.21M
   for (i=0;i<nbVec;i++)
140
4.15M
   {
141
4.15M
      dist=0;
142
26.5M
      for (j=0;j<nbDim;j++)
143
22.3M
      {
144
22.3M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
22.3M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
22.3M
      }
147
4.15M
      if (dist<best_dist)
148
329k
      {
149
329k
         best_dist=dist;
150
329k
         best_id=i;
151
329k
      }
152
4.15M
   }
153
154
414k
   for (j=0;j<nbDim;j++)
155
349k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
64.8k
   return best_id;
157
64.8k
}
quant_lsp.c:lsp_weight_quant
Line
Count
Source
132
64.8k
{
133
64.8k
   int i,j;
134
64.8k
   spx_word32_t dist;
135
64.8k
   spx_word16_t tmp;
136
64.8k
   spx_word32_t best_dist=VERY_LARGE32;
137
64.8k
   int best_id=0;
138
64.8k
   const signed char *ptr=cdbk;
139
4.21M
   for (i=0;i<nbVec;i++)
140
4.15M
   {
141
4.15M
      dist=0;
142
26.5M
      for (j=0;j<nbDim;j++)
143
22.3M
      {
144
22.3M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
22.3M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
22.3M
      }
147
4.15M
      if (dist<best_dist)
148
329k
      {
149
329k
         best_dist=dist;
150
329k
         best_id=i;
151
329k
      }
152
4.15M
   }
153
154
414k
   for (j=0;j<nbDim;j++)
155
349k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
64.8k
   return best_id;
157
64.8k
}
158
#endif
159
160
void lsp_quant_nb(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
161
4.81k
{
162
4.81k
   int i;
163
4.81k
   int id;
164
4.81k
   spx_word16_t quant_weight[10];
165
166
52.9k
   for (i=0;i<order;i++)
167
48.1k
      qlsp[i]=lsp[i];
168
169
4.81k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
52.9k
   for (i=0;i<order;i++)
172
48.1k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
173
174
#ifndef FIXED_POINT
175
14.4k
   for (i=0;i<order;i++)
176
13.1k
      qlsp[i] = LSP_SCALE*qlsp[i];
177
#endif
178
4.81k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
4.81k
   speex_bits_pack(bits, id, 6);
180
181
52.9k
   for (i=0;i<order;i++)
182
48.1k
      qlsp[i]*=2;
183
184
4.81k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
4.81k
   speex_bits_pack(bits, id, 6);
186
187
28.8k
   for (i=0;i<5;i++)
188
24.0k
      qlsp[i]*=2;
189
190
4.81k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
4.81k
   speex_bits_pack(bits, id, 6);
192
193
4.81k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
4.81k
   speex_bits_pack(bits, id, 6);
195
196
28.8k
   for (i=5;i<10;i++)
197
24.0k
      qlsp[i]*=2;
198
199
4.81k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
4.81k
   speex_bits_pack(bits, id, 6);
201
202
#ifdef FIXED_POINT
203
38.5k
   for (i=0;i<order;i++)
204
35.0k
      qlsp[i]=PSHR16(qlsp[i],2);
205
#else
206
14.4k
   for (i=0;i<order;i++)
207
13.1k
      qlsp[i]=qlsp[i] * .00097656;
208
#endif
209
210
52.9k
   for (i=0;i<order;i++)
211
48.1k
      qlsp[i]=lsp[i]-qlsp[i];
212
4.81k
}
lsp_quant_nb
Line
Count
Source
161
1.31k
{
162
1.31k
   int i;
163
1.31k
   int id;
164
1.31k
   spx_word16_t quant_weight[10];
165
166
14.4k
   for (i=0;i<order;i++)
167
13.1k
      qlsp[i]=lsp[i];
168
169
1.31k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
14.4k
   for (i=0;i<order;i++)
172
13.1k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
173
174
1.31k
#ifndef FIXED_POINT
175
14.4k
   for (i=0;i<order;i++)
176
13.1k
      qlsp[i] = LSP_SCALE*qlsp[i];
177
1.31k
#endif
178
1.31k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
1.31k
   speex_bits_pack(bits, id, 6);
180
181
14.4k
   for (i=0;i<order;i++)
182
13.1k
      qlsp[i]*=2;
183
184
1.31k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
1.31k
   speex_bits_pack(bits, id, 6);
186
187
7.87k
   for (i=0;i<5;i++)
188
6.56k
      qlsp[i]*=2;
189
190
1.31k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
1.31k
   speex_bits_pack(bits, id, 6);
192
193
1.31k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
1.31k
   speex_bits_pack(bits, id, 6);
195
196
7.87k
   for (i=5;i<10;i++)
197
6.56k
      qlsp[i]*=2;
198
199
1.31k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
1.31k
   speex_bits_pack(bits, id, 6);
201
202
#ifdef FIXED_POINT
203
   for (i=0;i<order;i++)
204
      qlsp[i]=PSHR16(qlsp[i],2);
205
#else
206
14.4k
   for (i=0;i<order;i++)
207
13.1k
      qlsp[i]=qlsp[i] * .00097656;
208
1.31k
#endif
209
210
14.4k
   for (i=0;i<order;i++)
211
13.1k
      qlsp[i]=lsp[i]-qlsp[i];
212
1.31k
}
lsp_quant_nb
Line
Count
Source
161
3.50k
{
162
3.50k
   int i;
163
3.50k
   int id;
164
3.50k
   spx_word16_t quant_weight[10];
165
166
38.5k
   for (i=0;i<order;i++)
167
35.0k
      qlsp[i]=lsp[i];
168
169
3.50k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
38.5k
   for (i=0;i<order;i++)
172
35.0k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
173
174
#ifndef FIXED_POINT
175
   for (i=0;i<order;i++)
176
      qlsp[i] = LSP_SCALE*qlsp[i];
177
#endif
178
3.50k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
3.50k
   speex_bits_pack(bits, id, 6);
180
181
38.5k
   for (i=0;i<order;i++)
182
35.0k
      qlsp[i]*=2;
183
184
3.50k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
3.50k
   speex_bits_pack(bits, id, 6);
186
187
21.0k
   for (i=0;i<5;i++)
188
17.5k
      qlsp[i]*=2;
189
190
3.50k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
3.50k
   speex_bits_pack(bits, id, 6);
192
193
3.50k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
3.50k
   speex_bits_pack(bits, id, 6);
195
196
21.0k
   for (i=5;i<10;i++)
197
17.5k
      qlsp[i]*=2;
198
199
3.50k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
3.50k
   speex_bits_pack(bits, id, 6);
201
202
3.50k
#ifdef FIXED_POINT
203
38.5k
   for (i=0;i<order;i++)
204
35.0k
      qlsp[i]=PSHR16(qlsp[i],2);
205
#else
206
   for (i=0;i<order;i++)
207
      qlsp[i]=qlsp[i] * .00097656;
208
#endif
209
210
38.5k
   for (i=0;i<order;i++)
211
35.0k
      qlsp[i]=lsp[i]-qlsp[i];
212
3.50k
}
213
#endif /* DISABLE_ENCODER */
214
215
#ifndef DISABLE_DECODER
216
void lsp_unquant_nb(spx_lsp_t *lsp, int order, SpeexBits *bits)
217
9.88k
{
218
9.88k
   int i, id;
219
108k
   for (i=0;i<order;i++)
220
98.8k
      lsp[i]=LSP_LINEAR(i);
221
222
223
9.88k
   id=speex_bits_unpack_unsigned(bits, 6);
224
108k
   for (i=0;i<10;i++)
225
98.8k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
9.88k
   id=speex_bits_unpack_unsigned(bits, 6);
228
59.3k
   for (i=0;i<5;i++)
229
49.4k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
9.88k
   id=speex_bits_unpack_unsigned(bits, 6);
232
59.3k
   for (i=0;i<5;i++)
233
49.4k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
9.88k
   id=speex_bits_unpack_unsigned(bits, 6);
236
59.3k
   for (i=0;i<5;i++)
237
49.4k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
9.88k
   id=speex_bits_unpack_unsigned(bits, 6);
240
59.3k
   for (i=0;i<5;i++)
241
49.4k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
9.88k
}
lsp_unquant_nb
Line
Count
Source
217
4.94k
{
218
4.94k
   int i, id;
219
54.3k
   for (i=0;i<order;i++)
220
49.4k
      lsp[i]=LSP_LINEAR(i);
221
222
223
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
224
54.3k
   for (i=0;i<10;i++)
225
49.4k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
228
29.6k
   for (i=0;i<5;i++)
229
24.7k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
232
29.6k
   for (i=0;i<5;i++)
233
24.7k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
236
29.6k
   for (i=0;i<5;i++)
237
24.7k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
240
29.6k
   for (i=0;i<5;i++)
241
24.7k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
4.94k
}
lsp_unquant_nb
Line
Count
Source
217
4.94k
{
218
4.94k
   int i, id;
219
54.3k
   for (i=0;i<order;i++)
220
49.4k
      lsp[i]=LSP_LINEAR(i);
221
222
223
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
224
54.3k
   for (i=0;i<10;i++)
225
49.4k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
228
29.6k
   for (i=0;i<5;i++)
229
24.7k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
232
29.6k
   for (i=0;i<5;i++)
233
24.7k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
236
29.6k
   for (i=0;i<5;i++)
237
24.7k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
4.94k
   id=speex_bits_unpack_unsigned(bits, 6);
240
29.6k
   for (i=0;i<5;i++)
241
24.7k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
4.94k
}
243
#endif /* DISABLE_DECODER */
244
245
#ifndef DISABLE_ENCODER
246
void lsp_quant_lbr(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
247
18.5k
{
248
18.5k
   int i;
249
18.5k
   int id;
250
18.5k
   spx_word16_t quant_weight[10];
251
252
204k
   for (i=0;i<order;i++)
253
185k
      qlsp[i]=lsp[i];
254
255
18.5k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
204k
   for (i=0;i<order;i++)
258
185k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
259
#ifndef FIXED_POINT
260
63.9k
   for (i=0;i<order;i++)
261
58.1k
      qlsp[i]=qlsp[i]*LSP_SCALE;
262
#endif
263
18.5k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
18.5k
   speex_bits_pack(bits, id, 6);
265
266
204k
   for (i=0;i<order;i++)
267
185k
      qlsp[i]*=2;
268
269
18.5k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
18.5k
   speex_bits_pack(bits, id, 6);
271
272
18.5k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
18.5k
   speex_bits_pack(bits, id, 6);
274
275
#ifdef FIXED_POINT
276
140k
   for (i=0;i<order;i++)
277
127k
      qlsp[i] = PSHR16(qlsp[i],1);
278
#else
279
63.9k
   for (i=0;i<order;i++)
280
58.1k
      qlsp[i] = qlsp[i]*0.0019531;
281
#endif
282
283
204k
   for (i=0;i<order;i++)
284
185k
      qlsp[i]=lsp[i]-qlsp[i];
285
18.5k
}
lsp_quant_lbr
Line
Count
Source
247
5.81k
{
248
5.81k
   int i;
249
5.81k
   int id;
250
5.81k
   spx_word16_t quant_weight[10];
251
252
63.9k
   for (i=0;i<order;i++)
253
58.1k
      qlsp[i]=lsp[i];
254
255
5.81k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
63.9k
   for (i=0;i<order;i++)
258
58.1k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
259
5.81k
#ifndef FIXED_POINT
260
63.9k
   for (i=0;i<order;i++)
261
58.1k
      qlsp[i]=qlsp[i]*LSP_SCALE;
262
5.81k
#endif
263
5.81k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
5.81k
   speex_bits_pack(bits, id, 6);
265
266
63.9k
   for (i=0;i<order;i++)
267
58.1k
      qlsp[i]*=2;
268
269
5.81k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
5.81k
   speex_bits_pack(bits, id, 6);
271
272
5.81k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
5.81k
   speex_bits_pack(bits, id, 6);
274
275
#ifdef FIXED_POINT
276
   for (i=0;i<order;i++)
277
      qlsp[i] = PSHR16(qlsp[i],1);
278
#else
279
63.9k
   for (i=0;i<order;i++)
280
58.1k
      qlsp[i] = qlsp[i]*0.0019531;
281
5.81k
#endif
282
283
63.9k
   for (i=0;i<order;i++)
284
58.1k
      qlsp[i]=lsp[i]-qlsp[i];
285
5.81k
}
lsp_quant_lbr
Line
Count
Source
247
12.7k
{
248
12.7k
   int i;
249
12.7k
   int id;
250
12.7k
   spx_word16_t quant_weight[10];
251
252
140k
   for (i=0;i<order;i++)
253
127k
      qlsp[i]=lsp[i];
254
255
12.7k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
140k
   for (i=0;i<order;i++)
258
127k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
259
#ifndef FIXED_POINT
260
   for (i=0;i<order;i++)
261
      qlsp[i]=qlsp[i]*LSP_SCALE;
262
#endif
263
12.7k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
12.7k
   speex_bits_pack(bits, id, 6);
265
266
140k
   for (i=0;i<order;i++)
267
127k
      qlsp[i]*=2;
268
269
12.7k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
12.7k
   speex_bits_pack(bits, id, 6);
271
272
12.7k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
12.7k
   speex_bits_pack(bits, id, 6);
274
275
12.7k
#ifdef FIXED_POINT
276
140k
   for (i=0;i<order;i++)
277
127k
      qlsp[i] = PSHR16(qlsp[i],1);
278
#else
279
   for (i=0;i<order;i++)
280
      qlsp[i] = qlsp[i]*0.0019531;
281
#endif
282
283
140k
   for (i=0;i<order;i++)
284
127k
      qlsp[i]=lsp[i]-qlsp[i];
285
12.7k
}
286
#endif /* DISABLE_ENCODER */
287
288
#ifndef DISABLE_DECODER
289
void lsp_unquant_lbr(spx_lsp_t *lsp, int order, SpeexBits *bits)
290
35.9k
{
291
35.9k
   int i, id;
292
395k
   for (i=0;i<order;i++)
293
359k
      lsp[i]=LSP_LINEAR(i);
294
295
296
35.9k
   id=speex_bits_unpack_unsigned(bits, 6);
297
395k
   for (i=0;i<10;i++)
298
359k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
35.9k
   id=speex_bits_unpack_unsigned(bits, 6);
301
215k
   for (i=0;i<5;i++)
302
179k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
35.9k
   id=speex_bits_unpack_unsigned(bits, 6);
305
215k
   for (i=0;i<5;i++)
306
179k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
35.9k
}
lsp_unquant_lbr
Line
Count
Source
290
17.9k
{
291
17.9k
   int i, id;
292
197k
   for (i=0;i<order;i++)
293
179k
      lsp[i]=LSP_LINEAR(i);
294
295
296
17.9k
   id=speex_bits_unpack_unsigned(bits, 6);
297
197k
   for (i=0;i<10;i++)
298
179k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
17.9k
   id=speex_bits_unpack_unsigned(bits, 6);
301
107k
   for (i=0;i<5;i++)
302
89.9k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
17.9k
   id=speex_bits_unpack_unsigned(bits, 6);
305
107k
   for (i=0;i<5;i++)
306
89.9k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
17.9k
}
lsp_unquant_lbr
Line
Count
Source
290
17.9k
{
291
17.9k
   int i, id;
292
197k
   for (i=0;i<order;i++)
293
179k
      lsp[i]=LSP_LINEAR(i);
294
295
296
17.9k
   id=speex_bits_unpack_unsigned(bits, 6);
297
197k
   for (i=0;i<10;i++)
298
179k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
17.9k
   id=speex_bits_unpack_unsigned(bits, 6);
301
107k
   for (i=0;i<5;i++)
302
89.9k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
17.9k
   id=speex_bits_unpack_unsigned(bits, 6);
305
107k
   for (i=0;i<5;i++)
306
89.9k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
17.9k
}
309
#endif /* DISABLE_DECODER */
310
311
#ifndef DISABLE_WIDEBAND
312
extern const signed char high_lsp_cdbk[];
313
extern const signed char high_lsp_cdbk2[];
314
315
#ifndef DISABLE_ENCODER
316
void lsp_quant_high(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
317
8.44k
{
318
8.44k
   int i;
319
8.44k
   int id;
320
8.44k
   spx_word16_t quant_weight[10];
321
322
76.0k
   for (i=0;i<order;i++)
323
67.5k
      qlsp[i]=lsp[i];
324
325
8.44k
   compute_quant_weights(qlsp, quant_weight, order);
326
327
   /*   quant_weight[0] = 10/(qlsp[1]-qlsp[0]);
328
   quant_weight[order-1] = 10/(qlsp[order-1]-qlsp[order-2]);
329
   for (i=1;i<order-1;i++)
330
   {
331
      tmp1 = 10/(qlsp[i]-qlsp[i-1]);
332
      tmp2 = 10/(qlsp[i+1]-qlsp[i]);
333
      quant_weight[i] = tmp1 > tmp2 ? tmp1 : tmp2;
334
      }*/
335
336
76.0k
   for (i=0;i<order;i++)
337
67.5k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR_HIGH(i));
338
#ifndef FIXED_POINT
339
27.1k
   for (i=0;i<order;i++)
340
24.1k
      qlsp[i] = qlsp[i]*LSP_SCALE;
341
#endif
342
8.44k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
8.44k
   speex_bits_pack(bits, id, 6);
344
345
76.0k
   for (i=0;i<order;i++)
346
67.5k
      qlsp[i]*=2;
347
348
8.44k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
8.44k
   speex_bits_pack(bits, id, 6);
350
351
#ifdef FIXED_POINT
352
48.8k
   for (i=0;i<order;i++)
353
43.4k
      qlsp[i] = PSHR16(qlsp[i],1);
354
#else
355
27.1k
   for (i=0;i<order;i++)
356
24.1k
      qlsp[i] = qlsp[i]*0.0019531;
357
#endif
358
359
76.0k
   for (i=0;i<order;i++)
360
67.5k
      qlsp[i]=lsp[i]-qlsp[i];
361
8.44k
}
lsp_quant_high
Line
Count
Source
317
3.01k
{
318
3.01k
   int i;
319
3.01k
   int id;
320
3.01k
   spx_word16_t quant_weight[10];
321
322
27.1k
   for (i=0;i<order;i++)
323
24.1k
      qlsp[i]=lsp[i];
324
325
3.01k
   compute_quant_weights(qlsp, quant_weight, order);
326
327
   /*   quant_weight[0] = 10/(qlsp[1]-qlsp[0]);
328
   quant_weight[order-1] = 10/(qlsp[order-1]-qlsp[order-2]);
329
   for (i=1;i<order-1;i++)
330
   {
331
      tmp1 = 10/(qlsp[i]-qlsp[i-1]);
332
      tmp2 = 10/(qlsp[i+1]-qlsp[i]);
333
      quant_weight[i] = tmp1 > tmp2 ? tmp1 : tmp2;
334
      }*/
335
336
27.1k
   for (i=0;i<order;i++)
337
24.1k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR_HIGH(i));
338
3.01k
#ifndef FIXED_POINT
339
27.1k
   for (i=0;i<order;i++)
340
24.1k
      qlsp[i] = qlsp[i]*LSP_SCALE;
341
3.01k
#endif
342
3.01k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
3.01k
   speex_bits_pack(bits, id, 6);
344
345
27.1k
   for (i=0;i<order;i++)
346
24.1k
      qlsp[i]*=2;
347
348
3.01k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
3.01k
   speex_bits_pack(bits, id, 6);
350
351
#ifdef FIXED_POINT
352
   for (i=0;i<order;i++)
353
      qlsp[i] = PSHR16(qlsp[i],1);
354
#else
355
27.1k
   for (i=0;i<order;i++)
356
24.1k
      qlsp[i] = qlsp[i]*0.0019531;
357
3.01k
#endif
358
359
27.1k
   for (i=0;i<order;i++)
360
24.1k
      qlsp[i]=lsp[i]-qlsp[i];
361
3.01k
}
lsp_quant_high
Line
Count
Source
317
5.43k
{
318
5.43k
   int i;
319
5.43k
   int id;
320
5.43k
   spx_word16_t quant_weight[10];
321
322
48.8k
   for (i=0;i<order;i++)
323
43.4k
      qlsp[i]=lsp[i];
324
325
5.43k
   compute_quant_weights(qlsp, quant_weight, order);
326
327
   /*   quant_weight[0] = 10/(qlsp[1]-qlsp[0]);
328
   quant_weight[order-1] = 10/(qlsp[order-1]-qlsp[order-2]);
329
   for (i=1;i<order-1;i++)
330
   {
331
      tmp1 = 10/(qlsp[i]-qlsp[i-1]);
332
      tmp2 = 10/(qlsp[i+1]-qlsp[i]);
333
      quant_weight[i] = tmp1 > tmp2 ? tmp1 : tmp2;
334
      }*/
335
336
48.8k
   for (i=0;i<order;i++)
337
43.4k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR_HIGH(i));
338
#ifndef FIXED_POINT
339
   for (i=0;i<order;i++)
340
      qlsp[i] = qlsp[i]*LSP_SCALE;
341
#endif
342
5.43k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
5.43k
   speex_bits_pack(bits, id, 6);
344
345
48.8k
   for (i=0;i<order;i++)
346
43.4k
      qlsp[i]*=2;
347
348
5.43k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
5.43k
   speex_bits_pack(bits, id, 6);
350
351
5.43k
#ifdef FIXED_POINT
352
48.8k
   for (i=0;i<order;i++)
353
43.4k
      qlsp[i] = PSHR16(qlsp[i],1);
354
#else
355
   for (i=0;i<order;i++)
356
      qlsp[i] = qlsp[i]*0.0019531;
357
#endif
358
359
48.8k
   for (i=0;i<order;i++)
360
43.4k
      qlsp[i]=lsp[i]-qlsp[i];
361
5.43k
}
362
#endif /* DISABLE_ENCODER */
363
364
365
#ifndef DISABLE_DECODER
366
void lsp_unquant_high(spx_lsp_t *lsp, int order, SpeexBits *bits)
367
12.2k
{
368
369
12.2k
   int i, id;
370
110k
   for (i=0;i<order;i++)
371
98.3k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
12.2k
   id=speex_bits_unpack_unsigned(bits, 6);
375
110k
   for (i=0;i<order;i++)
376
98.3k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
12.2k
   id=speex_bits_unpack_unsigned(bits, 6);
380
110k
   for (i=0;i<order;i++)
381
98.3k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
12.2k
}
lsp_unquant_high
Line
Count
Source
367
6.14k
{
368
369
6.14k
   int i, id;
370
55.3k
   for (i=0;i<order;i++)
371
49.1k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
6.14k
   id=speex_bits_unpack_unsigned(bits, 6);
375
55.3k
   for (i=0;i<order;i++)
376
49.1k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
6.14k
   id=speex_bits_unpack_unsigned(bits, 6);
380
55.3k
   for (i=0;i<order;i++)
381
49.1k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
6.14k
}
lsp_unquant_high
Line
Count
Source
367
6.14k
{
368
369
6.14k
   int i, id;
370
55.3k
   for (i=0;i<order;i++)
371
49.1k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
6.14k
   id=speex_bits_unpack_unsigned(bits, 6);
375
55.3k
   for (i=0;i<order;i++)
376
49.1k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
6.14k
   id=speex_bits_unpack_unsigned(bits, 6);
380
55.3k
   for (i=0;i<order;i++)
381
49.1k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
6.14k
}
383
#endif /* DISABLE_DECODER */
384
385
#endif /* DISABLE_WIDEBAND */
386