X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=vq%2Fvqgen.c;h=45f7790d788827fbe4e64ee45cdb4863f01124bc;hb=4ba8efed8797016a85e57bc3cc7975bb31d65db5;hp=2e46dd1f4bbd8872549225fa9a09e1345a431763;hpb=effaee032d0c72f5f67edacbb8fb3c7399dbe1e0;p=platform%2Fupstream%2Flibvorbis.git diff --git a/vq/vqgen.c b/vq/vqgen.c index 2e46dd1..45f7790 100644 --- a/vq/vqgen.c +++ b/vq/vqgen.c @@ -6,12 +6,11 @@ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 * - * by the Xiph.Org Foundation http://www.xiph.org/ * + * by the Xiph.Org Foundation https://xiph.org/ * * * ******************************************************************** - function: train a VQ codebook - last mod: $Id$ + function: train a VQ codebook ********************************************************************/ @@ -32,13 +31,13 @@ #include "vqgen.h" #include "bookutil.h" -/* Codebook generation happens in two steps: +/* Codebook generation happens in two steps: 1) Train the codebook with data collected from the encoder: We use one of a few error metrics (which represent the distance between a given data point and a candidate point in the training set) to divide the training set up into cells representing roughly equal - probability of occurring. + probability of occurring. 2) Generate the codebook and auxiliary data from the trained data set */ @@ -110,7 +109,7 @@ void vqgen_cellmetric(vqgen *v){ if(this>0){ if(v->assigned[k] && (localmin==-1 || thismax[j]+localmin/2; /* this gives us rough diameter */ if(min==-1 || localminmax)max=localmin; @@ -143,7 +142,7 @@ void vqgen_cellmetric(vqgen *v){ for(i=0;ientries;j++){ float last=0.f; for(k=0;kelements;k++){ @@ -201,7 +200,7 @@ void vqgen_quantize(vqgen *v,quant_meta *q){ for(k=0;kelements;k++){ float val=_now(v,j)[k]; float now=rint((val-last-mindel)/delta); - + _now(v,j)[k]=now; if(now<0){ /* be paranoid; this should be impossible */ @@ -282,7 +281,7 @@ void vqgen_addpoint(vqgen *v, float *p,float *a){ memcpy(_point(v,v->points),p,sizeof(float)*v->elements); if(v->aux)memcpy(_point(v,v->points)+v->elements,a,sizeof(float)*v->aux); - + /* quantize to the density mesh if it's selected */ if(v->mindist>0.f){ /* quantize to the mesh */ @@ -355,7 +354,7 @@ float vqgen_iterate(vqgen *v,int biasp){ sprintf(buff,"bias%d.m",v->it); bias=fopen(buff,"w"); #endif - + if(v->entries<2){ fprintf(stderr,"generation requires at least two entries\n"); @@ -384,9 +383,9 @@ float vqgen_iterate(vqgen *v,int biasp){ float secondmetric=v->metric_func(v,_now(v,1),ppt)+v->bias[1]; long firstentry=0; long secondentry=1; - + if(!(i&0xff))spinnit("biasing... ",v->points+v->points+v->entries-i); - + if(firstmetric>secondmetric){ float temp=firstmetric; firstmetric=secondmetric; @@ -394,7 +393,7 @@ float vqgen_iterate(vqgen *v,int biasp){ firstentry=1; secondentry=0; } - + for(j=2;jentries;j++){ float thismetric=v->metric_func(v,_now(v,j),ppt)+v->bias[j]; if(thismetricentries;j++){ - + float thismetric,localmetric; float *nearbiasptr=nearbias+desired2*j; long k=nearcount[j]; - + localmetric=v->metric_func(v,_now(v,j),ppt); /* 'thismetric' is to be the bias value necessary in the current arrangement for entry j to capture point i */ @@ -427,11 +426,11 @@ float vqgen_iterate(vqgen *v,int biasp){ /* use the primary entry as the threshhold */ thismetric=firstmetric-localmetric; } - + /* support the idea of 'minimum distance'... if we want the cells in a codebook to be roughly some minimum size (as with the low resolution residue books) */ - + /* a cute two-stage delayed sorting hack */ if(kpoints+v->points+v->entries-i); qsort(nearbiasptr,desired,sizeof(float),directdsort); } - + }else if(thismetric>nearbiasptr[desired-1]){ nearbiasptr[k]=thismetric; k++; @@ -453,14 +452,14 @@ float vqgen_iterate(vqgen *v,int biasp){ nearcount[j]=k; } } - + /* inflate/deflate */ - + for(i=0;ientries;i++){ float *nearbiasptr=nearbias+desired2*i; - + spinnit("biasing... ",v->points+v->entries-i); - + /* due to the delayed sorting, we likely need to finish it off....*/ if(nearcount[i]>desired) qsort(nearbiasptr,nearcount[i],sizeof(float),directdsort); @@ -468,7 +467,7 @@ float vqgen_iterate(vqgen *v,int biasp){ v->bias[i]=nearbiasptr[desired-1]; } - }else{ + }else{ memset(v->bias,0,v->entries*sizeof(float)); } @@ -489,7 +488,7 @@ float vqgen_iterate(vqgen *v,int biasp){ } j=firstentry; - + #ifdef NOISY fprintf(cells,"%g %g\n%g %g\n\n", _now(v,j)[0],_now(v,j)[1], @@ -553,7 +552,7 @@ float vqgen_iterate(vqgen *v,int biasp){ fprintf(stderr,": dist %g(%g) metric error=%g \n", asserror,fdesired,meterror/v->points); v->it++; - + free(new); free(nearcount); free(nearbias);