summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2001-08-07 19:50:02 +0000
committerMonty <xiphmont@xiph.org>2001-08-07 19:50:02 +0000
commit47d732a8a6a2163792ae310e6f2cf745bb782fcb (patch)
tree62c7955864079a591320bfe06d9dc4f97bc378b9
parent04c48b1e6748f45318c0adb5f71d470167bc4964 (diff)
downloadlibvorbis-git-47d732a8a6a2163792ae310e6f2cf745bb782fcb.tar.gz
Bugfixes, tweaks, minor coupling config rearrangement.
Monty svn path=/branches/branch_monty_20010708/vorbis/; revision=1710
-rw-r--r--lib/envelope.c6
-rw-r--r--lib/modes/mode_A.h20
-rw-r--r--lib/psy.c149
-rw-r--r--lib/psy.h27
-rw-r--r--lib/res0.c25
5 files changed, 115 insertions, 112 deletions
diff --git a/lib/envelope.c b/lib/envelope.c
index 75fa8104..d9ab6592 100644
--- a/lib/envelope.c
+++ b/lib/envelope.c
@@ -11,7 +11,7 @@
********************************************************************
function: PCM data envelope analysis and manipulation
- last mod: $Id: envelope.c,v 1.36.2.1 2001/07/08 08:48:01 xiphmont Exp $
+ last mod: $Id: envelope.c,v 1.36.2.2 2001/08/07 19:50:00 xiphmont Exp $
Preecho calculation.
@@ -133,8 +133,8 @@ static float _ve_deltai(envelope_lookup *ve,float *pre,float *post){
basing blocks on quantization noise that outweighs the signal
itself (for low power signals) */
- float min=ve->minenergy;
- float A=min*min*n;
+ float minV=ve->minenergy;
+ float A=minV*minV*n;
float B=A;
for(i=0;i<n;i++){
diff --git a/lib/modes/mode_A.h b/lib/modes/mode_A.h
index 57b577e8..0cf601b0 100644
--- a/lib/modes/mode_A.h
+++ b/lib/modes/mode_A.h
@@ -11,7 +11,7 @@
********************************************************************
function: predefined encoding modes
- last mod: $Id: mode_A.h,v 1.14.4.5.2.4 2001/08/07 05:03:20 xiphmont Exp $
+ last mod: $Id: mode_A.h,v 1.14.4.5.2.5 2001/08/07 19:50:02 xiphmont Exp $
********************************************************************/
@@ -78,15 +78,19 @@ static vorbis_info_psy_global _psy_set_AG={
0,
};
-static vp_couple_pass _psy_passA0[]={
- {1.f,1.f, { {24, {9e10f,0.f}, {0.f,0.f}, {0.f,0.f}, {0.f,0.f}},
- {9999, {0.f,0.f}, {0.f,0.f}, {9e10f,12.f}, {0.f,0.f}} },
- }
+static struct vp_couple_pass _psy_passA0[]={
+ {
+ {{24, 1.f,1.f, 1.f,1.f, 0, 0, 0, 0},
+ {128, 1.f,1.f, 2.f,.5f, 22.f, 0.0f, 4.5f, 0.0f},
+ {9999, 1.f,1.f, 2.f,.5f, 22.f, 0.0f, 4.5f, 2.5f}}
+ },
};
static vp_couple_pass _psy_passA[]={
- {1.f,1.f, { {192, {9e10f,0.f}, {0.f,0.f}, {0.f,0.f}, {0.f,0.f}},
- {9999, {0.f,0.f}, {0.f,0.f}, {9e10f,12.f}, {0.f,0.f}} },
+ {
+ {{288, 1.f,1.f, 1.f,1.f, 0, 0, 0, 0},
+ {512, 1.f,1.f, 2.f,.5f, 22.f, 0.0f, 4.5f, 0.0f},
+ {9999, 1.f,1.f, 2.f,.5f, 22.f, 0.0f, 4.5f, 2.5f}}
}
};
@@ -203,7 +207,7 @@ static vorbis_info_psy _psy_set_A={
10,10,100,
/*63 125 250 500 1k 2k 4k 8k 16k*/
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, -3, 0, 0, 0, 0, 0},
+ {-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, -3, -3, 0, 0, 0, 0, 0},
{.3f,.3f,.3f,.3f,.3f,.3f,.3f,.3f,.5f,.5f,.5f,.5f,.7f,.75f,.8f,.8f,.8f},
95.f, /* even decade + 5 is important; saves an rint() later in a
diff --git a/lib/psy.c b/lib/psy.c
index 12741c84..1eda73ad 100644
--- a/lib/psy.c
+++ b/lib/psy.c
@@ -11,7 +11,7 @@
********************************************************************
function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.48.2.6 2001/08/07 03:47:22 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.48.2.7 2001/08/07 19:50:00 xiphmont Exp $
********************************************************************/
@@ -527,24 +527,24 @@ static void max_seeds(vorbis_look_psy *p,
pos=p->octave[0]-p->firstoc-(linesper>>1);
while(linpos+1<p->n){
- float min=seed[pos];
+ float minV=seed[pos];
long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
while(pos+1<=end){
pos++;
- if((seed[pos]>NEGINF && seed[pos]<min) || min==NEGINF)
- min=seed[pos];
+ if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
+ minV=seed[pos];
}
/* seed scale is log. Floor is linear. Map back to it */
end=pos+p->firstoc;
for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
- if(flr[linpos]<min)flr[linpos]=min;
+ if(flr[linpos]<minV)flr[linpos]=minV;
}
{
- float min=seed[p->total_octave_lines-1];
+ float minV=seed[p->total_octave_lines-1];
for(;linpos<p->n;linpos++)
- if(flr[linpos]<min)flr[linpos]=min;
+ if(flr[linpos]<minV)flr[linpos]=minV;
}
}
@@ -1005,110 +1005,84 @@ float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
return(amp);
}
-static void couple_lossless(float A, float B, float *mag, float *ang,float t){
- float fmag;
-
+static void couple_lossless(float A, float B, float *mag, float *ang){
if(fabs(A)>fabs(B)){
- fmag=fabs(*mag=A); *ang=(A>0.f?A-B:B-A);
+ *mag=A; *ang=(A>0.f?A-B:B-A);
}else{
- fmag=fabs(*mag=B); *ang=(B>0.f?A-B:B-A);
+ *mag=B; *ang=(B>0.f?A-B:B-A);
}
-
- if(*ang>fmag*1.9999f)*ang=-fmag*2.f;
-
}
-static void couple_8phase(float A, float B, float *mag, float *ang,float t){
- float fmag;
+static void couple_Nphase(float A, float B, float Aa, float Ba,
+ float *mag, float *ang){
+ if(fabs(A)>fabs(B)){
+ *mag=A;*ang=(A>0.f?Aa-Ba:Ba-Aa);
+ }else{
+ *mag=B;*ang=(B>0.f?Aa-Ba:Ba-Aa);
+ }
+}
+static void couple_8phase(float A, float B, float *mag, float *ang){
if(fabs(A)>fabs(B)){
- fmag=fabs(*mag=A); *ang=(A>0?A-B:B-A);
+ *mag=A; *ang=(A>0?A-B:B-A);
}else{
- fmag=fabs(*mag=B); *ang=(B>0?A-B:B-A);
+ *mag=B; *ang=(B>0?A-B:B-A);
}
- if(fmag>0.f)
- switch((int)(rint(*ang/fmag))){
+ if(*mag!=0.f)
+ switch((int)(rint(*ang / *mag))){
case 0:
- if(fmag>t){
- if(*ang>fmag-t)*ang=fmag-t;
- if(*ang<t-fmag)*ang=t-fmag;
- }else{
- *ang=0;
- }
+ *ang=0;
break;
case 2:case -2:
- *ang=-2*fmag;
+ *ang=-2*fabs(*mag);
break;
case 1:
- *ang=fmag;
+ *ang= *mag;
break;
case -1:
- *ang=-fmag;
+ *ang= -*mag;
break;
}
}
-static void couple_6phase(float A, float B, float *mag, float *ang,float t){
- float fmag;
-
+static void couple_6phase(float A, float B, float *mag, float *ang){
if(fabs(A)>fabs(B)){
- fmag=fabs(*mag=A); *ang=(A>0?A-B:B-A);
+ *mag=A; *ang=(A>0?A-B:B-A);
}else{
- fmag=fabs(*mag=B); *ang=(B>0?A-B:B-A);
+ *mag=B; *ang=(B>0?A-B:B-A);
}
- if(fmag>0.f)
- switch((int)(rint(*ang/fmag))){
+ if(*mag!=0.f)
+ switch((int)(rint(*ang / *mag))){
case -2:case 2:
- *ang=0;
*mag=0;
- break;
+ /*fall*/
case 0:
- if(fmag>t){
- if(*ang>fmag-t)*ang=fmag-t;
- if(*ang<t-fmag)*ang=t-fmag;
- }else{
- *ang=0;
- }
+ *ang=0;
break;
case 1:
- *ang=fmag;
+ *ang= *mag;
break;
case -1:
- *ang=-fmag;
+ *ang= -*mag;
break;
}
}
-static void couple_point(float A, float B, float *mag, float *ang,float t){
- float fmag;
-
+static void couple_point(float A, float B, float *mag, float *ang){
if(fabs(A)>fabs(B)){
- fmag=fabs(*mag=A); *ang=(A>0?A-B:B-A);
+ *mag=A; *ang=(A>0?A-B:B-A);
}else{
- fmag=fabs(*mag=B); *ang=(B>0?A-B:B-A);
+ *mag=B; *ang=(B>0?A-B:B-A);
}
- if(fmag>0.f)
- switch((int)(rint(*ang/fmag))){
- case 0:
- if(fmag>t){
- if(*ang>fmag-t)*ang=fmag-t;
- if(*ang<t-fmag)*ang=t-fmag;
- }else{
- *ang=0;
- }
- break;
-
- case 1:
- case -1:
- *ang=0;
- break;
-
- case -2:
- case 2:
+ if(*mag!=0.f)
+ switch((int)(rint(*ang / *mag))){
+ case -2:case 2:
*mag=0;
+ /* fall */
+ case 0:case 1: case -1:
*ang=0;
break;
}
@@ -1124,8 +1098,6 @@ void _vp_quantize_couple(vorbis_look_psy *p,
int i,j,k,n=p->n;
vorbis_info_psy *info=p->vi;
- float granule=info->couple_pass[passno].granule;
- float igranule=info->couple_pass[passno].igranule;
/* perform any requested channel coupling */
for(i=0;i<vi->coupling_steps;i++){
@@ -1146,28 +1118,39 @@ void _vp_quantize_couple(vorbis_look_psy *p,
nonzero[vi->coupling_ang[i]]=1;
for(j=0,k=0;j<n;k++){
- vp_couple *part=info->couple_pass[passno].couple+k;
+ vp_couple *part=info->couple_pass[passno].couple_pass+k;
for(;j<part->limit && j<p->n;j++){
/* partition by partition; k is our by-location partition
class counter */
- float ang,mag=max(fabs(pcmM[j]),fabs(pcmA[j]));
- float M=rint(pcmM[j]*igranule)*granule;
- float A=rint(pcmA[j]*igranule)*granule;
+
+ float granulem=part->granulem;
+ float igranulem=part->igranulem;
+
+ float Am=rint(pcmM[j]*igranulem)*granulem;
+ float Bm=rint(pcmA[j]*igranulem)*granulem;
+ float ang,mag,fmag=max(fabs(Am),fabs(Bm));
- if(mag<part->couple_point.amppost){
- couple_point(M,A,&mag,&ang,part->couple_point.threshhold);
+ if(fmag<part->amppost_point){
+ couple_point(Am,Bm,&mag,&ang);
}else{
- if(mag<part->couple_sixphase.amppost){
- couple_6phase(M,A,&mag,&ang,part->couple_point.threshhold);
+ if(fmag<part->amppost_6phase){
+ couple_6phase(Am,Bm,&mag,&ang);
}else{
- if(mag<part->couple_eightphase.amppost){
- couple_8phase(M,A,&mag,&ang,part->couple_point.threshhold);
+ if(fmag<part->amppost_8phase){
+ couple_8phase(Am,Bm,&mag,&ang);
}else{
- couple_lossless(M,A,&mag,&ang,part->couple_point.threshhold);
+ if(fmag<part->amppost_Nphase){
+ float Aa=rint(pcmM[j]*part->igranulea)*part->granulea;
+ float Ba=rint(pcmA[j]*part->igranulea)*part->granulea;
+ couple_Nphase(Am,Bm,Aa,Ba,&mag,&ang);
+ }else{
+ couple_lossless(Am,Bm,&mag,&ang);
+ }
}
}
}
+ if(ang>fmag*1.9999f)ang=-fmag*2.f;
qM[j]=mag-sofarM[j];
qA[j]=ang-sofarA[j];
diff --git a/lib/psy.h b/lib/psy.h
index f15ae30f..17f43f98 100644
--- a/lib/psy.h
+++ b/lib/psy.h
@@ -11,7 +11,7 @@
********************************************************************
function: random psychoacoustics (not including preecho)
- last mod: $Id: psy.h,v 1.21.2.5 2001/08/07 03:47:22 xiphmont Exp $
+ last mod: $Id: psy.h,v 1.21.2.6 2001/08/07 19:50:00 xiphmont Exp $
********************************************************************/
@@ -36,26 +36,23 @@
#define P_BANDS 17
#define P_LEVELS 11
-typedef struct couple_part{
- float amppost;
- float threshhold;
-} couple_part;
-
typedef struct vp_couple{
int limit; /* sample post */
- couple_part couple_lossless;
- couple_part couple_eightphase;
- couple_part couple_sixphase;
- couple_part couple_point;
+ float granulem;
+ float igranulem;
+ float granulea;
+ float igranulea;
+
+ float amppost_Nphase;
+ float amppost_8phase;
+ float amppost_6phase;
+ float amppost_point;
} vp_couple;
-typedef struct vp_couple_pass{
- float granule;
- float igranule;
-
- vp_couple couple[8];
+typedef struct vp_couple_pass{
+ vp_couple couple_pass[8];
} vp_couple_pass;
typedef struct vp_attenblock{
diff --git a/lib/res0.c b/lib/res0.c
index f6707594..33a4f660 100644
--- a/lib/res0.c
+++ b/lib/res0.c
@@ -11,7 +11,7 @@
********************************************************************
function: residue backend 0, 1 and 2 implementation
- last mod: $Id: res0.c,v 1.32.2.3 2001/08/02 22:14:21 xiphmont Exp $
+ last mod: $Id: res0.c,v 1.32.2.4 2001/08/07 19:50:00 xiphmont Exp $
********************************************************************/
@@ -488,6 +488,12 @@ static int _01forward(vorbis_block *vb,vorbis_look_residue *vl,
int n=info->end-info->begin;
int partvals=n/samples_per_partition;
+
+ long resbits[possible_partitions];
+ long resvals[possible_partitions];
+ memset(resbits,0,sizeof(resbits));
+ memset(resvals,0,sizeof(resvals));
+
#ifdef TRAIN_RES
FILE *of;
@@ -539,14 +545,14 @@ static int _01forward(vorbis_block *vb,vorbis_look_residue *vl,
long offset=i*samples_per_partition+info->begin;
for(j=0;j<ch;j++){
- /*if(s==0)look->resvals[partword[j][i]]++;*/
+ if(s==0)resvals[partword[j][i]]+=samples_per_partition;
if(info->secondstages[partword[j][i]]&(1<<s)){
codebook *statebook=look->partbooks[partword[j][i]][s];
if(statebook){
int ret=encode(&vb->opb,in[j]+offset,samples_per_partition,
statebook,look);
- /*look->resbits[partword[j][i]][s]+=ret;*/
look->postbits+=ret;
+ resbits[partword[j][i]]+=ret;
}
}
@@ -554,6 +560,19 @@ static int _01forward(vorbis_block *vb,vorbis_look_residue *vl,
}
}
}
+
+ {
+ long total=0;
+ long totalbits=0;
+ fprintf(stderr,"%d :: ",vb->mode);
+ for(k=0;k<possible_partitions;k++){
+ fprintf(stderr,"%d/%1.2g, ",resvals[k],(float)resbits[k]/resvals[k]);
+ total+=resvals[k];
+ totalbits+=resbits[k];
+ }
+
+ fprintf(stderr,":: %ld:%1.2g\n",total,(double)totalbits/total);
+ }
return(0);
}