changeset 5457:0a5849a4858b libavcodec

use table for converting dynamic range codes to scale factors
author jbr
date Sat, 04 Aug 2007 03:27:05 +0000
parents 2335f18d1b47
children ebe106e3339e
files ac3dec.c
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ac3dec.c	Sat Aug 04 03:21:17 2007 +0000
+++ b/ac3dec.c	Sat Aug 04 03:27:05 2007 +0000
@@ -69,6 +69,9 @@
     5, 6, 7, 8, 9, 10, 11, 12, 14, 16
 };
 
+/** dynamic range table. converts codes to scale factors. */
+static float dynrng_tbl[256];
+
 /* Adjustmens in dB gain */
 #define LEVEL_MINUS_3DB         0.7071067811865476
 #define LEVEL_MINUS_4POINT5DB   0.5946035575013605
@@ -235,6 +238,13 @@
         b5_mantissas[i] = symmetric_dequant(i, 15);
     }
 
+    /* generate dynamic range table
+       reference: Section 7.7.1 Dynamic Range Control */
+    for(i=0; i<256; i++) {
+        int v = (i >> 5) - ((i >> 7) << 3) - 5;
+        dynrng_tbl[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20);
+    }
+
     //generate scale factors
     for (i = 0; i < 25; i++)
         scale_factors[i] = pow(2.0, -i);
@@ -692,7 +702,7 @@
     int bit_alloc_flags = 0;
     int8_t *dexps;
     int mstrcplco, cplcoexp, cplcomant;
-    int dynrng, chbwcod, ngrps, cplabsexp, skipl;
+    int chbwcod, ngrps, cplabsexp, skipl;
 
     for (i = 0; i < nfchans; i++) /*block switch flag */
         ctx->blksw[i] = get_bits1(gb);
@@ -705,16 +715,14 @@
     }
 
     if (get_bits1(gb)) { /* dynamic range */
-        dynrng = get_sbits(gb, 8);
-        ctx->dynrng = (((dynrng & 0x1f) | 0x20) << 13) * pow(2.0, -(18 - (dynrng >> 5)));
+        ctx->dynrng = dynrng_tbl[get_bits(gb, 8)];
     } else if(blk == 0) {
         ctx->dynrng = 1.0;
     }
 
     if(acmod == AC3_ACMOD_DUALMONO) { /* dynamic range 1+1 mode */
         if(get_bits1(gb)) {
-            dynrng = get_sbits(gb, 8);
-            ctx->dynrng2 = (((dynrng & 0x1f) | 0x20) << 13) * pow(2.0, -(18 - (dynrng >> 5)));
+            ctx->dynrng2 = dynrng_tbl[get_bits(gb, 8)];
         } else if(blk == 0) {
             ctx->dynrng2 = 1.0;
         }