X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fres0.c;h=837f5fdc4512331c834c4cf01f21fd4c3169feca;hb=20104ce7e73d9fc0467e0b16f1d0b614836a4f56;hp=e550768e1ae66be9b60fba27b078e1f3acb9887d;hpb=3c059fb9731de843d2172d526b4da8396cb9b26f;p=platform%2Fupstream%2Flibvorbis.git diff --git a/lib/res0.c b/lib/res0.c index e550768..837f5fd 100644 --- a/lib/res0.c +++ b/lib/res0.c @@ -5,7 +5,7 @@ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * - * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010 * * by the Xiph.Org Foundation http://www.xiph.org/ * * * ******************************************************************** @@ -31,6 +31,9 @@ #include "misc.h" #include "os.h" +//#define TRAIN_RES 1 +//#define TRAIN_RESAUX 1 + #if defined(TRAIN_RES) || defined (TRAIN_RESAUX) #include #endif @@ -58,6 +61,7 @@ typedef struct { float training_min[8][64]; float tmin; float tmax; + int submap; #endif } vorbis_look_residue0; @@ -88,7 +92,7 @@ void res0_free_look(vorbis_look_residue *i){ codebook *statebook=look->partbooks[j][k]; /* long and short into the same bucket by current convention */ - sprintf(buffer,"res_part%d_pass%d.vqd",j,k); + sprintf(buffer,"res_sub%d_part%d_pass%d.vqd",look->submap,j,k); of=fopen(buffer,"a"); for(l=0;lentries;l++) @@ -148,15 +152,6 @@ void res0_free_look(vorbis_look_residue *i){ } } -static int ilog(unsigned int v){ - int ret=0; - while(v){ - ret++; - v>>=1; - } - return(ret); -} - static int icount(unsigned int v){ int ret=0; while(v){ @@ -182,7 +177,7 @@ void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){ bitmask of one indicates this partition class has bits to write this pass */ for(j=0;jpartitions;j++){ - if(ilog(info->secondstages[j])>3){ + if(ov_ilog(info->secondstages[j])>3){ /* yes, this is a minor hack due to not thinking ahead */ oggpack_write(opb,info->secondstages[j],3); oggpack_write(opb,1,1); @@ -246,6 +241,7 @@ vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){ int entries = ci->book_param[info->groupbook]->entries; int dim = ci->book_param[info->groupbook]->dim; int partvals = 1; + if (dim<1) goto errout; while(dim>0){ partvals *= info->partitions; if(partvals > entries) goto errout; @@ -279,7 +275,7 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd, look->partbooks=_ogg_calloc(look->parts,sizeof(*look->partbooks)); for(j=0;jparts;j++){ - int stages=ilog(info->secondstages[j]); + int stages=ov_ilog(info->secondstages[j]); if(stages){ if(stages>maxstage)maxstage=stages; look->partbooks[j]=_ogg_calloc(stages,sizeof(*look->partbooks[j])); @@ -358,7 +354,7 @@ static int local_book_besterror(codebook *book,int *a){ if(c->lengthlist[i]>0){ int this=0; for(j=0;jdim; int step=n/dim; @@ -492,17 +493,17 @@ static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,int **in, char buffer[80]; #endif - partword[0]=_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0])); - memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0])); + partword[0]=_vorbis_block_alloc(vb,partvals*sizeof(*partword[0])); + memset(partword[0],0,partvals*sizeof(*partword[0])); for(i=0,l=info->begin/ch;imagmax)magmax=abs(in[0][l]); for(k=1;kangmax)angmax=abs(in[k][l]); - l++; + l++; } for(j=0;jinfo; +#ifdef TRAIN_RES + look->submap=submap; +#endif + /* move all this setup out later */ int samples_per_partition=info->grouping; int possible_partitions=info->partitions; @@ -599,13 +611,12 @@ static int _01forward(oggpack_buffer *opb, codebook *statebook=look->partbooks[partword[j][i]][s]; if(statebook){ int ret; - long *accumulator=NULL; - #ifdef TRAIN_RES + long *accumulator=NULL; accumulator=look->training_data[s][partword[j][i]]; { int l; - float *samples=in[j]+offset; + int *samples=in[j]+offset; for(l=0;ltraining_min[s][partword[j][i]]) look->training_min[s][partword[j][i]]=samples[l]; @@ -613,10 +624,12 @@ static int _01forward(oggpack_buffer *opb, look->training_max[s][partword[j][i]]=samples[l]; } } -#endif - ret=encode(opb,in[j]+offset,samples_per_partition, statebook,accumulator); +#else + ret=encode(opb,in[j]+offset,samples_per_partition, + statebook); +#endif look->postbits+=ret; resbits[partword[j][i]]+=ret; @@ -627,19 +640,6 @@ static int _01forward(oggpack_buffer *opb, } } - /*{ - long total=0; - long totalbits=0; - fprintf(stderr,"%d :: ",vb->mode); - for(k=0;kpcmend/2; + int **in,int *nonzero,int ch, long **partword, int submap){ + int i,used=0; + (void)vb; for(i=0;ipcmend/2,used=0; /* don't duplicate the code; use a working vector hack for now and @@ -785,7 +791,12 @@ int res2_forward(oggpack_buffer *opb, } if(used){ - return _01forward(opb,vb,vl,&work,1,partword,_encodepart); +#ifdef TRAIN_RES + return _01forward(opb,vl,&work,1,partword,_encodepart,submap); +#else + (void)submap; + return _01forward(opb,vl,&work,1,partword,_encodepart); +#endif }else{ return(0); } @@ -819,7 +830,7 @@ int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl, if(s==0){ /* fetch the partition word */ int temp=vorbis_book_decode(look->phrasebook,&vb->opb); - if(temp==-1 || temp>info->partvals)goto eopbreak; + if(temp==-1 || temp>=info->partvals)goto eopbreak; partword[l]=look->decodemap[temp]; if(partword[l]==NULL)goto errout; }