cb_search.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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 OVERRIDE_COMPUTE_WEIGHTED_CODEBOOK
  44. 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)
  45. {
  46. int i, j, k;
  47. VARDECL(spx_word16_t *shape);
  48. ALLOC(shape, subvect_size, spx_word16_t);
  49. for (i=0;i<shape_cb_size;i++)
  50. {
  51. spx_word16_t *res;
  52. res = resp+i*subvect_size;
  53. for (k=0;k<subvect_size;k++)
  54. shape[k] = (spx_word16_t)shape_cb[i*subvect_size+k];
  55. E[i]=0;
  56. /* Compute codeword response using convolution with impulse response */
  57. for(j=0;j<subvect_size;j++)
  58. {
  59. spx_word32_t resj=0;
  60. spx_word16_t res16;
  61. for (k=0;k<=j;k++)
  62. resj = MAC16_16(resj,shape[k],r[j-k]);
  63. #ifdef FIXED_POINT
  64. res16 = EXTRACT16(SHR32(resj, 13));
  65. #else
  66. res16 = 0.03125f*resj;
  67. #endif
  68. /* Compute codeword energy */
  69. E[i]=MAC16_16(E[i],res16,res16);
  70. res[j] = res16;
  71. /*printf ("%d\n", (int)res[j]);*/
  72. }
  73. }
  74. }
  75. #endif
  76. #ifndef OVERRIDE_TARGET_UPDATE
  77. static inline void target_update(spx_word16_t *t, spx_word16_t g, spx_word16_t *r, int len)
  78. {
  79. int n;
  80. for (n=0;n<len;n++)
  81. t[n] = SUB16(t[n],PSHR32(MULT16_16(g,r[n]),13));
  82. }
  83. #endif
  84. static void split_cb_search_shape_sign_N1(
  85. spx_word16_t target[], /* target vector */
  86. spx_coef_t ak[], /* LPCs for this subframe */
  87. spx_coef_t awk1[], /* Weighted LPCs for this subframe */
  88. spx_coef_t awk2[], /* Weighted LPCs for this subframe */
  89. const void *par, /* Codebook/search parameters*/
  90. int p, /* number of LPC coeffs */
  91. int nsf, /* number of samples in subframe */
  92. spx_sig_t *exc,
  93. spx_word16_t *r,
  94. SpeexBits *bits,
  95. char *stack,
  96. int update_target
  97. )
  98. {
  99. int i,j,m,q;
  100. VARDECL(spx_word16_t *resp);
  101. #ifdef _USE_SSE
  102. VARDECL(__m128 *resp2);
  103. VARDECL(__m128 *E);
  104. #else
  105. spx_word16_t *resp2;
  106. VARDECL(spx_word32_t *E);
  107. #endif
  108. VARDECL(spx_word16_t *t);
  109. VARDECL(spx_sig_t *e);
  110. const signed char *shape_cb;
  111. int shape_cb_size, subvect_size, nb_subvect;
  112. const split_cb_params *params;
  113. int best_index;
  114. spx_word32_t best_dist;
  115. int have_sign;
  116. params = (const split_cb_params *) par;
  117. subvect_size = params->subvect_size;
  118. nb_subvect = params->nb_subvect;
  119. shape_cb_size = 1<<params->shape_bits;
  120. shape_cb = params->shape_cb;
  121. have_sign = params->have_sign;
  122. ALLOC(resp, shape_cb_size*subvect_size, spx_word16_t);
  123. #ifdef _USE_SSE
  124. ALLOC(resp2, (shape_cb_size*subvect_size)>>2, __m128);
  125. ALLOC(E, shape_cb_size>>2, __m128);
  126. #else
  127. resp2 = resp;
  128. ALLOC(E, shape_cb_size, spx_word32_t);
  129. #endif
  130. ALLOC(t, nsf, spx_word16_t);
  131. ALLOC(e, nsf, spx_sig_t);
  132. /* FIXME: Do we still need to copy the target? */
  133. SPEEX_COPY(t, target, nsf);
  134. compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack);
  135. for (i=0;i<nb_subvect;i++)
  136. {
  137. spx_word16_t *x=t+subvect_size*i;
  138. /*Find new n-best based on previous n-best j*/
  139. if (have_sign)
  140. vq_nbest_sign(x, resp2, subvect_size, shape_cb_size, E, 1, &best_index, &best_dist, stack);
  141. else
  142. vq_nbest(x, resp2, subvect_size, shape_cb_size, E, 1, &best_index, &best_dist, stack);
  143. speex_bits_pack(bits,best_index,params->shape_bits+have_sign);
  144. {
  145. int rind;
  146. spx_word16_t *res;
  147. spx_word16_t sign=1;
  148. rind = best_index;
  149. if (rind>=shape_cb_size)
  150. {
  151. sign=-1;
  152. rind-=shape_cb_size;
  153. }
  154. res = resp+rind*subvect_size;
  155. if (sign>0)
  156. for (m=0;m<subvect_size;m++)
  157. t[subvect_size*i+m] = SUB16(t[subvect_size*i+m], res[m]);
  158. else
  159. for (m=0;m<subvect_size;m++)
  160. t[subvect_size*i+m] = ADD16(t[subvect_size*i+m], res[m]);
  161. #ifdef FIXED_POINT
  162. if (sign==1)
  163. {
  164. for (j=0;j<subvect_size;j++)
  165. e[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5);
  166. } else {
  167. for (j=0;j<subvect_size;j++)
  168. e[subvect_size*i+j]=NEG32(SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5));
  169. }
  170. #else
  171. for (j=0;j<subvect_size;j++)
  172. e[subvect_size*i+j]=sign*0.03125*shape_cb[rind*subvect_size+j];
  173. #endif
  174. }
  175. for (m=0;m<subvect_size;m++)
  176. {
  177. spx_word16_t g;
  178. int rind;
  179. spx_word16_t sign=1;
  180. rind = best_index;
  181. if (rind>=shape_cb_size)
  182. {
  183. sign=-1;
  184. rind-=shape_cb_size;
  185. }
  186. q=subvect_size-m;
  187. #ifdef FIXED_POINT
  188. g=sign*shape_cb[rind*subvect_size+m];
  189. #else
  190. g=sign*0.03125*shape_cb[rind*subvect_size+m];
  191. #endif
  192. target_update(t+subvect_size*(i+1), g, r+q, nsf-subvect_size*(i+1));
  193. }
  194. }
  195. /* Update excitation */
  196. /* FIXME: We could update the excitation directly above */
  197. for (j=0;j<nsf;j++)
  198. exc[j]=ADD32(exc[j],e[j]);
  199. /* Update target: only update target if necessary */
  200. if (update_target)
  201. {
  202. VARDECL(spx_word16_t *r2);
  203. ALLOC(r2, nsf, spx_word16_t);
  204. for (j=0;j<nsf;j++)
  205. r2[j] = EXTRACT16(PSHR32(e[j] ,6));
  206. syn_percep_zero16(r2, ak, awk1, awk2, r2, nsf,p, stack);
  207. for (j=0;j<nsf;j++)
  208. target[j]=SUB16(target[j],PSHR16(r2[j],2));
  209. }
  210. }
  211. void split_cb_search_shape_sign(
  212. spx_word16_t target[], /* target vector */
  213. spx_coef_t ak[], /* LPCs for this subframe */
  214. spx_coef_t awk1[], /* Weighted LPCs for this subframe */
  215. spx_coef_t awk2[], /* Weighted LPCs for this subframe */
  216. const void *par, /* Codebook/search parameters*/
  217. int p, /* number of LPC coeffs */
  218. int nsf, /* number of samples in subframe */
  219. spx_sig_t *exc,
  220. spx_word16_t *r,
  221. SpeexBits *bits,
  222. char *stack,
  223. int complexity,
  224. int update_target
  225. )
  226. {
  227. int i,j,k,m,n,q;
  228. VARDECL(spx_word16_t *resp);
  229. #ifdef _USE_SSE
  230. VARDECL(__m128 *resp2);
  231. VARDECL(__m128 *E);
  232. #else
  233. spx_word16_t *resp2;
  234. VARDECL(spx_word32_t *E);
  235. #endif
  236. VARDECL(spx_word16_t *t);
  237. VARDECL(spx_sig_t *e);
  238. VARDECL(spx_word16_t *tmp);
  239. VARDECL(spx_word32_t *ndist);
  240. VARDECL(spx_word32_t *odist);
  241. VARDECL(int *itmp);
  242. VARDECL(spx_word16_t **ot2);
  243. VARDECL(spx_word16_t **nt2);
  244. spx_word16_t **ot, **nt;
  245. VARDECL(int **nind);
  246. VARDECL(int **oind);
  247. VARDECL(int *ind);
  248. const signed char *shape_cb;
  249. int shape_cb_size, subvect_size, nb_subvect;
  250. const split_cb_params *params;
  251. int N=2;
  252. VARDECL(int *best_index);
  253. VARDECL(spx_word32_t *best_dist);
  254. VARDECL(int *best_nind);
  255. VARDECL(int *best_ntarget);
  256. int have_sign;
  257. N=complexity;
  258. if (N>10)
  259. N=10;
  260. /* Complexity isn't as important for the codebooks as it is for the pitch */
  261. N=(2*N)/3;
  262. if (N<1)
  263. N=1;
  264. if (N==1)
  265. {
  266. split_cb_search_shape_sign_N1(target,ak,awk1,awk2,par,p,nsf,exc,r,bits,stack,update_target);
  267. return;
  268. }
  269. ALLOC(ot2, N, spx_word16_t*);
  270. ALLOC(nt2, N, spx_word16_t*);
  271. ALLOC(oind, N, int*);
  272. ALLOC(nind, N, int*);
  273. params = (const split_cb_params *) par;
  274. subvect_size = params->subvect_size;
  275. nb_subvect = params->nb_subvect;
  276. shape_cb_size = 1<<params->shape_bits;
  277. shape_cb = params->shape_cb;
  278. have_sign = params->have_sign;
  279. ALLOC(resp, shape_cb_size*subvect_size, spx_word16_t);
  280. #ifdef _USE_SSE
  281. ALLOC(resp2, (shape_cb_size*subvect_size)>>2, __m128);
  282. ALLOC(E, shape_cb_size>>2, __m128);
  283. #else
  284. resp2 = resp;
  285. ALLOC(E, shape_cb_size, spx_word32_t);
  286. #endif
  287. ALLOC(t, nsf, spx_word16_t);
  288. ALLOC(e, nsf, spx_sig_t);
  289. ALLOC(ind, nb_subvect, int);
  290. ALLOC(tmp, 2*N*nsf, spx_word16_t);
  291. for (i=0;i<N;i++)
  292. {
  293. ot2[i]=tmp+2*i*nsf;
  294. nt2[i]=tmp+(2*i+1)*nsf;
  295. }
  296. ot=ot2;
  297. nt=nt2;
  298. ALLOC(best_index, N, int);
  299. ALLOC(best_dist, N, spx_word32_t);
  300. ALLOC(best_nind, N, int);
  301. ALLOC(best_ntarget, N, int);
  302. ALLOC(ndist, N, spx_word32_t);
  303. ALLOC(odist, N, spx_word32_t);
  304. ALLOC(itmp, 2*N*nb_subvect, int);
  305. for (i=0;i<N;i++)
  306. {
  307. nind[i]=itmp+2*i*nb_subvect;
  308. oind[i]=itmp+(2*i+1)*nb_subvect;
  309. }
  310. SPEEX_COPY(t, target, nsf);
  311. for (j=0;j<N;j++)
  312. SPEEX_COPY(&ot[j][0], t, nsf);
  313. /* Pre-compute codewords response and energy */
  314. compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack);
  315. for (j=0;j<N;j++)
  316. odist[j]=0;
  317. /*For all subvectors*/
  318. for (i=0;i<nb_subvect;i++)
  319. {
  320. /*"erase" nbest list*/
  321. for (j=0;j<N;j++)
  322. ndist[j]=VERY_LARGE32;
  323. /* This is not strictly necessary, but it provides an additonal safety
  324. to prevent crashes in case something goes wrong in the previous
  325. steps (e.g. NaNs) */
  326. for (j=0;j<N;j++)
  327. best_nind[j] = best_ntarget[j] = 0;
  328. /*For all n-bests of previous subvector*/
  329. for (j=0;j<N;j++)
  330. {
  331. spx_word16_t *x=ot[j]+subvect_size*i;
  332. spx_word32_t tener = 0;
  333. for (m=0;m<subvect_size;m++)
  334. tener = MAC16_16(tener, x[m],x[m]);
  335. #ifdef FIXED_POINT
  336. tener = SHR32(tener,1);
  337. #else
  338. tener *= .5;
  339. #endif
  340. /*Find new n-best based on previous n-best j*/
  341. if (have_sign)
  342. vq_nbest_sign(x, resp2, subvect_size, shape_cb_size, E, N, best_index, best_dist, stack);
  343. else
  344. vq_nbest(x, resp2, subvect_size, shape_cb_size, E, N, best_index, best_dist, stack);
  345. /*For all new n-bests*/
  346. for (k=0;k<N;k++)
  347. {
  348. /* Compute total distance (including previous sub-vectors */
  349. spx_word32_t err = ADD32(ADD32(odist[j],best_dist[k]),tener);
  350. /*update n-best list*/
  351. if (err<ndist[N-1])
  352. {
  353. for (m=0;m<N;m++)
  354. {
  355. if (err < ndist[m])
  356. {
  357. for (n=N-1;n>m;n--)
  358. {
  359. ndist[n] = ndist[n-1];
  360. best_nind[n] = best_nind[n-1];
  361. best_ntarget[n] = best_ntarget[n-1];
  362. }
  363. /* n is equal to m here, so they're interchangeable */
  364. ndist[m] = err;
  365. best_nind[n] = best_index[k];
  366. best_ntarget[n] = j;
  367. break;
  368. }
  369. }
  370. }
  371. }
  372. if (i==0)
  373. break;
  374. }
  375. for (j=0;j<N;j++)
  376. {
  377. /*previous target (we don't care what happened before*/
  378. for (m=(i+1)*subvect_size;m<nsf;m++)
  379. nt[j][m]=ot[best_ntarget[j]][m];
  380. /* New code: update the rest of the target only if it's worth it */
  381. for (m=0;m<subvect_size;m++)
  382. {
  383. spx_word16_t g;
  384. int rind;
  385. spx_word16_t sign=1;
  386. rind = best_nind[j];
  387. if (rind>=shape_cb_size)
  388. {
  389. sign=-1;
  390. rind-=shape_cb_size;
  391. }
  392. q=subvect_size-m;
  393. #ifdef FIXED_POINT
  394. g=sign*shape_cb[rind*subvect_size+m];
  395. #else
  396. g=sign*0.03125*shape_cb[rind*subvect_size+m];
  397. #endif
  398. target_update(nt[j]+subvect_size*(i+1), g, r+q, nsf-subvect_size*(i+1));
  399. }
  400. for (q=0;q<nb_subvect;q++)
  401. nind[j][q]=oind[best_ntarget[j]][q];
  402. nind[j][i]=best_nind[j];
  403. }
  404. /*update old-new data*/
  405. /* just swap pointers instead of a long copy */
  406. {
  407. spx_word16_t **tmp2;
  408. tmp2=ot;
  409. ot=nt;
  410. nt=tmp2;
  411. }
  412. for (j=0;j<N;j++)
  413. for (m=0;m<nb_subvect;m++)
  414. oind[j][m]=nind[j][m];
  415. for (j=0;j<N;j++)
  416. odist[j]=ndist[j];
  417. }
  418. /*save indices*/
  419. for (i=0;i<nb_subvect;i++)
  420. {
  421. ind[i]=nind[0][i];
  422. speex_bits_pack(bits,ind[i],params->shape_bits+have_sign);
  423. }
  424. /* Put everything back together */
  425. for (i=0;i<nb_subvect;i++)
  426. {
  427. int rind;
  428. spx_word16_t sign=1;
  429. rind = ind[i];
  430. if (rind>=shape_cb_size)
  431. {
  432. sign=-1;
  433. rind-=shape_cb_size;
  434. }
  435. #ifdef FIXED_POINT
  436. if (sign==1)
  437. {
  438. for (j=0;j<subvect_size;j++)
  439. e[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5);
  440. } else {
  441. for (j=0;j<subvect_size;j++)
  442. e[subvect_size*i+j]=NEG32(SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5));
  443. }
  444. #else
  445. for (j=0;j<subvect_size;j++)
  446. e[subvect_size*i+j]=sign*0.03125*shape_cb[rind*subvect_size+j];
  447. #endif
  448. }
  449. /* Update excitation */
  450. for (j=0;j<nsf;j++)
  451. exc[j]=ADD32(exc[j],e[j]);
  452. /* Update target: only update target if necessary */
  453. if (update_target)
  454. {
  455. VARDECL(spx_word16_t *r2);
  456. ALLOC(r2, nsf, spx_word16_t);
  457. for (j=0;j<nsf;j++)
  458. r2[j] = EXTRACT16(PSHR32(e[j] ,6));
  459. syn_percep_zero16(r2, ak, awk1, awk2, r2, nsf,p, stack);
  460. for (j=0;j<nsf;j++)
  461. target[j]=SUB16(target[j],PSHR16(r2[j],2));
  462. }
  463. }
  464. void split_cb_shape_sign_unquant(
  465. spx_sig_t *exc,
  466. const void *par, /* non-overlapping codebook */
  467. int nsf, /* number of samples in subframe */
  468. SpeexBits *bits,
  469. char *stack,
  470. spx_int32_t *seed
  471. )
  472. {
  473. int i,j;
  474. VARDECL(int *ind);
  475. VARDECL(int *signs);
  476. const signed char *shape_cb;
  477. int shape_cb_size, subvect_size, nb_subvect;
  478. const split_cb_params *params;
  479. int have_sign;
  480. params = (const split_cb_params *) par;
  481. subvect_size = params->subvect_size;
  482. nb_subvect = params->nb_subvect;
  483. shape_cb_size = 1<<params->shape_bits;
  484. shape_cb = params->shape_cb;
  485. have_sign = params->have_sign;
  486. ALLOC(ind, nb_subvect, int);
  487. ALLOC(signs, nb_subvect, int);
  488. /* Decode codewords and gains */
  489. for (i=0;i<nb_subvect;i++)
  490. {
  491. if (have_sign)
  492. signs[i] = speex_bits_unpack_unsigned(bits, 1);
  493. else
  494. signs[i] = 0;
  495. ind[i] = speex_bits_unpack_unsigned(bits, params->shape_bits);
  496. }
  497. /* Compute decoded excitation */
  498. for (i=0;i<nb_subvect;i++)
  499. {
  500. spx_word16_t s=1;
  501. if (signs[i])
  502. s=-1;
  503. #ifdef FIXED_POINT
  504. if (s==1)
  505. {
  506. for (j=0;j<subvect_size;j++)
  507. exc[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[ind[i]*subvect_size+j]),SIG_SHIFT-5);
  508. } else {
  509. for (j=0;j<subvect_size;j++)
  510. exc[subvect_size*i+j]=NEG32(SHL32(EXTEND32(shape_cb[ind[i]*subvect_size+j]),SIG_SHIFT-5));
  511. }
  512. #else
  513. for (j=0;j<subvect_size;j++)
  514. exc[subvect_size*i+j]+=s*0.03125*shape_cb[ind[i]*subvect_size+j];
  515. #endif
  516. }
  517. }
  518. void noise_codebook_quant(
  519. spx_word16_t target[], /* target vector */
  520. spx_coef_t ak[], /* LPCs for this subframe */
  521. spx_coef_t awk1[], /* Weighted LPCs for this subframe */
  522. spx_coef_t awk2[], /* Weighted LPCs for this subframe */
  523. const void *par, /* Codebook/search parameters*/
  524. int p, /* number of LPC coeffs */
  525. int nsf, /* number of samples in subframe */
  526. spx_sig_t *exc,
  527. spx_word16_t *r,
  528. SpeexBits *bits,
  529. char *stack,
  530. int complexity,
  531. int update_target
  532. )
  533. {
  534. int i;
  535. VARDECL(spx_word16_t *tmp);
  536. ALLOC(tmp, nsf, spx_word16_t);
  537. residue_percep_zero16(target, ak, awk1, awk2, tmp, nsf, p, stack);
  538. for (i=0;i<nsf;i++)
  539. exc[i]+=SHL32(EXTEND32(tmp[i]),8);
  540. SPEEX_MEMSET(target, 0, nsf);
  541. }
  542. void noise_codebook_unquant(
  543. spx_sig_t *exc,
  544. const void *par, /* non-overlapping codebook */
  545. int nsf, /* number of samples in subframe */
  546. SpeexBits *bits,
  547. char *stack,
  548. spx_int32_t *seed
  549. )
  550. {
  551. int i;
  552. /* FIXME: This is bad, but I don't think the function ever gets called anyway */
  553. for (i=0;i<nsf;i++)
  554. exc[i]=SHL32(EXTEND32(speex_rand(1, seed)),SIG_SHIFT);
  555. }