X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fres0.c;h=206494f47a9e9cea66050cc5cce19bec9cc20e43;hb=f0761cde7af9ee803b76ccac920675f333afc321;hp=5b4c013d3d61f4638f18d231104cbbe62940c691;hpb=78954af268efa76094ca24e0d63aed7e4435df42;p=platform%2Fupstream%2Flibvorbis.git diff --git a/lib/res0.c b/lib/res0.c index 5b4c013..206494f 100644 --- a/lib/res0.c +++ b/lib/res0.c @@ -5,13 +5,12 @@ * 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/ * * * ******************************************************************** function: residue backend 0, 1 and 2 implementation - last mod: $Id$ ********************************************************************/ @@ -58,6 +57,7 @@ typedef struct { float training_min[8][64]; float tmin; float tmax; + int submap; #endif } vorbis_look_residue0; @@ -88,7 +88,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 +148,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 +173,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 +237,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 +271,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])); @@ -321,66 +313,77 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd, } /* break an abstraction and copy some code for performance purposes */ -static int local_book_besterror(codebook *book,float *a){ - int dim=book->dim,i,k,o; - int best=0; - encode_aux_threshmatch *tt=book->c->thresh_tree; - - /* find the quant val of each scalar */ - for(k=0,o=dim;kthreshvals>>1; - - if(valquantthresh[i]){ - if(valquantthresh[i-1]){ - for(--i;i>0;--i) - if(val>=tt->quantthresh[i-1]) - break; - } - }else{ - - for(++i;ithreshvals-1;++i) - if(valquantthresh[i])break; - +static int local_book_besterror(codebook *book,int *a){ + int dim=book->dim; + int i,j,o; + int minval=book->minval; + int del=book->delta; + int qv=book->quantvals; + int ze=(qv>>1); + int index=0; + /* assumes integer/centered encoder codebook maptype 1 no more than dim 8 */ + int p[8]={0,0,0,0,0,0,0,0}; + + if(del!=1){ + for(i=0,o=dim;i>1))/del; + int m = (v=qv?qv-1:m)); + p[o]=v*del+minval; + } + }else{ + for(i=0,o=dim;i=qv?qv-1:m)); + p[o]=v*del+minval; } - - best=(best*tt->quantvals)+tt->quantmap[i]; } - /* regular lattices are easy :-) */ - if(book->c->lengthlist[best]<=0){ + if(book->c->lengthlist[index]<=0){ const static_codebook *c=book->c; - int i,j; - float bestf=0.f; - float *e=book->valuelist; - best=-1; + int best=-1; + /* assumes integer/centered encoder codebook maptype 1 no more than dim 8 */ + int e[8]={0,0,0,0,0,0,0,0}; + int maxval = book->minval + book->delta*(book->quantvals-1); for(i=0;ientries;i++){ if(c->lengthlist[i]>0){ - float this=0.f; + int this=0; for(j=0;j=maxval) + e[j++]=0; + if(e[j]>=0) + e[j]+=book->delta; + e[j]= -e[j]; } } - if(best>-1){ - float *ptr=book->valuelist+best*dim; + if(index>-1){ for(i=0;idim; int step=n/dim; @@ -401,7 +404,7 @@ static int _encodepart(oggpack_buffer *opb,float *vec, int n, } static long **_01class(vorbis_block *vb,vorbis_look_residue *vl, - float **in,int ch){ + int **in,int ch){ long i,j,k; vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; vorbis_info_residue0 *info=look->info; @@ -427,17 +430,17 @@ static long **_01class(vorbis_block *vb,vorbis_look_residue *vl, for(i=0;ibegin; for(j=0;jmax)max=fabs(in[j][offset+k]); - ent+=fabs(rint(in[j][offset+k])); + if(abs(in[j][offset+k])>max)max=abs(in[j][offset+k]); + ent+=abs(in[j][offset+k]); } ent*=scale; for(k=0;kclassmetric1[k] && - (info->classmetric2[k]<0 || (int)entclassmetric2[k])) + (info->classmetric2[k]<0 || entclassmetric2[k])) break; partword[j][i]=k; @@ -467,7 +470,7 @@ static long **_01class(vorbis_block *vb,vorbis_look_residue *vl, /* designed for stereo or other modes where the partition size is an integer multiple of the number of channels encoded in the current submap */ -static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in, +static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,int **in, int ch){ long i,j,k,l; vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; @@ -486,17 +489,17 @@ static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **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=fabs(in[0][l]); + if(abs(in[0][l])>magmax)magmax=abs(in[0][l]); for(k=1;kangmax)angmax=fabs(in[k][l]); - l++; + if(abs(in[k][l])>angmax)angmax=abs(in[k][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; @@ -593,13 +607,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]; @@ -607,10 +620,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; @@ -621,19 +636,6 @@ static int _01forward(oggpack_buffer *opb, } } - /*{ - long total=0; - long totalbits=0; - fprintf(stderr,"%d :: ",vb->mode); - for(k=0;kpcmend/2; - for(i=0;ipcmend/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 reshape ourselves into a single channel res1 */ /* ugly; reallocs for each coupling pass :-( */ - float *work=_vorbis_block_alloc(vb,ch*n*sizeof(*work)); + int *work=_vorbis_block_alloc(vb,ch*n*sizeof(*work)); for(i=0;iphrasebook,&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; }