examples/sfexamples/oggvorbiscodec/src/libvorbis/vq/bookutil.c

00001 /********************************************************************
00002  *                                                                  *
00003  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
00004  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00005  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00006  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00007  *                                                                  *
00008  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
00009  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
00010  *                                                                  *
00011  ********************************************************************
00012 
00013  function: utility functions for loading .vqh and .vqd files
00014  last mod: $Id: bookutil.c 7187 2004-07-20 07:24:27Z xiphmont $
00015 
00016  ********************************************************************/
00017 
00018 #include <stdlib.h>
00019 #include <stdio.h>
00020 #include <math.h>
00021 #include <string.h>
00022 #include <errno.h>
00023 #include "bookutil.h"
00024 
00025 /* A few little utils for reading files */
00026 /* read a line.  Use global, persistent buffering */
00027 static char *linebuffer=NULL;
00028 static int  lbufsize=0;
00029 char *get_line(FILE *in){
00030   long sofar=0;
00031   if(feof(in))return NULL;
00032 
00033   while(1){
00034     int gotline=0;
00035 
00036     while(!gotline){
00037       if(sofar+1>=lbufsize){
00038         if(!lbufsize){  
00039           lbufsize=1024;
00040           linebuffer=_ogg_malloc(lbufsize);
00041         }else{
00042           lbufsize*=2;
00043           linebuffer=_ogg_realloc(linebuffer,lbufsize);
00044         }
00045       }
00046       {
00047         long c=fgetc(in);
00048         switch(c){
00049         case EOF:
00050           if(sofar==0)return(NULL);
00051           /* fallthrough correct */
00052         case '\n':
00053           linebuffer[sofar]='\0';
00054           gotline=1;
00055           break;
00056         default:
00057           linebuffer[sofar++]=c;
00058           linebuffer[sofar]='\0';
00059           break;
00060         }
00061       }
00062     }
00063     
00064     if(linebuffer[0]=='#'){
00065       sofar=0;
00066     }else{
00067       return(linebuffer);
00068     }
00069   }
00070 }
00071 
00072 /* read the next numerical value from the given file */
00073 static char *value_line_buff=NULL;
00074 
00075 int get_line_value(FILE *in,float *value){
00076   char *next;
00077 
00078   if(!value_line_buff)return(-1);
00079 
00080   *value=strtod(value_line_buff, &next);
00081   if(next==value_line_buff){
00082     value_line_buff=NULL;
00083     return(-1);
00084   }else{
00085     value_line_buff=next;
00086     while(*value_line_buff>44)value_line_buff++;
00087     if(*value_line_buff==44)value_line_buff++;
00088     return(0);
00089   }
00090 }
00091 
00092 int get_next_value(FILE *in,float *value){
00093   while(1){
00094     if(get_line_value(in,value)){
00095       value_line_buff=get_line(in);
00096       if(!value_line_buff)return(-1);
00097     }else{
00098       return(0);
00099     }
00100   }
00101 }
00102 
00103 int get_next_ivalue(FILE *in,long *ivalue){
00104   float value;
00105   int ret=get_next_value(in,&value);
00106   *ivalue=value;
00107   return(ret);
00108 }
00109 
00110 static float sequence_base=0.f;
00111 static int v_sofar=0;
00112 void reset_next_value(void){
00113   value_line_buff=NULL;
00114   sequence_base=0.f;
00115   v_sofar=0;
00116 }
00117 
00118 char *setup_line(FILE *in){
00119   reset_next_value();
00120   value_line_buff=get_line(in);
00121   return(value_line_buff);
00122 }
00123 
00124 
00125 int get_vector(codebook *b,FILE *in,int start, int n,float *a){
00126   int i;
00127   const static_codebook *c=b->c;
00128 
00129   while(1){
00130 
00131     if(v_sofar==n || get_line_value(in,a)){
00132       reset_next_value();
00133       if(get_next_value(in,a))
00134         break;
00135       for(i=0;i<start;i++){
00136         sequence_base=*a;
00137         get_line_value(in,a);
00138       }
00139     }
00140 
00141     for(i=1;i<c->dim;i++)
00142       if(get_line_value(in,a+i))
00143         break;
00144     
00145     if(i==c->dim){
00146       float temp=a[c->dim-1];
00147       for(i=0;i<c->dim;i++)a[i]-=sequence_base;
00148       if(c->q_sequencep)sequence_base=temp;
00149       v_sofar++;
00150       return(0);
00151     }
00152     sequence_base=0.f;
00153   }
00154 
00155   return(-1);
00156 }
00157 
00158 /* read lines fromt he beginning until we find one containing the
00159    specified string */
00160 char *find_seek_to(FILE *in,char *s){
00161   rewind(in);
00162   while(1){
00163     char *line=get_line(in);
00164     if(line){
00165       if(strstr(line,s))
00166         return(line);
00167     }else
00168       return(NULL);
00169   }
00170 }
00171 
00172 
00173 /* this reads the format as written by vqbuild/latticebuild; innocent
00174    (legal) tweaking of the file that would not affect its valid
00175    header-ness will break this routine */
00176 
00177 codebook *codebook_load(char *filename){
00178   codebook *b=_ogg_calloc(1,sizeof(codebook));
00179   static_codebook *c=(static_codebook *)(b->c=_ogg_calloc(1,sizeof(static_codebook)));
00180   encode_aux_nearestmatch *a=NULL;
00181   encode_aux_threshmatch *t=NULL;
00182   encode_aux_pigeonhole *p=NULL;
00183   int quant_to_read=0;
00184   FILE *in=fopen(filename,"r");
00185   char *line;
00186   long i;
00187 
00188   if(in==NULL){
00189     fprintf(stderr,"Couldn't open codebook %s\n",filename);
00190     exit(1);
00191   }
00192 
00193   /* find the codebook struct */
00194   find_seek_to(in,"static static_codebook ");
00195 
00196   /* get the major important values */
00197   line=get_line(in);
00198   if(sscanf(line,"%ld, %ld,",
00199             &(c->dim),&(c->entries))!=2){
00200     fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line);
00201     exit(1);
00202   }
00203   line=get_line(in);
00204   line=get_line(in);
00205   if(sscanf(line,"%d, %ld, %ld, %d, %d,",
00206             &(c->maptype),&(c->q_min),&(c->q_delta),&(c->q_quant),
00207             &(c->q_sequencep))!=5){
00208     fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line);
00209     exit(1);
00210   }
00211   
00212   /* find the auxiliary encode struct[s] (if any) */
00213   if(find_seek_to(in,"static encode_aux_nearestmatch _vq_aux")){
00214     /* how big? */
00215     c->nearest_tree=a=_ogg_calloc(1,sizeof(encode_aux_nearestmatch));
00216     line=get_line(in);
00217     line=get_line(in);
00218     line=get_line(in);
00219     line=get_line(in);
00220     line=get_line(in);
00221     if(sscanf(line,"%ld, %ld",&(a->aux),&(a->alloc))!=2){
00222       fprintf(stderr,"2: syntax in %s in line:\t %s",filename,line);
00223       exit(1);
00224     }
00225 
00226     /* load ptr0 */
00227     find_seek_to(in,"static long _vq_ptr0");
00228     reset_next_value();
00229     a->ptr0=_ogg_malloc(sizeof(long)*a->aux);
00230     for(i=0;i<a->aux;i++)
00231       if(get_next_ivalue(in,a->ptr0+i)){
00232         fprintf(stderr,"out of data while reading codebook %s\n",filename);
00233         exit(1);
00234       }
00235     
00236     /* load ptr1 */
00237     find_seek_to(in,"static long _vq_ptr1");
00238     reset_next_value();
00239     a->ptr1=_ogg_malloc(sizeof(long)*a->aux);
00240     for(i=0;i<a->aux;i++)
00241       if(get_next_ivalue(in,a->ptr1+i)){
00242         fprintf(stderr,"out of data while reading codebook %s\n",filename);
00243         exit(1);
00244     }
00245     
00246     
00247     /* load p */
00248     find_seek_to(in,"static long _vq_p_");
00249     reset_next_value();
00250     a->p=_ogg_malloc(sizeof(long)*a->aux);
00251     for(i=0;i<a->aux;i++)
00252       if(get_next_ivalue(in,a->p+i)){
00253         fprintf(stderr,"out of data while reading codebook %s\n",filename);
00254         exit(1);
00255       }
00256     
00257     /* load q */
00258     find_seek_to(in,"static long _vq_q_");
00259     reset_next_value();
00260     a->q=_ogg_malloc(sizeof(long)*a->aux);
00261     for(i=0;i<a->aux;i++)
00262       if(get_next_ivalue(in,a->q+i)){
00263         fprintf(stderr,"out of data while reading codebook %s\n",filename);
00264         exit(1);
00265       }    
00266   }
00267   
00268   if(find_seek_to(in,"static encode_aux_threshmatch _vq_aux")){
00269     /* how big? */
00270     c->thresh_tree=t=_ogg_calloc(1,sizeof(encode_aux_threshmatch));
00271     line=get_line(in);
00272     line=get_line(in);
00273     line=get_line(in);
00274     if(sscanf(line,"%d",&(t->quantvals))!=1){
00275       fprintf(stderr,"3: syntax in %s in line:\t %s",filename,line);
00276       exit(1);
00277     }
00278     line=get_line(in);
00279     if(sscanf(line,"%d",&(t->threshvals))!=1){
00280       fprintf(stderr,"4: syntax in %s in line:\t %s",filename,line);
00281       exit(1);
00282     }
00283     /* load quantthresh */
00284     find_seek_to(in,"static float _vq_quantthresh_");
00285     reset_next_value();
00286     t->quantthresh=_ogg_malloc(sizeof(float)*t->threshvals);
00287     for(i=0;i<t->threshvals-1;i++)
00288       if(get_next_value(in,t->quantthresh+i)){
00289         fprintf(stderr,"out of data 1 while reading codebook %s\n",filename);
00290         exit(1);
00291       }    
00292     /* load quantmap */
00293     find_seek_to(in,"static long _vq_quantmap_");
00294     reset_next_value();
00295     t->quantmap=_ogg_malloc(sizeof(long)*t->threshvals);
00296     for(i=0;i<t->threshvals;i++)
00297       if(get_next_ivalue(in,t->quantmap+i)){
00298         fprintf(stderr,"out of data 2 while reading codebook %s\n",filename);
00299         exit(1);
00300       }    
00301   }
00302     
00303   if(find_seek_to(in,"static encode_aux_pigeonhole _vq_aux")){
00304     int pigeons=1,i;
00305     /* how big? */
00306     c->pigeon_tree=p=_ogg_calloc(1,sizeof(encode_aux_pigeonhole));
00307     line=get_line(in);
00308     if(sscanf(line,"%f, %f, %d, %d",&(p->min),&(p->del),
00309               &(p->mapentries),&(p->quantvals))!=4){
00310       fprintf(stderr,"5: syntax in %s in line:\t %s",filename,line);
00311       exit(1);
00312     }
00313     line=get_line(in);
00314     line=get_line(in);
00315     if(sscanf(line,"%ld",&(p->fittotal))!=1){
00316       fprintf(stderr,"6: syntax in %s in line:\t %s",filename,line);
00317       exit(1);
00318     }
00319     /* load pigeonmap */
00320     find_seek_to(in,"static long _vq_pigeonmap_");
00321     reset_next_value();
00322     p->pigeonmap=_ogg_malloc(sizeof(long)*p->mapentries);
00323     for(i=0;i<p->mapentries;i++)
00324       if(get_next_ivalue(in,p->pigeonmap+i)){
00325         fprintf(stderr,"out of data (pigeonmap) while reading codebook %s\n",filename);
00326         exit(1);
00327       }    
00328     /* load fitlist */
00329     find_seek_to(in,"static long _vq_fitlist_");
00330     reset_next_value();
00331     p->fitlist=_ogg_malloc(sizeof(long)*p->fittotal);
00332     for(i=0;i<p->fittotal;i++)
00333       if(get_next_ivalue(in,p->fitlist+i)){
00334         fprintf(stderr,"out of data (fitlist) while reading codebook %s\n",filename);
00335         exit(1);
00336       }    
00337     /* load fitmap */
00338     find_seek_to(in,"static long _vq_fitmap_");
00339     reset_next_value();
00340     for(i=0;i<c->dim;i++)pigeons*=p->quantvals;
00341     p->fitmap=_ogg_malloc(sizeof(long)*pigeons);
00342     for(i=0;i<pigeons;i++)
00343       if(get_next_ivalue(in,p->fitmap+i)){
00344         fprintf(stderr,"out of data (fitmap) while reading codebook %s\n",filename);
00345         exit(1);
00346       }    
00347  
00348     /* load fitlength */
00349     find_seek_to(in,"static long _vq_fitlength_");
00350     reset_next_value();
00351     p->fitlength=_ogg_malloc(sizeof(long)*pigeons);
00352     for(i=0;i<pigeons;i++)
00353       if(get_next_ivalue(in,p->fitlength+i)){
00354         fprintf(stderr,"out of data (fitlength) while reading codebook %s\n",filename);
00355         exit(1);
00356       }    
00357   }
00358 
00359   switch(c->maptype){
00360   case 0:
00361     quant_to_read=0;
00362     break;
00363   case 1:
00364     quant_to_read=_book_maptype1_quantvals(c);
00365     break;
00366   case 2:
00367     quant_to_read=c->entries*c->dim;
00368     break;
00369   }
00370     
00371   /* load the quantized entries */
00372   find_seek_to(in,"static long _vq_quantlist_");
00373   reset_next_value();
00374   c->quantlist=_ogg_malloc(sizeof(long)*quant_to_read);
00375   for(i=0;i<quant_to_read;i++)
00376     if(get_next_ivalue(in,c->quantlist+i)){
00377       fprintf(stderr,"out of data while reading codebook %s\n",filename);
00378       exit(1);
00379     }
00380   
00381   /* load the lengthlist */
00382   find_seek_to(in,"_lengthlist");
00383   reset_next_value();
00384   c->lengthlist=_ogg_malloc(sizeof(long)*c->entries);
00385   for(i=0;i<c->entries;i++)
00386     if(get_next_ivalue(in,c->lengthlist+i)){
00387       fprintf(stderr,"out of data while reading codebook %s\n",filename);
00388       exit(1);
00389     }
00390 
00391   /* got it all */
00392   fclose(in);
00393   
00394   vorbis_book_init_encode(b,c);
00395 
00396   return(b);
00397 }
00398 
00399 void spinnit(char *s,int n){
00400   static int p=0;
00401   static long lasttime=0;
00402   long test;
00403   struct timeval thistime;
00404 
00405   gettimeofday(&thistime,NULL);
00406   test=thistime.tv_sec*10+thistime.tv_usec/100000;
00407   if(lasttime!=test){
00408     lasttime=test;
00409 
00410     fprintf(stderr,"%s%d ",s,n);
00411 
00412     p++;if(p>3)p=0;
00413     switch(p){
00414     case 0:
00415       fprintf(stderr,"|    \r");
00416       break;
00417     case 1:
00418       fprintf(stderr,"/    \r");
00419       break;
00420     case 2:
00421       fprintf(stderr,"-    \r");
00422       break;
00423     case 3:
00424       fprintf(stderr,"\\    \r");
00425       break;
00426     }
00427     fflush(stderr);
00428   }
00429 }
00430 
00431 void build_tree_from_lengths(int vals, long *hist, long *lengths){
00432   int i,j;
00433   long *membership=_ogg_malloc(vals*sizeof(long));
00434   long *histsave=alloca(vals*sizeof(long));
00435   memcpy(histsave,hist,vals*sizeof(long));
00436 
00437   for(i=0;i<vals;i++)membership[i]=i;
00438 
00439   /* find codeword lengths */
00440   /* much more elegant means exist.  Brute force n^2, minimum thought */
00441   for(i=vals;i>1;i--){
00442     int first=-1,second=-1;
00443     long least=-1;
00444         
00445     spinnit("building... ",i);
00446     
00447     /* find the two nodes to join */
00448     for(j=0;j<vals;j++)
00449       if(least==-1 || hist[j]<=least){
00450         least=hist[j];
00451         first=membership[j];
00452       }
00453     least=-1;
00454     for(j=0;j<vals;j++)
00455       if((least==-1 || hist[j]<=least) && membership[j]!=first){
00456         least=hist[j];
00457         second=membership[j];
00458       }
00459     if(first==-1 || second==-1){
00460       fprintf(stderr,"huffman fault; no free branch\n");
00461       exit(1);
00462     }
00463     
00464     /* join them */
00465     least=hist[first]+hist[second];
00466     for(j=0;j<vals;j++)
00467       if(membership[j]==first || membership[j]==second){
00468         membership[j]=first;
00469         hist[j]=least;
00470         lengths[j]++;
00471       }
00472   }
00473   for(i=0;i<vals-1;i++)
00474     if(membership[i]!=membership[i+1]){
00475       fprintf(stderr,"huffman fault; failed to build single tree\n");
00476       exit(1);
00477     }
00478 
00479   /* for sanity check purposes: how many bits would it have taken to
00480      encode the training set? */
00481   {
00482     long bitsum=0;
00483     long samples=0;
00484     for(i=0;i<vals;i++){
00485       bitsum+=(histsave[i]-1)*lengths[i];
00486       samples+=histsave[i]-1;
00487     }
00488 
00489     if(samples){
00490       fprintf(stderr,"\rTotal samples in training set: %ld      \n",samples);
00491       fprintf(stderr,"\rTotal bits used to represent training set: %ld\n",
00492               bitsum);
00493     }
00494   }
00495 
00496   free(membership);
00497 }
00498 
00499 /* wrap build_tree_from_lengths to allow zero entries in the histogram */
00500 void build_tree_from_lengths0(int vals, long *hist, long *lengths){
00501 
00502   /* pack the 'sparse' hit list into a dense list, then unpack
00503      the lengths after the build */
00504 
00505   int upper=0,i;
00506   long *lengthlist=_ogg_calloc(vals,sizeof(long));
00507   long *newhist=alloca(vals*sizeof(long));
00508 
00509   for(i=0;i<vals;i++)
00510     if(hist[i]>0)
00511       newhist[upper++]=hist[i];
00512 
00513   if(upper != vals){
00514     fprintf(stderr,"\rEliminating %d unused entries; %d entries remain\n",
00515             vals-upper,upper);
00516   }
00517     
00518   build_tree_from_lengths(upper,newhist,lengthlist);
00519       
00520   upper=0;
00521   for(i=0;i<vals;i++)
00522     if(hist[i]>0)
00523       lengths[i]=lengthlist[upper++];
00524     else
00525       lengths[i]=0;
00526 
00527   free(lengthlist);
00528 }
00529 
00530 void write_codebook(FILE *out,char *name,const static_codebook *c){
00531   encode_aux_pigeonhole *p=c->pigeon_tree;
00532   encode_aux_threshmatch *t=c->thresh_tree;
00533   encode_aux_nearestmatch *n=c->nearest_tree;
00534   int i,j,k;
00535 
00536   /* save the book in C header form */
00537 
00538   /* first, the static vectors, then the book structure to tie it together. */
00539   /* quantlist */
00540   if(c->quantlist){
00541     long vals=(c->maptype==1?_book_maptype1_quantvals(c):c->entries*c->dim);
00542     fprintf(out,"static long _vq_quantlist_%s[] = {\n",name);
00543     for(j=0;j<vals;j++){
00544       fprintf(out,"\t%ld,\n",c->quantlist[j]);
00545     }
00546     fprintf(out,"};\n\n");
00547   }
00548 
00549   /* lengthlist */
00550   fprintf(out,"static long _vq_lengthlist_%s[] = {\n",name);
00551   for(j=0;j<c->entries;){
00552     fprintf(out,"\t");
00553     for(k=0;k<16 && j<c->entries;k++,j++)
00554       fprintf(out,"%2ld,",c->lengthlist[j]);
00555     fprintf(out,"\n");
00556   }
00557   fprintf(out,"};\n\n");
00558 
00559   if(t){
00560     /* quantthresh */
00561     fprintf(out,"static float _vq_quantthresh_%s[] = {\n",name);
00562     for(j=0;j<t->threshvals-1;){
00563       fprintf(out,"\t");
00564       for(k=0;k<8 && j<t->threshvals-1;k++,j++)
00565         fprintf(out,"%.5g, ",t->quantthresh[j]);
00566       fprintf(out,"\n");
00567     }
00568     fprintf(out,"};\n\n");
00569 
00570     /* quantmap */
00571     fprintf(out,"static long _vq_quantmap_%s[] = {\n",name);
00572     for(j=0;j<t->threshvals;){
00573       fprintf(out,"\t");
00574       for(k=0;k<8 && j<t->threshvals;k++,j++)
00575         fprintf(out,"%5ld,",t->quantmap[j]);
00576       fprintf(out,"\n");
00577     }
00578     fprintf(out,"};\n\n");  
00579 
00580     fprintf(out,"static encode_aux_threshmatch _vq_auxt_%s = {\n",name);
00581     fprintf(out,"\t_vq_quantthresh_%s,\n",name);
00582     fprintf(out,"\t_vq_quantmap_%s,\n",name);
00583     fprintf(out,"\t%d,\n",t->quantvals);
00584     fprintf(out,"\t%d\n};\n\n",t->threshvals);
00585   }
00586 
00587   if(p){
00588     int pigeons=1;
00589     for(i=0;i<c->dim;i++)pigeons*=p->quantvals;
00590 
00591     /* pigeonmap */
00592     fprintf(out,"static long _vq_pigeonmap_%s[] = {\n",name);
00593     for(j=0;j<p->mapentries;){
00594       fprintf(out,"\t");
00595       for(k=0;k<8 && j<p->mapentries;k++,j++)
00596         fprintf(out,"%5ld, ",p->pigeonmap[j]);
00597       fprintf(out,"\n");
00598     }
00599     fprintf(out,"};\n\n");
00600     /* fitlist */
00601     fprintf(out,"static long _vq_fitlist_%s[] = {\n",name);
00602     for(j=0;j<p->fittotal;){
00603       fprintf(out,"\t");
00604       for(k=0;k<8 && j<p->fittotal;k++,j++)
00605         fprintf(out,"%5ld, ",p->fitlist[j]);
00606       fprintf(out,"\n");
00607     }
00608     fprintf(out,"};\n\n");
00609     /* fitmap */
00610     fprintf(out,"static long _vq_fitmap_%s[] = {\n",name);
00611     for(j=0;j<pigeons;){
00612       fprintf(out,"\t");
00613       for(k=0;k<8 && j<pigeons;k++,j++)
00614         fprintf(out,"%5ld, ",p->fitmap[j]);
00615       fprintf(out,"\n");
00616     }
00617     fprintf(out,"};\n\n");
00618     /* fitlength */
00619     fprintf(out,"static long _vq_fitlength_%s[] = {\n",name);
00620     for(j=0;j<pigeons;){
00621       fprintf(out,"\t");
00622       for(k=0;k<8 && j<pigeons;k++,j++)
00623         fprintf(out,"%5ld, ",p->fitlength[j]);
00624       fprintf(out,"\n");
00625     }
00626     fprintf(out,"};\n\n");
00627 
00628     fprintf(out,"static encode_aux_pigeonhole _vq_auxp_%s = {\n",name);
00629     fprintf(out,"\t%g, %g, %d, %d,\n",
00630             p->min,p->del,p->mapentries,p->quantvals);
00631 
00632     fprintf(out,"\t_vq_pigeonmap_%s,\n",name);
00633 
00634     fprintf(out,"\t%ld,\n",p->fittotal);
00635     fprintf(out,"\t_vq_fitlist_%s,\n",name);
00636     fprintf(out,"\t_vq_fitmap_%s,\n",name);
00637     fprintf(out,"\t_vq_fitlength_%s\n};\n\n",name);
00638   }
00639 
00640   if(n){
00641     
00642     /* ptr0 */
00643     fprintf(out,"static long _vq_ptr0_%s[] = {\n",name);
00644     for(j=0;j<n->aux;){
00645       fprintf(out,"\t");
00646       for(k=0;k<8 && j<n->aux;k++,j++)
00647         fprintf(out,"%6ld,",n->ptr0[j]);
00648       fprintf(out,"\n");
00649     }
00650     fprintf(out,"};\n\n");
00651     
00652     /* ptr1 */
00653     fprintf(out,"static long _vq_ptr1_%s[] = {\n",name);
00654     for(j=0;j<n->aux;){
00655       fprintf(out,"\t");
00656       for(k=0;k<8 && j<n->aux;k++,j++)
00657         fprintf(out,"%6ld,",n->ptr1[j]);
00658       fprintf(out,"\n");
00659     }
00660     fprintf(out,"};\n\n");
00661     
00662     /* p */
00663     fprintf(out,"static long _vq_p_%s[] = {\n",name);
00664     for(j=0;j<n->aux;){
00665       fprintf(out,"\t");
00666       for(k=0;k<8 && j<n->aux;k++,j++)
00667         fprintf(out,"%6ld,",n->p[j]*c->dim);
00668       fprintf(out,"\n");
00669     }
00670     fprintf(out,"};\n\n");
00671     
00672     /* q */
00673     fprintf(out,"static long _vq_q_%s[] = {\n",name);
00674     for(j=0;j<n->aux;){
00675       fprintf(out,"\t");
00676       for(k=0;k<8 && j<n->aux;k++,j++)
00677         fprintf(out,"%6ld,",n->q[j]*c->dim);
00678       fprintf(out,"\n");
00679     }
00680     fprintf(out,"};\n\n");
00681   
00682     fprintf(out,"static encode_aux_nearestmatch _vq_auxn_%s = {\n",name);
00683     fprintf(out,"\t_vq_ptr0_%s,\n",name);
00684     fprintf(out,"\t_vq_ptr1_%s,\n",name);
00685     fprintf(out,"\t_vq_p_%s,\n",name);
00686     fprintf(out,"\t_vq_q_%s,\n",name);
00687     fprintf(out,"\t%ld, %ld\n};\n\n",n->aux,n->aux);
00688   }
00689 
00690   /* tie it all together */
00691   
00692   fprintf(out,"static static_codebook %s = {\n",name);
00693   
00694   fprintf(out,"\t%ld, %ld,\n",c->dim,c->entries);
00695   fprintf(out,"\t_vq_lengthlist_%s,\n",name);
00696   fprintf(out,"\t%d, %ld, %ld, %d, %d,\n",
00697           c->maptype,c->q_min,c->q_delta,c->q_quant,c->q_sequencep);
00698   if(c->quantlist)
00699     fprintf(out,"\t_vq_quantlist_%s,\n",name);
00700   else
00701     fprintf(out,"\tNULL,\n");
00702 
00703   if(n)
00704     fprintf(out,"\t&_vq_auxn_%s,\n",name);
00705   else
00706     fprintf(out,"\tNULL,\n");
00707   if(t)
00708     fprintf(out,"\t&_vq_auxt_%s,\n",name);
00709   else
00710     fprintf(out,"\tNULL,\n");
00711   if(p)
00712     fprintf(out,"\t&_vq_auxp_%s,\n",name);
00713   else
00714     fprintf(out,"\tNULL,\n");
00715 
00716   fprintf(out,"\t0\n};\n\n");
00717 }

Generated by  doxygen 1.6.2