shithub: aacenc

Download patch

ref: 191d2de75e1259a15d2d84ece35b688a13615329
parent: 569967e2655151bbf256036f34e8a4a4d6cb2b16
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Fri Sep 1 06:15:18 EDT 2017

added scalefactor output counter, it will be useful for window grouping;
increased default quality level

--- a/libfaac/coder.h
+++ b/libfaac/coder.h
@@ -119,6 +119,7 @@
 
     int global_gain;
     int scale_factor[MAX_SCFAC_BANDS];
+    int sfcnt;
 
     struct {
         int n;
--- a/libfaac/huffman.c
+++ b/libfaac/huffman.c
@@ -1058,8 +1058,8 @@
     int bit_count = 0;
     int previous;
     int max, bit_len/*,sfbs*/;
-    int max_sfb,g,band;
-	int sect_cb_bits = 4;
+    int g,band;
+    int sect_cb_bits = 4;
 
     /* Set local pointers to coderInfo elements */
     int* book_vector = coderInfo->book_vector;
@@ -1076,12 +1076,8 @@
         bit_len = 5;
     }
 
-    /* Compute number of scalefactor bands */
-    max_sfb = coderInfo->sfbn / coderInfo->groups.n;
-
-
     for (g = 0; g < coderInfo->groups.n; g++) {
-        band=g*max_sfb;
+        band = g * coderInfo->sfbn;
 
         repeat_counter=1;
 
@@ -1091,7 +1087,7 @@
         }
         bit_count += sect_cb_bits;
 
-        for (i=band+1;i<band+max_sfb;i++) {
+        for (i = band + 1; i < (band + coderInfo->sfbn); i++) {
 #ifdef DRM
             /* sect_len is not transmitted in case the codebook for a */
             /* section is 11 or in the range of 16 and 31 */
@@ -1179,7 +1175,7 @@
     int* scale_factors = coderInfo->scale_factor;
 
     if (coderInfo->block_type == ONLY_SHORT_WINDOW) { /* short windows */
-        nr_of_sfb_per_group = coderInfo->sfbn/coderInfo->groups.n;
+        nr_of_sfb_per_group = coderInfo->sfbn;
     } else {
         nr_of_sfb_per_group = coderInfo->sfbn;
         coderInfo->groups.n = 1;
--- a/libfaac/quantize.c
+++ b/libfaac/quantize.c
@@ -23,6 +23,7 @@
 #include "quantize.h"
 
 #define MAGIC_NUMBER  0.4054
+enum {NULL_SF = 0};
 
 // band sound masking
 static void bmask(CoderInfo *coderInfo, double *xr, double *bandqual,
@@ -70,7 +71,7 @@
         target *= 0.45;
     }
 
-    target *= 8.0 / (1.0 + ((double)(start+end)/last));
+    target *= 10.0 / (1.0 + ((double)(start+end)/last));
 
     bandqual[sfb] = target * quality;
   }
@@ -114,7 +115,7 @@
       {
           for (cnt = start; cnt < end; cnt++)
               xi[cnt] = 0;
-          coderInfo->scale_factor[sb] = 10;
+          coderInfo->scale_factor[coderInfo->sfcnt++] = NULL_SF;
           continue;
       }
 
@@ -130,7 +131,7 @@
           xi[cnt] = (int)(tmp + MAGIC_NUMBER);
       }
 
-      coderInfo->scale_factor[sb] = sfac;
+      coderInfo->scale_factor[coderInfo->sfcnt++] = sfac;
     }
 }
 
@@ -139,6 +140,8 @@
     double bandlvl[MAX_SCFAC_BANDS];
     int cnt;
     int nonzero = 0;
+
+    coderInfo->sfcnt = 0;
 
     for (cnt = 0; cnt < FRAME_LEN; cnt++)
         nonzero += (fabs(xr[cnt]) > 1E-20);