summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2000-02-13 10:23:51 +0000
committerMonty <xiphmont@xiph.org>2000-02-13 10:23:51 +0000
commiteaf29d90e892dde843bad47ea5f579abf6bda8d5 (patch)
tree3c6697e8e58fb8739db18ce44beebd7500cd53b0
parentecb297c571c2a493585b0f169c753ba714864fd3 (diff)
downloadlibvorbis-git-eaf29d90e892dde843bad47ea5f579abf6bda8d5.tar.gz
Fixed bug reading codebooks with very large auxiliary encoding structs
svn path=/trunk/vorbis/; revision=259
-rw-r--r--vq/bookutil.c35
-rw-r--r--vq/vqsplit.c26
2 files changed, 39 insertions, 22 deletions
diff --git a/vq/bookutil.c b/vq/bookutil.c
index d22742eb..c4de2c0f 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.8 2000/02/07 19:39:44 xiphmont Exp $
+ last mod: $Id: bookutil.c,v 1.9 2000/02/13 10:23:50 xiphmont Exp $
********************************************************************/
@@ -103,7 +103,8 @@ int get_line_value(FILE *in,double *value){
return(-1);
}else{
value_line_buff=next;
- while(*value_line_buff>32)value_line_buff++;
+ while(*value_line_buff>44)value_line_buff++;
+ if(*value_line_buff==44)value_line_buff++;
return(0);
}
}
@@ -297,12 +298,36 @@ codebook *codebook_load(char *filename){
return(b);
}
+static double _dist(int el,double *a, double *b){
+ int i;
+ double acc=0.;
+ for(i=0;i<el;i++){
+ double val=(a[i]-b[i]);
+ acc+=val*val;
+ }
+ return acc;
+}
+
int codebook_entry(codebook *b,double *val){
const static_codebook *c=b->c;
encode_aux *t=c->encode_tree;
int ptr=0,k;
+
+ /*{
+ brute force
+ double this,best=_dist(c->dim,val,b->valuelist);
+ int i;
+ for(i=1;i<c->entries;i++){
+ this=_dist(c->dim,val,b->valuelist+i*c->dim);
+ if(this<best){
+ ptr=-i;
+ best=this;
+ }
+ }
+ }*/
+
double *n=alloca(c->dim*sizeof(double));
-
+
while(1){
double C=0.;
double *p=b->valuelist+t->p[ptr];
@@ -313,10 +338,10 @@ int codebook_entry(codebook *b,double *val){
C-=(p[k]+q[k])*n[k];
}
C/=2.;
-
+
for(k=0;k<c->dim;k++)
C+=n[k]*val[k];
-
+
if(C>0.) /* in A */
ptr= -t->ptr0[ptr];
else /* in B */
diff --git a/vq/vqsplit.c b/vq/vqsplit.c
index a3409cf3..bf4e8c4b 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.14 2000/01/28 09:05:21 xiphmont Exp $
+ last mod: $Id: vqsplit.c,v 1.15 2000/02/13 10:23:51 xiphmont Exp $
********************************************************************/
@@ -371,18 +371,14 @@ int lp_split(vqgen *v,codebook *b,
static int _node_eq(encode_aux *v, long a, long b){
long Aptr0=v->ptr0[a];
long Aptr1=v->ptr1[a];
- long Ap =v->p[a];
- long Aq =v->q[a];
long Bptr0=v->ptr0[b];
long Bptr1=v->ptr1[b];
- long Bp =v->p[b];
- long Bq =v->q[b];
/* the possibility of choosing the same p and q, but switched, can;t
happen because we always look for the best p/q in the same search
order and the search is stable */
- if(Aptr0==Bptr0 && Aptr1==Bptr1 && Ap==Bp && Aq==Bq)
+ if(Aptr0==Bptr0 && Aptr1==Bptr1)
return(1);
return(0);
@@ -428,10 +424,8 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){
/* The tree is likely big and redundant. Pare and reroute branches */
{
int changedflag=1;
- long *unique_entries=alloca(t->aux*sizeof(long));
while(changedflag){
- int nodes=0;
changedflag=0;
fprintf(stderr,"\t...");
@@ -442,19 +436,16 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){
int k;
/* check list of unique decisions */
- for(j=0;j<nodes;j++)
- if(_node_eq(t,i,unique_entries[j]))break;
+ for(j=0;j<i;j++)
+ if(_node_eq(t,i,j))break;
- if(j==nodes){
- /* a new entry */
- unique_entries[nodes++]=i++;
- }else{
+ if(j<i){
/* a redundant entry; find all higher nodes referencing it and
short circuit them to the previously noted unique entry */
changedflag=1;
for(k=0;k<t->aux;k++){
- if(t->ptr0[k]==-i)t->ptr0[k]=-unique_entries[j];
- if(t->ptr1[k]==-i)t->ptr1[k]=-unique_entries[j];
+ if(t->ptr0[k]==-i)t->ptr0[k]=-j;
+ if(t->ptr1[k]==-i)t->ptr1[k]=-j;
}
/* Now, we need to fill in the hole from this redundant
@@ -471,7 +462,8 @@ void vqsp_book(vqgen *v, codebook *b, long *quantlist){
}
/* hole plugged */
- }
+ }else
+ i++;
}
fprintf(stderr," %ld remaining\n",t->aux);