Coverage Report

Created: 2025-08-29 06:24

/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
238k
#define LSP_LINEAR(i) (SHL16(i+1,11))
53
49.3k
#define LSP_LINEAR_HIGH(i) (ADD16(MULT16_16_16(i,2560),6144))
54
234k
#define LSP_DIV_256(x) (SHL16((spx_word16_t)x, 5))
55
234k
#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.4k
#define LSP_PI 25736
58
59
#else
60
61
238k
#define LSP_LINEAR(i) (.25*(i)+.25)
62
49.3k
#define LSP_LINEAR_HIGH(i) (.3125*(i)+.75)
63
98.6k
#define LSP_SCALE 256.
64
234k
#define LSP_DIV_256(x) (0.0039062*(x))
65
234k
#define LSP_DIV_512(x) (0.0019531*(x))
66
#define LSP_DIV_1024(x) (0.00097656*(x))
67
36.4k
#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.8k
{
74
72.8k
   int i;
75
72.8k
   spx_word16_t tmp1, tmp2;
76
764k
   for (i=0;i<order;i++)
77
691k
   {
78
691k
      if (i==0)
79
72.8k
         tmp1 = qlsp[i];
80
618k
      else
81
618k
         tmp1 = qlsp[i]-qlsp[i-1];
82
691k
      if (i==order-1)
83
72.8k
         tmp2 = LSP_PI-qlsp[i];
84
618k
      else
85
618k
         tmp2 = qlsp[i+1]-qlsp[i];
86
691k
      if (tmp2<tmp1)
87
359k
         tmp1 = tmp2;
88
#ifdef FIXED_POINT
89
345k
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
      quant_weight[i] = 10/(.04+tmp1);
92
#endif
93
691k
   }
94
95
72.8k
}
quant_lsp.c:compute_quant_weights
Line
Count
Source
73
36.4k
{
74
36.4k
   int i;
75
36.4k
   spx_word16_t tmp1, tmp2;
76
382k
   for (i=0;i<order;i++)
77
345k
   {
78
345k
      if (i==0)
79
36.4k
         tmp1 = qlsp[i];
80
309k
      else
81
309k
         tmp1 = qlsp[i]-qlsp[i-1];
82
345k
      if (i==order-1)
83
36.4k
         tmp2 = LSP_PI-qlsp[i];
84
309k
      else
85
309k
         tmp2 = qlsp[i+1]-qlsp[i];
86
345k
      if (tmp2<tmp1)
87
179k
         tmp1 = tmp2;
88
#ifdef FIXED_POINT
89
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
345k
      quant_weight[i] = 10/(.04+tmp1);
92
345k
#endif
93
345k
   }
94
95
36.4k
}
quant_lsp.c:compute_quant_weights
Line
Count
Source
73
36.4k
{
74
36.4k
   int i;
75
36.4k
   spx_word16_t tmp1, tmp2;
76
382k
   for (i=0;i<order;i++)
77
345k
   {
78
345k
      if (i==0)
79
36.4k
         tmp1 = qlsp[i];
80
309k
      else
81
309k
         tmp1 = qlsp[i]-qlsp[i-1];
82
345k
      if (i==order-1)
83
36.4k
         tmp2 = LSP_PI-qlsp[i];
84
309k
      else
85
309k
         tmp2 = qlsp[i+1]-qlsp[i];
86
345k
      if (tmp2<tmp1)
87
179k
         tmp1 = tmp2;
88
345k
#ifdef FIXED_POINT
89
345k
      quant_weight[i] = DIV32_16(81920,ADD16(300,tmp1));
90
#else
91
      quant_weight[i] = 10/(.04+tmp1);
92
#endif
93
345k
   }
94
95
36.4k
}
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.8k
{
101
72.8k
   int i,j;
102
72.8k
   spx_word32_t dist;
103
72.8k
   spx_word16_t tmp;
104
72.8k
   spx_word32_t best_dist=VERY_LARGE32;
105
72.8k
   int best_id=0;
106
72.8k
   const signed char *ptr=cdbk;
107
4.73M
   for (i=0;i<nbVec;i++)
108
4.66M
   {
109
4.66M
      dist=0;
110
48.9M
      for (j=0;j<nbDim;j++)
111
44.2M
      {
112
44.2M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
44.2M
         dist=MAC16_16(dist,tmp,tmp);
114
44.2M
      }
115
4.66M
      if (dist<best_dist)
116
245k
      {
117
245k
         best_dist=dist;
118
245k
         best_id=i;
119
245k
      }
120
4.66M
   }
121
122
764k
   for (j=0;j<nbDim;j++)
123
691k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
72.8k
   return best_id;
126
72.8k
}
quant_lsp.c:lsp_quant
Line
Count
Source
100
36.4k
{
101
36.4k
   int i,j;
102
36.4k
   spx_word32_t dist;
103
36.4k
   spx_word16_t tmp;
104
36.4k
   spx_word32_t best_dist=VERY_LARGE32;
105
36.4k
   int best_id=0;
106
36.4k
   const signed char *ptr=cdbk;
107
2.36M
   for (i=0;i<nbVec;i++)
108
2.33M
   {
109
2.33M
      dist=0;
110
24.4M
      for (j=0;j<nbDim;j++)
111
22.1M
      {
112
22.1M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
22.1M
         dist=MAC16_16(dist,tmp,tmp);
114
22.1M
      }
115
2.33M
      if (dist<best_dist)
116
122k
      {
117
122k
         best_dist=dist;
118
122k
         best_id=i;
119
122k
      }
120
2.33M
   }
121
122
382k
   for (j=0;j<nbDim;j++)
123
345k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
36.4k
   return best_id;
126
36.4k
}
quant_lsp.c:lsp_quant
Line
Count
Source
100
36.4k
{
101
36.4k
   int i,j;
102
36.4k
   spx_word32_t dist;
103
36.4k
   spx_word16_t tmp;
104
36.4k
   spx_word32_t best_dist=VERY_LARGE32;
105
36.4k
   int best_id=0;
106
36.4k
   const signed char *ptr=cdbk;
107
2.36M
   for (i=0;i<nbVec;i++)
108
2.33M
   {
109
2.33M
      dist=0;
110
24.4M
      for (j=0;j<nbDim;j++)
111
22.1M
      {
112
22.1M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
113
22.1M
         dist=MAC16_16(dist,tmp,tmp);
114
22.1M
      }
115
2.33M
      if (dist<best_dist)
116
122k
      {
117
122k
         best_dist=dist;
118
122k
         best_id=i;
119
122k
      }
120
2.33M
   }
121
122
382k
   for (j=0;j<nbDim;j++)
123
345k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
124
125
36.4k
   return best_id;
126
36.4k
}
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
147k
{
133
147k
   int i,j;
134
147k
   spx_word32_t dist;
135
147k
   spx_word16_t tmp;
136
147k
   spx_word32_t best_dist=VERY_LARGE32;
137
147k
   int best_id=0;
138
147k
   const signed char *ptr=cdbk;
139
9.58M
   for (i=0;i<nbVec;i++)
140
9.43M
   {
141
9.43M
      dist=0;
142
60.2M
      for (j=0;j<nbDim;j++)
143
50.7M
      {
144
50.7M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
50.7M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
50.7M
      }
147
9.43M
      if (dist<best_dist)
148
746k
      {
149
746k
         best_dist=dist;
150
746k
         best_id=i;
151
746k
      }
152
9.43M
   }
153
154
940k
   for (j=0;j<nbDim;j++)
155
793k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
147k
   return best_id;
157
147k
}
quant_lsp.c:lsp_weight_quant
Line
Count
Source
132
73.7k
{
133
73.7k
   int i,j;
134
73.7k
   spx_word32_t dist;
135
73.7k
   spx_word16_t tmp;
136
73.7k
   spx_word32_t best_dist=VERY_LARGE32;
137
73.7k
   int best_id=0;
138
73.7k
   const signed char *ptr=cdbk;
139
4.79M
   for (i=0;i<nbVec;i++)
140
4.71M
   {
141
4.71M
      dist=0;
142
30.1M
      for (j=0;j<nbDim;j++)
143
25.3M
      {
144
25.3M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
25.3M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
25.3M
      }
147
4.71M
      if (dist<best_dist)
148
373k
      {
149
373k
         best_dist=dist;
150
373k
         best_id=i;
151
373k
      }
152
4.71M
   }
153
154
470k
   for (j=0;j<nbDim;j++)
155
396k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
73.7k
   return best_id;
157
73.7k
}
quant_lsp.c:lsp_weight_quant
Line
Count
Source
132
73.7k
{
133
73.7k
   int i,j;
134
73.7k
   spx_word32_t dist;
135
73.7k
   spx_word16_t tmp;
136
73.7k
   spx_word32_t best_dist=VERY_LARGE32;
137
73.7k
   int best_id=0;
138
73.7k
   const signed char *ptr=cdbk;
139
4.79M
   for (i=0;i<nbVec;i++)
140
4.71M
   {
141
4.71M
      dist=0;
142
30.1M
      for (j=0;j<nbDim;j++)
143
25.3M
      {
144
25.3M
         tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
145
25.3M
         dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
146
25.3M
      }
147
4.71M
      if (dist<best_dist)
148
373k
      {
149
373k
         best_dist=dist;
150
373k
         best_id=i;
151
373k
      }
152
4.71M
   }
153
154
470k
   for (j=0;j<nbDim;j++)
155
396k
      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
156
73.7k
   return best_id;
157
73.7k
}
158
#endif
159
160
void lsp_quant_nb(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
161
5.10k
{
162
5.10k
   int i;
163
5.10k
   int id;
164
5.10k
   spx_word16_t quant_weight[10];
165
166
56.1k
   for (i=0;i<order;i++)
167
51.0k
      qlsp[i]=lsp[i];
168
169
5.10k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
56.1k
   for (i=0;i<order;i++)
172
51.0k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
173
174
#ifndef FIXED_POINT
175
14.3k
   for (i=0;i<order;i++)
176
13.0k
      qlsp[i] = LSP_SCALE*qlsp[i];
177
#endif
178
5.10k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
5.10k
   speex_bits_pack(bits, id, 6);
180
181
56.1k
   for (i=0;i<order;i++)
182
51.0k
      qlsp[i]*=2;
183
184
5.10k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
5.10k
   speex_bits_pack(bits, id, 6);
186
187
30.6k
   for (i=0;i<5;i++)
188
25.5k
      qlsp[i]*=2;
189
190
5.10k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
5.10k
   speex_bits_pack(bits, id, 6);
192
193
5.10k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
5.10k
   speex_bits_pack(bits, id, 6);
195
196
30.6k
   for (i=5;i<10;i++)
197
25.5k
      qlsp[i]*=2;
198
199
5.10k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
5.10k
   speex_bits_pack(bits, id, 6);
201
202
#ifdef FIXED_POINT
203
41.7k
   for (i=0;i<order;i++)
204
37.9k
      qlsp[i]=PSHR16(qlsp[i],2);
205
#else
206
14.3k
   for (i=0;i<order;i++)
207
13.0k
      qlsp[i]=qlsp[i] * .00097656;
208
#endif
209
210
56.1k
   for (i=0;i<order;i++)
211
51.0k
      qlsp[i]=lsp[i]-qlsp[i];
212
5.10k
}
lsp_quant_nb
Line
Count
Source
161
1.30k
{
162
1.30k
   int i;
163
1.30k
   int id;
164
1.30k
   spx_word16_t quant_weight[10];
165
166
14.3k
   for (i=0;i<order;i++)
167
13.0k
      qlsp[i]=lsp[i];
168
169
1.30k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
14.3k
   for (i=0;i<order;i++)
172
13.0k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
173
174
1.30k
#ifndef FIXED_POINT
175
14.3k
   for (i=0;i<order;i++)
176
13.0k
      qlsp[i] = LSP_SCALE*qlsp[i];
177
1.30k
#endif
178
1.30k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
1.30k
   speex_bits_pack(bits, id, 6);
180
181
14.3k
   for (i=0;i<order;i++)
182
13.0k
      qlsp[i]*=2;
183
184
1.30k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
1.30k
   speex_bits_pack(bits, id, 6);
186
187
7.85k
   for (i=0;i<5;i++)
188
6.54k
      qlsp[i]*=2;
189
190
1.30k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
1.30k
   speex_bits_pack(bits, id, 6);
192
193
1.30k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
1.30k
   speex_bits_pack(bits, id, 6);
195
196
7.85k
   for (i=5;i<10;i++)
197
6.54k
      qlsp[i]*=2;
198
199
1.30k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
1.30k
   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.3k
   for (i=0;i<order;i++)
207
13.0k
      qlsp[i]=qlsp[i] * .00097656;
208
1.30k
#endif
209
210
14.3k
   for (i=0;i<order;i++)
211
13.0k
      qlsp[i]=lsp[i]-qlsp[i];
212
1.30k
}
lsp_quant_nb
Line
Count
Source
161
3.79k
{
162
3.79k
   int i;
163
3.79k
   int id;
164
3.79k
   spx_word16_t quant_weight[10];
165
166
41.7k
   for (i=0;i<order;i++)
167
37.9k
      qlsp[i]=lsp[i];
168
169
3.79k
   compute_quant_weights(qlsp, quant_weight, order);
170
171
41.7k
   for (i=0;i<order;i++)
172
37.9k
      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.79k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
179
3.79k
   speex_bits_pack(bits, id, 6);
180
181
41.7k
   for (i=0;i<order;i++)
182
37.9k
      qlsp[i]*=2;
183
184
3.79k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
185
3.79k
   speex_bits_pack(bits, id, 6);
186
187
22.7k
   for (i=0;i<5;i++)
188
18.9k
      qlsp[i]*=2;
189
190
3.79k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
191
3.79k
   speex_bits_pack(bits, id, 6);
192
193
3.79k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
194
3.79k
   speex_bits_pack(bits, id, 6);
195
196
22.7k
   for (i=5;i<10;i++)
197
18.9k
      qlsp[i]*=2;
198
199
3.79k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
200
3.79k
   speex_bits_pack(bits, id, 6);
201
202
3.79k
#ifdef FIXED_POINT
203
41.7k
   for (i=0;i<order;i++)
204
37.9k
      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.7k
   for (i=0;i<order;i++)
211
37.9k
      qlsp[i]=lsp[i]-qlsp[i];
212
3.79k
}
213
#endif /* DISABLE_ENCODER */
214
215
#ifndef DISABLE_DECODER
216
void lsp_unquant_nb(spx_lsp_t *lsp, int order, SpeexBits *bits)
217
10.7k
{
218
10.7k
   int i, id;
219
118k
   for (i=0;i<order;i++)
220
107k
      lsp[i]=LSP_LINEAR(i);
221
222
223
10.7k
   id=speex_bits_unpack_unsigned(bits, 6);
224
118k
   for (i=0;i<10;i++)
225
107k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
10.7k
   id=speex_bits_unpack_unsigned(bits, 6);
228
64.7k
   for (i=0;i<5;i++)
229
53.9k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
10.7k
   id=speex_bits_unpack_unsigned(bits, 6);
232
64.7k
   for (i=0;i<5;i++)
233
53.9k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
10.7k
   id=speex_bits_unpack_unsigned(bits, 6);
236
64.7k
   for (i=0;i<5;i++)
237
53.9k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
10.7k
   id=speex_bits_unpack_unsigned(bits, 6);
240
64.7k
   for (i=0;i<5;i++)
241
53.9k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
10.7k
}
lsp_unquant_nb
Line
Count
Source
217
5.39k
{
218
5.39k
   int i, id;
219
59.3k
   for (i=0;i<order;i++)
220
53.9k
      lsp[i]=LSP_LINEAR(i);
221
222
223
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
224
59.3k
   for (i=0;i<10;i++)
225
53.9k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
228
32.3k
   for (i=0;i<5;i++)
229
26.9k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
232
32.3k
   for (i=0;i<5;i++)
233
26.9k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
236
32.3k
   for (i=0;i<5;i++)
237
26.9k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
240
32.3k
   for (i=0;i<5;i++)
241
26.9k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
5.39k
}
lsp_unquant_nb
Line
Count
Source
217
5.39k
{
218
5.39k
   int i, id;
219
59.3k
   for (i=0;i<order;i++)
220
53.9k
      lsp[i]=LSP_LINEAR(i);
221
222
223
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
224
59.3k
   for (i=0;i<10;i++)
225
53.9k
      lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
226
227
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
228
32.3k
   for (i=0;i<5;i++)
229
26.9k
      lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
230
231
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
232
32.3k
   for (i=0;i<5;i++)
233
26.9k
      lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
234
235
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
236
32.3k
   for (i=0;i<5;i++)
237
26.9k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
238
239
5.39k
   id=speex_bits_unpack_unsigned(bits, 6);
240
32.3k
   for (i=0;i<5;i++)
241
26.9k
      lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
242
5.39k
}
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.9k
{
248
21.9k
   int i;
249
21.9k
   int id;
250
21.9k
   spx_word16_t quant_weight[10];
251
252
241k
   for (i=0;i<order;i++)
253
219k
      qlsp[i]=lsp[i];
254
255
21.9k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
241k
   for (i=0;i<order;i++)
258
219k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
259
#ifndef FIXED_POINT
260
67.8k
   for (i=0;i<order;i++)
261
61.6k
      qlsp[i]=qlsp[i]*LSP_SCALE;
262
#endif
263
21.9k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
21.9k
   speex_bits_pack(bits, id, 6);
265
266
241k
   for (i=0;i<order;i++)
267
219k
      qlsp[i]*=2;
268
269
21.9k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
21.9k
   speex_bits_pack(bits, id, 6);
271
272
21.9k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
21.9k
   speex_bits_pack(bits, id, 6);
274
275
#ifdef FIXED_POINT
276
173k
   for (i=0;i<order;i++)
277
158k
      qlsp[i] = PSHR16(qlsp[i],1);
278
#else
279
67.8k
   for (i=0;i<order;i++)
280
61.6k
      qlsp[i] = qlsp[i]*0.0019531;
281
#endif
282
283
241k
   for (i=0;i<order;i++)
284
219k
      qlsp[i]=lsp[i]-qlsp[i];
285
21.9k
}
lsp_quant_lbr
Line
Count
Source
247
6.16k
{
248
6.16k
   int i;
249
6.16k
   int id;
250
6.16k
   spx_word16_t quant_weight[10];
251
252
67.8k
   for (i=0;i<order;i++)
253
61.6k
      qlsp[i]=lsp[i];
254
255
6.16k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
67.8k
   for (i=0;i<order;i++)
258
61.6k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
259
6.16k
#ifndef FIXED_POINT
260
67.8k
   for (i=0;i<order;i++)
261
61.6k
      qlsp[i]=qlsp[i]*LSP_SCALE;
262
6.16k
#endif
263
6.16k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
6.16k
   speex_bits_pack(bits, id, 6);
265
266
67.8k
   for (i=0;i<order;i++)
267
61.6k
      qlsp[i]*=2;
268
269
6.16k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
6.16k
   speex_bits_pack(bits, id, 6);
271
272
6.16k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
6.16k
   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.8k
   for (i=0;i<order;i++)
280
61.6k
      qlsp[i] = qlsp[i]*0.0019531;
281
6.16k
#endif
282
283
67.8k
   for (i=0;i<order;i++)
284
61.6k
      qlsp[i]=lsp[i]-qlsp[i];
285
6.16k
}
lsp_quant_lbr
Line
Count
Source
247
15.8k
{
248
15.8k
   int i;
249
15.8k
   int id;
250
15.8k
   spx_word16_t quant_weight[10];
251
252
173k
   for (i=0;i<order;i++)
253
158k
      qlsp[i]=lsp[i];
254
255
15.8k
   compute_quant_weights(qlsp, quant_weight, order);
256
257
173k
   for (i=0;i<order;i++)
258
158k
      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.8k
   id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
264
15.8k
   speex_bits_pack(bits, id, 6);
265
266
173k
   for (i=0;i<order;i++)
267
158k
      qlsp[i]*=2;
268
269
15.8k
   id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
270
15.8k
   speex_bits_pack(bits, id, 6);
271
272
15.8k
   id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
273
15.8k
   speex_bits_pack(bits, id, 6);
274
275
15.8k
#ifdef FIXED_POINT
276
173k
   for (i=0;i<order;i++)
277
158k
      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
173k
   for (i=0;i<order;i++)
284
158k
      qlsp[i]=lsp[i]-qlsp[i];
285
15.8k
}
286
#endif /* DISABLE_ENCODER */
287
288
#ifndef DISABLE_DECODER
289
void lsp_unquant_lbr(spx_lsp_t *lsp, int order, SpeexBits *bits)
290
36.9k
{
291
36.9k
   int i, id;
292
406k
   for (i=0;i<order;i++)
293
369k
      lsp[i]=LSP_LINEAR(i);
294
295
296
36.9k
   id=speex_bits_unpack_unsigned(bits, 6);
297
406k
   for (i=0;i<10;i++)
298
369k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
36.9k
   id=speex_bits_unpack_unsigned(bits, 6);
301
221k
   for (i=0;i<5;i++)
302
184k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
36.9k
   id=speex_bits_unpack_unsigned(bits, 6);
305
221k
   for (i=0;i<5;i++)
306
184k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
36.9k
}
lsp_unquant_lbr
Line
Count
Source
290
18.4k
{
291
18.4k
   int i, id;
292
203k
   for (i=0;i<order;i++)
293
184k
      lsp[i]=LSP_LINEAR(i);
294
295
296
18.4k
   id=speex_bits_unpack_unsigned(bits, 6);
297
203k
   for (i=0;i<10;i++)
298
184k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
18.4k
   id=speex_bits_unpack_unsigned(bits, 6);
301
110k
   for (i=0;i<5;i++)
302
92.4k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
18.4k
   id=speex_bits_unpack_unsigned(bits, 6);
305
110k
   for (i=0;i<5;i++)
306
92.4k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
18.4k
}
lsp_unquant_lbr
Line
Count
Source
290
18.4k
{
291
18.4k
   int i, id;
292
203k
   for (i=0;i<order;i++)
293
184k
      lsp[i]=LSP_LINEAR(i);
294
295
296
18.4k
   id=speex_bits_unpack_unsigned(bits, 6);
297
203k
   for (i=0;i<10;i++)
298
184k
      lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
299
300
18.4k
   id=speex_bits_unpack_unsigned(bits, 6);
301
110k
   for (i=0;i<5;i++)
302
92.4k
      lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
303
304
18.4k
   id=speex_bits_unpack_unsigned(bits, 6);
305
110k
   for (i=0;i<5;i++)
306
92.4k
      lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
307
308
18.4k
}
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.35k
{
318
9.35k
   int i;
319
9.35k
   int id;
320
9.35k
   spx_word16_t quant_weight[10];
321
322
84.1k
   for (i=0;i<order;i++)
323
74.8k
      qlsp[i]=lsp[i];
324
325
9.35k
   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.1k
   for (i=0;i<order;i++)
337
74.8k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR_HIGH(i));
338
#ifndef FIXED_POINT
339
26.8k
   for (i=0;i<order;i++)
340
23.8k
      qlsp[i] = qlsp[i]*LSP_SCALE;
341
#endif
342
9.35k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
9.35k
   speex_bits_pack(bits, id, 6);
344
345
84.1k
   for (i=0;i<order;i++)
346
74.8k
      qlsp[i]*=2;
347
348
9.35k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
9.35k
   speex_bits_pack(bits, id, 6);
350
351
#ifdef FIXED_POINT
352
57.3k
   for (i=0;i<order;i++)
353
50.9k
      qlsp[i] = PSHR16(qlsp[i],1);
354
#else
355
26.8k
   for (i=0;i<order;i++)
356
23.8k
      qlsp[i] = qlsp[i]*0.0019531;
357
#endif
358
359
84.1k
   for (i=0;i<order;i++)
360
74.8k
      qlsp[i]=lsp[i]-qlsp[i];
361
9.35k
}
lsp_quant_high
Line
Count
Source
317
2.98k
{
318
2.98k
   int i;
319
2.98k
   int id;
320
2.98k
   spx_word16_t quant_weight[10];
321
322
26.8k
   for (i=0;i<order;i++)
323
23.8k
      qlsp[i]=lsp[i];
324
325
2.98k
   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
26.8k
   for (i=0;i<order;i++)
337
23.8k
      qlsp[i]=SUB16(qlsp[i],LSP_LINEAR_HIGH(i));
338
2.98k
#ifndef FIXED_POINT
339
26.8k
   for (i=0;i<order;i++)
340
23.8k
      qlsp[i] = qlsp[i]*LSP_SCALE;
341
2.98k
#endif
342
2.98k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
2.98k
   speex_bits_pack(bits, id, 6);
344
345
26.8k
   for (i=0;i<order;i++)
346
23.8k
      qlsp[i]*=2;
347
348
2.98k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
2.98k
   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
26.8k
   for (i=0;i<order;i++)
356
23.8k
      qlsp[i] = qlsp[i]*0.0019531;
357
2.98k
#endif
358
359
26.8k
   for (i=0;i<order;i++)
360
23.8k
      qlsp[i]=lsp[i]-qlsp[i];
361
2.98k
}
lsp_quant_high
Line
Count
Source
317
6.36k
{
318
6.36k
   int i;
319
6.36k
   int id;
320
6.36k
   spx_word16_t quant_weight[10];
321
322
57.3k
   for (i=0;i<order;i++)
323
50.9k
      qlsp[i]=lsp[i];
324
325
6.36k
   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
57.3k
   for (i=0;i<order;i++)
337
50.9k
      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.36k
   id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
343
6.36k
   speex_bits_pack(bits, id, 6);
344
345
57.3k
   for (i=0;i<order;i++)
346
50.9k
      qlsp[i]*=2;
347
348
6.36k
   id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
349
6.36k
   speex_bits_pack(bits, id, 6);
350
351
6.36k
#ifdef FIXED_POINT
352
57.3k
   for (i=0;i<order;i++)
353
50.9k
      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
57.3k
   for (i=0;i<order;i++)
360
50.9k
      qlsp[i]=lsp[i]-qlsp[i];
361
6.36k
}
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.3k
{
368
369
12.3k
   int i, id;
370
110k
   for (i=0;i<order;i++)
371
98.6k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
12.3k
   id=speex_bits_unpack_unsigned(bits, 6);
375
110k
   for (i=0;i<order;i++)
376
98.6k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
12.3k
   id=speex_bits_unpack_unsigned(bits, 6);
380
110k
   for (i=0;i<order;i++)
381
98.6k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
12.3k
}
lsp_unquant_high
Line
Count
Source
367
6.16k
{
368
369
6.16k
   int i, id;
370
55.4k
   for (i=0;i<order;i++)
371
49.3k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
6.16k
   id=speex_bits_unpack_unsigned(bits, 6);
375
55.4k
   for (i=0;i<order;i++)
376
49.3k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
6.16k
   id=speex_bits_unpack_unsigned(bits, 6);
380
55.4k
   for (i=0;i<order;i++)
381
49.3k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
6.16k
}
lsp_unquant_high
Line
Count
Source
367
6.16k
{
368
369
6.16k
   int i, id;
370
55.4k
   for (i=0;i<order;i++)
371
49.3k
      lsp[i]=LSP_LINEAR_HIGH(i);
372
373
374
6.16k
   id=speex_bits_unpack_unsigned(bits, 6);
375
55.4k
   for (i=0;i<order;i++)
376
49.3k
      lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
377
378
379
6.16k
   id=speex_bits_unpack_unsigned(bits, 6);
380
55.4k
   for (i=0;i<order;i++)
381
49.3k
      lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
382
6.16k
}
383
#endif /* DISABLE_DECODER */
384
385
#endif /* DISABLE_WIDEBAND */
386