shithub: aacenc

Download patch

ref: 569967e2655151bbf256036f34e8a4a4d6cb2b16
parent: a2d516f900c555c2367fb51a06506f78763fc968
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Thu Aug 31 16:46:07 EDT 2017

coder data struct cleaned up; fields renamed

--- a/libfaac/aacquant.c
+++ b/libfaac/aacquant.c
@@ -66,7 +66,7 @@
 
     /* Set all scalefactors to 0 */
     coderInfo->global_gain = 0;
-    for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
+    for (sb = 0; sb < coderInfo->sfbn; sb++)
         scale_factor[sb] = 0;
 
     if (BlocQuant(coderInfo, xr, xi, aacquantCfg))
@@ -77,11 +77,10 @@
         }
     }
 
-
     BitSearch(coderInfo, xi);
 
     /* offset the difference of common_scalefac and scalefactors by SF_OFFSET  */
-    for (i = 0; i < coderInfo->nr_of_sfb; i++) {
+    for (i = 0; i < coderInfo->sfbn; i++) {
         if ((coderInfo->book_vector[i]!=INTENSITY_HCB)&&(coderInfo->book_vector[i]!=INTENSITY_HCB2)) {
             scale_factor[i] = coderInfo->global_gain - scale_factor[i] + SF_OFFSET;
         }
@@ -91,7 +90,7 @@
     {
       int previous_scale_factor = coderInfo->global_gain;
       int previous_is_factor = 0;
-      for (i = 0; i < coderInfo->nr_of_sfb; i++) {
+      for (i = 0; i < coderInfo->sfbn; i++) {
         if ((coderInfo->book_vector[i]==INTENSITY_HCB) ||
             (coderInfo->book_vector[i]==INTENSITY_HCB2)) {
             const int diff = scale_factor[i] - previous_is_factor;
@@ -118,7 +117,7 @@
 #endif
     coderInfo->spectral_count = 0;
     sb = 0;
-    for(i = 0; i < coderInfo->nr_of_sfb; i++) {
+    for(i = 0; i < coderInfo->sfbn; i++) {
         OutputBits(
             coderInfo,
 #ifdef DRM
@@ -134,8 +133,7 @@
               sb = i;
     }
 
-    // FIXME: Check those max_sfb/nr_of_sfb. Isn't it the same?
-    coderInfo->max_sfb = coderInfo->nr_of_sfb = sb + 1;
+    coderInfo->sfbn = sb + 1;
 
     return bits;
 }
@@ -154,16 +152,13 @@
 
     /* set up local variables for used quantInfo elements */
     int* sfb_offset = coderInfo->sfb_offset;
-    int* nr_of_sfb = &(coderInfo->nr_of_sfb);
-    int* window_group_length;
-    int num_window_groups;
-    *nr_of_sfb = coderInfo->max_sfb;              /* Init to max_sfb */
-    window_group_length = coderInfo->window_group_length;
-    num_window_groups = coderInfo->num_window_groups;
+    int sfbn = coderInfo->sfbn;
+    int* groups = coderInfo->groups.len;
+    int num_window_groups = coderInfo->groups.n;
 
     /* calc org sfb_offset just for shortblock */
     sfb_offset[k]=0;
-    for (k=1 ; k <*nr_of_sfb+1; k++) {
+    for (k=1 ; k < sfbn; k++) {
         sfb_offset[k] = sfb_offset[k-1] + sfb_width_table[k-1];
     }
 
@@ -171,13 +166,13 @@
     index = 0;
     group_offset=0;
     for (i=0; i< num_window_groups; i++) {
-        for (k=0; k<*nr_of_sfb; k++) {
-            for (j=0; j < window_group_length[i]; j++) {
+        for (k=0; k < sfbn; k++) {
+            for (j=0; j < groups[i]; j++) {
                 for (ii=0;ii< sfb_width_table[k];ii++)
                     xr_tmp[index++] = xr[ii+ sfb_offset[k] + BLOCK_LEN_SHORT*j +group_offset];
             }
         }
-        group_offset +=  BLOCK_LEN_SHORT*window_group_length[i];
+        group_offset +=  BLOCK_LEN_SHORT*groups[i];
     }
 
     for (k=0; k<FRAME_LEN; k++){
@@ -190,14 +185,14 @@
     sfb_offset[index++] = 0;
     windowOffset = 0;
     for (i=0; i < num_window_groups; i++) {
-        for (k=0 ; k <*nr_of_sfb; k++) {
-            sfb_offset[index] = sfb_offset[index-1] + sfb_width_table[k]*window_group_length[i] ;
+        for (k=0; k < sfbn; k++) {
+            sfb_offset[index] = sfb_offset[index-1] + sfb_width_table[k]*groups[i] ;
             index++;
         }
-        windowOffset += window_group_length[i];
+        windowOffset += groups[i];
     }
 
-    *nr_of_sfb = *nr_of_sfb * num_window_groups;  /* Number interleaved bands. */
+    coderInfo->sfbn = sfbn * num_window_groups;
 
     return 0;
 }
@@ -209,7 +204,7 @@
   int last = 0;
   double totenrg = 0.0;
 
-  end = coderInfo->sfb_offset[coderInfo->nr_of_sfb];
+  end = coderInfo->sfb_offset[coderInfo->sfbn];
   for (l = 0; l < end; l++)
   {
     if (xr[l])
@@ -220,6 +215,5 @@
     }
   last++;
 
-  coderInfo->lastx = last;
   coderInfo->avgenrg = totenrg / last;
 }
--- a/libfaac/bitstream.c
+++ b/libfaac/bitstream.c
@@ -23,9 +23,6 @@
 
 Copyright (c) 1997.
 **********************************************************************/
-/*
- * $Id: bitstream.c,v 1.35 2012/03/01 18:34:17 knik Exp $
- */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -406,8 +403,8 @@
         int numWindows, maxSfb;
 
         bits += WriteICSInfo(coderInfoL, bitStream, objectType, channelInfo->common_window, writeFlag);
-        numWindows = coderInfoL->num_window_groups;
-        maxSfb = coderInfoL->max_sfb;
+        numWindows = coderInfoL->groups.n;
+        maxSfb = coderInfoL->sfbn;
 
         if (writeFlag) {
             PutBit(bitStream, channelInfo->msInfo.is_present, LEN_MASK_PRES);
@@ -512,7 +509,7 @@
     /* For short windows, write out max_sfb and scale_factor_grouping */
     if (coderInfo->block_type == ONLY_SHORT_WINDOW){
         if (writeFlag) {
-            PutBit(bitStream, coderInfo->max_sfb, LEN_MAX_SFBS);
+            PutBit(bitStream, coderInfo->sfbn, LEN_MAX_SFBS);
             grouping_bits = FindGroupingBits(coderInfo);
             PutBit(bitStream, grouping_bits, MAX_SHORT_WINDOWS - 1);  /* the grouping bits */
         }
@@ -520,7 +517,7 @@
         bits += MAX_SHORT_WINDOWS - 1;
     } else { /* Otherwise, write out max_sfb and predictor data */
         if (writeFlag) {
-            PutBit(bitStream, coderInfo->max_sfb, LEN_MAX_SFBL);
+            PutBit(bitStream, coderInfo->sfbn, LEN_MAX_SFBL);
         }
         bits += LEN_MAX_SFBL;
 #ifdef DRM
@@ -813,8 +810,8 @@
     int i, j;
     int index = 0;
 
-    for(i = 0; i < coderInfo->num_window_groups; i++){
-        for (j = 0; j < coderInfo->window_group_length[i]; j++){
+    for(i = 0; i < coderInfo->groups.n; i++){
+        for (j = 0; j < coderInfo->groups.len[i]; j++){
             tmp[index++] = i;
         }
     }
@@ -992,7 +989,7 @@
     int segmcnt = 0;
     long startbitpos;
     segment_t segment[FRAME_LEN];
-    int* window_group_length = coderInfo->window_group_length;
+    int* groups = coderInfo->groups.len;
     int* sfb_offset = coderInfo->sfb_offset;
 
     cw_info_t cw_info[FRAME_LEN];
@@ -1037,7 +1034,7 @@
         /* presort codewords ------------------------------------------------ */
         /* classify codewords first */
         sfb_cnt = win_cnt = win_grp_cnt = coeff_cnt = last_sfb = acc_win_cnt = 0;
-        cur_sfb_len = sfb_offset[1] / window_group_length[0];
+        cur_sfb_len = sfb_offset[1] / groups[0];
         cur_cb = coderInfo->book_vector[0];
         for (i = 0; i < num_cw; i++) {
             /* Set codeword info parameters */
@@ -1053,7 +1050,7 @@
                 last_sfb += cur_sfb_len;
 
                 win_cnt++; /* next window */
-                if (win_cnt == window_group_length[win_grp_cnt]) {
+                if (win_cnt == groups[win_grp_cnt]) {
                     win_cnt = 0;
 
                     sfb_cnt++; /* next sfb */
@@ -1060,7 +1057,7 @@
                     if (sfb_cnt == coderInfo->all_sfb) {
                         sfb_cnt = 0;
 
-                        acc_win_cnt += window_group_length[win_grp_cnt];
+                        acc_win_cnt += groups[win_grp_cnt];
                         win_grp_cnt++; /* next window group */
                     }
 
@@ -1068,7 +1065,7 @@
                     cur_cb = coderInfo->book_vector[sfb_cnt];
                     if (last_sfb < FRAME_LEN) {
                         cur_sfb_len = (sfb_offset[sfb_cnt + 1] - sfb_offset[sfb_cnt])
-                            / window_group_length[win_grp_cnt];
+                            / groups[win_grp_cnt];
                     }
                 }
             }
--- a/libfaac/coder.h
+++ b/libfaac/coder.h
@@ -120,12 +120,12 @@
     int global_gain;
     int scale_factor[MAX_SCFAC_BANDS];
 
-    int num_window_groups;
-    int window_group_length[8];
-    int max_sfb;
-    int nr_of_sfb;
+    struct {
+        int n;
+        int len[8];
+    } groups;
+    int sfbn;
     int sfb_offset[250];
-    int lastx;
     double avgenrg;
 
     int spectral_count;
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -343,8 +343,8 @@
         hEncoder->coderInfo[channel].prev_window_shape = SINE_WINDOW;
         hEncoder->coderInfo[channel].window_shape = SINE_WINDOW;
         hEncoder->coderInfo[channel].block_type = ONLY_LONG_WINDOW;
-        hEncoder->coderInfo[channel].num_window_groups = 1;
-        hEncoder->coderInfo[channel].window_group_length[0] = 1;
+        hEncoder->coderInfo[channel].groups.n = 1;
+        hEncoder->coderInfo[channel].groups.len[0] = 1;
 
         hEncoder->sampleBuff[channel] = NULL;
         hEncoder->nextSampleBuff[channel] = NULL;
@@ -585,38 +585,36 @@
         channelInfo[channel].msInfo.is_present = 0;
 
         if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
-			coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_short;
-            coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_short;
+            coderInfo[channel].sfbn = hEncoder->aacquantCfg.max_cbs;
 
-            coderInfo[channel].num_window_groups = 1;
-            coderInfo[channel].window_group_length[0] = 8;
-            coderInfo[channel].window_group_length[1] = 0;
-            coderInfo[channel].window_group_length[2] = 0;
-            coderInfo[channel].window_group_length[3] = 0;
-            coderInfo[channel].window_group_length[4] = 0;
-            coderInfo[channel].window_group_length[5] = 0;
-            coderInfo[channel].window_group_length[6] = 0;
-            coderInfo[channel].window_group_length[7] = 0;
+            coderInfo[channel].groups.n = 1;
+            coderInfo[channel].groups.len[0] = 8;
+            coderInfo[channel].groups.len[1] = 0;
+            coderInfo[channel].groups.len[2] = 0;
+            coderInfo[channel].groups.len[3] = 0;
+            coderInfo[channel].groups.len[4] = 0;
+            coderInfo[channel].groups.len[5] = 0;
+            coderInfo[channel].groups.len[6] = 0;
+            coderInfo[channel].groups.len[7] = 0;
 
             offset = 0;
-            for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
+            for (sb = 0; sb < coderInfo[channel].sfbn; sb++) {
                 coderInfo[channel].sfb_offset[sb] = offset;
                 offset += hEncoder->srInfo->cb_width_short[sb];
             }
-            coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
+            coderInfo[channel].sfb_offset[sb] = offset;
         } else {
-            coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_long;
-            coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_long;
+            coderInfo[channel].sfbn = hEncoder->aacquantCfg.max_cbl;
 
-            coderInfo[channel].num_window_groups = 1;
-            coderInfo[channel].window_group_length[0] = 1;
+            coderInfo[channel].groups.n = 1;
+            coderInfo[channel].groups.len[0] = 1;
 
             offset = 0;
-            for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
+            for (sb = 0; sb < coderInfo[channel].sfbn; sb++) {
                 coderInfo[channel].sfb_offset[sb] = offset;
                 offset += hEncoder->srInfo->cb_width_long[sb];
             }
-            coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
+            coderInfo[channel].sfb_offset[sb] = offset;
         }
     }
 
@@ -624,11 +622,11 @@
     for (channel = 0; channel < numChannels; channel++) {
         if ((!channelInfo[channel].lfe) && (useTns)) {
             TnsEncode(&(coderInfo[channel].tnsInfo),
-					coderInfo[channel].max_sfb,
-					coderInfo[channel].max_sfb,
-					coderInfo[channel].block_type,
-					coderInfo[channel].sfb_offset,
-					hEncoder->freqBuff[channel]);
+                      coderInfo[channel].sfbn,
+                      coderInfo[channel].sfbn,
+                      coderInfo[channel].block_type,
+                      coderInfo[channel].sfb_offset,
+                      hEncoder->freqBuff[channel]);
         } else {
             coderInfo[channel].tnsInfo.tnsDataPresent = 0;      /* TNS not used for LFE */
         }
@@ -645,7 +643,7 @@
       // reduce LFE bandwidth
 		if (!channelInfo[channel].cpe && channelInfo[channel].lfe)
 		{
-			coderInfo[channel].nr_of_sfb = coderInfo[channel].max_sfb = 3;
+                    coderInfo[channel].sfbn = 3;
 		}
 	}
 
@@ -718,8 +716,7 @@
 			cil = &coderInfo[channel];
 			cir = &coderInfo[channelInfo[channel].paired_ch];
 
-			cil->max_sfb = cir->max_sfb = max(cil->max_sfb, cir->max_sfb);
-			cil->nr_of_sfb = cir->nr_of_sfb = cil->max_sfb;
+                        cil->sfbn = cir->sfbn = max(cil->sfbn, cir->sfbn);
 		}
     }
 #ifndef DRM
--- a/libfaac/huffman.c
+++ b/libfaac/huffman.c
@@ -108,7 +108,7 @@
     /* Set local pointer to coderInfo book_vector */
     int* book_vector = coderInfo -> book_vector;
 
-    levels = (int) ((log((double)coderInfo->nr_of_sfb)/log((double)2.0))+1);
+    levels = (int) ((log((double)coderInfo->sfbn)/log((double)2.0))+1);
 
 /* #define SLOW */
 
@@ -125,8 +125,8 @@
         k=0;
         total_bit_count = 0;
 
-	pow2levels = 1 << (levels - i);
-	fracpow2lev = pow2levels + (coderInfo->nr_of_sfb >> i);
+        pow2levels = 1 << (levels - i);
+        fracpow2lev = pow2levels + (coderInfo->sfbn >> i);
 
         for (j=pow2levels; j < fracpow2lev; j++)
         {
@@ -203,10 +203,10 @@
 
     /* set local pointer to sfb_offset */
     int *sfb_offset = coderInfo->sfb_offset;
-    int nr_of_sfb = coderInfo->nr_of_sfb;
+    int sfbn = coderInfo->sfbn;
 
     /* each section is 'hop' scalefactor bands wide */
-    for (i=0; i < nr_of_sfb; i=i+hop){
+    for (i = 0; i < sfbn; i = i + hop){
 #ifdef SLOW
         if ((i+hop) > nr_of_sfb)
             q = nr_of_sfb;
@@ -1077,10 +1077,10 @@
     }
 
     /* Compute number of scalefactor bands */
-    max_sfb = coderInfo->nr_of_sfb / coderInfo->num_window_groups;
+    max_sfb = coderInfo->sfbn / coderInfo->groups.n;
 
 
-    for (g = 0; g < coderInfo->num_window_groups; g++) {
+    for (g = 0; g < coderInfo->groups.n; g++) {
         band=g*max_sfb;
 
         repeat_counter=1;
@@ -1179,17 +1179,17 @@
     int* scale_factors = coderInfo->scale_factor;
 
     if (coderInfo->block_type == ONLY_SHORT_WINDOW) { /* short windows */
-        nr_of_sfb_per_group = coderInfo->nr_of_sfb/coderInfo->num_window_groups;
+        nr_of_sfb_per_group = coderInfo->sfbn/coderInfo->groups.n;
     } else {
-        nr_of_sfb_per_group = coderInfo->nr_of_sfb;
-        coderInfo->num_window_groups = 1;
-        coderInfo->window_group_length[0] = 1;
+        nr_of_sfb_per_group = coderInfo->sfbn;
+        coderInfo->groups.n = 1;
+        coderInfo->groups.len[0] = 1;
     }
 
     previous_scale_factor = coderInfo->global_gain;
     previous_is_factor = 0;
 
-    for(j=0; j<coderInfo->num_window_groups; j++){
+    for(j=0; j<coderInfo->groups.n; j++){
         for(i=0;i<nr_of_sfb_per_group;i++) {
             /* test to see if any codebooks in a group are zero */
             if ( (coderInfo->book_vector[index]==INTENSITY_HCB) ||
--- a/libfaac/midside.c
+++ b/libfaac/midside.c
@@ -47,7 +47,7 @@
 	if ((coderInfo[chn].block_type == coderInfo[rch].block_type)
 	    && allowms)
 	{
-	  int nsfb = coderInfo[chn].nr_of_sfb;
+            int nsfb = coderInfo[chn].sfbn;
 	  MSInfo *msInfoL = &(channelInfo[chn].msInfo);
 	  MSInfo *msInfoR = &(channelInfo[rch].msInfo);
 	  int sfb;
--- a/libfaac/quantize.c
+++ b/libfaac/quantize.c
@@ -29,28 +29,16 @@
                   AACQuantCfg *aacquantCfg)
 {
   int sfb, start, end, cnt;
-  int last = coderInfo->lastx;
-  int lastsb = 0;
   int *cb_offset = coderInfo->sfb_offset;
-  int num_cb = coderInfo->nr_of_sfb;
+  int last;
   double avgenrg = coderInfo->avgenrg;
   double powm = 0.4;
-  int nullcb;
   double quality = (double)aacquantCfg->quality/DEFQUAL;
 
-  if (coderInfo->block_type == ONLY_SHORT_WINDOW)
-      nullcb = aacquantCfg->max_cbs;
-  else
-      nullcb = aacquantCfg->max_cbl;
+  last = BLOCK_LEN_LONG;
 
-  for (sfb = 0; sfb < num_cb; sfb++)
+  for (sfb = 0; sfb < coderInfo->sfbn; sfb++)
   {
-    if (last > cb_offset[sfb])
-      lastsb = sfb;
-  }
-
-  for (sfb = 0; sfb < nullcb; sfb++)
-  {
     double avge, maxe;
     double target;
 
@@ -57,12 +45,6 @@
     start = cb_offset[sfb];
     end = cb_offset[sfb + 1];
 
-    if (sfb > lastsb)
-    {
-      bandqual[sfb] = 0;
-      continue;
-    }
-
     avge = 0.0;
     maxe = 0.0;
     for (cnt = start; cnt < end; cnt++)
@@ -92,10 +74,6 @@
 
     bandqual[sfb] = target * quality;
   }
-  for (; sfb < num_cb; sfb++)
-  {
-    bandqual[sfb] = 0;
-  }
 }
 
 // use band quality levels to quantize a block
@@ -109,7 +87,7 @@
     // 1.5dB step
     static const double sfstep = 20.0 / 1.5 / log(10);
 
-    for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
+    for (sb = 0; sb < coderInfo->sfbn; sb++)
     {
       double sfacfix;
       int sfac;