shithub: aacenc

Download patch

ref: 1142f086784e83999d53a560448aa80e392f0811
parent: 01e7ed7a09fda1c453edb6aed593ce402e88ddd6
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Fri Oct 27 11:51:38 EDT 2017

allow finer bandwidth setting

--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -196,7 +196,7 @@
 
     /* set quantization quality */
     hEncoder->aacquantCfg.quality = config->quantqual;
-    BandLimit(&hEncoder->config.bandWidth,
+    CalcBW(&hEncoder->config.bandWidth,
               hEncoder->sampleRate,
               hEncoder->srInfo,
               &hEncoder->aacquantCfg);
@@ -526,7 +526,7 @@
                 offset += hEncoder->srInfo->cb_width_short[sb];
             }
             coderInfo[channel].sfb_offset[sb] = offset;
-            BlocGroup(hEncoder->freqBuff[channel], coderInfo + channel, hEncoder->aacquantCfg.max_cbs);
+            BlocGroup(hEncoder->freqBuff[channel], coderInfo + channel, &hEncoder->aacquantCfg);
         } else {
             coderInfo[channel].sfbn = hEncoder->aacquantCfg.max_cbl;
 
--- a/libfaac/quantize.c
+++ b/libfaac/quantize.c
@@ -338,7 +338,7 @@
     return 0;
 }
 
-void BandLimit(unsigned *bw, int rate, SR_INFO *sr, AACQuantCfg *aacquantCfg)
+void CalcBW(unsigned *bw, int rate, SR_INFO *sr, AACQuantCfg *aacquantCfg)
 {
     // find max short frame band
     int max = *bw * (BLOCK_LEN_SHORT << 1) / rate;
@@ -353,7 +353,6 @@
         l += sr->cb_width_short[cnt];
     }
     aacquantCfg->max_cbs = cnt;
-    *bw = (double)l * rate / (BLOCK_LEN_SHORT << 1);
 
     // find max long frame band
     max = *bw * (BLOCK_LEN_LONG << 1) / rate;
@@ -365,6 +364,7 @@
         l += sr->cb_width_long[cnt];
     }
     aacquantCfg->max_cbl = cnt;
+    aacquantCfg->max_l = l;
 
     *bw = (double)l * rate / (BLOCK_LEN_LONG << 1);
 }
@@ -371,13 +371,18 @@
 
 enum {MINSFB = 2};
 
-static void calce(double *xr, int *bands, double e[NSFB_SHORT], int maxsfb)
+static void calce(double *xr, int *bands, double e[NSFB_SHORT], int maxsfb,
+                  int maxl)
 {
     int sfb;
+    int l;
+
+    // mute lines above cutoff freq
+    for (l = maxl; l < bands[maxsfb]; l++)
+        xr[l] = 0.0;
+
     for (sfb = MINSFB; sfb < maxsfb; sfb++)
     {
-        int l;
-
         e[sfb] = 0;
         for (l = bands[sfb]; l < bands[sfb + 1]; l++)
             e[sfb] += xr[l] * xr[l];
@@ -397,7 +402,7 @@
 static int groups = 0;
 static int frames = 0;
 #endif
-void BlocGroup(double *xr, CoderInfo *coderInfo, int maxsfb)
+void BlocGroup(double *xr, CoderInfo *coderInfo, AACQuantCfg *cfg)
 {
     int win, sfb;
     double e[NSFB_SHORT];
@@ -406,6 +411,7 @@
     const double thr = 3.0;
     int win0;
     int fastmin;
+    int maxsfb, maxl;
 
     if (coderInfo->block_type != ONLY_SHORT_WINDOW)
     {
@@ -414,6 +420,8 @@
         return;
     }
 
+    maxl = cfg->max_l / 8;
+    maxsfb = cfg->max_cbs;
     fastmin = ((maxsfb - MINSFB) * 3) >> 2;
 
 #ifdef DRM
@@ -425,7 +433,7 @@
 #if PRINTSTAT
     frames++;
 #endif
-    calce(xr, coderInfo->sfb_offset, e, maxsfb);
+    calce(xr, coderInfo->sfb_offset, e, maxsfb, maxl);
     resete(min, max, e, maxsfb);
     win0 = 0;
     coderInfo->groups.n = 0;
@@ -433,7 +441,7 @@
     {
         int fast = 0;
 
-        calce(xr + win * BLOCK_LEN_SHORT, coderInfo->sfb_offset, e, maxsfb);
+        calce(xr + win * BLOCK_LEN_SHORT, coderInfo->sfb_offset, e, maxsfb, maxl);
         for (sfb = MINSFB; sfb < maxsfb; sfb++)
         {
             if (min[sfb] > e[sfb])
--- a/libfaac/quantize.h
+++ b/libfaac/quantize.h
@@ -29,6 +29,7 @@
     double quality;
     int max_cbl;
     int max_cbs;
+    int max_l;
 } AACQuantCfg;
 
 #include "quantize.h"
@@ -42,8 +43,8 @@
 };
 
 int BlocQuant(CoderInfo *coderInfo, double *xr, AACQuantCfg *aacquantCfg);
-void BandLimit(unsigned *bw, int rate, SR_INFO *sr, AACQuantCfg *aacquantCfg);
-void BlocGroup(double *xr, CoderInfo *coderInfo, int maxsfb);
+void CalcBW(unsigned *bw, int rate, SR_INFO *sr, AACQuantCfg *aacquantCfg);
+void BlocGroup(double *xr, CoderInfo *coderInfo, AACQuantCfg *aacquantCfg);
 void BlocStat(void);
 
 #endif