sharedbook.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. function: basic shared codebook operations
  12. last mod: $Id: sharedbook.c,v 1.16.6.1 2001/07/08 08:48:02 xiphmont Exp $
  13. ********************************************************************/
  14. #include <stdlib.h>
  15. #include <math.h>
  16. #include <string.h>
  17. #include <ogg/ogg.h>
  18. #include "os.h"
  19. #include "vorbis/codec.h"
  20. #include "codebook.h"
  21. #include "scales.h"
  22. /**** pack/unpack helpers ******************************************/
  23. int _ilog(unsigned int v){
  24. int ret=0;
  25. while(v){
  26. ret++;
  27. v>>=1;
  28. }
  29. return(ret);
  30. }
  31. /* 32 bit float (not IEEE; nonnormalized mantissa +
  32. biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm
  33. Why not IEEE? It's just not that important here. */
  34. #define VQ_FEXP 10
  35. #define VQ_FMAN 21
  36. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  37. /* doesn't currently guard under/overflow */
  38. long _float32_pack(float val){
  39. int sign=0;
  40. long exp;
  41. long mant;
  42. if(val<0){
  43. sign=0x80000000;
  44. val= -val;
  45. }
  46. exp= floor(log(val)/log(2));
  47. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  48. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  49. return(sign|exp|mant);
  50. }
  51. float _float32_unpack(long val){
  52. double mant=val&0x1fffff;
  53. int sign=val&0x80000000;
  54. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  55. if(sign)mant= -mant;
  56. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  57. }
  58. /* given a list of word lengths, generate a list of codewords. Works
  59. for length ordered or unordered, always assigns the lowest valued
  60. codewords first. Extended to handle unused entries (length 0) */
  61. long *_make_words(long *l,long n){
  62. long i,j;
  63. long marker[33];
  64. long *r=_ogg_malloc(n*sizeof(long));
  65. memset(marker,0,sizeof(marker));
  66. for(i=0;i<n;i++){
  67. long length=l[i];
  68. if(length>0){
  69. long entry=marker[length];
  70. /* when we claim a node for an entry, we also claim the nodes
  71. below it (pruning off the imagined tree that may have dangled
  72. from it) as well as blocking the use of any nodes directly
  73. above for leaves */
  74. /* update ourself */
  75. if(length<32 && (entry>>length)){
  76. /* error condition; the lengths must specify an overpopulated tree */
  77. _ogg_free(r);
  78. return(NULL);
  79. }
  80. r[i]=entry;
  81. /* Look to see if the next shorter marker points to the node
  82. above. if so, update it and repeat. */
  83. {
  84. for(j=length;j>0;j--){
  85. if(marker[j]&1){
  86. /* have to jump branches */
  87. if(j==1)
  88. marker[1]++;
  89. else
  90. marker[j]=marker[j-1]<<1;
  91. break; /* invariant says next upper marker would already
  92. have been moved if it was on the same path */
  93. }
  94. marker[j]++;
  95. }
  96. }
  97. /* prune the tree; the implicit invariant says all the longer
  98. markers were dangling from our just-taken node. Dangle them
  99. from our *new* node. */
  100. for(j=length+1;j<33;j++)
  101. if((marker[j]>>1) == entry){
  102. entry=marker[j];
  103. marker[j]=marker[j-1]<<1;
  104. }else
  105. break;
  106. }
  107. }
  108. /* bitreverse the words because our bitwise packer/unpacker is LSb
  109. endian */
  110. for(i=0;i<n;i++){
  111. long temp=0;
  112. for(j=0;j<l[i];j++){
  113. temp<<=1;
  114. temp|=(r[i]>>j)&1;
  115. }
  116. r[i]=temp;
  117. }
  118. return(r);
  119. }
  120. /* build the decode helper tree from the codewords */
  121. decode_aux *_make_decode_tree(codebook *c){
  122. const static_codebook *s=c->c;
  123. long top=0,i,j,n;
  124. decode_aux *t=_ogg_malloc(sizeof(decode_aux));
  125. long *ptr0=t->ptr0=_ogg_calloc(c->entries*2,sizeof(long));
  126. long *ptr1=t->ptr1=_ogg_calloc(c->entries*2,sizeof(long));
  127. long *codelist=_make_words(s->lengthlist,s->entries);
  128. if(codelist==NULL)return(NULL);
  129. t->aux=c->entries*2;
  130. for(i=0;i<c->entries;i++){
  131. if(s->lengthlist[i]>0){
  132. long ptr=0;
  133. for(j=0;j<s->lengthlist[i]-1;j++){
  134. int bit=(codelist[i]>>j)&1;
  135. if(!bit){
  136. if(!ptr0[ptr])
  137. ptr0[ptr]= ++top;
  138. ptr=ptr0[ptr];
  139. }else{
  140. if(!ptr1[ptr])
  141. ptr1[ptr]= ++top;
  142. ptr=ptr1[ptr];
  143. }
  144. }
  145. if(!((codelist[i]>>j)&1))
  146. ptr0[ptr]=-i;
  147. else
  148. ptr1[ptr]=-i;
  149. }
  150. }
  151. _ogg_free(codelist);
  152. t->tabn = _ilog(c->entries)-4; /* this is magic */
  153. if(t->tabn<5)t->tabn=5;
  154. n = 1<<t->tabn;
  155. t->tab = _ogg_malloc(n*sizeof(long));
  156. t->tabl = _ogg_malloc(n*sizeof(int));
  157. for (i = 0; i < n; i++) {
  158. long p = 0;
  159. for (j = 0; j < t->tabn && (p > 0 || j == 0); j++) {
  160. if (i & (1 << j))
  161. p = ptr1[p];
  162. else
  163. p = ptr0[p];
  164. }
  165. /* now j == length, and p == -code */
  166. t->tab[i] = p;
  167. t->tabl[i] = j;
  168. }
  169. return(t);
  170. }
  171. /* there might be a straightforward one-line way to do the below
  172. that's portable and totally safe against roundoff, but I haven't
  173. thought of it. Therefore, we opt on the side of caution */
  174. long _book_maptype1_quantvals(const static_codebook *b){
  175. long vals=floor(pow(b->entries,1.f/b->dim));
  176. /* the above *should* be reliable, but we'll not assume that FP is
  177. ever reliable when bitstream sync is at stake; verify via integer
  178. means that vals really is the greatest value of dim for which
  179. vals^b->bim <= b->entries */
  180. /* treat the above as an initial guess */
  181. while(1){
  182. long acc=1;
  183. long acc1=1;
  184. int i;
  185. for(i=0;i<b->dim;i++){
  186. acc*=vals;
  187. acc1*=vals+1;
  188. }
  189. if(acc<=b->entries && acc1>b->entries){
  190. return(vals);
  191. }else{
  192. if(acc>b->entries){
  193. vals--;
  194. }else{
  195. vals++;
  196. }
  197. }
  198. }
  199. }
  200. /* unpack the quantized list of values for encode/decode ***********/
  201. /* we need to deal with two map types: in map type 1, the values are
  202. generated algorithmically (each column of the vector counts through
  203. the values in the quant vector). in map type 2, all the values came
  204. in in an explicit list. Both value lists must be unpacked */
  205. float *_book_unquantize(const static_codebook *b){
  206. long j,k;
  207. if(b->maptype==1 || b->maptype==2){
  208. int quantvals;
  209. float mindel=_float32_unpack(b->q_min);
  210. float delta=_float32_unpack(b->q_delta);
  211. float *r=_ogg_calloc(b->entries*b->dim,sizeof(float));
  212. /* maptype 1 and 2 both use a quantized value vector, but
  213. different sizes */
  214. switch(b->maptype){
  215. case 1:
  216. /* most of the time, entries%dimensions == 0, but we need to be
  217. well defined. We define that the possible vales at each
  218. scalar is values == entries/dim. If entries%dim != 0, we'll
  219. have 'too few' values (values*dim<entries), which means that
  220. we'll have 'left over' entries; left over entries use zeroed
  221. values (and are wasted). So don't generate codebooks like
  222. that */
  223. quantvals=_book_maptype1_quantvals(b);
  224. for(j=0;j<b->entries;j++){
  225. float last=0.f;
  226. int indexdiv=1;
  227. for(k=0;k<b->dim;k++){
  228. int index= (j/indexdiv)%quantvals;
  229. float val=b->quantlist[index];
  230. val=fabs(val)*delta+mindel+last;
  231. if(b->q_sequencep)last=val;
  232. r[j*b->dim+k]=val;
  233. indexdiv*=quantvals;
  234. }
  235. }
  236. break;
  237. case 2:
  238. for(j=0;j<b->entries;j++){
  239. float last=0.f;
  240. for(k=0;k<b->dim;k++){
  241. float val=b->quantlist[j*b->dim+k];
  242. val=fabs(val)*delta+mindel+last;
  243. if(b->q_sequencep)last=val;
  244. r[j*b->dim+k]=val;
  245. }
  246. }
  247. break;
  248. }
  249. return(r);
  250. }
  251. return(NULL);
  252. }
  253. void vorbis_staticbook_clear(static_codebook *b){
  254. if(b->allocedp){
  255. if(b->quantlist)_ogg_free(b->quantlist);
  256. if(b->lengthlist)_ogg_free(b->lengthlist);
  257. if(b->nearest_tree){
  258. _ogg_free(b->nearest_tree->ptr0);
  259. _ogg_free(b->nearest_tree->ptr1);
  260. _ogg_free(b->nearest_tree->p);
  261. _ogg_free(b->nearest_tree->q);
  262. memset(b->nearest_tree,0,sizeof(encode_aux_nearestmatch));
  263. _ogg_free(b->nearest_tree);
  264. }
  265. if(b->thresh_tree){
  266. _ogg_free(b->thresh_tree->quantthresh);
  267. _ogg_free(b->thresh_tree->quantmap);
  268. memset(b->thresh_tree,0,sizeof(encode_aux_threshmatch));
  269. _ogg_free(b->thresh_tree);
  270. }
  271. memset(b,0,sizeof(static_codebook));
  272. }
  273. }
  274. void vorbis_staticbook_destroy(static_codebook *b){
  275. if(b->allocedp){
  276. vorbis_staticbook_clear(b);
  277. _ogg_free(b);
  278. }
  279. }
  280. void vorbis_book_clear(codebook *b){
  281. /* static book is not cleared; we're likely called on the lookup and
  282. the static codebook belongs to the info struct */
  283. if(b->decode_tree){
  284. _ogg_free(b->decode_tree->tab);
  285. _ogg_free(b->decode_tree->tabl);
  286. _ogg_free(b->decode_tree->ptr0);
  287. _ogg_free(b->decode_tree->ptr1);
  288. memset(b->decode_tree,0,sizeof(decode_aux));
  289. _ogg_free(b->decode_tree);
  290. }
  291. if(b->valuelist)_ogg_free(b->valuelist);
  292. if(b->codelist)_ogg_free(b->codelist);
  293. memset(b,0,sizeof(codebook));
  294. }
  295. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  296. long j,k;
  297. memset(c,0,sizeof(codebook));
  298. c->c=s;
  299. c->entries=s->entries;
  300. c->dim=s->dim;
  301. c->codelist=_make_words(s->lengthlist,s->entries);
  302. c->valuelist=_book_unquantize(s);
  303. /* set the 'zero entry' */
  304. c->zeroentry=-1;
  305. if(c->valuelist){
  306. for(j=0;j<s->entries;j++){
  307. int flag=1;
  308. for(k=0;k<s->dim;k++){
  309. if(fabs(c->valuelist[j*s->dim+k])>1e-12f){
  310. flag=0;
  311. break;
  312. }
  313. }
  314. if(flag)
  315. c->zeroentry=j;
  316. }
  317. }
  318. return(0);
  319. }
  320. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  321. memset(c,0,sizeof(codebook));
  322. c->c=s;
  323. c->entries=s->entries;
  324. c->dim=s->dim;
  325. c->valuelist=_book_unquantize(s);
  326. c->decode_tree=_make_decode_tree(c);
  327. if(c->decode_tree==NULL)goto err_out;
  328. return(0);
  329. err_out:
  330. vorbis_book_clear(c);
  331. return(-1);
  332. }
  333. static float _dist(int el,float *ref, float *b,int step){
  334. int i;
  335. float acc=0.f;
  336. for(i=0;i<el;i++){
  337. float val=(ref[i]-b[i*step]);
  338. acc+=val*val;
  339. }
  340. return(acc);
  341. }
  342. #include <stdio.h>
  343. int _best(codebook *book, float *a, int step){
  344. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  345. encode_aux_threshmatch *tt=book->c->thresh_tree;
  346. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  347. int dim=book->dim;
  348. int ptr=0,k,o;
  349. /*int savebest=-1;
  350. float saverr;*/
  351. /* do we have a threshhold encode hint? */
  352. if(tt){
  353. int index=0;
  354. /* find the quant val of each scalar */
  355. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  356. int i;
  357. /* linear search the quant list for now; it's small and although
  358. with > ~8 entries, it would be faster to bisect, this would be
  359. a misplaced optimization for now */
  360. for(i=0;i<tt->threshvals-1;i++)
  361. if(a[o]<tt->quantthresh[i])break;
  362. index=(index*tt->quantvals)+tt->quantmap[i];
  363. }
  364. /* regular lattices are easy :-) */
  365. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  366. use a decision tree after all
  367. and fall through*/
  368. return(index);
  369. }
  370. /* do we have a pigeonhole encode hint? */
  371. if(pt){
  372. const static_codebook *c=book->c;
  373. int i,besti=-1;
  374. float best;
  375. int entry=0;
  376. /* dealing with sequentialness is a pain in the ass */
  377. if(c->q_sequencep){
  378. int pv;
  379. long mul=1;
  380. float qlast=0;
  381. for(k=0,o=0;k<dim;k++,o+=step){
  382. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  383. if(pv<0 || pv>=pt->mapentries)break;
  384. entry+=pt->pigeonmap[pv]*mul;
  385. mul*=pt->quantvals;
  386. qlast+=pv*pt->del+pt->min;
  387. }
  388. }else{
  389. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  390. int pv=(int)((a[o]-pt->min)/pt->del);
  391. if(pv<0 || pv>=pt->mapentries)break;
  392. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  393. }
  394. }
  395. /* must be within the pigeonholable range; if we quant outside (or
  396. in an entry that we define no list for), brute force it */
  397. if(k==dim && pt->fitlength[entry]){
  398. /* search the abbreviated list */
  399. long *list=pt->fitlist+pt->fitmap[entry];
  400. for(i=0;i<pt->fitlength[entry];i++){
  401. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  402. if(besti==-1 || this<best){
  403. best=this;
  404. besti=list[i];
  405. }
  406. }
  407. return(besti);
  408. }
  409. }
  410. if(nt){
  411. /* optimized using the decision tree */
  412. while(1){
  413. float c=0.f;
  414. float *p=book->valuelist+nt->p[ptr];
  415. float *q=book->valuelist+nt->q[ptr];
  416. for(k=0,o=0;k<dim;k++,o+=step)
  417. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  418. if(c>0.f) /* in A */
  419. ptr= -nt->ptr0[ptr];
  420. else /* in B */
  421. ptr= -nt->ptr1[ptr];
  422. if(ptr<=0)break;
  423. }
  424. return(-ptr);
  425. }
  426. /* brute force it! */
  427. {
  428. const static_codebook *c=book->c;
  429. int i,besti=-1;
  430. float best;
  431. float *e=book->valuelist;
  432. for(i=0;i<book->entries;i++){
  433. if(c->lengthlist[i]>0){
  434. float this=_dist(dim,e,a,step);
  435. if(besti==-1 || this<best){
  436. best=this;
  437. besti=i;
  438. }
  439. }
  440. e+=dim;
  441. }
  442. /*if(savebest!=-1 && savebest!=besti){
  443. fprintf(stderr,"brute force/pigeonhole disagreement:\n"
  444. "original:");
  445. for(i=0;i<dim*step;i+=step)fprintf(stderr,"%g,",a[i]);
  446. fprintf(stderr,"\n"
  447. "pigeonhole (entry %d, err %g):",savebest,saverr);
  448. for(i=0;i<dim;i++)fprintf(stderr,"%g,",
  449. (book->valuelist+savebest*dim)[i]);
  450. fprintf(stderr,"\n"
  451. "bruteforce (entry %d, err %g):",besti,best);
  452. for(i=0;i<dim;i++)fprintf(stderr,"%g,",
  453. (book->valuelist+besti*dim)[i]);
  454. fprintf(stderr,"\n");
  455. }*/
  456. return(besti);
  457. }
  458. }
  459. /* returns the entry number and *modifies a* to the remainder value ********/
  460. int vorbis_book_besterror(codebook *book,float *a,int step,int addmul){
  461. int dim=book->dim,i,o;
  462. int best=_best(book,a,step);
  463. switch(addmul){
  464. case 0:
  465. for(i=0,o=0;i<dim;i++,o+=step)
  466. a[o]-=(book->valuelist+best*dim)[i];
  467. break;
  468. case 1:
  469. for(i=0,o=0;i<dim;i++,o+=step){
  470. float val=(book->valuelist+best*dim)[i];
  471. if(val==0){
  472. a[o]=0;
  473. }else{
  474. a[o]/=val;
  475. }
  476. }
  477. break;
  478. }
  479. return(best);
  480. }
  481. long vorbis_book_codeword(codebook *book,int entry){
  482. return book->codelist[entry];
  483. }
  484. long vorbis_book_codelen(codebook *book,int entry){
  485. return book->c->lengthlist[entry];
  486. }
  487. #ifdef _V_SELFTEST
  488. /* Unit tests of the dequantizer; this stuff will be OK
  489. cross-platform, I simply want to be sure that special mapping cases
  490. actually work properly; a bug could go unnoticed for a while */
  491. #include <stdio.h>
  492. /* cases:
  493. no mapping
  494. full, explicit mapping
  495. algorithmic mapping
  496. nonsequential
  497. sequential
  498. */
  499. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  500. static long partial_quantlist1[]={0,7,2};
  501. /* no mapping */
  502. static_codebook test1={
  503. 4,16,
  504. NULL,
  505. 0,
  506. 0,0,0,0,
  507. NULL,
  508. NULL,NULL
  509. };
  510. static float *test1_result=NULL;
  511. /* linear, full mapping, nonsequential */
  512. static_codebook test2={
  513. 4,3,
  514. NULL,
  515. 2,
  516. -533200896,1611661312,4,0,
  517. full_quantlist1,
  518. NULL,NULL
  519. };
  520. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  521. /* linear, full mapping, sequential */
  522. static_codebook test3={
  523. 4,3,
  524. NULL,
  525. 2,
  526. -533200896,1611661312,4,1,
  527. full_quantlist1,
  528. NULL,NULL
  529. };
  530. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  531. /* linear, algorithmic mapping, nonsequential */
  532. static_codebook test4={
  533. 3,27,
  534. NULL,
  535. 1,
  536. -533200896,1611661312,4,0,
  537. partial_quantlist1,
  538. NULL,NULL
  539. };
  540. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  541. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  542. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  543. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  544. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  545. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  546. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  547. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  548. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  549. /* linear, algorithmic mapping, sequential */
  550. static_codebook test5={
  551. 3,27,
  552. NULL,
  553. 1,
  554. -533200896,1611661312,4,1,
  555. partial_quantlist1,
  556. NULL,NULL
  557. };
  558. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  559. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  560. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  561. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  562. -3, 1, 5, 4, 8,12, -1, 3, 7,
  563. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  564. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  565. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  566. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  567. void run_test(static_codebook *b,float *comp){
  568. float *out=_book_unquantize(b);
  569. int i;
  570. if(comp){
  571. if(!out){
  572. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  573. exit(1);
  574. }
  575. for(i=0;i<b->entries*b->dim;i++)
  576. if(fabs(out[i]-comp[i])>.0001){
  577. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  578. "position %d, %g != %g\n",i,out[i],comp[i]);
  579. exit(1);
  580. }
  581. }else{
  582. if(out){
  583. fprintf(stderr,"_book_unquantize returned a value array: \n"
  584. " correct result should have been NULL\n");
  585. exit(1);
  586. }
  587. }
  588. }
  589. int main(){
  590. /* run the nine dequant tests, and compare to the hand-rolled results */
  591. fprintf(stderr,"Dequant test 1... ");
  592. run_test(&test1,test1_result);
  593. fprintf(stderr,"OK\nDequant test 2... ");
  594. run_test(&test2,test2_result);
  595. fprintf(stderr,"OK\nDequant test 3... ");
  596. run_test(&test3,test3_result);
  597. fprintf(stderr,"OK\nDequant test 4... ");
  598. run_test(&test4,test4_result);
  599. fprintf(stderr,"OK\nDequant test 5... ");
  600. run_test(&test5,test5_result);
  601. fprintf(stderr,"OK\n\n");
  602. return(0);
  603. }
  604. #endif