Port r17543 from Tremor.
[platform/upstream/libvorbis.git] / lib / floor1.c
index 5c290fc..e1dc2c7 100644 (file)
@@ -476,15 +476,7 @@ static int fit_line(lsfit_acc *a,int fits,int *y0,int *y1,
   int x1=a[fits-1].x1;
 
   for(i=0;i<fits;i++){
-
-    /* This process is a bit odd as I'm preserving the weighting
-       behavior of 1.2.3 for now.  Although I can hear no difference,
-       what appears to be a better more straightforward weighting
-       slightly drops PEAQ and increases bitrate.  For that reason,
-       I'm preserving the old behavior until I can explain why the
-       bettwer weighting measures poorly. */
-
-    double weight = floor((a[i].bn+a[i].an)*info->twofitweight/(a[i].an+1))+1.;
+    double weight = (a[i].bn+a[i].an)*info->twofitweight/(a[i].an+1)+1.;
 
     xb+=a[i].xb + a[i].xa * weight;
     yb+=a[i].yb + a[i].ya * weight;
@@ -1043,7 +1035,7 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
           }
         }
 
-        fit_value[i]=val+predicted;
+        fit_value[i]=val+predicted&0x7fff;
         fit_value[look->loneighbor[i-2]]&=0x7fff;
         fit_value[look->hineighbor[i-2]]&=0x7fff;
 
@@ -1074,13 +1066,18 @@ static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
     int hx=0;
     int lx=0;
     int ly=fit_value[0]*info->mult;
+    /* guard lookup against out-of-range values */
+    ly=(ly<0?0:ly>255?255:ly);
+
     for(j=1;j<look->posts;j++){
       int current=look->forward_index[j];
       int hy=fit_value[current]&0x7fff;
       if(hy==fit_value[current]){
 
-        hy*=info->mult;
         hx=info->postlist[current];
+        hy*=info->mult;
+        /* guard lookup against out-of-range values */
+        hy=(hy<0?0:hy>255?255:hy);
 
         render_line(n,lx,hx,ly,hy,out);