From 3c059fb9731de843d2172d526b4da8396cb9b26f Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 1 Mar 2010 11:24:39 +0000 Subject: [PATCH] Move partition calssification metrics to integer as the actual operations were integer anyway. svn path=/trunk/vorbis/; revision=16940 --- lib/backends.h | 6 ++--- lib/mapping0.c | 24 +++++++++---------- lib/modes/residue_44.h | 18 +++++++------- lib/modes/residue_44u.h | 16 ++++++------- lib/res0.c | 26 ++++++++++---------- vq/bookutil.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ vq/localcodebook.h | 3 --- 7 files changed, 108 insertions(+), 49 deletions(-) diff --git a/lib/backends.h b/lib/backends.h index d49052d..0de40f2 100644 --- a/lib/backends.h +++ b/lib/backends.h @@ -93,7 +93,7 @@ typedef struct{ void (*free_info) (vorbis_info_residue *); void (*free_look) (vorbis_look_residue *); long **(*class) (struct vorbis_block *,vorbis_look_residue *, - float **,int *,int); + int **,int *,int); int (*forward) (oggpack_buffer *,struct vorbis_block *, vorbis_look_residue *, int **,int *,int,long **); @@ -114,8 +114,8 @@ typedef struct vorbis_info_residue0{ int secondstages[64]; /* expanded out to pointers in lookup */ int booklist[512]; /* list of second stage books */ - const float classmetric1[64]; - const float classmetric2[64]; + const int classmetric1[64]; + const int classmetric2[64]; } vorbis_info_residue0; /* Mapping backend generic *****************************************/ diff --git a/lib/mapping0.c b/lib/mapping0.c index c8c66b6..2e470ae 100644 --- a/lib/mapping0.c +++ b/lib/mapping0.c @@ -598,8 +598,7 @@ static int mapping0_forward(vorbis_block *vb){ /* iterate over the many masking curve fits we've created */ { - float **res_bundle=alloca(sizeof(*res_bundle)*vi->channels); - float **couple_bundle=alloca(sizeof(*couple_bundle)*vi->channels); + int **couple_bundle=alloca(sizeof(*couple_bundle)*vi->channels); int *zerobundle=alloca(sizeof(*zerobundle)*vi->channels); int **sortindex=alloca(sizeof(*sortindex)*vi->channels); float **mag_memo=NULL; @@ -709,6 +708,12 @@ static int mapping0_forward(vorbis_block *vb){ nonzero, ci->psy_g_param.sliding_lowpass[vb->W][k]); } + for(j=0;jchannels;j++){ + int *ires = iwork[j]; + float *res = vb->pcm[j]+n/2; + for(i=0;isubmaps;i++){ @@ -720,8 +725,7 @@ static int mapping0_forward(vorbis_block *vb){ if(info->chmuxlist[j]==i){ zerobundle[ch_in_bundle]=0; if(nonzero[j])zerobundle[ch_in_bundle]=1; - res_bundle[ch_in_bundle]=vb->pcm[j]; - couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2; + couple_bundle[ch_in_bundle++]=iwork[j]; } } @@ -730,18 +734,12 @@ static int mapping0_forward(vorbis_block *vb){ ch_in_bundle=0; for(j=0;jchannels;j++) - if(info->chmuxlist[j]==i){ - /* move from float to int vector; temporary until new coupling lands */ - float *res=vb->pcm[j]+n/2; - int *ires=iwork[ch_in_bundle++]; - int k; - for(k=0;kchmuxlist[j]==i) + couple_bundle[ch_in_bundle++]=iwork[j]; _residue_P[ci->residue_type[resnum]]-> forward(opb,vb,b->residue[resnum], - iwork,zerobundle,ch_in_bundle,classifications); + couple_bundle,zerobundle,ch_in_bundle,classifications); } /* ok, done encoding. Next protopacket. */ diff --git a/lib/modes/residue_44.h b/lib/modes/residue_44.h index eb0e8e5..0e683e9 100644 --- a/lib/modes/residue_44.h +++ b/lib/modes/residue_44.h @@ -23,29 +23,29 @@ static const vorbis_info_residue0 _residue_44_low={ 0,-1, -1, 9,-1,-1, - /* 0 1 2 3 4 5 6 7 */ + /* 0 1 2 3 4 5 6 7 */ {0}, {-1}, - { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5}, - { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5}, + { 0, 1, 2, 2, 4, 8, 16, 32}, + { 0, 0, 0,999, 4, 8, 16, 32}, }; static const vorbis_info_residue0 _residue_44_mid={ 0,-1, -1, 10,-1,-1, - /* 0 1 2 3 4 5 6 7 8 */ + /* 0 1 2 3 4 5 6 7 8 */ {0}, {-1}, - { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5}, - { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5}, + { 0, 1, 1, 2, 2, 4, 8, 16, 32}, + { 0, 0,999, 0,999, 4, 8, 16, 32}, }; static const vorbis_info_residue0 _residue_44_high={ 0,-1, -1, 10,-1,-1, - /* 0 1 2 3 4 5 6 7 8 */ + /* 0 1 2 3 4 5 6 7 8 */ {0}, {-1}, - { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5}, - { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5}, + { 0, 1, 2, 4, 8, 16, 32, 71,157}, + { 0, 1, 2, 3, 4, 8, 16, 71,157}, }; static const static_bookblock _resbook_44s_n1={ diff --git a/lib/modes/residue_44u.h b/lib/modes/residue_44u.h index 90e0f23..b2724fe 100644 --- a/lib/modes/residue_44u.h +++ b/lib/modes/residue_44u.h @@ -26,26 +26,26 @@ static const vorbis_info_residue0 _residue_44_low_un={ 0,-1, -1, 8,-1,-1, {0}, {-1}, - { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5}, - { -1, 25, -1, 45, -1, -1, -1} + { 0, 1, 1, 2, 2, 4, 28}, + { -1, 25, -1, 45, -1, -1, -1} }; static const vorbis_info_residue0 _residue_44_mid_un={ 0,-1, -1, 10,-1,-1, - /* 0 1 2 3 4 5 6 7 8 9 */ + /* 0 1 2 3 4 5 6 7 8 9 */ {0}, {-1}, - { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5}, - { -1, 30, -1, 50, -1, 80, -1, -1, -1} + { 0, 1, 1, 2, 2, 4, 4, 16, 60}, + { -1, 30, -1, 50, -1, 80, -1, -1, -1} }; static const vorbis_info_residue0 _residue_44_hi_un={ 0,-1, -1, 10,-1,-1, - /* 0 1 2 3 4 5 6 7 8 9 */ + /* 0 1 2 3 4 5 6 7 8 9 */ {0}, {-1}, - { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5}, - { -1, -1, -1, -1, -1, -1, -1, -1, -1} + { 0, 1, 2, 4, 8, 16, 32, 71,157}, + { -1, -1, -1, -1, -1, -1, -1, -1, -1} }; /* mapping conventions: diff --git a/lib/res0.c b/lib/res0.c index c8e4e78..e550768 100644 --- a/lib/res0.c +++ b/lib/res0.c @@ -407,7 +407,7 @@ static int _encodepart(oggpack_buffer *opb,int *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; @@ -433,17 +433,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; @@ -473,7 +473,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; @@ -496,12 +496,12 @@ static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in, 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]); + if(abs(in[0][l])>magmax)magmax=abs(in[0][l]); for(k=1;kangmax)angmax=fabs(in[k][l]); + if(abs(in[k][l])>angmax)angmax=abs(in[k][l]); l++; } @@ -731,7 +731,7 @@ int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl, } long **res1_class(vorbis_block *vb,vorbis_look_residue *vl, - float **in,int *nonzero,int ch){ + int **in,int *nonzero,int ch){ int i,used=0; for(i=0;i #include "bookutil.h" + +/* as of current encoder, only centered, integer val, maptype 1 is in + use */ +int _best(codebook *book, int *a, int step){ + int dim=book->dim; + int k,o; + int del=book->delta; + int qv=book->quantvals; + int ze=(qv>>1); + + if(delta!=1){ + for(k=0,o=step*(dim-1);k>1))/delta; + int m = (v=qv?qv-1:m)); + } + }else{ + for(k=0,o=step*(dim-1);k=qv?qv-1:m)); + } + } + + /* did the direct lookup find a used entry? */ + if(book->c->lengthlist[index]>0) + return(index); + + /* brute force it */ + { + const static_codebook *c=book->c; + int i,besti=-1; + float best=0.f; + float *e=book->valuelist; + for(i=0;ientries;i++){ + if(c->lengthlist[i]>0){ + float this=_dist(dim,e,a,step); + if(besti==-1 || thisvaluelist+savebest*dim)[i]); + fprintf(stderr,"\n" + "bruteforce (entry %d, err %g):",besti,best); + for(i=0;ivaluelist+besti*dim)[i]); + fprintf(stderr,"\n"); + }*/ + return(besti); + } +} + + /* A few little utils for reading files */ /* read a line. Use global, persistent buffering */ static char *linebuffer=NULL; diff --git a/vq/localcodebook.h b/vq/localcodebook.h index 0024456..7fc7d92 100644 --- a/vq/localcodebook.h +++ b/vq/localcodebook.h @@ -140,9 +140,6 @@ extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b); extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c); extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b); -extern int vorbis_book_errorv(codebook *book, float *a); -extern int vorbis_book_encodev(codebook *book, int best,float *a, - oggpack_buffer *b); extern long vorbis_book_decode(codebook *book, oggpack_buffer *b); extern long vorbis_book_decodevs_add(codebook *book, float *a, -- 2.7.4