comparison ac3dec.c @ 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 4f010d49bee1
comparison
equal deleted inserted replaced
5456:2335f18d1b47 5457:0a5849a4858b
66 */ 66 */
67 static const uint8_t qntztab[16] = { 67 static const uint8_t qntztab[16] = {
68 0, 3, 5, 7, 11, 15, 68 0, 3, 5, 7, 11, 15,
69 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 69 5, 6, 7, 8, 9, 10, 11, 12, 14, 16
70 }; 70 };
71
72 /** dynamic range table. converts codes to scale factors. */
73 static float dynrng_tbl[256];
71 74
72 /* Adjustmens in dB gain */ 75 /* Adjustmens in dB gain */
73 #define LEVEL_MINUS_3DB 0.7071067811865476 76 #define LEVEL_MINUS_3DB 0.7071067811865476
74 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605 77 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605
75 #define LEVEL_MINUS_6DB 0.5000000000000000 78 #define LEVEL_MINUS_6DB 0.5000000000000000
233 for(i=0; i<15; i++) { 236 for(i=0; i<15; i++) {
234 /* bap=5 mantissas */ 237 /* bap=5 mantissas */
235 b5_mantissas[i] = symmetric_dequant(i, 15); 238 b5_mantissas[i] = symmetric_dequant(i, 15);
236 } 239 }
237 240
241 /* generate dynamic range table
242 reference: Section 7.7.1 Dynamic Range Control */
243 for(i=0; i<256; i++) {
244 int v = (i >> 5) - ((i >> 7) << 3) - 5;
245 dynrng_tbl[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20);
246 }
247
238 //generate scale factors 248 //generate scale factors
239 for (i = 0; i < 25; i++) 249 for (i = 0; i < 25; i++)
240 scale_factors[i] = pow(2.0, -i); 250 scale_factors[i] = pow(2.0, -i);
241 251
242 /* generate exponent tables 252 /* generate exponent tables
690 int i, bnd, seg, grpsize, ch; 700 int i, bnd, seg, grpsize, ch;
691 GetBitContext *gb = &ctx->gb; 701 GetBitContext *gb = &ctx->gb;
692 int bit_alloc_flags = 0; 702 int bit_alloc_flags = 0;
693 int8_t *dexps; 703 int8_t *dexps;
694 int mstrcplco, cplcoexp, cplcomant; 704 int mstrcplco, cplcoexp, cplcomant;
695 int dynrng, chbwcod, ngrps, cplabsexp, skipl; 705 int chbwcod, ngrps, cplabsexp, skipl;
696 706
697 for (i = 0; i < nfchans; i++) /*block switch flag */ 707 for (i = 0; i < nfchans; i++) /*block switch flag */
698 ctx->blksw[i] = get_bits1(gb); 708 ctx->blksw[i] = get_bits1(gb);
699 709
700 ctx->dither_all = 1; 710 ctx->dither_all = 1;
703 if(!ctx->dithflag[i]) 713 if(!ctx->dithflag[i])
704 ctx->dither_all = 0; 714 ctx->dither_all = 0;
705 } 715 }
706 716
707 if (get_bits1(gb)) { /* dynamic range */ 717 if (get_bits1(gb)) { /* dynamic range */
708 dynrng = get_sbits(gb, 8); 718 ctx->dynrng = dynrng_tbl[get_bits(gb, 8)];
709 ctx->dynrng = (((dynrng & 0x1f) | 0x20) << 13) * pow(2.0, -(18 - (dynrng >> 5)));
710 } else if(blk == 0) { 719 } else if(blk == 0) {
711 ctx->dynrng = 1.0; 720 ctx->dynrng = 1.0;
712 } 721 }
713 722
714 if(acmod == AC3_ACMOD_DUALMONO) { /* dynamic range 1+1 mode */ 723 if(acmod == AC3_ACMOD_DUALMONO) { /* dynamic range 1+1 mode */
715 if(get_bits1(gb)) { 724 if(get_bits1(gb)) {
716 dynrng = get_sbits(gb, 8); 725 ctx->dynrng2 = dynrng_tbl[get_bits(gb, 8)];
717 ctx->dynrng2 = (((dynrng & 0x1f) | 0x20) << 13) * pow(2.0, -(18 - (dynrng >> 5)));
718 } else if(blk == 0) { 726 } else if(blk == 0) {
719 ctx->dynrng2 = 1.0; 727 ctx->dynrng2 = 1.0;
720 } 728 }
721 } 729 }
722 730