[FFmpeg-soc] [soc]: r523 - in eac3: ac3tab.c ac3tab.h eac3.h eac3_parser.c

bwolowiec subversion at mplayerhq.hu
Tue Jul 24 15:11:57 CEST 2007


Author: bwolowiec
Date: Tue Jul 24 15:11:57 2007
New Revision: 523

Log:
Add Vector Quantization and Gain Adaptive Quantization.


Modified:
   eac3/ac3tab.c
   eac3/ac3tab.h
   eac3/eac3.h
   eac3/eac3_parser.c

Modified: eac3/ac3tab.c
==============================================================================
--- eac3/ac3tab.c	(original)
+++ eac3/ac3tab.c	Tue Jul 24 15:11:57 2007
@@ -228,6 +228,11 @@ const uint8_t ff_ac3_baptab[64]= {
     15, 15, 15, 15,
 };
 
+const uint8_t ff_bits_vs_hebap[20] = {
+    0,  2,  3,  4,  5,  7,  8,  9,  3,  4,
+    5,  6,  7,  8,  9, 10, 11, 12, 14, 16,
+};
+
 const uint8_t ff_sdecaytab[4]={
     0x0f, 0x11, 0x13, 0x15,
 };
@@ -273,6 +278,49 @@ const uint8_t ff_eac3_blocks[4] = {
 
 const uint8_t ff_nfchans_tbl[8] = { 2, 1, 2, 3, 3, 4, 4, 5 };
 
+/**
+ * Table E3.6
+ * Large mantissa inverse quantization (remapping) constants
+ * ff_eac3_gaq_remap[hebap+8][x<0,x>=0][Gk=1,2,4][a,b]
+ */
+const int16_t ff_eac3_gaq_remap[12][2][3][2] = {
+{{{   4681,       0}, { -10923,   16384}, {  -4681,    8192}},
+ {{   4681,       0}, { -10923,   -5461}, {  -4681,   -1170}}},
+{{{   2185,       0}, { -14043,   16384}, {  -6554,    8192}},
+ {{   2185,       0}, { -14043,  -11703}, {  -6554,   -4915}}},
+{{{   1057,       0}, { -15292,   16384}, {  -7399,    8192}},
+ {{   1057,       0}, { -15292,  -14199}, {  -7399,   -6606}}},
+{{{    520,       0}, { -15855,   16384}, {  -7802,    8192}},
+ {{    520,       0}, { -15855,  -15327}, {  -7802,   -7412}}},
+{{{    258,       0}, { -16124,   16384}, {  -7998,    8192}},
+ {{    258,       0}, { -16124,  -15864}, {  -7998,   -7805}}},
+{{{    129,       0}, { -16255,   16384}, {  -8096,    8192}},
+ {{    129,       0}, { -16255,  -16126}, {  -8096,   -7999}}},
+{{{     64,       0}, { -16320,   16384}, {  -8144,    8192}},
+ {{     64,       0}, { -16320,  -16255}, {  -8144,   -8096}}},
+{{{     32,       0}, { -16352,   16384}, {  -8168,    8192}},
+ {{     32,       0}, { -16352,  -16320}, {  -8168,   -8144}}},
+{{{     16,       0}, { -16368,   16384}, {  -8180,    8192}},
+ {{     16,       0}, { -16368,  -16352}, {  -8180,   -8168}}},
+{{{      8,       0}, {      0,       0}, {      0,       0}},
+ {{      8,       0}, {      0,       0}, {      0,       0}}},
+{{{      2,       0}, {      0,       0}, {      0,       0}},
+ {{      2,       0}, {      0,       0}, {      0,       0}}},
+{{{      0,       0}, {      0,       0}, {      0,       0}},
+ {{      0,       0}, {      0,       0}, {      0,       0}}},
+};
+
+/**
+ * Map GAQ mode and gaqgain to Gk
+ * Gk = 1 << ff_gaq_gk[GAQ Mode][gaqgain]
+ */
+const uint8_t ff_gaq_gk[4][3]={
+    {0, 0, 0},
+    {0, 1, 0},
+    {0, 2, 0},
+    {0, 1, 2}
+};
+
 const int16_t ff_vq_hebap1[4][6] = {
 {   7167,    4739,    1106,    4269,   10412,    4820},
 {  -5702,   -3187,  -14483,   -1392,   -2027,     849},
@@ -1242,3 +1290,15 @@ const int16_t ff_vq_hebap7[512][6] = {
 {  19067,   17630,   17929,  -10654,   10928,   -4958},
 {   3231,   -3284,   27336,    4174,   -1683,     497},
 };
+
+const int16_t (*ff_vq_hebap[8])[6] = {
+    NULL,
+    ff_vq_hebap1,
+    ff_vq_hebap2,
+    ff_vq_hebap3,
+    ff_vq_hebap4,
+    ff_vq_hebap5,
+    ff_vq_hebap6,
+    ff_vq_hebap7,
+};
+

Modified: eac3/ac3tab.h
==============================================================================
--- eac3/ac3tab.h	(original)
+++ eac3/ac3tab.h	Tue Jul 24 15:11:57 2007
@@ -43,6 +43,9 @@ extern const uint8_t  ff_ac3_bndsz[50];
 extern const uint8_t  ff_qntztab[16];
 extern const uint8_t ff_nfchans_tbl[8];
 extern const uint8_t ff_eac3_blocks[4];
+extern const uint8_t ff_bits_vs_hebap[20];
+extern const int16_t ff_eac3_gaq_remap[12][2][3][2];
+extern const uint8_t ff_gaq_gk[4][3];
 
 extern const int16_t ff_vq_hebap1[4][6];
 extern const int16_t ff_vq_hebap2[8][6];
@@ -51,6 +54,7 @@ extern const int16_t ff_vq_hebap4[32][6]
 extern const int16_t ff_vq_hebap5[128][6];
 extern const int16_t ff_vq_hebap6[256][6];
 extern const int16_t ff_vq_hebap7[512][6];
+extern const int16_t (*ff_vq_hebap[8])[6];
 
 
 #endif /* AC3TAB_H */

Modified: eac3/eac3.h
==============================================================================
--- eac3/eac3.h	(original)
+++ eac3/eac3.h	Tue Jul 24 15:11:57 2007
@@ -269,7 +269,7 @@ typedef struct EAC3Context{
 //    int chmant[MAX_CHANNELS][TODO_SIZE];
     int chgaqmod[MAX_CHANNELS];                 ///< Channel gain adaptive quantization mode
     int chgaqgain[MAX_CHANNELS][TODO_SIZE];     ///< Channel gain adaptive quantization gain
-    int pre_chmant[6][MAX_CHANNELS][TODO_SIZE]; ///< Pre channel mantissas
+    float pre_chmant[6][MAX_CHANNELS][TODO_SIZE];///< Pre channel mantissas
     int cplmant[TODO_SIZE]; // cplmant          ///< Coupling mantisass
     int cplgaqmod;                              ///< Coupling channel gain adaptive quantization mode
     int cplgaqgain[TODO_SIZE];                  ///< Coupling gain adaptive quantization gain

Modified: eac3/eac3_parser.c
==============================================================================
--- eac3/eac3_parser.c	(original)
+++ eac3/eac3_parser.c	Tue Jul 24 15:11:57 2007
@@ -28,8 +28,10 @@
 
 #ifdef DEBUG
 #define GET_BITS(a, gbc, n) a = get_bits(gbc, n); av_log(NULL, AV_LOG_INFO, "%s: %i\n", __STRING(a), a)
+#define GET_SBITS(a, gbc, n) a = get_sbits(gbc, n); av_log(NULL, AV_LOG_INFO, "%s: %i\n", __STRING(a), a)
 #else
 #define GET_BITS(a, gbc, n) a = get_bits(gbc, n)
+#define GET_SBITS(a, gbc, n) a = get_sbits(gbc, n)
 #endif //DEBUG
 
 #include "eac3.h"
@@ -1213,7 +1215,9 @@ int ff_eac3_parse_audblk(GetBitContext *
         }
         else if(s->chahtinu[ch] == 1)
         {
-            int endbap, bin, n;
+            int endbap, bin, n, m;
+            int bg, g, bits, pre_chmant, remap;
+            float mant;
 
             av_log(s->avctx, AV_LOG_INFO,  "AHT NOT TESTED");
 
@@ -1263,28 +1267,94 @@ int ff_eac3_parse_audblk(GetBitContext *
             }
             else if(s->chgaqmod[ch] == 0x3)
             {
+                int grpgain;
                 for(n = 0; n < s->chgaqsections[ch]; n++) {
-                    GET_BITS(s->chgaqgain[ch][n], gbc, 5);
+                    GET_BITS(grpgain, gbc, 5);
+                    s->chgaqgain[ch][3*n]   = grpgain/9;
+                    s->chgaqgain[ch][3*n+1] = (grpgain%9)/3;
+                    s->chgaqgain[ch][3*n+2] = grpgain%3;
                 }
             }
 
-            // TODO add VQ and GAQ
-#if 0
+            // TODO test VQ and GAQ
+            m=0;
             for(bin = 0; bin < s->nchmant[ch]; bin++)
             {
-                if(s->chgaqbin[ch][bin]>0) // XXX !=0, >0 ?
+                if(s->chgaqbin[ch][bin]!=0)
                 {
-                    for(n = 0; n < 6; n++) {
-                        GET_BITS(s->pre_chmant[n][ch][bin], gbc, (0-16)); // TODO 0-16 :]
+                    // GAQ (E3.3.4.2)
+                    // XXX what about gaqmod = 0 ?
+                    // difference between Gk=1 and gaqmod=0 ?
+                    if(s->chgaqbin[ch][bin]>0){
+                        // hebap in active range
+                        // Gk = 1<<bg
+                        bg = ff_gaq_gk[s->chgaqmod[ch]][s->chgaqgain[ch][m++]];
+                    }else{
+                        bg = 0;
+                    }
+                    bits = ff_bits_vs_hebap[s->hebap[ch][bin]];
+
+                    for(n = 0; n < 6; n++){
+                        // pre_chmant[n][ch][bin]
+                        GET_SBITS(pre_chmant, gbc, bits-bg);
+                        if(s->chgaqbin[ch][bin]>0 && bg && pre_chmant == -(1<<(bits-bg-1))){
+                            // large mantissa
+                            GET_SBITS(pre_chmant, gbc, bits - ((bg==1)?1:0));
+                            mant = (float) pre_chmant / (1<<(bits - ((bg==1)?2:1)));
+                            g = 0;
+                            remap = 1;
+                        }else{
+                            // small mantissa
+                            mant = (float) pre_chmant / (1<<(bits-bg-1));
+                            g = bg;
+                            remap = bg?0:1;
+                        }
+
+                        //TODO when remap needed ?
+                        if(remap){
+                            if(mant>=0){
+                                mant = (float)
+                                    ((ff_eac3_gaq_remap[s->hebap[ch][bin]-8][0][g][0] + 1.0f)
+                                     * mant / (1<<g) +
+                                     ff_eac3_gaq_remap[s->hebap[ch][bin]-8][0][g][1]) / 32768.0f;
+                            }else{
+                                mant = (float)
+                                    ((ff_eac3_gaq_remap[s->hebap[ch][bin]-8][1][g][0] + 1.0f)
+                                     * mant / (1<<g) +
+                                     ff_eac3_gaq_remap[s->hebap[ch][bin]-8][1][g][1]) / 32768.0f;
+                            }
+                        }
+                        s->pre_chmant[n][ch][bin] = mant;
                     }
                 }
                 else {
-                    GET_BITS(s->pre_chmant[0][ch][bin], gbc, (0-9)); //  TODO 0-9 :]
+                    // hebap = 0 or VQ
+                    if(s->hebap[ch][bin]){
+                        GET_BITS(pre_chmant, gbc, ff_bits_vs_hebap[s->hebap[ch][bin]]);
+                        for(n = 0; n < 6; n++){
+                            s->pre_chmant[n][ch][bin] = ff_vq_hebap[s->hebap[ch][bin]][pre_chmant][n];
+                        }
+                    }else{
+                        for(n = 0; n < 6; n++){
+                            s->pre_chmant[n][ch][bin] = 0;
+                        }
+                    }
                 }
             }
-#endif
             s->chahtinu[ch] = -1; /* AHT info for this frame has been read ? do not read again */
         }
+        if(s->chahtinu[ch] != 0){
+            // TODO fast DCT
+            int bin;
+            float tmp;
+            for(bin=0; bin<s->nchmant[ch]; bin++){
+                tmp = 0;
+                for(i=0; i<6; i++){
+                    tmp += (i?sqrt(2):1) * s->pre_chmant[i][ch][bin] * cos(M_PI*i*(2*blk + 1)/12);
+                }
+                s->transform_coeffs[ch][bin] = tmp;
+            }
+        }
         if(s->cplinu[blk] && s->chincpl[ch] && !got_cplchan)
         {
             av_log(s->avctx, AV_LOG_ERROR,  "NOT IMPLEMENTED");



More information about the FFmpeg-soc mailing list