Coverage Report

Created: 2025-07-23 06:50

/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
240k
#define LSP_LINEAR(i) (SHL16(i+1,11))
53
54.7k
#define LSP_LINEAR_HIGH(i) (ADD16(MULT16_16_16(i,2560),6144))
54
245k
#define LSP_DIV_256(x) (SHL16((spx_word16_t)x, 5))
55
245k
#define LSP_DIV_512(x) (SHL16((spx_word16_t)x, 4))
56
#define LSP_DIV_1024(x) (SHL16((spx_word16_t)x, 3))
57
36.1k
#define LSP_PI 25736
58
59
#else
60
61
240k
#define LSP_LINEAR(i) (.25*(i)+.25)
62
54.7k
#define LSP_LINEAR_HIGH(i) (.3125*(i)+.75)
63
99.6k
#define LSP_SCALE 256.
64
245k
#define LSP_DIV_256(x) (0.0039062*(x))
65
245k
#define LSP_DIV_512(x) (0.0019531*(x))
66
#define LSP_DIV_1024(x) (0.00097656*(x))
67
36.1k
#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
72.3k
{
74
72.3k
   int i;
75
72.3k
   spx_word16_t tmp1, tmp2;
76
758k
   for (i=0;i<order;i++)
77
686k
   {
78
686k
      if (i==0)
79
72.3k
         tmp1 = qlsp[i];
80
613k
      else
81
613k
         tmp1 = qlsp[i]-qlsp[i-1];
82
686k
      if (i==order-1)
83
72.3k
         tmp2 = LSP_PI-qlsp[i];
84
613k
      else
85
613k
         tmp2 = qlsp[i+1]-qlsp[i];
86
686k
      if (tmp2<tmp1)
87
356k
         tmp1 = tmp2;
88
#ifdef FIXED_POINT
89
343k
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
      quant_weight[i] = 10/(.04+tmp1);
92
#endif
93
686k
   }
94
95
72.3k
}
quant_lsp.c:compute_quant_weights
Line
Count
Source
73
36.1k
{
74
36.1k
   int i;
75
36.1k
   spx_word16_t tmp1, tmp2;
76
379k
   for (i=0;i<order;i++)
77
343k
   {
78
343k
      if (i==0)
79
36.1k
         tmp1 = qlsp[i];
80
306k
      else
81
306k
         tmp1 = qlsp[i]-qlsp[i-1];
82
343k
      if (i==order-1)
83
36.1k
         tmp2 = LSP_PI-qlsp[i];
84
306k
      else
85
306k
         tmp2 = qlsp[i+1]-qlsp[i];
86
343k
      if (tmp2<tmp1)
87
178k
         tmp1 = tmp2;
88
#ifdef FIXED_POINT
89
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
343k
      quant_weight[i] = 10/(.04+tmp1);
92
343k
#endif
93
343k
   }
94
95
36.1k
}
quant_lsp.c:compute_quant_weights
Line
Count
Source
73
36.1k
{
74
36.1k
   int i;
75
36.1k
   spx_word16_t tmp1, tmp2;
76
379k
   for (i=0;i<order;i++)
77
343k
   {
78
343k
      if (i==0)
79
36.1k
         tmp1 = qlsp[i];
80
306k
      else
81
306k
         tmp1 = qlsp[i]-qlsp[i-1];
82
343k
      if (i==order-1)
83
36.1k
         tmp2 = LSP_PI-qlsp[i];
84
306k
      else
85
306k
         tmp2 = qlsp[i+1]-qlsp[i];
86
343k
      if (tmp2<tmp1)
87
178k
         tmp1 = tmp2;
88
343k
#ifdef FIXED_POINT
89
343k
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
      quant_weight[i] = 10/(.04+tmp1);
92
#endif
93
343k
   }
94
95
36.1k
}
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
72.3k
{
101
72.3k
   int i,j;
102
72.3k
   spx_word32_t dist;
103
72.3k
   spx_word16_t tmp;
104
72.3k
   spx_word32_t best_dist=VERY_LARGE32;
105
72.3k
   int best_id=0;
106
72.3k
   const signed char *ptr=cdbk;
107
4.70M
   for (i=0;i<nbVec;i++)
108
4.63M
   {
109
4.63M
      dist=0;
110
48.5M
      for (j=0;j<nbDim;j++)
111
43.9M
      {
112
43.9M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
43.9M
         dist=MAC16_16(dist,tmp,tmp);
114
43.9M
      }
115
4.63M
      if (dist<best_dist)
116
245k
      {
117
245k
         best_dist=dist;
118
245k
         best_id=i;
119
245k
      }
120
4.63M
   }
121
122
758k
   for (j=0;j<nbDim;j++)
123
686k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
72.3k
   return best_id;
126
72.3k
}
quant_lsp.c:lsp_quant
Line
Count
Source
100
36.1k
{
101
36.1k
   int i,j;
102
36.1k
   spx_word32_t dist;
103
36.1k
   spx_word16_t tmp;
104
36.1k
   spx_word32_t best_dist=VERY_LARGE32;
105
36.1k
   int best_id=0;
106
36.1k
   const signed char *ptr=cdbk;
107
2.35M
   for (i=0;i<nbVec;i++)
108
2.31M
   {
109
2.31M
      dist=0;
110
24.2M
      for (j=0;j<nbDim;j++)
111
21.9M
      {
112
21.9M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
21.9M
         dist=MAC16_16(dist,tmp,tmp);
114
21.9M
      }
115
2.31M
      if (dist<best_dist)
116
122k
      {
117
122k
         best_dist=dist;
118
122k
         best_id=i;
119
122k
      }
120
2.31M
   }
121
122
379k
   for (j=0;j<nbDim;j++)
123
343k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
36.1k
   return best_id;
126
36.1k
}
quant_lsp.c:lsp_quant
Line
Count
Source
100
36.1k
{
101
36.1k
   int i,j;
102
36.1k
   spx_word32_t dist;
103
36.1k
   spx_word16_t tmp;
104
36.1k
   spx_word32_t best_dist=VERY_LARGE32;
105
36.1k
   int best_id=0;
106
36.1k
   const signed char *ptr=cdbk;
107
2.35M
   for (i=0;i<nbVec;i++)
108
2.31M
   {
109
2.31M
      dist=0;
110
24.2M
      for (j=0;j<nbDim;j++)
111
21.9M
      {
112
21.9M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
21.9M
         dist=MAC16_16(dist,tmp,tmp);
114
21.9M
      }
115
2.31M
      if (dist<best_dist)
116
122k
      {
117
122k
         best_dist=dist;
118
122k
         best_id=i;
119
122k
      }
120
2.31M
   }
121
122
379k
   for (j=0;j<nbDim;j++)
123
343k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
36.1k
   return best_id;
126
36.1k
}
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
146k
{
133
146k
   int i,j;
134
146k
   spx_word32_t dist;
135
146k
   spx_word16_t tmp;
136
146k
   spx_word32_t best_dist=VERY_LARGE32;
137
146k
   int best_id=0;
138
146k
   const signed char *ptr=cdbk;
139
9.53M
   for (i=0;i<nbVec;i++)
140
9.38M
   {
141
9.38M
      dist=0;
142
59.9M
      for (j=0;j<nbDim;j++)
143
50.5M
      {
144
50.5M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
50.5M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
50.5M
      }
147
9.38M
      if (dist<best_dist)
148
740k
      {
149
740k
         best_dist=dist;
150
740k
         best_id=i;
151
740k
      }
152
9.38M
   }
153
154
936k
   for (j=0;j<nbDim;j++)
155
789k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
146k
   return best_id;
157
146k
}
quant_lsp.c:lsp_weight_quant
Line
Count
Source
132
73.3k
{
133
73.3k
   int i,j;
134
73.3k
   spx_word32_t dist;
135
73.3k
   spx_word16_t tmp;
136
73.3k
   spx_word32_t best_dist=VERY_LARGE32;
137
73.3k
   int best_id=0;
138
73.3k
   const signed char *ptr=cdbk;
139
4.76M
   for (i=0;i<nbVec;i++)
140
4.69M
   {
141
4.69M
      dist=0;
142
29.9M
      for (j=0;j<nbDim;j++)
143
25.2M
      {
144
25.2M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
25.2M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
25.2M
      }
147
4.69M
      if (dist<best_dist)
148
370k
      {
149
370k
         best_dist=dist;
150
370k
         best_id=i;
151
370k
      }
152
4.69M
   }
153
154
468k
   for (j=0;j<nbDim;j++)
155
394k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
73.3k
   return best_id;
157
73.3k
}
quant_lsp.c:lsp_weight_quant
Line
Count
Source
132
73.3k
{
133
73.3k
   int i,j;
134
73.3k
   spx_word32_t dist;
135
73.3k
   spx_word16_t tmp;
136
73.3k
   spx_word32_t best_dist=VERY_LARGE32;
137
73.3k
   int best_id=0;
138
73.3k
   const signed char *ptr=cdbk;
139
4.76M
   for (i=0;i<nbVec;i++)
140
4.69M
   {
141
4.69M
      dist=0;
142
29.9M
      for (j=0;j<nbDim;j++)
143
25.2M
      {
144
25.2M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
25.2M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
25.2M
      }
147
4.69M
      if (dist<best_dist)
148
370k
      {
149
370k
         best_dist=dist;
150
370k
         best_id=i;
151
370k
      }
152
4.69M
   }
153
154
468k
   for (j=0;j<nbDim;j++)
155
394k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
73.3k
   return best_id;
157
73.3k
}
158
#endif
159
160
void lsp_quant_nb(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
161
5.19k
{
162
5.19k
   int i;
163
5.19k
   int id;
164
5.19k
   spx_word16_t quant_weight[10];
165
166
57.1k
   for (i=0;i<order;i++)
167
51.9k
      qlsp[i]=lsp[i];
168
169
5.19k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
57.1k
   for (i=0;i<order;i++)
172
51.9k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
173
174
#ifndef FIXED_POINT
175
15.2k
   for (i=0;i<order;i++)
176
13.9k
      qlsp[i] = LSP_SCALE*qlsp[i];
177
#endif
178
5.19k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
5.19k
   speex_bits_pack(bits, id, 6);
180
181
57.1k
   for (i=0;i<order;i++)
182
51.9k
      qlsp[i]*=2;
183
184
5.19k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
5.19k
   speex_bits_pack(bits, id, 6);
186
187
31.1k
   for (i=0;i<5;i++)
188
25.9k
      qlsp[i]*=2;
189
190
5.19k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
5.19k
   speex_bits_pack(bits, id, 6);
192
193
5.19k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
5.19k
   speex_bits_pack(bits, id, 6);
195
196
31.1k
   for (i=5;i<10;i++)
197
25.9k
      qlsp[i]*=2;
198
199
5.19k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
5.19k
   speex_bits_pack(bits, id, 6);
201
202
#ifdef FIXED_POINT
203
41.8k
   for (i=0;i<order;i++)
204
38.0k
      qlsp[i]=PSHR16(qlsp[i],2);
205
#else
206
15.2k
   for (i=0;i<order;i++)
207
13.9k
      qlsp[i]=qlsp[i] * .00097656;
208
#endif
209
210
57.1k
   for (i=0;i<order;i++)
211
51.9k
      qlsp[i]=lsp[i]-qlsp[i];
212
5.19k
}
lsp_quant_nb
Line
Count
Source
161
1.39k
{
162
1.39k
   int i;
163
1.39k
   int id;
164
1.39k
   spx_word16_t quant_weight[10];
165
166
15.2k
   for (i=0;i<order;i++)
167
13.9k
      qlsp[i]=lsp[i];
168
169
1.39k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
15.2k
   for (i=0;i<order;i++)
172
13.9k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
173
174
1.39k
#ifndef FIXED_POINT
175
15.2k
   for (i=0;i<order;i++)
176
13.9k
      qlsp[i] = LSP_SCALE*qlsp[i];
177
1.39k
#endif
178
1.39k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
1.39k
   speex_bits_pack(bits, id, 6);
180
181
15.2k
   for (i=0;i<order;i++)
182
13.9k
      qlsp[i]*=2;
183
184
1.39k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
1.39k
   speex_bits_pack(bits, id, 6);
186
187
8.34k
   for (i=0;i<5;i++)
188
6.95k
      qlsp[i]*=2;
189
190
1.39k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
1.39k
   speex_bits_pack(bits, id, 6);
192
193
1.39k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
1.39k
   speex_bits_pack(bits, id, 6);
195
196
8.34k
   for (i=5;i<10;i++)
197
6.95k
      qlsp[i]*=2;
198
199
1.39k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
1.39k
   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
15.2k
   for (i=0;i<order;i++)
207
13.9k
      qlsp[i]=qlsp[i] * .00097656;
208
1.39k
#endif
209
210
15.2k
   for (i=0;i<order;i++)
211
13.9k
      qlsp[i]=lsp[i]-qlsp[i];
212
1.39k
}
lsp_quant_nb
Line
Count
Source
161
3.80k
{
162
3.80k
   int i;
163
3.80k
   int id;
164
3.80k
   spx_word16_t quant_weight[10];
165
166
41.8k
   for (i=0;i<order;i++)
167
38.0k
      qlsp[i]=lsp[i];
168
169
3.80k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
41.8k
   for (i=0;i<order;i++)
172
38.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.80k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
3.80k
   speex_bits_pack(bits, id, 6);
180
181
41.8k
   for (i=0;i<order;i++)
182
38.0k
      qlsp[i]*=2;
183
184
3.80k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
3.80k
   speex_bits_pack(bits, id, 6);
186
187
22.8k
   for (i=0;i<5;i++)
188
19.0k
      qlsp[i]*=2;
189
190
3.80k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
3.80k
   speex_bits_pack(bits, id, 6);
192
193
3.80k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
3.80k
   speex_bits_pack(bits, id, 6);
195
196
22.8k
   for (i=5;i<10;i++)
197
19.0k
      qlsp[i]*=2;
198
199
3.80k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
3.80k
   speex_bits_pack(bits, id, 6);
201
202
3.80k
#ifdef FIXED_POINT
203
41.8k
   for (i=0;i<order;i++)
204
38.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
41.8k
   for (i=0;i<order;i++)
211
38.0k
      qlsp[i]=lsp[i]-qlsp[i];
212
3.80k
}
213
#endif /* DISABLE_ENCODER */
214
215
#ifndef DISABLE_DECODER
216
void lsp_unquant_nb(spx_lsp_t *lsp, int order, SpeexBits *bits)
217
10.0k
{
218
10.0k
   int i, id;
219
110k
   for (i=0;i<order;i++)
220
100k
      lsp[i]=LSP_LINEAR(i);
221
222
223
10.0k
   id=speex_bits_unpack_unsigned(bits, 6);
224
110k
   for (i=0;i<10;i++)
225
100k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
10.0k
   id=speex_bits_unpack_unsigned(bits, 6);
228
60.3k
   for (i=0;i<5;i++)
229
50.3k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
10.0k
   id=speex_bits_unpack_unsigned(bits, 6);
232
60.3k
   for (i=0;i<5;i++)
233
50.3k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
10.0k
   id=speex_bits_unpack_unsigned(bits, 6);
236
60.3k
   for (i=0;i<5;i++)
237
50.3k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
10.0k
   id=speex_bits_unpack_unsigned(bits, 6);
240
60.3k
   for (i=0;i<5;i++)
241
50.3k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
10.0k
}
lsp_unquant_nb
Line
Count
Source
217
5.03k
{
218
5.03k
   int i, id;
219
55.3k
   for (i=0;i<order;i++)
220
50.3k
      lsp[i]=LSP_LINEAR(i);
221
222
223
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
224
55.3k
   for (i=0;i<10;i++)
225
50.3k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
228
30.1k
   for (i=0;i<5;i++)
229
25.1k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
232
30.1k
   for (i=0;i<5;i++)
233
25.1k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
236
30.1k
   for (i=0;i<5;i++)
237
25.1k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
240
30.1k
   for (i=0;i<5;i++)
241
25.1k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
5.03k
}
lsp_unquant_nb
Line
Count
Source
217
5.03k
{
218
5.03k
   int i, id;
219
55.3k
   for (i=0;i<order;i++)
220
50.3k
      lsp[i]=LSP_LINEAR(i);
221
222
223
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
224
55.3k
   for (i=0;i<10;i++)
225
50.3k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
228
30.1k
   for (i=0;i<5;i++)
229
25.1k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
232
30.1k
   for (i=0;i<5;i++)
233
25.1k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
236
30.1k
   for (i=0;i<5;i++)
237
25.1k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
5.03k
   id=speex_bits_unpack_unsigned(bits, 6);
240
30.1k
   for (i=0;i<5;i++)
241
25.1k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
5.03k
}
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
21.5k
{
248
21.5k
   int i;
249
21.5k
   int id;
250
21.5k
   spx_word16_t quant_weight[10];
251
252
237k
   for (i=0;i<order;i++)
253
215k
      qlsp[i]=lsp[i];
254
255
21.5k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
237k
   for (i=0;i<order;i++)
258
215k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
259
#ifndef FIXED_POINT
260
67.3k
   for (i=0;i<order;i++)
261
61.2k
      qlsp[i]=qlsp[i]*LSP_SCALE;
262
#endif
263
21.5k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
21.5k
   speex_bits_pack(bits, id, 6);
265
266
237k
   for (i=0;i<order;i++)
267
215k
      qlsp[i]*=2;
268
269
21.5k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
21.5k
   speex_bits_pack(bits, id, 6);
271
272
21.5k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
21.5k
   speex_bits_pack(bits, id, 6);
274
275
#ifdef FIXED_POINT
276
170k
   for (i=0;i<order;i++)
277
154k
      qlsp[i] = PSHR16(qlsp[i],1);
278
#else
279
67.3k
   for (i=0;i<order;i++)
280
61.2k
      qlsp[i] = qlsp[i]*0.0019531;
281
#endif
282
283
237k
   for (i=0;i<order;i++)
284
215k
      qlsp[i]=lsp[i]-qlsp[i];
285
21.5k
}
lsp_quant_lbr
Line
Count
Source
247
6.12k
{
248
6.12k
   int i;
249
6.12k
   int id;
250
6.12k
   spx_word16_t quant_weight[10];
251
252
67.3k
   for (i=0;i<order;i++)
253
61.2k
      qlsp[i]=lsp[i];
254
255
6.12k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
67.3k
   for (i=0;i<order;i++)
258
61.2k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
259
6.12k
#ifndef FIXED_POINT
260
67.3k
   for (i=0;i<order;i++)
261
61.2k
      qlsp[i]=qlsp[i]*LSP_SCALE;
262
6.12k
#endif
263
6.12k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
6.12k
   speex_bits_pack(bits, id, 6);
265
266
67.3k
   for (i=0;i<order;i++)
267
61.2k
      qlsp[i]*=2;
268
269
6.12k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
6.12k
   speex_bits_pack(bits, id, 6);
271
272
6.12k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
6.12k
   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
67.3k
   for (i=0;i<order;i++)
280
61.2k
      qlsp[i] = qlsp[i]*0.0019531;
281
6.12k
#endif
282
283
67.3k
   for (i=0;i<order;i++)
284
61.2k
      qlsp[i]=lsp[i]-qlsp[i];
285
6.12k
}
lsp_quant_lbr
Line
Count
Source
247
15.4k
{
248
15.4k
   int i;
249
15.4k
   int id;
250
15.4k
   spx_word16_t quant_weight[10];
251
252
170k
   for (i=0;i<order;i++)
253
154k
      qlsp[i]=lsp[i];
254
255
15.4k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
170k
   for (i=0;i<order;i++)
258
154k
      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
15.4k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
15.4k
   speex_bits_pack(bits, id, 6);
265
266
170k
   for (i=0;i<order;i++)
267
154k
      qlsp[i]*=2;
268
269
15.4k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
15.4k
   speex_bits_pack(bits, id, 6);
271
272
15.4k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
15.4k
   speex_bits_pack(bits, id, 6);
274
275
15.4k
#ifdef FIXED_POINT
276
170k
   for (i=0;i<order;i++)
277
154k
      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
170k
   for (i=0;i<order;i++)
284
154k
      qlsp[i]=lsp[i]-qlsp[i];
285
15.4k
}
286
#endif /* DISABLE_ENCODER */
287
288
#ifndef DISABLE_DECODER
289
void lsp_unquant_lbr(spx_lsp_t *lsp, int order, SpeexBits *bits)
290
38.1k
{
291
38.1k
   int i, id;
292
419k
   for (i=0;i<order;i++)
293
381k
      lsp[i]=LSP_LINEAR(i);
294
295
296
38.1k
   id=speex_bits_unpack_unsigned(bits, 6);
297
419k
   for (i=0;i<10;i++)
298
381k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
38.1k
   id=speex_bits_unpack_unsigned(bits, 6);
301
228k
   for (i=0;i<5;i++)
302
190k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
38.1k
   id=speex_bits_unpack_unsigned(bits, 6);
305
228k
   for (i=0;i<5;i++)
306
190k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
38.1k
}
lsp_unquant_lbr
Line
Count
Source
290
19.0k
{
291
19.0k
   int i, id;
292
209k
   for (i=0;i<order;i++)
293
190k
      lsp[i]=LSP_LINEAR(i);
294
295
296
19.0k
   id=speex_bits_unpack_unsigned(bits, 6);
297
209k
   for (i=0;i<10;i++)
298
190k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
19.0k
   id=speex_bits_unpack_unsigned(bits, 6);
301
114k
   for (i=0;i<5;i++)
302
95.3k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
19.0k
   id=speex_bits_unpack_unsigned(bits, 6);
305
114k
   for (i=0;i<5;i++)
306
95.3k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
19.0k
}
lsp_unquant_lbr
Line
Count
Source
290
19.0k
{
291
19.0k
   int i, id;
292
209k
   for (i=0;i<order;i++)
293
190k
      lsp[i]=LSP_LINEAR(i);
294
295
296
19.0k
   id=speex_bits_unpack_unsigned(bits, 6);
297
209k
   for (i=0;i<10;i++)
298
190k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
19.0k
   id=speex_bits_unpack_unsigned(bits, 6);
301
114k
   for (i=0;i<5;i++)
302
95.3k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
19.0k
   id=speex_bits_unpack_unsigned(bits, 6);
305
114k
   for (i=0;i<5;i++)
306
95.3k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
19.0k
}
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
9.39k
{
318
9.39k
   int i;
319
9.39k
   int id;
320
9.39k
   spx_word16_t quant_weight[10];
321
322
84.5k
   for (i=0;i<order;i++)
323
75.1k
      qlsp[i]=lsp[i];
324
325
9.39k
   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
84.5k
   for (i=0;i<order;i++)
337
75.1k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR_HIGH(i));
338
#ifndef FIXED_POINT
339
27.6k
   for (i=0;i<order;i++)
340
24.5k
      qlsp[i] = qlsp[i]*LSP_SCALE;
341
#endif
342
9.39k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
9.39k
   speex_bits_pack(bits, id, 6);
344
345
84.5k
   for (i=0;i<order;i++)
346
75.1k
      qlsp[i]*=2;
347
348
9.39k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
9.39k
   speex_bits_pack(bits, id, 6);
350
351
#ifdef FIXED_POINT
352
56.9k
   for (i=0;i<order;i++)
353
50.5k
      qlsp[i] = PSHR16(qlsp[i],1);
354
#else
355
27.6k
   for (i=0;i<order;i++)
356
24.5k
      qlsp[i] = qlsp[i]*0.0019531;
357
#endif
358
359
84.5k
   for (i=0;i<order;i++)
360
75.1k
      qlsp[i]=lsp[i]-qlsp[i];
361
9.39k
}
lsp_quant_high
Line
Count
Source
317
3.06k
{
318
3.06k
   int i;
319
3.06k
   int id;
320
3.06k
   spx_word16_t quant_weight[10];
321
322
27.6k
   for (i=0;i<order;i++)
323
24.5k
      qlsp[i]=lsp[i];
324
325
3.06k
   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.6k
   for (i=0;i<order;i++)
337
24.5k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR_HIGH(i));
338
3.06k
#ifndef FIXED_POINT
339
27.6k
   for (i=0;i<order;i++)
340
24.5k
      qlsp[i] = qlsp[i]*LSP_SCALE;
341
3.06k
#endif
342
3.06k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
3.06k
   speex_bits_pack(bits, id, 6);
344
345
27.6k
   for (i=0;i<order;i++)
346
24.5k
      qlsp[i]*=2;
347
348
3.06k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
3.06k
   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.6k
   for (i=0;i<order;i++)
356
24.5k
      qlsp[i] = qlsp[i]*0.0019531;
357
3.06k
#endif
358
359
27.6k
   for (i=0;i<order;i++)
360
24.5k
      qlsp[i]=lsp[i]-qlsp[i];
361
3.06k
}
lsp_quant_high
Line
Count
Source
317
6.32k
{
318
6.32k
   int i;
319
6.32k
   int id;
320
6.32k
   spx_word16_t quant_weight[10];
321
322
56.9k
   for (i=0;i<order;i++)
323
50.5k
      qlsp[i]=lsp[i];
324
325
6.32k
   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
56.9k
   for (i=0;i<order;i++)
337
50.5k
      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
6.32k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
6.32k
   speex_bits_pack(bits, id, 6);
344
345
56.9k
   for (i=0;i<order;i++)
346
50.5k
      qlsp[i]*=2;
347
348
6.32k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
6.32k
   speex_bits_pack(bits, id, 6);
350
351
6.32k
#ifdef FIXED_POINT
352
56.9k
   for (i=0;i<order;i++)
353
50.5k
      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
56.9k
   for (i=0;i<order;i++)
360
50.5k
      qlsp[i]=lsp[i]-qlsp[i];
361
6.32k
}
362
#endif /* DISABLE_ENCODER */
363
364
365
#ifndef DISABLE_DECODER
366
void lsp_unquant_high(spx_lsp_t *lsp, int order, SpeexBits *bits)
367
13.6k
{
368
369
13.6k
   int i, id;
370
123k
   for (i=0;i<order;i++)
371
109k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
13.6k
   id=speex_bits_unpack_unsigned(bits, 6);
375
123k
   for (i=0;i<order;i++)
376
109k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
13.6k
   id=speex_bits_unpack_unsigned(bits, 6);
380
123k
   for (i=0;i<order;i++)
381
109k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
13.6k
}
lsp_unquant_high
Line
Count
Source
367
6.84k
{
368
369
6.84k
   int i, id;
370
61.5k
   for (i=0;i<order;i++)
371
54.7k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
6.84k
   id=speex_bits_unpack_unsigned(bits, 6);
375
61.5k
   for (i=0;i<order;i++)
376
54.7k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
6.84k
   id=speex_bits_unpack_unsigned(bits, 6);
380
61.5k
   for (i=0;i<order;i++)
381
54.7k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
6.84k
}
lsp_unquant_high
Line
Count
Source
367
6.84k
{
368
369
6.84k
   int i, id;
370
61.5k
   for (i=0;i<order;i++)
371
54.7k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
6.84k
   id=speex_bits_unpack_unsigned(bits, 6);
375
61.5k
   for (i=0;i<order;i++)
376
54.7k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
6.84k
   id=speex_bits_unpack_unsigned(bits, 6);
380
61.5k
   for (i=0;i<order;i++)
381
54.7k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
6.84k
}
383
#endif /* DISABLE_DECODER */
384
385
#endif /* DISABLE_WIDEBAND */
386