[xiph-cvs] cvs commit: speex/libspeex nb_celp.c sb_celp.c vbr.c vbr.h

Jean-Marc Valin jm at xiph.org
Tue Nov 26 18:54:35 PST 2002



jm          02/11/26 21:54:35

  Modified:    libspeex nb_celp.c sb_celp.c vbr.c vbr.h
  Log:
  ...

Revision  Changes    Path
1.84      +1 -1      speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- nb_celp.c	15 Nov 2002 06:26:50 -0000	1.83
+++ nb_celp.c	27 Nov 2002 02:54:34 -0000	1.84
@@ -384,7 +384,7 @@
                break;
             mode--;
          }
-         /*fprintf (stderr, "%f %d\n", st->relative_quality, mode);*/
+         fprintf (stderr, "%f %d\n", st->relative_quality, mode);
          speex_encoder_ctl(state, SPEEX_SET_MODE, &mode);
       } else {
          st->relative_quality = -1;

<p><p>1.95      +21 -2     speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- sb_celp.c	15 Nov 2002 06:26:50 -0000	1.94
+++ sb_celp.c	27 Nov 2002 02:54:34 -0000	1.95
@@ -363,7 +363,7 @@
          ratio=0;
       /*if (ratio>-2)*/
       low_qual+=1.0*(ratio+2);
-      {
+      /*{
          int high_mode=2;
          if (low_qual>10)
             high_mode=4;
@@ -371,8 +371,26 @@
             high_mode=3;
          else if (low_qual>5)
             high_mode=2;
-         /*high_mode=1;*/
          speex_encoder_ctl(st, SPEEX_SET_HIGH_MODE, &high_mode);
+      }*/
+      {
+         int mode;
+         mode = 4;
+         while (mode)
+         {
+            int v1;
+            float thresh;
+            v1=(int)floor(st->vbr_quality);
+            if (v1==10)
+               thresh = vbr_nb_thresh[mode][v1];
+            else
+               thresh = (st->vbr_quality-v1)*vbr_hb_thresh[mode][v1+1] + (1+v1-st->vbr_quality)*vbr_hb_thresh[mode][v1];
+            if (low_qual > thresh)
+               break;
+            mode--;
+         }
+         fprintf (stderr, "%f %d\n", low_qual, mode);
+         speex_encoder_ctl(state, SPEEX_SET_HIGH_MODE, &mode);
       }
       /*fprintf (stderr, "%f %f\n", ratio, low_qual);*/
    }
@@ -970,6 +988,7 @@
       {
          int q;
          float qual = (*(float*)ptr)+.5;
+         st->vbr_quality = (*(float*)ptr);
          if (qual>10)
             qual=10;
          q=(int)floor(.5+*(float*)ptr);

<p><p>1.12      +35 -26    speex/libspeex/vbr.c

Index: vbr.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/vbr.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- vbr.c	15 Nov 2002 06:26:50 -0000	1.11
+++ vbr.c	27 Nov 2002 02:54:34 -0000	1.12
@@ -47,9 +47,9 @@
 
 float vbr_nb_thresh[8][11]={
    {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}, /* silence */
-   { 3.9,  2.5,  2.0,  1.5,  0.5,  0.0,  0.0,  0.0,  0.0,  0.0, -1.0}, /*  2 kbps */
-   { 8.0,  6.0,  3.9,  4.5,  4.0,  3.5,  3.0,  2.5,  2.0,  1.0,  0.0}, /*  6 kbps */
-   {11.0,  8.5,  7.5,  7.0,  6.5,  6.0,  5.5,  5.0,  4.0,  3.0,  1.0}, /*  8 kbps */
+   { 3.9,  2.5,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0, -1.0}, /*  2 kbps */
+   { 8.0,  5.6,  4.7,  4.2,  3.9,  3.5,  3.0,  2.5,  2.0,  1.0,  0.0}, /*  6 kbps */
+   {11.0,  8.5,  7.5,  6.5,  5.0,  3.9,  3.9,  3.9,  3.5,  3.0,  1.0}, /*  8 kbps */
    {11.0, 11.0,  9.9,  9.0,  8.0,  7.0,  6.5,  6.0,  5.0,  4.0,  2.0}, /* 11 kbps */
    {11.0, 11.0, 11.0, 11.0,  9.5,  9.0,  8.0,  7.0,  6.5,  5.0,  3.0}, /* 15 kbps */
    {11.0, 11.0, 11.0, 11.0, 11.0, 11.0,  9.5,  8.5,  8.0,  6.5,  4.0}, /* 18 kbps */
@@ -57,6 +57,14 @@
 };
 
 
+float vbr_hb_thresh[5][11]={
+   {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}, /* silence */
+   { 3.9,  2.5,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0, -1.0}, /*  2 kbps */
+   {11.0, 11.0,  9.9,  9.0,  8.0,  7.0,  6.5,  6.0,  5.0,  4.0,  2.0}, /*  6 kbps */
+   {11.0, 11.0, 11.0, 11.0, 11.0, 11.0,  9.5,  8.5,  8.0,  6.5,  4.0}, /* 10 kbps */
+   {11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0,  9.8,  7.5,  5.5}  /* 18 kbps */ 
+};
+
 void vbr_init(VBRState *vbr)
 {
    int i;
@@ -104,6 +112,7 @@
   non-stationary (harder to notice high-frequency noise)???
 
 */
+#include <stdio.h>
 float vbr_analysis(VBRState *vbr, float *sig, int len, int pitch, float pitch_coef)
 {
    int i;
@@ -153,13 +162,6 @@
       vbr->consec_noise=0;
    }
 
-   /* Checking for "pseudo temporal masking" */
-   if (ener < .1*vbr->average_energy)
-      qual -= .5;
-   if (ener < .01*vbr->average_energy)
-      qual -= .5;
-   if (ener < .001*vbr->average_energy)
-      qual -= .5;
    /* Checking for very low absolute energy */
    if (ener < 30000)
    {
@@ -169,26 +171,33 @@
       if (ener < 3000)
          qual-=.7;
    } else {
+      float short_diff, long_diff;
+      short_diff = log((ener+1)/(1+vbr->last_energy));
+      long_diff = log((ener+1)/(1+vbr->average_energy));
+      /*fprintf (stderr, "%f %f\n", short_diff, long_diff);*/
+
+      if (long_diff<-5)
+         long_diff=-5;
+      if (long_diff>2)
+         long_diff=2;
+
+      if (long_diff>0)
+         qual += .6*long_diff;
+      if (long_diff<0)
+         qual += .5*long_diff;
+      if (short_diff>0)
+      {
+         if (short_diff>5)
+            short_diff=5;
+         qual += .5*short_diff;
+      }
       /* Checking for energy increases */
-      if (ener > vbr->last_energy*4.0)
-         qual += .7;
-      if (ener > vbr->last_energy*1.8)
-         qual += .7;
-      if (ener > 2*vbr->average_energy)
-         qual += .7;
-      if (ener > 4*vbr->average_energy)
-         qual += .7;
       if (ener2 > 1.6*ener1)
-         qual += .7;
-      if (ener2 < .6*ener1)
-         qual -= .5;
-
-      if (ener < .3*vbr->last_energy)
-         qual -= .6;
+         qual += .5;
    }
    vbr->last_energy = ener;
    vbr->soft_pitch = .6*vbr->soft_pitch + .4*pitch_coef;
-   qual += 2.5*((pitch_coef-.4) + (vbr->soft_pitch-.4));
+   qual += 2.2*((pitch_coef-.4) + (vbr->soft_pitch-.4));
 
    if (qual < vbr->last_quality)
       qual = .5*qual + .5*vbr->last_quality;
@@ -197,7 +206,7 @@
    if (qual>10)
       qual=10;
    
-   if (vbr->consec_noise>=1)
+   if (vbr->consec_noise>=2)
       qual-=1.3;
    if (vbr->consec_noise>=5)
       qual-=1.3;

<p><p>1.8       +1 -0      speex/libspeex/vbr.h

Index: vbr.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/vbr.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- vbr.h	14 Nov 2002 00:51:35 -0000	1.7
+++ vbr.h	27 Nov 2002 02:54:34 -0000	1.8
@@ -39,6 +39,7 @@
 #define VBR_MEMORY_SIZE 5
 
 extern float vbr_nb_thresh[8][11];
+extern float vbr_hb_thresh[5][11];
 
 typedef struct VBRState {
    float energy_alpha;

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list