diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2007-08-04 03:27:05 +0000 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2007-08-04 03:27:05 +0000 |
commit | 3357ff338b54ed1897443c712fbb52bed5ca48a1 (patch) | |
tree | 810d4096d0ec65e49f55bd85c2458d67c29511bb /libavcodec | |
parent | 5aefe3ebefd7aa4febdda4cb39640603ed15b6a1 (diff) | |
download | ffmpeg-3357ff338b54ed1897443c712fbb52bed5ca48a1.tar.gz |
use table for converting dynamic range codes to scale factors
Originally committed as revision 9889 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/ac3dec.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 63145c3e73..0571b007dc 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -69,6 +69,9 @@ static const uint8_t qntztab[16] = { 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 @@ static void ac3_tables_init(void) 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 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) 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 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) } 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; } |