shithub: aacenc

Download patch

ref: 77fb24d09536c95cafad47cd62e10054e1970d22
parent: 08ff1d310799a9725ce709a8227ba5f6ff7045c0
author: knik <knik@users.sourceforge.net>
date: Fri Jul 28 08:37:37 EDT 2017

use +60 value for scalefactor and use clipped diff instead of original value (Arcen@github)

--- a/libfaac/aacquant.c
+++ b/libfaac/aacquant.c
@@ -235,13 +235,13 @@
             (coderInfo->book_vector[i]==INTENSITY_HCB2)) {
             const int diff = scale_factor[i] - previous_is_factor;
             if (diff < -60) scale_factor[i] = previous_is_factor - 60;
-            else if (diff > 59) scale_factor[i] = previous_is_factor + 59;
+            else if (diff > 60) scale_factor[i] = previous_is_factor + 60;
             previous_is_factor = scale_factor[i];
 //            printf("sf %d: %d diff=%d **\n", i, coderInfo->scale_factor[i], diff);
         } else if (coderInfo->book_vector[i]) {
             const int diff = scale_factor[i] - previous_scale_factor;
             if (diff < -60) scale_factor[i] = previous_scale_factor - 60;
-            else if (diff > 59) scale_factor[i] = previous_scale_factor + 59;
+            else if (diff > 60) scale_factor[i] = previous_scale_factor + 60;
             previous_scale_factor = scale_factor[i];
 //            printf("sf %d: %d diff=%d\n", i, coderInfo->scale_factor[i], diff);
         }
--- a/libfaac/huffman.c
+++ b/libfaac/huffman.c
@@ -1196,14 +1196,14 @@
                 (coderInfo->book_vector[index]==INTENSITY_HCB2) ) {
                 /* only send scalefactors if using non-zero codebooks */
                 diff = scale_factors[index] - previous_is_factor;
-                if ((diff < 60)&&(diff >= -60))
+                if ((diff <= 60)&&(diff >= -60))
 				{
 					length = huff12[diff+60][FIRSTINTAB];
 				}
-                else if ( diff >= 60 ) // frank 30.Oct.2007 added this because faad2 decoder and QuickTime choke when nothing is written and the codebook says a number is expected.
+                else if ( diff > 60 ) // frank 30.Oct.2007 added this because faad2 decoder and QuickTime choke when nothing is written and the codebook says a number is expected.
 				{
-					diff = 59;
-					length = huff12[119][FIRSTINTAB]; //max
+					diff = 60;
+					length = huff12[120][FIRSTINTAB]; //max
 				}
                 else 
 				{
@@ -1211,7 +1211,7 @@
 					length = huff12[0][FIRSTINTAB]; // min
 				}
                 bit_count+=length;
-                previous_is_factor = scale_factors[index];
+                previous_is_factor += diff;
                 if (writeFlag == 1 ) {
                     codeword = huff12[diff+60][LASTINTAB];
                     PutBit(bitStream,codeword,length);
@@ -1219,14 +1219,14 @@
             } else if (coderInfo->book_vector[index]) {
                 /* only send scalefactors if using non-zero codebooks */
                 diff = scale_factors[index] - previous_scale_factor;
-                if ((diff < 60)&&(diff >= -60))
+                if ((diff <= 60)&&(diff >= -60))
 				{
 					length = huff12[diff+60][FIRSTINTAB];
 				}
-                else if ( diff >= 60 ) // frank 30.Oct.2007 added this because faad2 decoder and QuickTime choke when nothing is written and the codebook says a number is expected.
+                else if ( diff > 60 ) // frank 30.Oct.2007 added this because faad2 decoder and QuickTime choke when nothing is written and the codebook says a number is expected.
 				{
-					diff = 59;
-					length = huff12[119][FIRSTINTAB]; //max
+					diff = 60;
+					length = huff12[120][FIRSTINTAB]; //max
 				}
                 else 
 				{
@@ -1234,7 +1234,7 @@
 					length = huff12[0][FIRSTINTAB]; //min
 				}
                 bit_count+=length;
-                previous_scale_factor = scale_factors[index];
+                previous_scale_factor += diff;
                 if (writeFlag == 1 ) {
                     codeword = huff12[diff+60][LASTINTAB];
                     PutBit(bitStream,codeword,length);