21 #include "../ogg/ogg.h"
24 #include "../vorbis/codec.h"
44 #define VQ_FEXP_BIAS 768
55 exp= floor(log(val)/log(2.
f));
56 mant=rint(ldexp(val,(
VQ_FMAN-1)-exp));
59 return(sign|exp|mant);
63 double mant=val&0x1fffff;
64 int sign=val&0x80000000;
65 long exp =(val&0x7fe00000
L)>>
VQ_FMAN;
77 memset(marker,0,
sizeof(marker));
90 if(length<32 && (entry>>length)){
100 for(j=length;j>0;j--){
107 marker[
j]=marker[j-1]<<1;
118 for(j=length+1;j<33;j++)
119 if((marker[j]>>1) == entry){
121 marker[
j]=marker[j-1]<<1;
125 if(sparsecount==0)count++;
130 for(i=0,count=0;i<
n;i++){
151 long vals=floor(pow((
float)b->
entries,1.f/b->
dim));
162 for(i=0;i<b->
dim;i++){
166 if(acc<=b->entries && acc1>b->
entries){
204 if((sparsemap && b->
lengthlist[j]) || !sparsemap){
207 for(k=0;k<b->
dim;k++){
208 int index= (j/indexdiv)%quantvals;
210 val=fabs(val)*delta+mindel+last;
215 r[count*b->
dim+k]=val;
225 if((sparsemap && b->
lengthlist[j]) || !sparsemap){
228 for(k=0;k<b->
dim;k++){
230 val=fabs(val)*delta+mindel+last;
235 r[count*b->
dim+k]=val;
267 memset(b,0,
sizeof(*b));
288 memset(b,0,
sizeof(*b));
293 memset(c,0,
sizeof(*c));
305 x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
306 x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
307 x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
308 x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
309 return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
312 static int sort32a(
const void *
a,
const void *
b){
321 memset(c,0,
sizeof(*c));
347 if(codes==
NULL)
goto err_out;
350 codes[
i]=bitreverse(codes[i]);
354 qsort(codep,n,
sizeof(*codep),sort32a);
356 sortindex=alloca(n*
sizeof(*sortindex));
360 int position=codep[
i]-codes;
361 sortindex[position]=
i;
409 while( hi<n && word>=(c->
codelist[hi]&mask))hi++;
415 unsigned long loval=lo;
416 unsigned long hival=n-hi;
418 if(loval>0x7fff)loval=0x7fff;
419 if(hival>0x7fff)hival=0x7fff;
421 0x80000000UL | (loval<<15) | hival;
434 static float _dist(
int el,
float *
ref,
float *b,
int step){
438 float val=(ref[
i]-b[i*step]);
460 for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
498 for(k=0,o=0;k<dim;k++,o+=step){
503 qlast+=pv*pt->
del+pt->
min;
506 for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
519 float this=_dist(dim,book->
valuelist+list[i]*dim,a,step);
520 if(besti==-1 ||
this<best){
537 for(k=0,o=0;k<dim;k++,o+=step)
538 c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
558 float this=_dist(dim,e,a,step);
559 if(besti==-1 ||
this<best){
617 static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
618 static long partial_quantlist1[]={0,7,2};
629 static float *test1_result=
NULL;
636 -533200896,1611661312,4,0,
640 static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
647 -533200896,1611661312,4,1,
651 static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
658 -533200896,1611661312,4,0,
662 static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
663 -3, 4,-3, 4, 4,-3, -1, 4,-3,
664 -3,-1,-3, 4,-1,-3, -1,-1,-3,
665 -3,-3, 4, 4,-3, 4, -1,-3, 4,
666 -3, 4, 4, 4, 4, 4, -1, 4, 4,
667 -3,-1, 4, 4,-1, 4, -1,-1, 4,
668 -3,-3,-1, 4,-3,-1, -1,-3,-1,
669 -3, 4,-1, 4, 4,-1, -1, 4,-1,
670 -3,-1,-1, 4,-1,-1, -1,-1,-1};
677 -533200896,1611661312,4,1,
681 static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
682 -3, 1,-2, 4, 8, 5, -1, 3, 0,
683 -3,-4,-7, 4, 3, 0, -1,-2,-5,
684 -3,-6,-2, 4, 1, 5, -1,-4, 0,
685 -3, 1, 5, 4, 8,12, -1, 3, 7,
686 -3,-4, 0, 4, 3, 7, -1,-2, 2,
687 -3,-6,-7, 4, 1, 0, -1,-4,-5,
688 -3, 1, 0, 4, 8, 7, -1, 3, 2,
689 -3,-4,-5, 4, 3, 2, -1,-2,-3};
697 fprintf(stderr,
"_book_unquantize incorrectly returned NULL\n");
702 if(fabs(out[i]-comp[i])>.0001){
703 fprintf(stderr,
"disagreement in unquantized and reference data:\n"
704 "position %d, %g != %g\n",i,out[i],comp[i]);
710 fprintf(stderr,
"_book_unquantize returned a value array: \n"
711 " correct result should have been NULL\n");
719 fprintf(stderr,
"Dequant test 1... ");
720 run_test(&test1,test1_result);
721 fprintf(stderr,
"OK\nDequant test 2... ");
722 run_test(&test2,test2_result);
723 fprintf(stderr,
"OK\nDequant test 3... ");
724 run_test(&test3,test3_result);
725 fprintf(stderr,
"OK\nDequant test 4... ");
726 run_test(&test4,test4_result);
727 fprintf(stderr,
"OK\nDequant test 5... ");
728 run_test(&test5,test5_result);
729 fprintf(stderr,
"OK\n\n");
GLdouble GLdouble GLdouble GLdouble q
void vorbis_staticbook_clear(static_codebook *b)
int _best(codebook *book, float *a, int step)
const static_codebook * c
long _float32_pack(float val)
struct encode_aux_pigeonhole * pigeon_tree
int vorbis_book_init_encode(codebook *c, const static_codebook *s)
ogg_uint32_t * _make_words(long *l, long n, long sparsecount)
ogg_uint32_t * dec_firsttable
void vorbis_book_clear(codebook *b)
void vorbis_staticbook_destroy(static_codebook *b)
GLuint GLuint GLsizei count
int _ilog(unsigned int v)
long vorbis_book_codeword(codebook *book, int entry)
GLubyte GLubyte GLubyte a
float * _book_unquantize(const static_codebook *b, int n, int *sparsemap)
float _float32_unpack(long val)
long vorbis_book_codelen(codebook *book, int entry)
GLdouble GLdouble GLdouble r
int vorbis_book_init_decode(codebook *c, const static_codebook *s)
GLsizei const GLcharARB const GLint * length
struct encode_aux_threshmatch * thresh_tree
long _book_maptype1_quantvals(const static_codebook *b)
struct encode_aux_nearestmatch * nearest_tree