shithub: aacenc

Download patch

ref: 777d4f6dbd6865112037111c3ea80b7a4efc52ed
parent: 26a6f3c02bf39024cfcc55e7af889b1da966f152
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Mon Aug 14 15:04:49 EDT 2017

a better way to balance band volume

--- a/libfaac/quantize.c
+++ b/libfaac/quantize.c
@@ -82,7 +82,7 @@
 
         target *= 0.45;
     }
-    bandqual[sfb] = 3.0 * target * quality;
+    bandqual[sfb] = 3.5 * target * quality;
   }
 }
 
@@ -134,9 +134,19 @@
       coderInfo->scale_factor[sb] = sfac;
       for (cnt = start; cnt < end; cnt++)
       {
+          int x0, x1;
+          double err0, err1;
           double tmp = fabs(xr[cnt]) * sfacfix;
           tmp = sqrt(tmp * sqrt(tmp));
-          xi[cnt] = (int)(tmp + 0.2);
+          x0 = tmp;
+          x1 = x0 + 1;
+          err0 = fabs(tmp * tmp - x0 * x0);
+          err1 = fabs(tmp * tmp - x1 * x1);
+
+          if (err0 < err1)
+              xi[cnt] = x0;
+          else
+              xi[cnt] = x1;
       }
     }
 }