cb_search.c 18 KB

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