/src/vlc/contrib/contrib-build/speex/libspeex/cb_search.c
Line | Count | Source |
1 | | /* Copyright (C) 2002-2006 Jean-Marc Valin |
2 | | File: cb_search.c |
3 | | |
4 | | Redistribution and use in source and binary forms, with or without |
5 | | modification, are permitted provided that the following conditions |
6 | | are met: |
7 | | |
8 | | - Redistributions of source code must retain the above copyright |
9 | | notice, this list of conditions and the following disclaimer. |
10 | | |
11 | | - Redistributions in binary form must reproduce the above copyright |
12 | | notice, this list of conditions and the following disclaimer in the |
13 | | documentation and/or other materials provided with the distribution. |
14 | | |
15 | | - Neither the name of the Xiph.org Foundation nor the names of its |
16 | | contributors may be used to endorse or promote products derived from |
17 | | this software without specific prior written permission. |
18 | | |
19 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 | | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
23 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
24 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
25 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
26 | | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
27 | | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
28 | | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
29 | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | | */ |
31 | | |
32 | | #ifdef HAVE_CONFIG_H |
33 | | #include "config.h" |
34 | | #endif |
35 | | |
36 | | #include "cb_search.h" |
37 | | #include "filters.h" |
38 | | #include "stack_alloc.h" |
39 | | #include "vq.h" |
40 | | #include "arch.h" |
41 | | #include "math_approx.h" |
42 | | #include "os_support.h" |
43 | | |
44 | | #ifdef _USE_SSE |
45 | | #include "cb_search_sse.h" |
46 | | #elif defined(ARM4_ASM) || defined(ARM5E_ASM) |
47 | | #include "cb_search_arm4.h" |
48 | | #elif defined(BFIN_ASM) |
49 | | #include "cb_search_bfin.h" |
50 | | #endif |
51 | | |
52 | | #ifndef DISABLE_ENCODER |
53 | | |
54 | | #ifndef OVERRIDE_COMPUTE_WEIGHTED_CODEBOOK |
55 | | static void compute_weighted_codebook(const signed char *shape_cb, const spx_word16_t *r, spx_word16_t *resp, spx_word16_t *resp2, spx_word32_t *E, int shape_cb_size, int subvect_size, char *stack) |
56 | | { |
57 | | int i, j, k; |
58 | | VARDECL(spx_word16_t *shape); |
59 | | ALLOC(shape, subvect_size, spx_word16_t); |
60 | | for (i=0;i<shape_cb_size;i++) |
61 | | { |
62 | | spx_word16_t *res; |
63 | | |
64 | | res = resp+i*subvect_size; |
65 | | for (k=0;k<subvect_size;k++) |
66 | | shape[k] = (spx_word16_t)shape_cb[i*subvect_size+k]; |
67 | | E[i]=0; |
68 | | |
69 | | /* Compute codeword response using convolution with impulse response */ |
70 | | for(j=0;j<subvect_size;j++) |
71 | | { |
72 | | spx_word32_t resj=0; |
73 | | spx_word16_t res16; |
74 | | for (k=0;k<=j;k++) |
75 | | resj = MAC16_16(resj,shape[k],r[j-k]); |
76 | | #ifdef FIXED_POINT |
77 | | res16 = EXTRACT16(SHR32(resj, 13)); |
78 | | #else |
79 | | res16 = 0.03125f*resj; |
80 | | #endif |
81 | | /* Compute codeword energy */ |
82 | | E[i]=MAC16_16(E[i],res16,res16); |
83 | | res[j] = res16; |
84 | | /*printf ("%d\n", (int)res[j]);*/ |
85 | | } |
86 | | } |
87 | | |
88 | | } |
89 | | #endif |
90 | | |
91 | | #ifndef OVERRIDE_TARGET_UPDATE |
92 | | static inline void target_update(spx_word16_t *t, spx_word16_t g, spx_word16_t *r, int len) |
93 | 0 | { |
94 | 0 | int n; |
95 | 0 | for (n=0;n<len;n++) |
96 | 0 | t[n] = SUB16(t[n],PSHR32(MULT16_16(g,r[n]),13)); |
97 | 0 | } |
98 | | #endif |
99 | | |
100 | | |
101 | | |
102 | | static void split_cb_search_shape_sign_N1( |
103 | | spx_word16_t target[], /* target vector */ |
104 | | spx_coef_t ak[], /* LPCs for this subframe */ |
105 | | spx_coef_t awk1[], /* Weighted LPCs for this subframe */ |
106 | | spx_coef_t awk2[], /* Weighted LPCs for this subframe */ |
107 | | const void *par, /* Codebook/search parameters*/ |
108 | | int p, /* number of LPC coeffs */ |
109 | | int nsf, /* number of samples in subframe */ |
110 | | spx_sig_t *exc, |
111 | | spx_word16_t *r, |
112 | | SpeexBits *bits, |
113 | | char *stack, |
114 | | int update_target |
115 | | ) |
116 | 0 | { |
117 | 0 | int i,j,m,q; |
118 | 0 | VARDECL(spx_word16_t *resp); |
119 | 0 | #ifdef _USE_SSE |
120 | 0 | VARDECL(__m128 *resp2); |
121 | 0 | VARDECL(__m128 *E); |
122 | | #else |
123 | | spx_word16_t *resp2; |
124 | | VARDECL(spx_word32_t *E); |
125 | | #endif |
126 | 0 | VARDECL(spx_word16_t *t); |
127 | 0 | VARDECL(spx_sig_t *e); |
128 | 0 | const signed char *shape_cb; |
129 | 0 | int shape_cb_size, subvect_size, nb_subvect; |
130 | 0 | const split_cb_params *params; |
131 | 0 | int best_index; |
132 | 0 | spx_word32_t best_dist; |
133 | 0 | int have_sign; |
134 | |
|
135 | 0 | params = (const split_cb_params *) par; |
136 | 0 | subvect_size = params->subvect_size; |
137 | 0 | nb_subvect = params->nb_subvect; |
138 | 0 | shape_cb_size = 1<<params->shape_bits; |
139 | 0 | shape_cb = params->shape_cb; |
140 | 0 | have_sign = params->have_sign; |
141 | 0 | ALLOC(resp, shape_cb_size*subvect_size, spx_word16_t); |
142 | 0 | #ifdef _USE_SSE |
143 | 0 | ALLOC(resp2, (shape_cb_size*subvect_size)>>2, __m128); |
144 | 0 | ALLOC(E, shape_cb_size>>2, __m128); |
145 | | #else |
146 | | resp2 = resp; |
147 | | ALLOC(E, shape_cb_size, spx_word32_t); |
148 | | #endif |
149 | 0 | ALLOC(t, nsf, spx_word16_t); |
150 | 0 | ALLOC(e, nsf, spx_sig_t); |
151 | | |
152 | | /* FIXME: Do we still need to copy the target? */ |
153 | 0 | SPEEX_COPY(t, target, nsf); |
154 | |
|
155 | 0 | compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack); |
156 | |
|
157 | 0 | for (i=0;i<nb_subvect;i++) |
158 | 0 | { |
159 | 0 | spx_word16_t *x=t+subvect_size*i; |
160 | | /*Find new n-best based on previous n-best j*/ |
161 | 0 | #ifndef DISABLE_WIDEBAND |
162 | 0 | if (have_sign) |
163 | 0 | vq_nbest_sign(x, resp2, subvect_size, shape_cb_size, E, 1, &best_index, &best_dist, stack); |
164 | 0 | else |
165 | 0 | #endif /* DISABLE_WIDEBAND */ |
166 | 0 | vq_nbest(x, resp2, subvect_size, shape_cb_size, E, 1, &best_index, &best_dist, stack); |
167 | |
|
168 | 0 | speex_bits_pack(bits,best_index,params->shape_bits+have_sign); |
169 | |
|
170 | 0 | { |
171 | 0 | int rind; |
172 | 0 | spx_word16_t *res; |
173 | 0 | spx_word16_t sign=1; |
174 | 0 | rind = best_index; |
175 | 0 | if (rind>=shape_cb_size) |
176 | 0 | { |
177 | 0 | sign=-1; |
178 | 0 | rind-=shape_cb_size; |
179 | 0 | } |
180 | 0 | res = resp+rind*subvect_size; |
181 | 0 | if (sign>0) |
182 | 0 | for (m=0;m<subvect_size;m++) |
183 | 0 | t[subvect_size*i+m] = SUB16(t[subvect_size*i+m], res[m]); |
184 | 0 | else |
185 | 0 | for (m=0;m<subvect_size;m++) |
186 | 0 | t[subvect_size*i+m] = ADD16(t[subvect_size*i+m], res[m]); |
187 | |
|
188 | | #ifdef FIXED_POINT |
189 | | if (sign==1) |
190 | | { |
191 | | for (j=0;j<subvect_size;j++) |
192 | | e[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5); |
193 | | } else { |
194 | | for (j=0;j<subvect_size;j++) |
195 | | e[subvect_size*i+j]=NEG32(SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5)); |
196 | | } |
197 | | #else |
198 | 0 | for (j=0;j<subvect_size;j++) |
199 | 0 | e[subvect_size*i+j]=sign*0.03125*shape_cb[rind*subvect_size+j]; |
200 | 0 | #endif |
201 | |
|
202 | 0 | } |
203 | |
|
204 | 0 | for (m=0;m<subvect_size;m++) |
205 | 0 | { |
206 | 0 | spx_word16_t g; |
207 | 0 | int rind; |
208 | 0 | spx_word16_t sign=1; |
209 | 0 | rind = best_index; |
210 | 0 | if (rind>=shape_cb_size) |
211 | 0 | { |
212 | 0 | sign=-1; |
213 | 0 | rind-=shape_cb_size; |
214 | 0 | } |
215 | |
|
216 | 0 | q=subvect_size-m; |
217 | | #ifdef FIXED_POINT |
218 | | g=sign*shape_cb[rind*subvect_size+m]; |
219 | | #else |
220 | 0 | g=sign*0.03125*shape_cb[rind*subvect_size+m]; |
221 | 0 | #endif |
222 | 0 | target_update(t+subvect_size*(i+1), g, r+q, nsf-subvect_size*(i+1)); |
223 | 0 | } |
224 | 0 | } |
225 | | |
226 | | /* Update excitation */ |
227 | | /* FIXME: We could update the excitation directly above */ |
228 | 0 | for (j=0;j<nsf;j++) |
229 | 0 | exc[j]=ADD32(exc[j],e[j]); |
230 | | |
231 | | /* Update target: only update target if necessary */ |
232 | 0 | if (update_target) |
233 | 0 | { |
234 | 0 | VARDECL(spx_word16_t *r2); |
235 | 0 | ALLOC(r2, nsf, spx_word16_t); |
236 | 0 | for (j=0;j<nsf;j++) |
237 | 0 | r2[j] = EXTRACT16(PSHR32(e[j] ,6)); |
238 | 0 | syn_percep_zero16(r2, ak, awk1, awk2, r2, nsf,p, stack); |
239 | 0 | for (j=0;j<nsf;j++) |
240 | 0 | target[j]=SUB16(target[j],PSHR16(r2[j],2)); |
241 | 0 | } |
242 | 0 | } |
243 | | |
244 | | |
245 | | |
246 | | void split_cb_search_shape_sign( |
247 | | spx_word16_t target[], /* target vector */ |
248 | | spx_coef_t ak[], /* LPCs for this subframe */ |
249 | | spx_coef_t awk1[], /* Weighted LPCs for this subframe */ |
250 | | spx_coef_t awk2[], /* Weighted LPCs for this subframe */ |
251 | | const void *par, /* Codebook/search parameters*/ |
252 | | int p, /* number of LPC coeffs */ |
253 | | int nsf, /* number of samples in subframe */ |
254 | | spx_sig_t *exc, |
255 | | spx_word16_t *r, |
256 | | SpeexBits *bits, |
257 | | char *stack, |
258 | | int complexity, |
259 | | int update_target |
260 | | ) |
261 | 0 | { |
262 | 0 | int i,j,k,m,n,q; |
263 | 0 | VARDECL(spx_word16_t *resp); |
264 | 0 | #ifdef _USE_SSE |
265 | 0 | VARDECL(__m128 *resp2); |
266 | 0 | VARDECL(__m128 *E); |
267 | | #else |
268 | | spx_word16_t *resp2; |
269 | | VARDECL(spx_word32_t *E); |
270 | | #endif |
271 | 0 | VARDECL(spx_word16_t *t); |
272 | 0 | VARDECL(spx_sig_t *e); |
273 | 0 | VARDECL(spx_word16_t *tmp); |
274 | 0 | VARDECL(spx_word32_t *ndist); |
275 | 0 | VARDECL(spx_word32_t *odist); |
276 | 0 | VARDECL(int *itmp); |
277 | 0 | VARDECL(spx_word16_t **ot2); |
278 | 0 | VARDECL(spx_word16_t **nt2); |
279 | 0 | spx_word16_t **ot, **nt; |
280 | 0 | VARDECL(int **nind); |
281 | 0 | VARDECL(int **oind); |
282 | 0 | VARDECL(int *ind); |
283 | 0 | const signed char *shape_cb; |
284 | 0 | int shape_cb_size, subvect_size, nb_subvect; |
285 | 0 | const split_cb_params *params; |
286 | 0 | int N=2; |
287 | 0 | VARDECL(int *best_index); |
288 | 0 | VARDECL(spx_word32_t *best_dist); |
289 | 0 | VARDECL(int *best_nind); |
290 | 0 | VARDECL(int *best_ntarget); |
291 | 0 | int have_sign; |
292 | 0 | N=complexity; |
293 | 0 | if (N>10) |
294 | 0 | N=10; |
295 | | /* Complexity isn't as important for the codebooks as it is for the pitch */ |
296 | 0 | N=(2*N)/3; |
297 | 0 | if (N<1) |
298 | 0 | N=1; |
299 | 0 | if (N==1) |
300 | 0 | { |
301 | 0 | split_cb_search_shape_sign_N1(target,ak,awk1,awk2,par,p,nsf,exc,r,bits,stack,update_target); |
302 | 0 | return; |
303 | 0 | } |
304 | 0 | ALLOC(ot2, N, spx_word16_t*); |
305 | 0 | ALLOC(nt2, N, spx_word16_t*); |
306 | 0 | ALLOC(oind, N, int*); |
307 | 0 | ALLOC(nind, N, int*); |
308 | |
|
309 | 0 | params = (const split_cb_params *) par; |
310 | 0 | subvect_size = params->subvect_size; |
311 | 0 | nb_subvect = params->nb_subvect; |
312 | 0 | shape_cb_size = 1<<params->shape_bits; |
313 | 0 | shape_cb = params->shape_cb; |
314 | 0 | have_sign = params->have_sign; |
315 | 0 | ALLOC(resp, shape_cb_size*subvect_size, spx_word16_t); |
316 | 0 | #ifdef _USE_SSE |
317 | 0 | ALLOC(resp2, (shape_cb_size*subvect_size)>>2, __m128); |
318 | 0 | ALLOC(E, shape_cb_size>>2, __m128); |
319 | | #else |
320 | | resp2 = resp; |
321 | | ALLOC(E, shape_cb_size, spx_word32_t); |
322 | | #endif |
323 | 0 | ALLOC(t, nsf, spx_word16_t); |
324 | 0 | ALLOC(e, nsf, spx_sig_t); |
325 | 0 | ALLOC(ind, nb_subvect, int); |
326 | |
|
327 | 0 | ALLOC(tmp, 2*N*nsf, spx_word16_t); |
328 | 0 | for (i=0;i<N;i++) |
329 | 0 | { |
330 | 0 | ot2[i]=tmp+2*i*nsf; |
331 | 0 | nt2[i]=tmp+(2*i+1)*nsf; |
332 | 0 | } |
333 | 0 | ot=ot2; |
334 | 0 | nt=nt2; |
335 | 0 | ALLOC(best_index, N, int); |
336 | 0 | ALLOC(best_dist, N, spx_word32_t); |
337 | 0 | ALLOC(best_nind, N, int); |
338 | 0 | ALLOC(best_ntarget, N, int); |
339 | 0 | ALLOC(ndist, N, spx_word32_t); |
340 | 0 | ALLOC(odist, N, spx_word32_t); |
341 | |
|
342 | 0 | ALLOC(itmp, 2*N*nb_subvect, int); |
343 | 0 | for (i=0;i<N;i++) |
344 | 0 | { |
345 | 0 | nind[i]=itmp+2*i*nb_subvect; |
346 | 0 | oind[i]=itmp+(2*i+1)*nb_subvect; |
347 | 0 | } |
348 | |
|
349 | 0 | SPEEX_COPY(t, target, nsf); |
350 | |
|
351 | 0 | for (j=0;j<N;j++) |
352 | 0 | SPEEX_COPY(&ot[j][0], t, nsf); |
353 | | |
354 | | /* Pre-compute codewords response and energy */ |
355 | 0 | compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack); |
356 | |
|
357 | 0 | for (j=0;j<N;j++) |
358 | 0 | odist[j]=0; |
359 | | |
360 | | /*For all subvectors*/ |
361 | 0 | for (i=0;i<nb_subvect;i++) |
362 | 0 | { |
363 | | /*"erase" nbest list*/ |
364 | 0 | for (j=0;j<N;j++) |
365 | 0 | ndist[j]=VERY_LARGE32; |
366 | | /* This is not strictly necessary, but it provides an additonal safety |
367 | | to prevent crashes in case something goes wrong in the previous |
368 | | steps (e.g. NaNs) */ |
369 | 0 | for (j=0;j<N;j++) |
370 | 0 | best_nind[j] = best_ntarget[j] = 0; |
371 | | /*For all n-bests of previous subvector*/ |
372 | 0 | for (j=0;j<N;j++) |
373 | 0 | { |
374 | 0 | spx_word16_t *x=ot[j]+subvect_size*i; |
375 | 0 | spx_word32_t tener = 0; |
376 | 0 | for (m=0;m<subvect_size;m++) |
377 | 0 | tener = MAC16_16(tener, x[m],x[m]); |
378 | | #ifdef FIXED_POINT |
379 | | tener = SHR32(tener,1); |
380 | | #else |
381 | 0 | tener *= .5; |
382 | 0 | #endif |
383 | | /*Find new n-best based on previous n-best j*/ |
384 | 0 | #ifndef DISABLE_WIDEBAND |
385 | 0 | if (have_sign) |
386 | 0 | vq_nbest_sign(x, resp2, subvect_size, shape_cb_size, E, N, best_index, best_dist, stack); |
387 | 0 | else |
388 | 0 | #endif /* DISABLE_WIDEBAND */ |
389 | 0 | vq_nbest(x, resp2, subvect_size, shape_cb_size, E, N, best_index, best_dist, stack); |
390 | | |
391 | | /*For all new n-bests*/ |
392 | 0 | for (k=0;k<N;k++) |
393 | 0 | { |
394 | | /* Compute total distance (including previous sub-vectors */ |
395 | 0 | spx_word32_t err = ADD32(ADD32(odist[j],best_dist[k]),tener); |
396 | | |
397 | | /*update n-best list*/ |
398 | 0 | if (err<ndist[N-1]) |
399 | 0 | { |
400 | 0 | for (m=0;m<N;m++) |
401 | 0 | { |
402 | 0 | if (err < ndist[m]) |
403 | 0 | { |
404 | 0 | for (n=N-1;n>m;n--) |
405 | 0 | { |
406 | 0 | ndist[n] = ndist[n-1]; |
407 | 0 | best_nind[n] = best_nind[n-1]; |
408 | 0 | best_ntarget[n] = best_ntarget[n-1]; |
409 | 0 | } |
410 | | /* n is equal to m here, so they're interchangeable */ |
411 | 0 | ndist[m] = err; |
412 | 0 | best_nind[n] = best_index[k]; |
413 | 0 | best_ntarget[n] = j; |
414 | 0 | break; |
415 | 0 | } |
416 | 0 | } |
417 | 0 | } |
418 | 0 | } |
419 | 0 | if (i==0) |
420 | 0 | break; |
421 | 0 | } |
422 | 0 | for (j=0;j<N;j++) |
423 | 0 | { |
424 | | /*previous target (we don't care what happened before*/ |
425 | 0 | for (m=(i+1)*subvect_size;m<nsf;m++) |
426 | 0 | nt[j][m]=ot[best_ntarget[j]][m]; |
427 | | |
428 | | /* New code: update the rest of the target only if it's worth it */ |
429 | 0 | for (m=0;m<subvect_size;m++) |
430 | 0 | { |
431 | 0 | spx_word16_t g; |
432 | 0 | int rind; |
433 | 0 | spx_word16_t sign=1; |
434 | 0 | rind = best_nind[j]; |
435 | 0 | if (rind>=shape_cb_size) |
436 | 0 | { |
437 | 0 | sign=-1; |
438 | 0 | rind-=shape_cb_size; |
439 | 0 | } |
440 | |
|
441 | 0 | q=subvect_size-m; |
442 | | #ifdef FIXED_POINT |
443 | | g=sign*shape_cb[rind*subvect_size+m]; |
444 | | #else |
445 | 0 | g=sign*0.03125*shape_cb[rind*subvect_size+m]; |
446 | 0 | #endif |
447 | 0 | target_update(nt[j]+subvect_size*(i+1), g, r+q, nsf-subvect_size*(i+1)); |
448 | 0 | } |
449 | |
|
450 | 0 | for (q=0;q<nb_subvect;q++) |
451 | 0 | nind[j][q]=oind[best_ntarget[j]][q]; |
452 | 0 | nind[j][i]=best_nind[j]; |
453 | 0 | } |
454 | | |
455 | | /*update old-new data*/ |
456 | | /* just swap pointers instead of a long copy */ |
457 | 0 | { |
458 | 0 | spx_word16_t **tmp2; |
459 | 0 | tmp2=ot; |
460 | 0 | ot=nt; |
461 | 0 | nt=tmp2; |
462 | 0 | } |
463 | 0 | for (j=0;j<N;j++) |
464 | 0 | for (m=0;m<nb_subvect;m++) |
465 | 0 | oind[j][m]=nind[j][m]; |
466 | 0 | for (j=0;j<N;j++) |
467 | 0 | odist[j]=ndist[j]; |
468 | 0 | } |
469 | | |
470 | | /*save indices*/ |
471 | 0 | for (i=0;i<nb_subvect;i++) |
472 | 0 | { |
473 | 0 | ind[i]=nind[0][i]; |
474 | 0 | speex_bits_pack(bits,ind[i],params->shape_bits+have_sign); |
475 | 0 | } |
476 | | |
477 | | /* Put everything back together */ |
478 | 0 | for (i=0;i<nb_subvect;i++) |
479 | 0 | { |
480 | 0 | int rind; |
481 | 0 | spx_word16_t sign=1; |
482 | 0 | rind = ind[i]; |
483 | 0 | if (rind>=shape_cb_size) |
484 | 0 | { |
485 | 0 | sign=-1; |
486 | 0 | rind-=shape_cb_size; |
487 | 0 | } |
488 | | #ifdef FIXED_POINT |
489 | | if (sign==1) |
490 | | { |
491 | | for (j=0;j<subvect_size;j++) |
492 | | e[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5); |
493 | | } else { |
494 | | for (j=0;j<subvect_size;j++) |
495 | | e[subvect_size*i+j]=NEG32(SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5)); |
496 | | } |
497 | | #else |
498 | 0 | for (j=0;j<subvect_size;j++) |
499 | 0 | e[subvect_size*i+j]=sign*0.03125*shape_cb[rind*subvect_size+j]; |
500 | 0 | #endif |
501 | 0 | } |
502 | | /* Update excitation */ |
503 | 0 | for (j=0;j<nsf;j++) |
504 | 0 | exc[j]=ADD32(exc[j],e[j]); |
505 | | |
506 | | /* Update target: only update target if necessary */ |
507 | 0 | if (update_target) |
508 | 0 | { |
509 | 0 | VARDECL(spx_word16_t *r2); |
510 | 0 | ALLOC(r2, nsf, spx_word16_t); |
511 | 0 | for (j=0;j<nsf;j++) |
512 | 0 | r2[j] = EXTRACT16(PSHR32(e[j] ,6)); |
513 | 0 | syn_percep_zero16(r2, ak, awk1, awk2, r2, nsf,p, stack); |
514 | 0 | for (j=0;j<nsf;j++) |
515 | 0 | target[j]=SUB16(target[j],PSHR16(r2[j],2)); |
516 | 0 | } |
517 | 0 | } |
518 | | #endif /* DISABLE_ENCODER */ |
519 | | |
520 | | #ifndef DISABLE_DECODER |
521 | | void split_cb_shape_sign_unquant( |
522 | | spx_sig_t *exc, |
523 | | const void *par, /* non-overlapping codebook */ |
524 | | int nsf, /* number of samples in subframe */ |
525 | | SpeexBits *bits, |
526 | | char *stack, |
527 | | spx_uint32_t *seed |
528 | | ) |
529 | 17.5k | { |
530 | 17.5k | int i,j; |
531 | 17.5k | VARDECL(int *ind); |
532 | 17.5k | VARDECL(int *signs); |
533 | 17.5k | const signed char *shape_cb; |
534 | 17.5k | int subvect_size, nb_subvect; |
535 | 17.5k | const split_cb_params *params; |
536 | 17.5k | int have_sign; |
537 | | |
538 | 17.5k | params = (const split_cb_params *) par; |
539 | 17.5k | subvect_size = params->subvect_size; |
540 | 17.5k | nb_subvect = params->nb_subvect; |
541 | | |
542 | 17.5k | shape_cb = params->shape_cb; |
543 | 17.5k | have_sign = params->have_sign; |
544 | | |
545 | 17.5k | ALLOC(ind, nb_subvect, int); |
546 | 17.5k | ALLOC(signs, nb_subvect, int); |
547 | | |
548 | | /* Decode codewords and gains */ |
549 | 119k | for (i=0;i<nb_subvect;i++) |
550 | 101k | { |
551 | 101k | if (have_sign) |
552 | 0 | signs[i] = speex_bits_unpack_unsigned(bits, 1); |
553 | 101k | else |
554 | 101k | signs[i] = 0; |
555 | 101k | ind[i] = speex_bits_unpack_unsigned(bits, params->shape_bits); |
556 | 101k | } |
557 | | /* Compute decoded excitation */ |
558 | 119k | for (i=0;i<nb_subvect;i++) |
559 | 101k | { |
560 | 101k | spx_word16_t s=1; |
561 | 101k | if (signs[i]) |
562 | 0 | s=-1; |
563 | | #ifdef FIXED_POINT |
564 | | if (s==1) |
565 | | { |
566 | | for (j=0;j<subvect_size;j++) |
567 | | exc[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[ind[i]*subvect_size+j]),SIG_SHIFT-5); |
568 | | } else { |
569 | | for (j=0;j<subvect_size;j++) |
570 | | exc[subvect_size*i+j]=NEG32(SHL32(EXTEND32(shape_cb[ind[i]*subvect_size+j]),SIG_SHIFT-5)); |
571 | | } |
572 | | #else |
573 | 804k | for (j=0;j<subvect_size;j++) |
574 | 702k | exc[subvect_size*i+j]+=s*0.03125*shape_cb[ind[i]*subvect_size+j]; |
575 | 101k | #endif |
576 | 101k | } |
577 | 17.5k | } |
578 | | #endif /* DISABLE_DECODER */ |
579 | | |
580 | | #ifndef DISABLE_ENCODER |
581 | | void noise_codebook_quant( |
582 | | spx_word16_t target[], /* target vector */ |
583 | | spx_coef_t ak[], /* LPCs for this subframe */ |
584 | | spx_coef_t awk1[], /* Weighted LPCs for this subframe */ |
585 | | spx_coef_t awk2[], /* Weighted LPCs for this subframe */ |
586 | | const void *par, /* Codebook/search parameters*/ |
587 | | int p, /* number of LPC coeffs */ |
588 | | int nsf, /* number of samples in subframe */ |
589 | | spx_sig_t *exc, |
590 | | spx_word16_t *r, |
591 | | SpeexBits *bits, |
592 | | char *stack, |
593 | | int complexity, |
594 | | int update_target |
595 | | ) |
596 | 0 | { |
597 | 0 | int i; |
598 | 0 | VARDECL(spx_word16_t *tmp); |
599 | 0 | ALLOC(tmp, nsf, spx_word16_t); |
600 | 0 | residue_percep_zero16(target, ak, awk1, awk2, tmp, nsf, p, stack); |
601 | |
|
602 | 0 | for (i=0;i<nsf;i++) |
603 | 0 | exc[i]+=SHL32(EXTEND32(tmp[i]),8); |
604 | 0 | SPEEX_MEMSET(target, 0, nsf); |
605 | 0 | } |
606 | | #endif /* DISABLE_ENCODER */ |
607 | | |
608 | | #ifndef DISABLE_DECODER |
609 | | void noise_codebook_unquant( |
610 | | spx_sig_t *exc, |
611 | | const void *par, /* non-overlapping codebook */ |
612 | | int nsf, /* number of samples in subframe */ |
613 | | SpeexBits *bits, |
614 | | char *stack, |
615 | | spx_uint32_t *seed |
616 | | ) |
617 | 4.32k | { |
618 | 4.32k | int i; |
619 | | /* FIXME: This is bad, but I don't think the function ever gets called anyway */ |
620 | 177k | for (i=0;i<nsf;i++) |
621 | 172k | exc[i]=SHL32(EXTEND32(speex_rand(1, seed)),SIG_SHIFT); |
622 | 4.32k | } |
623 | | #endif /* DISABLE_DECODER */ |