res0.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
  9. * by the XIPHOPHORUS Company http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: residue backend 0, 1 and 2 implementation
  13. last mod: $Id: res0.c,v 1.32 2001/06/15 23:31:00 xiphmont Exp $
  14. ********************************************************************/
  15. /* Slow, slow, slow, simpleminded and did I mention it was slow? The
  16. encode/decode loops are coded for clarity and performance is not
  17. yet even a nagging little idea lurking in the shadows. Oh and BTW,
  18. it's slow. */
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <math.h>
  22. #include <stdio.h>
  23. #include <ogg/ogg.h>
  24. #include "vorbis/codec.h"
  25. #include "codec_internal.h"
  26. #include "registry.h"
  27. #include "codebook.h"
  28. #include "misc.h"
  29. #include "os.h"
  30. typedef struct {
  31. vorbis_info_residue0 *info;
  32. int map;
  33. int parts;
  34. int stages;
  35. codebook *fullbooks;
  36. codebook *phrasebook;
  37. codebook ***partbooks;
  38. int partvals;
  39. int **decodemap;
  40. /*long resbits[32][32];
  41. long resbitsflat;
  42. long resvals[32];
  43. long phrasebits;
  44. long frames;*/
  45. } vorbis_look_residue0;
  46. vorbis_info_residue *res0_copy_info(vorbis_info_residue *vr){
  47. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  48. vorbis_info_residue0 *ret=_ogg_malloc(sizeof(vorbis_info_residue0));
  49. memcpy(ret,info,sizeof(vorbis_info_residue0));
  50. return(ret);
  51. }
  52. void res0_free_info(vorbis_info_residue *i){
  53. if(i){
  54. memset(i,0,sizeof(vorbis_info_residue0));
  55. _ogg_free(i);
  56. }
  57. }
  58. void res0_free_look(vorbis_look_residue *i){
  59. int j,k;
  60. if(i){
  61. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  62. vorbis_info_residue0 *info=look->info;
  63. /*fprintf(stderr,
  64. "%ld frames encoded in %ld phrasebits and %ld residue bits "
  65. "(%g/frame) \n",look->frames,look->phrasebits,
  66. look->resbitsflat,
  67. (look->phrasebits+look->resbitsflat)/(float)look->frames);
  68. for(j=0;j<look->parts;j++){
  69. long acc=0;
  70. fprintf(stderr,"\t[%d] == ",j);
  71. for(k=0;k<look->stages;k++)
  72. if((info->secondstages[j]>>k)&1){
  73. fprintf(stderr,"%ld,",look->resbits[j][k]);
  74. acc+=look->resbits[j][k];
  75. }
  76. fprintf(stderr,":: (%ld vals) %1.2fbits/sample\n",look->resvals[j],
  77. acc?(float)acc/(look->resvals[j]*info->grouping):0);
  78. }
  79. fprintf(stderr,"\n");*/
  80. for(j=0;j<look->parts;j++)
  81. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  82. _ogg_free(look->partbooks);
  83. for(j=0;j<look->partvals;j++)
  84. _ogg_free(look->decodemap[j]);
  85. _ogg_free(look->decodemap);
  86. memset(i,0,sizeof(vorbis_look_residue0));
  87. _ogg_free(i);
  88. }
  89. }
  90. static int ilog(unsigned int v){
  91. int ret=0;
  92. while(v){
  93. ret++;
  94. v>>=1;
  95. }
  96. return(ret);
  97. }
  98. static int icount(unsigned int v){
  99. int ret=0;
  100. while(v){
  101. ret+=v&1;
  102. v>>=1;
  103. }
  104. return(ret);
  105. }
  106. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  107. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  108. int j,acc=0;
  109. oggpack_write(opb,info->begin,24);
  110. oggpack_write(opb,info->end,24);
  111. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  112. code with a partitioned book */
  113. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  114. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  115. /* secondstages is a bitmask; as encoding progresses pass by pass, a
  116. bitmask of one indicates this partition class has bits to write
  117. this pass */
  118. for(j=0;j<info->partitions;j++){
  119. if(ilog(info->secondstages[j])>3){
  120. /* yes, this is a minor hack due to not thinking ahead */
  121. oggpack_write(opb,info->secondstages[j],3);
  122. oggpack_write(opb,1,1);
  123. oggpack_write(opb,info->secondstages[j]>>3,5);
  124. }else
  125. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  126. acc+=icount(info->secondstages[j]);
  127. }
  128. for(j=0;j<acc;j++)
  129. oggpack_write(opb,info->booklist[j],8);
  130. }
  131. /* vorbis_info is for range checking */
  132. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  133. int j,acc=0;
  134. vorbis_info_residue0 *info=_ogg_calloc(1,sizeof(vorbis_info_residue0));
  135. codec_setup_info *ci=vi->codec_setup;
  136. info->begin=oggpack_read(opb,24);
  137. info->end=oggpack_read(opb,24);
  138. info->grouping=oggpack_read(opb,24)+1;
  139. info->partitions=oggpack_read(opb,6)+1;
  140. info->groupbook=oggpack_read(opb,8);
  141. for(j=0;j<info->partitions;j++){
  142. int cascade=oggpack_read(opb,3);
  143. if(oggpack_read(opb,1))
  144. cascade|=(oggpack_read(opb,5)<<3);
  145. info->secondstages[j]=cascade;
  146. acc+=icount(cascade);
  147. }
  148. for(j=0;j<acc;j++)
  149. info->booklist[j]=oggpack_read(opb,8);
  150. if(info->groupbook>=ci->books)goto errout;
  151. for(j=0;j<acc;j++)
  152. if(info->booklist[j]>=ci->books)goto errout;
  153. return(info);
  154. errout:
  155. res0_free_info(info);
  156. return(NULL);
  157. }
  158. vorbis_look_residue *res0_look (vorbis_dsp_state *vd,vorbis_info_mode *vm,
  159. vorbis_info_residue *vr){
  160. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  161. vorbis_look_residue0 *look=_ogg_calloc(1,sizeof(vorbis_look_residue0));
  162. backend_lookup_state *be=vd->backend_state;
  163. int j,k,acc=0;
  164. int dim;
  165. int maxstage=0;
  166. look->info=info;
  167. look->map=vm->mapping;
  168. look->parts=info->partitions;
  169. look->fullbooks=be->fullbooks;
  170. look->phrasebook=be->fullbooks+info->groupbook;
  171. dim=look->phrasebook->dim;
  172. look->partbooks=_ogg_calloc(look->parts,sizeof(codebook **));
  173. for(j=0;j<look->parts;j++){
  174. int stages=ilog(info->secondstages[j]);
  175. if(stages){
  176. if(stages>maxstage)maxstage=stages;
  177. look->partbooks[j]=_ogg_calloc(stages,sizeof(codebook *));
  178. for(k=0;k<stages;k++)
  179. if(info->secondstages[j]&(1<<k))
  180. look->partbooks[j][k]=be->fullbooks+info->booklist[acc++];
  181. }
  182. }
  183. look->partvals=rint(pow(look->parts,dim));
  184. look->stages=maxstage;
  185. look->decodemap=_ogg_malloc(look->partvals*sizeof(int *));
  186. for(j=0;j<look->partvals;j++){
  187. long val=j;
  188. long mult=look->partvals/look->parts;
  189. look->decodemap[j]=_ogg_malloc(dim*sizeof(int));
  190. for(k=0;k<dim;k++){
  191. long deco=val/mult;
  192. val-=deco*mult;
  193. mult/=look->parts;
  194. look->decodemap[j][k]=deco;
  195. }
  196. }
  197. return(look);
  198. }
  199. /* does not guard against invalid settings; eg, a subn of 16 and a
  200. subgroup request of 32. Max subn of 128 */
  201. static int _interleaved_testhack(float *vec,int n,vorbis_look_residue0 *look,
  202. int auxparts,int auxpartnum){
  203. vorbis_info_residue0 *info=look->info;
  204. int i,j=0;
  205. float max,localmax=0.f;
  206. float temp[128];
  207. float entropy[8];
  208. /* setup */
  209. for(i=0;i<n;i++)temp[i]=fabs(vec[i]);
  210. /* handle case subgrp==1 outside */
  211. for(i=0;i<n;i++)
  212. if(temp[i]>localmax)localmax=temp[i];
  213. max=localmax;
  214. for(i=0;i<n;i++)temp[i]=rint(temp[i]);
  215. while(1){
  216. entropy[j]=localmax;
  217. n>>=1;
  218. if(!n)break;
  219. j++;
  220. for(i=0;i<n;i++){
  221. temp[i]+=temp[i+n];
  222. }
  223. localmax=0.f;
  224. for(i=0;i<n;i++)
  225. if(temp[i]>localmax)localmax=temp[i];
  226. }
  227. for(i=0;i<auxparts-1;i++)
  228. if(auxpartnum<info->blimit[i] &&
  229. entropy[info->subgrp[i]]<=info->entmax[i] &&
  230. max<=info->ampmax[i])
  231. break;
  232. return(i);
  233. }
  234. static int _testhack(float *vec,int n,vorbis_look_residue0 *look,
  235. int auxparts,int auxpartnum){
  236. vorbis_info_residue0 *info=look->info;
  237. int i,j=0;
  238. float max,localmax=0.f;
  239. float temp[128];
  240. float entropy[8];
  241. /* setup */
  242. for(i=0;i<n;i++)temp[i]=fabs(vec[i]);
  243. /* handle case subgrp==1 outside */
  244. for(i=0;i<n;i++)
  245. if(temp[i]>localmax)localmax=temp[i];
  246. max=localmax;
  247. for(i=0;i<n;i++)temp[i]=rint(temp[i]);
  248. while(n){
  249. entropy[j]=localmax;
  250. n>>=1;
  251. j++;
  252. if(!n)break;
  253. for(i=0;i<n;i++){
  254. temp[i]=temp[i*2]+temp[i*2+1];
  255. }
  256. localmax=0.f;
  257. for(i=0;i<n;i++)
  258. if(temp[i]>localmax)localmax=temp[i];
  259. }
  260. for(i=0;i<auxparts-1;i++)
  261. if(auxpartnum<info->blimit[i] &&
  262. entropy[info->subgrp[i]]<=info->entmax[i] &&
  263. max<=info->ampmax[i])
  264. break;
  265. return(i);
  266. }
  267. static int _interleaved_encodepart(oggpack_buffer *opb,float *vec, int n,
  268. codebook *book,vorbis_look_residue0 *look){
  269. int i,bits=0;
  270. int dim=book->dim;
  271. int step=n/dim;
  272. #ifdef TRAIN_RESENT
  273. char buf[80];
  274. FILE *f;
  275. sprintf(buf,"res0_b%d.vqd",book-look->fullbooks);
  276. f=fopen(buf,"a");
  277. #endif
  278. for(i=0;i<step;i++){
  279. int entry=vorbis_book_besterror(book,vec+i,step,0);
  280. #ifdef TRAIN_RESENT
  281. fprintf(f,"%d\n",entry);
  282. #endif
  283. bits+=vorbis_book_encode(book,entry,opb);
  284. }
  285. #ifdef TRAIN_RESENT
  286. fclose(f);
  287. #endif
  288. return(bits);
  289. }
  290. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  291. codebook *book,vorbis_look_residue0 *look){
  292. int i,bits=0;
  293. int dim=book->dim;
  294. int step=n/dim;
  295. #ifdef TRAIN_RESENT
  296. char buf[80];
  297. FILE *f;
  298. sprintf(buf,"res0_b%d.vqd",book-look->fullbooks);
  299. f=fopen(buf,"a");
  300. #endif
  301. for(i=0;i<step;i++){
  302. int entry=vorbis_book_besterror(book,vec+i*dim,1,0);
  303. #ifdef TRAIN_RESENT
  304. fprintf(f,"%d\n",entry);
  305. #endif
  306. bits+=vorbis_book_encode(book,entry,opb);
  307. }
  308. #ifdef TRAIN_RESENT
  309. fclose(f);
  310. #endif
  311. return(bits);
  312. }
  313. static int _01forward(vorbis_block *vb,vorbis_look_residue *vl,
  314. float **in,int ch,
  315. int (*classify)(float *,int,vorbis_look_residue0 *,
  316. int,int),
  317. int (*encode)(oggpack_buffer *,float *,int,
  318. codebook *,vorbis_look_residue0 *)){
  319. long i,j,k,l,s;
  320. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  321. vorbis_info_residue0 *info=look->info;
  322. /* move all this setup out later */
  323. int samples_per_partition=info->grouping;
  324. int possible_partitions=info->partitions;
  325. int partitions_per_word=look->phrasebook->dim;
  326. int n=info->end-info->begin;
  327. int partvals=n/samples_per_partition;
  328. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  329. long **partword=_vorbis_block_alloc(vb,ch*sizeof(long *));
  330. #ifdef TRAIN_RES
  331. FILE *of;
  332. char buffer[80];
  333. int m;
  334. for(i=0;i<ch;i++){
  335. sprintf(buffer,"residue_%d.vqd",vb->mode);
  336. of=fopen(buffer,"a");
  337. for(m=0;m<info->end;m++)
  338. fprintf(of,"%.2f, ",in[i][m]);
  339. fprintf(of,"\n");
  340. fclose(of);
  341. }
  342. #endif
  343. partvals=partwords*partitions_per_word;
  344. /* we find the patition type for each partition of each
  345. channel. We'll go back and do the interleaved encoding in a
  346. bit. For now, clarity */
  347. for(i=0;i<ch;i++){
  348. partword[i]=_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(long));
  349. memset(partword[i],0,n/samples_per_partition*sizeof(long));
  350. }
  351. for(i=info->begin,l=0;i<info->end;i+=samples_per_partition,l++){
  352. for(j=0;j<ch;j++)
  353. /* do the partition decision based on the 'entropy'
  354. int the block */
  355. partword[j][l]=
  356. classify(in[j]+i,samples_per_partition,look,possible_partitions,l);
  357. }
  358. /* we code the partition words for each channel, then the residual
  359. words for a partition per channel until we've written all the
  360. residual words for that partition word. Then write the next
  361. partition channel words... */
  362. /*look->frames++;*/
  363. for(s=0;s<look->stages;s++){
  364. for(i=info->begin,l=0;i<info->end;){
  365. /* first we encode a partition codeword for each channel */
  366. if(s==0){
  367. for(j=0;j<ch;j++){
  368. long val=partword[j][l];
  369. long ret;
  370. for(k=1;k<partitions_per_word;k++)
  371. val= val*possible_partitions+partword[j][l+k];
  372. ret=vorbis_book_encode(look->phrasebook,val,&vb->opb);
  373. /*look->phrasebits+=ret;*/
  374. }
  375. }
  376. /* now we encode interleaved residual values for the partitions */
  377. for(k=0;k<partitions_per_word;k++,l++,i+=samples_per_partition){
  378. for(j=0;j<ch;j++){
  379. /*if(s==0)look->resvals[partword[j][l]]++;*/
  380. if(info->secondstages[partword[j][l]]&(1<<s)){
  381. codebook *statebook=look->partbooks[partword[j][l]][s];
  382. if(statebook){
  383. int ret=encode(&vb->opb,in[j]+i,samples_per_partition,
  384. statebook,look);
  385. /*look->resbits[partword[j][l]][s]+=ret;
  386. look->resbitsflat+=ret;*/
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. return(0);
  394. }
  395. /* a truncated packet here just means 'stop working'; it's not an error */
  396. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  397. float **in,int ch,
  398. long (*decodepart)(codebook *, float *,
  399. oggpack_buffer *,int)){
  400. long i,j,k,l,s;
  401. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  402. vorbis_info_residue0 *info=look->info;
  403. /* move all this setup out later */
  404. int samples_per_partition=info->grouping;
  405. int partitions_per_word=look->phrasebook->dim;
  406. int n=info->end-info->begin;
  407. int partvals=n/samples_per_partition;
  408. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  409. int ***partword=alloca(ch*sizeof(int **));
  410. partvals=partwords*partitions_per_word;
  411. for(j=0;j<ch;j++)
  412. partword[j]=_vorbis_block_alloc(vb,partwords*sizeof(int *));
  413. for(s=0;s<look->stages;s++){
  414. for(i=info->begin,l=0;i<info->end;l++){
  415. if(s==0){
  416. /* fetch the partition word for each channel */
  417. for(j=0;j<ch;j++){
  418. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  419. if(temp==-1)goto eopbreak;
  420. partword[j][l]=look->decodemap[temp];
  421. if(partword[j][l]==NULL)goto errout;
  422. }
  423. }
  424. /* now we decode residual values for the partitions */
  425. for(k=0;k<partitions_per_word;k++,i+=samples_per_partition)
  426. for(j=0;j<ch;j++){
  427. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  428. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  429. if(stagebook){
  430. if(decodepart(stagebook,in[j]+i,&vb->opb,
  431. samples_per_partition)==-1)goto eopbreak;
  432. }
  433. }
  434. }
  435. }
  436. }
  437. errout:
  438. eopbreak:
  439. return(0);
  440. }
  441. /* residue 0 and 1 are just slight variants of one another. 0 is
  442. interleaved, 1 is not */
  443. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  444. float **in,int *nonzero,int ch){
  445. /* we encode only the nonzero parts of a bundle */
  446. int i,used=0;
  447. for(i=0;i<ch;i++)
  448. if(nonzero[i])
  449. in[used++]=in[i];
  450. if(used)
  451. return(_01forward(vb,vl,in,used,_interleaved_testhack,_interleaved_encodepart));
  452. else
  453. return(0);
  454. }
  455. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  456. float **in,int *nonzero,int ch){
  457. int i,used=0;
  458. for(i=0;i<ch;i++)
  459. if(nonzero[i])
  460. in[used++]=in[i];
  461. if(used)
  462. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  463. else
  464. return(0);
  465. }
  466. int res1_forward(vorbis_block *vb,vorbis_look_residue *vl,
  467. float **in,int *nonzero,int ch){
  468. int i,used=0;
  469. for(i=0;i<ch;i++)
  470. if(nonzero[i])
  471. in[used++]=in[i];
  472. if(used)
  473. return(_01forward(vb,vl,in,used,_testhack,_encodepart));
  474. else
  475. return(0);
  476. }
  477. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  478. float **in,int *nonzero,int ch){
  479. int i,used=0;
  480. for(i=0;i<ch;i++)
  481. if(nonzero[i])
  482. in[used++]=in[i];
  483. if(used)
  484. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  485. else
  486. return(0);
  487. }
  488. /* res2 is slightly more different; all the channels are interleaved
  489. into a single vector and encoded. */
  490. int res2_forward(vorbis_block *vb,vorbis_look_residue *vl,
  491. float **in,int *nonzero,int ch){
  492. long i,j,k,n=vb->pcmend/2,used=0;
  493. /* don't duplicate the code; use a working vector hack for now and
  494. reshape ourselves into a single channel res1 */
  495. float *work=_vorbis_block_alloc(vb,ch*n*sizeof(float));
  496. for(i=0;i<ch;i++){
  497. float *pcm=vb->pcm[i];
  498. if(nonzero[i])used++;
  499. for(j=0,k=i;j<n;j++,k+=ch)
  500. work[k]=pcm[j];
  501. }
  502. if(used)
  503. return(_01forward(vb,vl,&work,1,_testhack,_encodepart));
  504. else
  505. return(0);
  506. }
  507. /* duplicate code here as speed is somewhat more important */
  508. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  509. float **in,int *nonzero,int ch){
  510. long i,k,l,s;
  511. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  512. vorbis_info_residue0 *info=look->info;
  513. /* move all this setup out later */
  514. int samples_per_partition=info->grouping;
  515. int partitions_per_word=look->phrasebook->dim;
  516. int n=info->end-info->begin;
  517. int partvals=n/samples_per_partition;
  518. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  519. int **partword=_vorbis_block_alloc(vb,partwords*sizeof(int *));
  520. int used;
  521. partvals=partwords*partitions_per_word;
  522. for(i=0;i<ch;i++)if(nonzero[i])break;
  523. if(i==ch)return(0); /* no nonzero vectors */
  524. for(s=0;s<look->stages;s++){
  525. for(i=info->begin,l=0;i<info->end;l++){
  526. if(s==0){
  527. /* fetch the partition word */
  528. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  529. if(temp==-1)goto eopbreak;
  530. partword[l]=look->decodemap[temp];
  531. if(partword[l]==NULL)goto errout;
  532. }
  533. /* now we decode residual values for the partitions */
  534. for(k=0;k<partitions_per_word;k++,i+=samples_per_partition)
  535. if(info->secondstages[partword[l][k]]&(1<<s)){
  536. codebook *stagebook=look->partbooks[partword[l][k]][s];
  537. if(stagebook){
  538. if(vorbis_book_decodevv_add(stagebook,in,i,ch,
  539. &vb->opb,samples_per_partition)==-1)
  540. goto eopbreak;
  541. }
  542. }
  543. }
  544. }
  545. errout:
  546. eopbreak:
  547. return(0);
  548. }
  549. vorbis_func_residue residue0_exportbundle={
  550. &res0_pack,
  551. &res0_unpack,
  552. &res0_look,
  553. &res0_copy_info,
  554. &res0_free_info,
  555. &res0_free_look,
  556. &res0_forward,
  557. &res0_inverse
  558. };
  559. vorbis_func_residue residue1_exportbundle={
  560. &res0_pack,
  561. &res0_unpack,
  562. &res0_look,
  563. &res0_copy_info,
  564. &res0_free_info,
  565. &res0_free_look,
  566. &res1_forward,
  567. &res1_inverse
  568. };
  569. vorbis_func_residue residue2_exportbundle={
  570. &res0_pack,
  571. &res0_unpack,
  572. &res0_look,
  573. &res0_copy_info,
  574. &res0_free_info,
  575. &res0_free_look,
  576. &res2_forward,
  577. &res2_inverse
  578. };