summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2010-03-01 11:24:39 +0000
committerMonty <xiphmont@xiph.org>2010-03-01 11:24:39 +0000
commit3c059fb9731de843d2172d526b4da8396cb9b26f (patch)
treed9b5a442a925b5b5c0ef91be78134c40b3096e07
parent32ab26519857244f10849f565f39c33b831137ca (diff)
downloadlibvorbis-git-3c059fb9731de843d2172d526b4da8396cb9b26f.tar.gz
Move partition calssification metrics to integer as the actual
operations were integer anyway. svn path=/trunk/vorbis/; revision=16940
-rw-r--r--lib/backends.h6
-rw-r--r--lib/mapping0.c24
-rw-r--r--lib/modes/residue_44.h18
-rw-r--r--lib/modes/residue_44u.h16
-rw-r--r--lib/res0.c26
-rw-r--r--vq/bookutil.c64
-rw-r--r--vq/localcodebook.h3
7 files changed, 108 insertions, 49 deletions
diff --git a/lib/backends.h b/lib/backends.h
index d49052dd..0de40f24 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 c8c66b65..2e470aee 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;j<vi->channels;j++){
+ int *ires = iwork[j];
+ float *res = vb->pcm[j]+n/2;
+ for(i=0;i<n/2;i++)
+ ires[i] = (int)rint(res[i]);
+ }
/* classify and encode by submap */
for(i=0;i<info->submaps;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;j<vi->channels;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;k<n/2;k++)
- ires[k]=(int)rint(res[k]);
- }
+ if(info->chmuxlist[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 eb0e8e5a..0e683e92 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 90e0f23c..b2724fe9 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 c8e4e780..e550768e 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;i<partvals;i++){
int offset=i*samples_per_partition+info->begin;
for(j=0;j<ch;j++){
- float max=0.;
- float ent=0.;
+ int max=0;
+ int ent=0;
for(k=0;k<samples_per_partition;k++){
- if(fabs(in[j][offset+k])>max)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;k<possible_partitions-1;k++)
if(max<=info->classmetric1[k] &&
- (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
+ (info->classmetric2[k]<0 || ent<info->classmetric2[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;i<partvals;i++){
- float magmax=0.f;
- float angmax=0.f;
+ int magmax=0.f;
+ int angmax=0.f;
for(j=0;j<samples_per_partition;j+=ch){
- if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
+ if(abs(in[0][l])>magmax)magmax=abs(in[0][l]);
for(k=1;k<ch;k++)
- if(fabs(in[k][l])>angmax)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<ch;i++)
if(nonzero[i])
@@ -755,7 +755,7 @@ int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
}
long **res2_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<ch;i++)
if(nonzero[i])used++;
diff --git a/vq/bookutil.c b/vq/bookutil.c
index 3fa54b23..05793621 100644
--- a/vq/bookutil.c
+++ b/vq/bookutil.c
@@ -22,6 +22,70 @@
#include <errno.h>
#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<dim;k++,o-=step){
+ int v = (a[o]-minval+(delta>>1))/delta;
+ int m = (v<ze ? ((ze-v)<<1)-1 : ((v-ze)<<1));
+ index = index*qv+ (m<0?0:(m>=qv?qv-1:m));
+ }
+ }else{
+ for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
+ int v = a[o]-minval;
+ int m = (v<ze ? ((ze-v)<<1)-1 : ((v-ze)<<1));
+ index = index*qv+ (m<0?0:(m>=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;i<book->entries;i++){
+ if(c->lengthlist[i]>0){
+ float this=_dist(dim,e,a,step);
+ if(besti==-1 || this<best){
+ best=this;
+ besti=i;
+ }
+ }
+ e+=dim;
+ }
+
+ /*if(savebest!=-1 && savebest!=besti){
+ fprintf(stderr,"brute force/pigeonhole disagreement:\n"
+ "original:");
+ for(i=0;i<dim*step;i+=step)fprintf(stderr,"%g,",a[i]);
+ fprintf(stderr,"\n"
+ "pigeonhole (entry %d, err %g):",savebest,saverr);
+ for(i=0;i<dim;i++)fprintf(stderr,"%g,",
+ (book->valuelist+savebest*dim)[i]);
+ fprintf(stderr,"\n"
+ "bruteforce (entry %d, err %g):",besti,best);
+ for(i=0;i<dim;i++)fprintf(stderr,"%g,",
+ (book->valuelist+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 0024456e..7fc7d92b 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,