shithub: aacenc

Download patch

ref: 6800064bf3e2725d164067d9277145f23e47e07e
parent: 38c1ef253431754d1a512b40d0d1ff1f42e98d33
author: corrados <corrados>
date: Mon Jul 12 04:46:43 EDT 2004

VCB11 fixes

--- a/libfaac/aacquant.c
+++ b/libfaac/aacquant.c
@@ -17,7 +17,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: aacquant.c,v 1.30 2004/07/04 12:10:52 corrados Exp $
+ * $Id: aacquant.c,v 1.31 2004/07/12 08:46:43 corrados Exp $
  */
 
 #include <math.h>
@@ -239,7 +239,11 @@
     for(i = 0; i < coderInfo->nr_of_sfb; i++) {
         OutputBits(
             coderInfo,
+#ifdef DRM
+            &coderInfo->book_vector[i], /* needed for VCB11 */
+#else
             coderInfo->book_vector[i],
+#endif
             xi,
             coderInfo->sfb_offset[i],
             coderInfo->sfb_offset[i+1]-coderInfo->sfb_offset[i]);
--- a/libfaac/huffman.c
+++ b/libfaac/huffman.c
@@ -23,7 +23,7 @@
 
 ***********/
 /*
- * $Id: huffman.c,v 1.9 2004/07/04 12:10:52 corrados Exp $
+ * $Id: huffman.c,v 1.10 2004/07/12 08:46:43 corrados Exp $
  */
 
 #include <math.h>
@@ -327,7 +327,11 @@
 }
 
 int OutputBits(CoderInfo *coderInfo,
+#ifdef DRM
+               int *book, /* we need to change book for VCB11 */
+#else
                int book,
+#endif
                int *quant,
                int offset,
                int length)
@@ -367,11 +371,16 @@
 #ifdef DRM
     int* num_data = coderInfo->num_data_cw;
     int cur_cw_len;
+    int max_esc_sequ = 0;
 #endif
 
     counter = coderInfo->spectral_count;
 
+#ifdef DRM
+    switch (*book) {
+#else
     switch (book) {
+#endif
     case 0:
     case INTENSITY_HCB2:
     case INTENSITY_HCB:
@@ -769,6 +778,9 @@
 #ifdef DRM
                 num_data[coderInfo->cur_cw]++;
                 cur_cw_len += len_esc;
+
+                if (esc_sequence > max_esc_sequ)
+                    max_esc_sequ = esc_sequence;
 #endif
 
                 /* then code and transmit the second escape_sequence */
@@ -779,6 +791,9 @@
 #ifdef DRM
                 num_data[coderInfo->cur_cw]++;
                 cur_cw_len += len_esc;
+
+                if (esc_sequence > max_esc_sequ)
+                    max_esc_sequ = esc_sequence;
 #endif
             }
             else if (ABS(quant[i]) >= 16) {  /* the first codeword was above 16, not the second one */
@@ -790,6 +805,9 @@
 #ifdef DRM
                 num_data[coderInfo->cur_cw]++;
                 cur_cw_len += len_esc;
+
+                if (esc_sequence > max_esc_sequ)
+                    max_esc_sequ = esc_sequence;
 #endif
             }
             else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
@@ -801,6 +819,9 @@
 #ifdef DRM
                 num_data[coderInfo->cur_cw]++;
                 cur_cw_len += len_esc;
+
+                if (esc_sequence > max_esc_sequ)
+                    max_esc_sequ = esc_sequence;
 #endif
             }
 #ifdef DRM
@@ -812,6 +833,45 @@
 #endif
         }
         coderInfo->spectral_count = counter;  /* send the current count back to the outside world */
+
+#ifdef DRM
+        /* VCB11: check which codebook should be used using max escape sequence */
+        /* 8.5.3.1.3, table 157 */
+        if (max_esc_sequ <= 15)
+            *book = 16;
+        else if (max_esc_sequ <= 31)
+            *book = 17;
+        else if (max_esc_sequ <= 47)
+            *book = 18;
+        else if (max_esc_sequ <= 63)
+            *book = 19;
+        else if (max_esc_sequ <= 95)
+            *book = 20;
+        else if (max_esc_sequ <= 127)
+            *book = 21;
+        else if (max_esc_sequ <= 159)
+            *book = 22;
+        else if (max_esc_sequ <= 191)
+            *book = 23;
+        else if (max_esc_sequ <= 223)
+            *book = 24;
+        else if (max_esc_sequ <= 255)
+            *book = 25;
+        else if (max_esc_sequ <= 319)
+            *book = 26;
+        else if (max_esc_sequ <= 383)
+            *book = 27;
+        else if (max_esc_sequ <= 511)
+            *book = 28;
+        else if (max_esc_sequ <= 767)
+            *book = 29;
+        else if (max_esc_sequ <= 1023)
+            *book = 30;
+        else if (max_esc_sequ <= 2047)
+            *book = 31;
+        /* else: codebook 11 -> it is already 11 */
+#endif
+
         return(bits);
     }
     return 0;
--- a/libfaac/huffman.h
+++ b/libfaac/huffman.h
@@ -22,7 +22,7 @@
 
 ***********/
 /*
- * $Id: huffman.h,v 1.5 2001/09/04 18:39:36 menno Exp $
+ * $Id: huffman.h,v 1.6 2004/07/12 08:46:43 corrados Exp $
  */
 
 #ifndef HUFFMAN_H
@@ -69,7 +69,11 @@
              int length);
 
 int OutputBits(CoderInfo *coderInfo,
+#ifdef DRM
+               int *book, /* we need to change book for VCB11 */
+#else
                int book,
+#endif
                int *quant,
                int offset,
                int length);