[xiph-cvs] cvs commit: vorbis/lib/modes psych_44.h

Monty xiphmont at xiph.org
Thu Oct 17 23:00:12 PDT 2002



xiphmont    02/10/18 02:00:12

  Modified:    lib      psy.c
               lib/modes psych_44.h
  Log:
  Elimintae two minor bugs; zero-bark wraparound in noise_hybridmp was
  slightly off, and <0 fixed evelope computation should be allowed to
  dip below zero (and be bounded later).

Revision  Changes    Path
1.80      +61 -45    vorbis/lib/psy.c

Index: psy.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/psy.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- psy.c	17 Oct 2002 04:56:23 -0000	1.79
+++ psy.c	18 Oct 2002 06:00:12 -0000	1.80
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: psychoacoustics not including preecho
- last mod: $Id: psy.c,v 1.79 2002/10/17 04:56:23 xiphmont Exp $
+ last mod: $Id: psy.c,v 1.80 2002/10/18 06:00:12 xiphmont Exp $
 
  ********************************************************************/
 
@@ -265,7 +265,7 @@
 
 void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
                   vorbis_info_psy_global *gi,int n,long rate){
-  long i,j,lo=-99,hi=0;
+  long i,j,lo=-99,hi=1;
   long maxoc;
   memset(p,0,sizeof(*p));
 
@@ -303,10 +303,10 @@
     for(;lo+vi->noisewindowlomin<i && 
           toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
     
-    for(;hi<n && (hi<i+vi->noisewindowhimin ||
+    for(;hi<=n && (hi<i+vi->noisewindowhimin ||
           toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
     
-    p->bark[i]=(lo<<16)+hi;
+    p->bark[i]=((lo-1)<<16)+(hi-1);
 
   }
 
@@ -536,45 +536,57 @@
                                 const float offset,
                                 const int fixed){
   
-  float *N=alloca((n+1)*sizeof(*N));
-  float *X=alloca((n+1)*sizeof(*N));
-  float *XX=alloca((n+1)*sizeof(*N));
-  float *Y=alloca((n+1)*sizeof(*N));
-  float *XY=alloca((n+1)*sizeof(*N));
+  float *N=alloca(n*sizeof(*N));
+  float *X=alloca(n*sizeof(*N));
+  float *XX=alloca(n*sizeof(*N));
+  float *Y=alloca(n*sizeof(*N));
+  float *XY=alloca(n*sizeof(*N));
 
   float tN, tX, tXX, tY, tXY;
-  float fi;
   int i;
 
   int lo, hi;
   float R, A, B, D;
-  
+  float w, x, y;
+
   tN = tX = tXX = tY = tXY = 0.f;
-  for (i = 0, fi = 0.f; i < n; i++, fi += 1.f) {
-    float w, x, y;
+
+  y = f[0] + offset;
+  if (y < 1.f) y = 1.f;
+
+  w = y * y * .5;
+    
+  tN += w;
+  tX += w;
+  tY += w * y;
+
+  N[0] = tN;
+  X[0] = tX;
+  XX[0] = tXX;
+  Y[0] = tY;
+  XY[0] = tXY;
+
+  for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
     
-    x = fi;
     y = f[i] + offset;
     if (y < 1.f) y = 1.f;
+
     w = y * y;
-    N[i] = tN;
-    X[i] = tX;
-    XX[i] = tXX;
-    Y[i] = tY;
-    XY[i] = tXY;
+    
     tN += w;
     tX += w * x;
     tXX += w * x * x;
     tY += w * y;
     tXY += w * x * y;
+
+    N[i] = tN;
+    X[i] = tX;
+    XX[i] = tXX;
+    Y[i] = tY;
+    XY[i] = tXY;
   }
-  N[i] = tN;
-  X[i] = tX;
-  XX[i] = tXX;
-  Y[i] = tY;
-  XY[i] = tXY;
   
-  for (i = 0, fi = 0.f;; i++, fi += 1.f) {
+  for (i = 0, x = 0.f;; i++, x += 1.f) {
     
     lo = b[i] >> 16;
     if( lo>=0 ) break;
@@ -589,17 +601,18 @@
     A = tY * tXX - tX * tXY;
     B = tN * tXY - tX * tY;
     D = tN * tXX - tX * tX;
-    R = (A + fi * B) / D;
+    R = (A + x * B) / D;
     if (R < 0.f)
       R = 0.f;
     
     noise[i] = R - offset;
   }
   
-  for ( ; hi < n; i++, fi += 1.f) {
+  for ( ;; i++, x += 1.f) {
     
     lo = b[i] >> 16;
     hi = b[i] & 0xffff;
+    if(hi>=n)break;
     
     tN = N[hi] - N[lo];
     tX = X[hi] - X[lo];
@@ -610,14 +623,14 @@
     A = tY * tXX - tX * tXY;
     B = tN * tXY - tX * tY;
     D = tN * tXX - tX * tX;
-    R = (A + fi * B) / D;
+    R = (A + x * B) / D;
     if (R < 0.f) R = 0.f;
     
     noise[i] = R - offset;
   }
-  for ( ; i < n; i++, fi += 1.f) {
+  for ( ; i < n; i++, x += 1.f) {
     
-    R = (A + fi * B) / D;
+    R = (A + x * B) / D;
     if (R < 0.f) R = 0.f;
     
     noise[i] = R - offset;
@@ -625,10 +638,11 @@
   
   if (fixed <= 0) return;
   
-  for (i = 0, fi = 0.f; i < (fixed + 1) / 2; i++, fi += 1.f) {
+  for (i = 0, x = 0.f;; i++, x += 1.f) {
     hi = i + fixed / 2;
     lo = hi - fixed;
-    
+    if(lo>=0)break;
+
     tN = N[hi] + N[-lo];
     tX = X[hi] - X[-lo];
     tXX = XX[hi] + XX[-lo];
@@ -639,14 +653,15 @@
     A = tY * tXX - tX * tXY;
     B = tN * tXY - tX * tY;
     D = tN * tXX - tX * tX;
-    R = (A + fi * B) / D;
+    R = (A + x * B) / D;
 
-    if (R > 0.f && R - offset < noise[i]) noise[i] = R - offset;
+    if (R - offset < noise[i]) noise[i] = R - offset;
   }
-  for ( ; hi < n; i++, fi += 1.f) {
+  for ( ;; i++, x += 1.f) {
     
     hi = i + fixed / 2;
     lo = hi - fixed;
+    if(hi>=n)break;
     
     tN = N[hi] - N[lo];
     tX = X[hi] - X[lo];
@@ -657,13 +672,13 @@
     A = tY * tXX - tX * tXY;
     B = tN * tXY - tX * tY;
     D = tN * tXX - tX * tX;
-    R = (A + fi * B) / D;
+    R = (A + x * B) / D;
     
-    if (R > 0.f && R - offset < noise[i]) noise[i] = R - offset;
+    if (R - offset < noise[i]) noise[i] = R - offset;
   }
-  for ( ; i < n; i++, fi += 1.f) {
-    R = (A + fi * B) / D;
-    if (R > 0.f && R - offset < noise[i]) noise[i] = R - offset;
+  for ( ; i < n; i++, x += 1.f) {
+    R = (A + x * B) / D;
+    if (R - offset < noise[i]) noise[i] = R - offset;
   }
 }
 
@@ -770,7 +785,7 @@
 
   for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
   
-#if 0
+  //#if 0
   {
     static int seq=0;
 
@@ -780,21 +795,22 @@
     }
     
     if(seq&1)
-      _analysis_output("medianR",seq/2,work,n,1,0,0);
+      _analysis_output("median2R",seq/2,work,n,1,0,0);
     else
-      _analysis_output("medianL",seq/2,work,n,1,0,0);
+      _analysis_output("median2L",seq/2,work,n,1,0,0);
     
     if(seq&1)
-      _analysis_output("envelopeR",seq/2,work2,n,1,0,0);
+      _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
     else
-      _analysis_output("enveloperL",seq/2,work2,n,1,0,0);
+      _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
     seq++;
   }
-#endif
+  //#endif
 
   for(i=0;i<n;i++){
     int dB=logmask[i]+.5;
     if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
+    if(dB<0)dB=0;
     logmask[i]= work[i]+p->vi->noisecompand[dB];
   }
 

<p><p>1.27      +3 -3      vorbis/lib/modes/psych_44.h

Index: psych_44.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/modes/psych_44.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- psych_44.h	13 Jul 2002 06:12:49 -0000	1.26
+++ psych_44.h	18 Oct 2002 06:00:12 -0000	1.27
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: key psychoacoustic settings for 44.1/48kHz
- last mod: $Id: psych_44.h,v 1.26 2002/07/13 06:12:49 xiphmont Exp $
+ last mod: $Id: psych_44.h,v 1.27 2002/10/18 06:00:12 xiphmont Exp $
 
  ********************************************************************/
 
@@ -353,8 +353,8 @@
 };
 
 static noiseguard _psy_noiseguards_44[4]={
-  {4,4,15},
-  {4,4,15},
+  {3,3,15},
+  {3,3,15},
   {10,10,100},
   {10,10,100},
 };

<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