From 67bf79deaf95ee0db971c3e396e71bbe432ed021 Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 21 Jan 2000 13:42:41 +0000 Subject: [PATCH] Minor change to the codebook abstraction (static books) Bugfix to get_line in bookutil.c Monty svn path=/trunk/vorbis/; revision=238 --- vq/bookutil.c | 89 +++++++++++++++++++++++++++------------------------------- vq/build.c | 54 ++++++++++++++--------------------- vq/cascade.c | 10 +++---- vq/metrics.c | 50 ++++++++++++++++----------------- vq/partition.c | 14 +++++---- vq/run.c | 5 ++-- vq/vqsplit.c | 78 ++++++++++++++++++-------------------------------- 7 files changed, 131 insertions(+), 169 deletions(-) diff --git a/vq/bookutil.c b/vq/bookutil.c index f3dc5ad..65c75c7 100644 --- a/vq/bookutil.c +++ b/vq/bookutil.c @@ -12,7 +12,7 @@ ******************************************************************** function: utility functions for loading .vqh and .vqd files - last mod: $Id: bookutil.c,v 1.5 2000/01/12 11:34:42 xiphmont Exp $ + last mod: $Id: bookutil.c,v 1.6 2000/01/21 13:42:35 xiphmont Exp $ ********************************************************************/ @@ -26,16 +26,17 @@ void codebook_unquantize(codebook *b){ long j,k; - double mindel=float24_unpack(b->q_min); - double delta=float24_unpack(b->q_delta); - if(!b->valuelist)b->valuelist=malloc(sizeof(double)*b->entries*b->dim); + static_codebook *c=b->c; + double mindel=float24_unpack(c->q_min); + double delta=float24_unpack(c->q_delta); + if(!b->valuelist)b->valuelist=malloc(sizeof(double)*c->entries*c->dim); - for(j=0;jentries;j++){ + for(j=0;jentries;j++){ double last=0.; - for(k=0;kdim;k++){ - double val=b->quantlist[j*b->dim+k]*delta+last+mindel; - b->valuelist[j*b->dim+k]=val; - if(b->q_sequencep)last=val; + for(k=0;kdim;k++){ + double val=c->quantlist[j*c->dim+k]*delta+last+mindel; + b->valuelist[j*c->dim+k]=val; + if(c->q_sequencep)last=val; } } @@ -101,7 +102,8 @@ int get_line_value(FILE *in,double *value){ value_line_buff=NULL; return(-1); }else{ - value_line_buff=next+1; + value_line_buff=next; + while(*value_line_buff>32)value_line_buff++; return(0); } } @@ -134,6 +136,7 @@ void reset_next_value(void){ int get_vector(codebook *b,FILE *in,int start, int n,double *a){ int i; + static_codebook *c=b->c; while(1){ @@ -147,14 +150,14 @@ int get_vector(codebook *b,FILE *in,int start, int n,double *a){ } } - for(i=1;idim;i++) + for(i=1;idim;i++) if(get_line_value(in,a+i)) break; - if(i==b->dim){ - double temp=a[b->dim-1]; - for(i=0;idim;i++)a[i]-=sequence_base; - if(b->q_sequencep)sequence_base=temp; + if(i==c->dim){ + double temp=a[c->dim-1]; + for(i=0;idim;i++)a[i]-=sequence_base; + if(c->q_sequencep)sequence_base=temp; v_sofar++; return(0); } @@ -185,12 +188,13 @@ char *find_seek_to(FILE *in,char *s){ codebook *codebook_load(char *filename){ codebook *b=calloc(1,sizeof(codebook)); + static_codebook *c=b->c=calloc(1,sizeof(static_codebook)); encode_aux *a=calloc(1,sizeof(encode_aux)); FILE *in=fopen(filename,"r"); char *line; long i; - b->encode_tree=a; + c->encode_tree=a; if(in==NULL){ fprintf(stderr,"Couldn't open codebook %s\n",filename); @@ -198,13 +202,13 @@ codebook *codebook_load(char *filename){ } /* find the codebook struct */ - find_seek_to(in,"static codebook _vq_book_"); + find_seek_to(in,"static static_codebook _vq_book_"); /* get the major important values */ line=get_line(in); if(sscanf(line,"%ld, %ld, %ld, %ld, %d, %d", - &(b->dim),&(b->entries),&(b->q_min),&(b->q_delta),&(b->q_quant), - &(b->q_sequencep))!=6){ + &(c->dim),&(c->entries),&(c->q_min),&(c->q_delta),&(c->q_quant), + &(c->q_sequencep))!=6){ fprintf(stderr,"1: syntax in %s in line:\t %s",filename,line); exit(1); } @@ -217,8 +221,6 @@ codebook *codebook_load(char *filename){ line=get_line(in); line=get_line(in); line=get_line(in); - line=get_line(in); - line=get_line(in); if(sscanf(line,"%ld, %ld",&(a->aux),&(a->alloc))!=2){ fprintf(stderr,"2: syntax in %s in line:\t %s",filename,line); exit(1); @@ -227,19 +229,9 @@ codebook *codebook_load(char *filename){ /* load the quantized entries */ find_seek_to(in,"static long _vq_quantlist_"); reset_next_value(); - b->quantlist=malloc(sizeof(long)*b->entries*b->dim); - for(i=0;ientries*b->dim;i++) - if(get_next_ivalue(in,b->quantlist+i)){ - fprintf(stderr,"out of data while reading codebook %s\n",filename); - exit(1); - } - - /* load the codewords */ - find_seek_to(in,"static long _vq_codelist"); - reset_next_value(); - b->codelist=malloc(sizeof(long)*b->entries); - for(i=0;ientries;i++) - if(get_next_ivalue(in,b->codelist+i)){ + c->quantlist=malloc(sizeof(long)*c->entries*c->dim); + for(i=0;ientries*c->dim;i++) + if(get_next_ivalue(in,c->quantlist+i)){ fprintf(stderr,"out of data while reading codebook %s\n",filename); exit(1); } @@ -247,9 +239,9 @@ codebook *codebook_load(char *filename){ /* load the lengthlist */ find_seek_to(in,"static long _vq_lengthlist"); reset_next_value(); - b->lengthlist=malloc(sizeof(long)*b->entries); - for(i=0;ientries;i++) - if(get_next_ivalue(in,b->lengthlist+i)){ + c->lengthlist=malloc(sizeof(long)*c->entries); + for(i=0;ientries;i++) + if(get_next_ivalue(in,c->lengthlist+i)){ fprintf(stderr,"out of data while reading codebook %s\n",filename); exit(1); } @@ -306,24 +298,25 @@ codebook *codebook_load(char *filename){ } int codebook_entry(codebook *b,double *val){ - encode_aux *t=b->encode_tree; + static_codebook *c=b->c; + encode_aux *t=c->encode_tree; int ptr=0,k; - double *n=alloca(b->dim*sizeof(double)); + double *n=alloca(c->dim*sizeof(double)); while(1){ - double c=0.; - double *p=b->valuelist+t->p[ptr]*b->dim; - double *q=b->valuelist+t->q[ptr]*b->dim; + double C=0.; + double *p=b->valuelist+t->p[ptr]*c->dim; + double *q=b->valuelist+t->q[ptr]*c->dim; - for(k=0;kdim;k++){ + for(k=0;kdim;k++){ n[k]=p[k]-q[k]; - c-=(p[k]+q[k])*n[k]; + C-=(p[k]+q[k])*n[k]; } - c/=2.; + C/=2.; - for(k=0;kdim;k++) - c+=n[k]*val[k]; - if(c>0.) /* in A */ + for(k=0;kdim;k++) + C+=n[k]*val[k]; + if(C>0.) /* in A */ ptr= -t->ptr0[ptr]; else /* in B */ ptr= -t->ptr1[ptr]; diff --git a/vq/build.c b/vq/build.c index 470db7d..b15aa52 100644 --- a/vq/build.c +++ b/vq/build.c @@ -12,7 +12,7 @@ ******************************************************************** function: utility main for building codebooks from training sets - last mod: $Id: build.c,v 1.8 2000/01/05 10:14:54 xiphmont Exp $ + last mod: $Id: build.c,v 1.9 2000/01/21 13:42:36 xiphmont Exp $ ********************************************************************/ @@ -74,6 +74,7 @@ static char *rline(FILE *in,FILE *out){ int main(int argc,char *argv[]){ vqgen v; + static_codebook c; codebook b; quant_meta q; @@ -84,6 +85,8 @@ int main(int argc,char *argv[]){ char *line,*name; long i,j,k; + b.c=&c; + if(argv[1]==NULL){ fprintf(stderr,"Need a trained data set on the command line.\n"); exit(1); @@ -210,17 +213,7 @@ int main(int argc,char *argv[]){ for(j=0;jaux;){ + for(j=0;jaux;){ fprintf(out,"\t"); - for(k=0;k<8 && jaux;k++,j++) - fprintf(out,"%6ld,",b.encode_tree->ptr0[j]); + for(k=0;k<8 && jaux;k++,j++) + fprintf(out,"%6ld,",c.encode_tree->ptr0[j]); fprintf(out,"\n"); } fprintf(out,"};\n\n"); /* ptr1 */ fprintf(out,"static long _vq_ptr1_%s[] = {\n",name); - for(j=0;jaux;){ + for(j=0;jaux;){ fprintf(out,"\t"); - for(k=0;k<8 && jaux;k++,j++) - fprintf(out,"%6ld,",b.encode_tree->ptr1[j]); + for(k=0;k<8 && jaux;k++,j++) + fprintf(out,"%6ld,",c.encode_tree->ptr1[j]); fprintf(out,"\n"); } fprintf(out,"};\n\n"); /* p */ fprintf(out,"static long _vq_p_%s[] = {\n",name); - for(j=0;jaux;){ + for(j=0;jaux;){ fprintf(out,"\t"); - for(k=0;k<8 && jaux;k++,j++) - fprintf(out,"%6ld,",b.encode_tree->p[j]); + for(k=0;k<8 && jaux;k++,j++) + fprintf(out,"%6ld,",c.encode_tree->p[j]); fprintf(out,"\n"); } fprintf(out,"};\n\n"); /* q */ fprintf(out,"static long _vq_q_%s[] = {\n",name); - for(j=0;jaux;){ + for(j=0;jaux;){ fprintf(out,"\t"); - for(k=0;k<8 && jaux;k++,j++) - fprintf(out,"%6ld,",b.encode_tree->q[j]); + for(k=0;k<8 && jaux;k++,j++) + fprintf(out,"%6ld,",c.encode_tree->q[j]); fprintf(out,"\n"); } fprintf(out,"};\n\n"); @@ -280,21 +273,16 @@ int main(int argc,char *argv[]){ fprintf(out,"static encode_aux _vq_aux_%s = {\n",name); fprintf(out,"\t_vq_ptr0_%s,\n",name); fprintf(out,"\t_vq_ptr1_%s,\n",name); - fprintf(out,"\t0,\n"); - fprintf(out,"\t0,\n"); fprintf(out,"\t_vq_p_%s,\n",name); fprintf(out,"\t_vq_q_%s,\n",name); - fprintf(out,"\t%ld, %ld\n};\n\n",b.encode_tree->aux,b.encode_tree->aux); + fprintf(out,"\t%ld, %ld\n};\n\n",c.encode_tree->aux,c.encode_tree->aux); - fprintf(out,"static codebook _vq_book_%s = {\n",name); + fprintf(out,"static static_codebook _vq_book_%s = {\n",name); fprintf(out,"\t%ld, %ld, %ld, %ld, %d, %d,\n", - b.dim,b.entries,q.min,q.delta,q.quant,q.sequencep); - fprintf(out,"\t0,\n"); /* valuelist */ + c.dim,c.entries,q.min,q.delta,q.quant,q.sequencep); fprintf(out,"\t_vq_quantlist_%s,\n",name); - fprintf(out,"\t_vq_codelist_%s,\n",name); fprintf(out,"\t_vq_lengthlist_%s,\n",name); fprintf(out,"\t&_vq_aux_%s,\n",name); - fprintf(out,"\t0\n"); fprintf(out,"};\n\n"); fprintf(out,"\n#endif\n"); diff --git a/vq/cascade.c b/vq/cascade.c index 6a48b40..dfd2a6e 100644 --- a/vq/cascade.c +++ b/vq/cascade.c @@ -12,7 +12,7 @@ ******************************************************************** function: function call to do simple data cascading - last mod: $Id: cascade.c,v 1.4 2000/01/07 12:11:30 xiphmont Exp $ + last mod: $Id: cascade.c,v 1.5 2000/01/21 13:42:37 xiphmont Exp $ ********************************************************************/ @@ -33,10 +33,10 @@ void process_preprocess(codebook **bs,char *basename){ while(*bs){ codebook *b=*bs; if(dim==-1){ - dim=b->dim; + dim=b->c->dim; work=malloc(sizeof(double)*dim); }else{ - if(dim!=b->dim){ + if(dim!=b->c->dim){ fprintf(stderr,"Each codebook in a cascade must have the same dimensional order\n"); exit(1); } @@ -56,9 +56,9 @@ void process_vector(codebook **bs,double *a){ while(*bs){ codebook *b=*bs; int entry=codebook_entry(b,work); - double *e=b->valuelist+b->dim*entry; + double *e=b->valuelist+b->c->dim*entry; - for(i=0;idim;i++)work[i]-=e[i]; + for(i=0;ic->dim;i++)work[i]-=e[i]; bs++; } diff --git a/vq/metrics.c b/vq/metrics.c index f7b9b00..be063f8 100644 --- a/vq/metrics.c +++ b/vq/metrics.c @@ -12,7 +12,7 @@ ******************************************************************** function: function calls to collect codebook metrics - last mod: $Id: metrics.c,v 1.3 2000/01/10 10:42:04 xiphmont Exp $ + last mod: $Id: metrics.c,v 1.4 2000/01/21 13:42:38 xiphmont Exp $ ********************************************************************/ @@ -54,10 +54,10 @@ void process_preprocess(codebook **bs,char *basename){ while(bs[books]){ codebook *b=bs[books]; if(dim==-1){ - dim=b->dim; + dim=b->c->dim; work=malloc(sizeof(double)*dim); }else{ - if(dim!=b->dim){ + if(dim!=b->c->dim){ fprintf(stderr,"Each codebook in a cascade must have the same dimensional order\n"); exit(1); } @@ -66,7 +66,7 @@ void process_preprocess(codebook **bs,char *basename){ } if(books){ - codebook *b=bs[books-1]; + static_codebook *b=bs[books-1]->c; histogram=calloc(b->entries,sizeof(double)); histogram_distance=calloc(b->entries,sizeof(double)); histogram_errorsq=calloc(b->entries*dim,sizeof(double)); @@ -85,7 +85,7 @@ void process_postprocess(codebook **b,char *basename){ codebook *bb=b[books-1]; fprintf(stderr,"Done. Processed %ld data points for %ld entries:\n", - (long)count,bb->entries); + (long)count,bb->c->entries); fprintf(stderr,"\tglobal mean amplitude: %g\n", meanamplitude_acc/(count*dim)); fprintf(stderr,"\tglobal mean squared amplitude: %g\n", @@ -107,11 +107,11 @@ void process_postprocess(codebook **b,char *basename){ exit(1); } - for(i=0;ientries;i++){ - for(k=0;kdim;k++){ + for(i=0;ic->entries;i++){ + for(k=0;kc->dim;k++){ fprintf(out,"%ld, %g, %g\n", - i*bb->dim+k,(bb->valuelist+i*bb->dim)[k], - sqrt((histogram_errorsq+i*bb->dim)[k]/histogram[i])); + i*bb->c->dim+k,(bb->valuelist+i*bb->c->dim)[k], + sqrt((histogram_errorsq+i*bb->c->dim)[k]/histogram[i])); } } fclose(out); @@ -123,11 +123,11 @@ void process_postprocess(codebook **b,char *basename){ exit(1); } - for(i=0;ientries;i++){ - for(k=0;kdim;k++){ + for(i=0;ic->entries;i++){ + for(k=0;kc->dim;k++){ fprintf(out,"%ld, %g, %g\n", - i*bb->dim+k,(bb->valuelist+i*bb->dim)[k], - (histogram_error+i*bb->dim)[k]/histogram[i]); + i*bb->c->dim+k,(bb->valuelist+i*bb->c->dim)[k], + (histogram_error+i*bb->c->dim)[k]/histogram[i]); } } fclose(out); @@ -139,12 +139,12 @@ void process_postprocess(codebook **b,char *basename){ exit(1); } - for(i=0;ientries;i++){ - for(k=0;kdim;k++){ + for(i=0;ic->entries;i++){ + for(k=0;kc->dim;k++){ fprintf(out,"%ld, %g, %g, %g\n", - i*bb->dim+k,(bb->valuelist+i*bb->dim)[k], - (bb->valuelist+i*bb->dim)[k]+(histogram_lo+i*bb->dim)[k], - (bb->valuelist+i*bb->dim)[k]+(histogram_hi+i*bb->dim)[k]); + i*bb->c->dim+k,(bb->valuelist+i*bb->c->dim)[k], + (bb->valuelist+i*bb->c->dim)[k]+(histogram_lo+i*bb->c->dim)[k], + (bb->valuelist+i*bb->c->dim)[k]+(histogram_hi+i*bb->c->dim)[k]); } } fclose(out); @@ -152,21 +152,21 @@ void process_postprocess(codebook **b,char *basename){ { FILE *out; - long *index=alloca(sizeof(long)*bb->entries); + long *index=alloca(sizeof(long)*bb->c->entries); sprintf(buffer,"%s-distance.m",basename); out=fopen(buffer,"w"); if(!out){ fprintf(stderr,"Could not open file %s for writing\n",buffer); exit(1); } - for(j=0;jentries;j++){ + for(j=0;jc->entries;j++){ if(histogram[j])histogram_distance[j]/=histogram[j]; index[j]=j; } - qsort(index,bb->entries,sizeof(long),histerrsort); + qsort(index,bb->c->entries,sizeof(long),histerrsort); - for(j=0;jentries;j++) + for(j=0;jc->entries;j++) for(k=0;kvaluelist+b->dim*entry; - for(i=0;idim;i++)work[i]-=e[i]; + e=b->valuelist+b->c->dim*entry; + for(i=0;ic->dim;i++)work[i]-=e[i]; } for(i=0;iq_sequencep){ + if(bs[0]->c->q_sequencep){ amplitude=a[i]-base; base=a[i]; }else diff --git a/vq/partition.c b/vq/partition.c index dfd0417..4694c57 100644 --- a/vq/partition.c +++ b/vq/partition.c @@ -12,7 +12,7 @@ ******************************************************************** function: function call to do data partitioning - last mod: $Id: partition.c,v 1.2 2000/01/07 12:11:32 xiphmont Exp $ + last mod: $Id: partition.c,v 1.3 2000/01/21 13:42:39 xiphmont Exp $ ********************************************************************/ @@ -41,8 +41,8 @@ void process_preprocess(codebook **b,char *basename){ exit(1); } - out=malloc(sizeof(FILE *)*b0->entries); - for(i=0;ientries;i++){ + out=malloc(sizeof(FILE *)*b0->c->entries); + for(i=0;ic->entries;i++){ sprintf(buffer,"%s-%dp.vqd",basename,i); out[i]=fopen(buffer,"w"); if(out[i]==NULL){ @@ -55,7 +55,7 @@ void process_preprocess(codebook **b,char *basename){ void process_postprocess(codebook **b,char *basename){ codebook *b0=*b; int i; - for(i=0;ientries;i++) + for(i=0;ic->entries;i++) fclose(out[i]); fprintf(stderr,"Done. \n"); } @@ -66,7 +66,7 @@ void process_vector(codebook **b,double *a){ int entry=codebook_entry(b0,a); int i; - for(i=0;idim;i++) + for(i=0;ic->dim;i++) fprintf(out[entry],"%f, ",a[i]); fprintf(out[entry],"\n"); if(count++%100)spinnit("working.... lines: ",count); @@ -80,3 +80,7 @@ void process_usage(void){ " files named -p.vqh.\n\n"); } + + + + diff --git a/vq/run.c b/vq/run.c index bd644e1..1d32c95 100644 --- a/vq/run.c +++ b/vq/run.c @@ -12,7 +12,7 @@ ******************************************************************** function: utility main for loading and operating on codebooks - last mod: $Id: run.c,v 1.7 2000/01/10 10:42:05 xiphmont Exp $ + last mod: $Id: run.c,v 1.8 2000/01/21 13:42:40 xiphmont Exp $ ********************************************************************/ @@ -42,7 +42,6 @@ extern void process_vector(codebook **b,double *a); extern void process_usage(void); int main(int argc,char *argv[]){ - char *name; char *basename; double *a=NULL; codebook **b=calloc(1,sizeof(codebook *)); @@ -105,7 +104,7 @@ int main(int argc,char *argv[]){ b=realloc(b,sizeof(codebook *)*(books+2)); b[books++]=codebook_load(name); b[books]=NULL; - if(!a)a=malloc(sizeof(double)*b[books-1]->dim); + if(!a)a=malloc(sizeof(double)*b[books-1]->c->dim); } /* data file */ diff --git a/vq/vqsplit.c b/vq/vqsplit.c index 55732ea..41a822e 100644 --- a/vq/vqsplit.c +++ b/vq/vqsplit.c @@ -12,7 +12,7 @@ ******************************************************************** function: build a VQ codebook and the encoding decision 'tree' - last mod: $Id: vqsplit.c,v 1.12 2000/01/10 10:42:07 xiphmont Exp $ + last mod: $Id: vqsplit.c,v 1.13 2000/01/21 13:42:41 xiphmont Exp $ ********************************************************************/ @@ -130,7 +130,7 @@ int lp_split(vqgen *v,codebook *b, long *pointindex,long points, long depth, long *pointsofar){ - encode_aux *t=b->encode_tree; + encode_aux *t=b->c->encode_tree; /* The encoder, regardless of book, will be using a straight euclidian distance-to-point metric to determine closest point. @@ -392,17 +392,20 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){ long *entryindex=malloc(sizeof(long)*v->entries); long *pointindex=malloc(sizeof(long)*v->points); long i,j; + static_codebook *c=b->c; encode_aux *t; memset(b,0,sizeof(codebook)); - t=b->encode_tree=calloc(1,sizeof(encode_aux)); + memset(c,0,sizeof(static_codebook)); + b->c=c; + t=c->encode_tree=calloc(1,sizeof(encode_aux)); for(i=0;ientries;i++)entryindex[i]=i; for(i=0;ipoints;i++)pointindex[i]=i; - b->dim=v->elements; - b->entries=v->entries; - b->lengthlist=calloc(b->entries,sizeof(long)); + c->dim=v->elements; + c->entries=v->entries; + c->lengthlist=calloc(c->entries,sizeof(long)); t->alloc=4096; t->ptr0=malloc(sizeof(long)*t->alloc); @@ -478,10 +481,10 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){ /* run all training points through the decision tree to get a final probability count */ { - long *probability=malloc(b->entries*sizeof(long)); - long *membership=malloc(b->entries*sizeof(long)); + long *probability=malloc(c->entries*sizeof(long)); + long *membership=malloc(c->entries*sizeof(long)); - for(i=0;ientries;i++)probability[i]=1; /* trivial guard */ + for(i=0;ientries;i++)probability[i]=1; /* trivial guard */ b->valuelist=v->entrylist; /* temporary for vqenc_entry; replaced later */ for(i=0;ipoints;i++){ @@ -519,7 +522,7 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){ if(membership[j]==first || membership[j]==second){ membership[j]=first; probability[j]=least; - b->lengthlist[j]++; + c->lengthlist[j]++; } } for(i=0;ientries-1;i++) @@ -542,17 +545,17 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){ /* Sort the entries by codeword length, short to long (eases assignment and packing to do it now) */ { - long *wordlen=b->lengthlist; - long *index=malloc(b->entries*sizeof(long)); - long *revindex=malloc(b->entries*sizeof(long)); + long *wordlen=c->lengthlist; + long *index=malloc(c->entries*sizeof(long)); + long *revindex=malloc(c->entries*sizeof(long)); int k; - for(i=0;ientries;i++)index[i]=i; - isortvals=b->lengthlist; - qsort(index,b->entries,sizeof(long),iascsort); + for(i=0;ientries;i++)index[i]=i; + isortvals=c->lengthlist; + qsort(index,c->entries,sizeof(long),iascsort); /* rearrange storage; ptr0/1 first as it needs a reverse index */ /* n and c stay unchanged */ - for(i=0;ientries;i++)revindex[index[i]]=i; + for(i=0;ientries;i++)revindex[index[i]]=i; for(i=0;iaux;i++){ if(t->ptr0[i]>=0)t->ptr0[i]=revindex[t->ptr0[i]]; if(t->ptr1[i]>=0)t->ptr1[i]=revindex[t->ptr1[i]]; @@ -562,46 +565,21 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){ free(revindex); /* map lengthlist and vallist with index */ - b->lengthlist=calloc(b->entries,sizeof(long)); - b->valuelist=malloc(sizeof(double)*b->entries*b->dim); - b->quantlist=malloc(sizeof(long)*b->entries*b->dim); - for(i=0;ientries;i++){ + c->lengthlist=calloc(c->entries,sizeof(long)); + b->valuelist=malloc(sizeof(double)*c->entries*c->dim); + c->quantlist=malloc(sizeof(long)*c->entries*c->dim); + for(i=0;ientries;i++){ long e=index[i]; - for(k=0;kdim;k++){ - b->valuelist[i*b->dim+k]=v->entrylist[e*b->dim+k]; - b->quantlist[i*b->dim+k]=quantlist[e*b->dim+k]; + for(k=0;kdim;k++){ + b->valuelist[i*c->dim+k]=v->entrylist[e*c->dim+k]; + c->quantlist[i*c->dim+k]=quantlist[e*c->dim+k]; } - b->lengthlist[i]=wordlen[e]; + c->lengthlist[i]=wordlen[e]; } free(wordlen); } - /* generate the codewords (short to long) */ - { - long current=0; - long length=0; - b->codelist=malloc(sizeof(long)*b->entries); - for(i=0;ientries;i++){ - if(length != b->lengthlist[i]){ - current<<=(b->lengthlist[i]-length); - length=b->lengthlist[i]; - } - b->codelist[i]=current; - current++; - } - } - - /* sanity check the codewords */ - for(i=0;ientries;i++){ - for(j=i+1;jentries;j++){ - if(b->codelist[i]==b->codelist[j]){ - fprintf(stderr,"Error; codewords for %ld and %ld both equal %lx\n", - i, j, b->codelist[i]); - exit(1); - } - } - } fprintf(stderr,"Done.\n\n"); } -- 2.7.4