From 5a598b485e80a1cb134252c3e05879c72624c49c Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 22 Jun 2007 00:58:15 +0000 Subject: [PATCH] Don't forget to test all changes in a code cleanup-- residue type 2 encoding was broken by last night's round of fixes. Tested fixed. svn path=/trunk/vorbis/; revision=13167 --- lib/res0.c | 317 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 154 insertions(+), 163 deletions(-) diff --git a/lib/res0.c b/lib/res0.c index 7da7c30..5720bac 100644 --- a/lib/res0.c +++ b/lib/res0.c @@ -375,63 +375,59 @@ static long **_01class(vorbis_block *vb,vorbis_look_residue *vl, /* move all this setup out later */ int samples_per_partition=info->grouping; int possible_partitions=info->partitions; - int end=(info->endpcmend/2?info->end:vb->pcmend/2); - int n=end-info->begin; + int n=info->end-info->begin; - if(n>0){ - int partvals=n/samples_per_partition; - long **partword=_vorbis_block_alloc(vb,ch*sizeof(*partword)); - float scale=100./samples_per_partition; - - /* we find the partition type for each partition of each - channel. We'll go back and do the interleaved encoding in a - bit. For now, clarity */ - - for(i=0;ibegin; - for(j=0;jmax)max=fabs(in[j][offset+k]); - ent+=fabs(rint(in[j][offset+k])); - } - ent*=scale; - - for(k=0;kclassmetric1[k] && - (info->classmetric2[k]<0 || (int)entclassmetric2[k])) - break; - - partword[j][i]=k; + int partvals=n/samples_per_partition; + long **partword=_vorbis_block_alloc(vb,ch*sizeof(*partword)); + float scale=100./samples_per_partition; + + /* we find the partition type for each partition of each + channel. We'll go back and do the interleaved encoding in a + bit. For now, clarity */ + + for(i=0;ibegin; + for(j=0;jmax)max=fabs(in[j][offset+k]); + ent+=fabs(rint(in[j][offset+k])); } + ent*=scale; + + for(k=0;kclassmetric1[k] && + (info->classmetric2[k]<0 || (int)entclassmetric2[k])) + break; + + partword[j][i]=k; } - + } + #ifdef TRAIN_RESAUX - { - FILE *of; - char buffer[80]; - - for(i=0;itrain_seq); - of=fopen(buffer,"a"); - for(j=0;jtrain_seq); + of=fopen(buffer,"a"); + for(j=0;jframes++; - - return(partword); - }else - return(0); + look->frames++; + + return(partword); } /* designed for stereo or other modes where the partition size is an @@ -446,54 +442,50 @@ static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in, /* move all this setup out later */ int samples_per_partition=info->grouping; int possible_partitions=info->partitions; - int end=(info->endpcmend/2?info->end:vb->pcmend/2); - int n=end-info->begin; + int n=info->end-info->begin; - if(n>0){ - int partvals=n/samples_per_partition; - long **partword=_vorbis_block_alloc(vb,sizeof(*partword)); - + int partvals=n/samples_per_partition; + long **partword=_vorbis_block_alloc(vb,sizeof(*partword)); + #if defined(TRAIN_RES) || defined (TRAIN_RESAUX) - FILE *of; - char buffer[80]; + FILE *of; + 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])); + + for(i=0,l=info->begin/ch;imagmax)magmax=fabs(in[0][l]); + for(k=1;kangmax)angmax=fabs(in[k][l]); + l++; + } - 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])); + for(j=0;jclassmetric1[j] && + angmax<=info->classmetric2[j]) + break; - for(i=0,l=info->begin/ch;imagmax)magmax=fabs(in[0][l]); - for(k=1;kangmax)angmax=fabs(in[k][l]); - l++; - } - - for(j=0;jclassmetric1[j] && - angmax<=info->classmetric2[j]) - break; - - partword[0][i]=j; - - } + partword[0][i]=j; + } + #ifdef TRAIN_RESAUX - sprintf(buffer,"resaux_%d.vqd",look->train_seq); - of=fopen(buffer,"a"); - for(i=0;itrain_seq); + of=fopen(buffer,"a"); + for(i=0;iframes++; - - return(partword); - }else - return(0); + + look->frames++; + + return(partword); } static int _01forward(oggpack_buffer *opb, @@ -512,93 +504,91 @@ static int _01forward(oggpack_buffer *opb, int samples_per_partition=info->grouping; int possible_partitions=info->partitions; int partitions_per_word=look->phrasebook->dim; - int end=(info->endpcmend/2?info->end:vb->pcmend/2); - int n=end-info->begin; + int n=info->end-info->begin; - if(n>0){ - int partvals=n/samples_per_partition; - long resbits[128]; - long resvals[128]; - + int partvals=n/samples_per_partition; + long resbits[128]; + long resvals[128]; + #ifdef TRAIN_RES - for(i=0;ibegin;jlook->tmax)look->tmax=in[i][j]; - if(in[i][j]tmin)look->tmin=in[i][j]; - } + for(i=0;ibegin;jlook->tmax)look->tmax=in[i][j]; + if(in[i][j]tmin)look->tmin=in[i][j]; + } #endif + + memset(resbits,0,sizeof(resbits)); + memset(resvals,0,sizeof(resvals)); + + /* we code the partition words for each channel, then the residual + words for a partition per channel until we've written all the + residual words for that partition word. Then write the next + partition channel words... */ + + for(s=0;sstages;s++){ - memset(resbits,0,sizeof(resbits)); - memset(resvals,0,sizeof(resvals)); - - /* we code the partition words for each channel, then the residual - words for a partition per channel until we've written all the - residual words for that partition word. Then write the next - partition channel words... */ - - for(s=0;sstages;s++){ + for(i=0;iphrasebook->entries) - look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb); + /* first we encode a partition codeword for each channel */ + if(s==0){ + for(j=0;jphrasebook->entries) + look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb); #if 0 /*def TRAIN_RES*/ - else - fprintf(stderr,"!"); + else + fprintf(stderr,"!"); #endif - - } + } - - /* now we encode interleaved residual values for the partitions */ - for(k=0;kbegin; + } + + /* now we encode interleaved residual values for the partitions */ + for(k=0;kbegin; - for(j=0;jsecondstages[partword[j][i]]&(1<partbooks[partword[j][i]][s]; - if(statebook){ - int ret; - long *accumulator=NULL; - + for(j=0;jsecondstages[partword[j][i]]&(1<partbooks[partword[j][i]][s]; + if(statebook){ + int ret; + long *accumulator=NULL; + #ifdef TRAIN_RES - accumulator=look->training_data[s][partword[j][i]]; - { - int l; - float *samples=in[j]+offset; - for(l=0;ltraining_min[s][partword[j][i]]) - look->training_min[s][partword[j][i]]=samples[l]; - if(samples[l]>look->training_max[s][partword[j][i]]) - look->training_max[s][partword[j][i]]=samples[l]; - } + accumulator=look->training_data[s][partword[j][i]]; + { + int l; + float *samples=in[j]+offset; + for(l=0;ltraining_min[s][partword[j][i]]) + look->training_min[s][partword[j][i]]=samples[l]; + if(samples[l]>look->training_max[s][partword[j][i]]) + look->training_max[s][partword[j][i]]=samples[l]; } -#endif - - ret=encode(opb,in[j]+offset,samples_per_partition, - statebook,accumulator); - - look->postbits+=ret; - resbits[partword[j][i]]+=ret; } +#endif + + ret=encode(opb,in[j]+offset,samples_per_partition, + statebook,accumulator); + + look->postbits+=ret; + resbits[partword[j][i]]+=ret; } } } } } - + } + /*{ long total=0; long totalbits=0; @@ -611,7 +601,7 @@ static int _01forward(oggpack_buffer *opb, fprintf(stderr,":: %ld:%1.2g\n",total,(double)totalbits/total); }*/ - } + return(0); } @@ -628,7 +618,8 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, /* move all this setup out later */ int samples_per_partition=info->grouping; int partitions_per_word=look->phrasebook->dim; - int end=(info->endpcmend/2?info->end:vb->pcmend/2); + int max=vb->pcmend>>1; + int end=(info->endend:max); int n=end-info->begin; if(n>0){ -- 2.7.4