Mercurial > libavcodec.hg
comparison ac3dec.c @ 5495:15c6ea63cb62 libavcodec
add dialogue normalization
author | jbr |
---|---|
date | Sun, 05 Aug 2007 19:36:35 +0000 |
parents | 930bca6dd95f |
children | 377e9152aa9b |
comparison
equal
deleted
inserted
replaced
5494:c2512a13877e | 5495:15c6ea63cb62 |
---|---|
70 }; | 70 }; |
71 | 71 |
72 /** dynamic range table. converts codes to scale factors. */ | 72 /** dynamic range table. converts codes to scale factors. */ |
73 static float dynrng_tbl[256]; | 73 static float dynrng_tbl[256]; |
74 | 74 |
75 /** dialogue normalization table */ | |
76 static float dialnorm_tbl[32]; | |
77 | |
75 /* Adjustmens in dB gain */ | 78 /* Adjustmens in dB gain */ |
76 #define LEVEL_MINUS_3DB 0.7071067811865476 | 79 #define LEVEL_MINUS_3DB 0.7071067811865476 |
77 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605 | 80 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605 |
78 #define LEVEL_MINUS_6DB 0.5000000000000000 | 81 #define LEVEL_MINUS_6DB 0.5000000000000000 |
79 #define LEVEL_MINUS_9DB 0.3535533905932738 | 82 #define LEVEL_MINUS_9DB 0.3535533905932738 |
157 int lfe_ch; ///< index of LFE channel | 160 int lfe_ch; ///< index of LFE channel |
158 int output_mode; ///< output channel configuration | 161 int output_mode; ///< output channel configuration |
159 int out_channels; ///< number of output channels | 162 int out_channels; ///< number of output channels |
160 | 163 |
161 float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients | 164 float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients |
165 float dialnorm[2]; ///< dialogue normalization | |
162 float dynrng; //dynamic range gain | 166 float dynrng; //dynamic range gain |
163 float dynrng2; //dynamic range gain for 1+1 mode | 167 float dynrng2; //dynamic range gain for 1+1 mode |
164 float cplco[AC3_MAX_CHANNELS][18]; //coupling coordinates | 168 float cplco[AC3_MAX_CHANNELS][18]; //coupling coordinates |
165 int ncplbnd; //number of coupling bands | 169 int ncplbnd; //number of coupling bands |
166 int ncplsubnd; //number of coupling sub bands | 170 int ncplsubnd; //number of coupling sub bands |
266 reference: Section 7.7.1 Dynamic Range Control */ | 270 reference: Section 7.7.1 Dynamic Range Control */ |
267 for(i=0; i<256; i++) { | 271 for(i=0; i<256; i++) { |
268 int v = (i >> 5) - ((i >> 7) << 3) - 5; | 272 int v = (i >> 5) - ((i >> 7) << 3) - 5; |
269 dynrng_tbl[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); | 273 dynrng_tbl[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); |
270 } | 274 } |
275 | |
276 /* generate dialogue normalization table | |
277 references: Section 5.4.2.8 dialnorm | |
278 Section 7.6 Dialogue Normalization */ | |
279 for(i=1; i<32; i++) { | |
280 dialnorm_tbl[i] = expf((i-31) * M_LN10 / 20.0f); | |
281 } | |
282 dialnorm_tbl[0] = dialnorm_tbl[31]; | |
271 | 283 |
272 //generate scale factors | 284 //generate scale factors |
273 for (i = 0; i < 25; i++) | 285 for (i = 0; i < 25; i++) |
274 scale_factors[i] = pow(2.0, -i); | 286 scale_factors[i] = pow(2.0, -i); |
275 | 287 |
360 skip_bits1(gb); // skip lfeon | 372 skip_bits1(gb); // skip lfeon |
361 | 373 |
362 /* read the rest of the bsi. read twice for dual mono mode. */ | 374 /* read the rest of the bsi. read twice for dual mono mode. */ |
363 i = !(ctx->acmod); | 375 i = !(ctx->acmod); |
364 do { | 376 do { |
365 skip_bits(gb, 5); //skip dialog normalization | 377 ctx->dialnorm[i] = dialnorm_tbl[get_bits(gb, 5)]; // dialogue normalization |
366 if (get_bits1(gb)) | 378 if (get_bits1(gb)) |
367 skip_bits(gb, 8); //skip compression | 379 skip_bits(gb, 8); //skip compression |
368 if (get_bits1(gb)) | 380 if (get_bits1(gb)) |
369 skip_bits(gb, 8); //skip language code | 381 skip_bits(gb, 8); //skip language code |
370 if (get_bits1(gb)) | 382 if (get_bits1(gb)) |
1005 | 1017 |
1006 /* recover coefficients if rematrixing is in use */ | 1018 /* recover coefficients if rematrixing is in use */ |
1007 if(ctx->acmod == AC3_ACMOD_STEREO) | 1019 if(ctx->acmod == AC3_ACMOD_STEREO) |
1008 do_rematrixing(ctx); | 1020 do_rematrixing(ctx); |
1009 | 1021 |
1010 /* apply scaling to coefficients (headroom, dynrng) */ | 1022 /* apply scaling to coefficients (headroom, dialnorm, dynrng) */ |
1011 for(ch=1; ch<=ctx->nchans; ch++) { | 1023 for(ch=1; ch<=ctx->nchans; ch++) { |
1012 float gain = 2.0f * ctx->mul_bias; | 1024 float gain = 2.0f * ctx->mul_bias; |
1013 if(ctx->acmod == AC3_ACMOD_DUALMONO && ch == 2) { | 1025 if(ctx->acmod == AC3_ACMOD_DUALMONO && ch == 2) { |
1014 gain *= ctx->dynrng2; | 1026 gain *= ctx->dialnorm[ch-1] * ctx->dynrng2; |
1015 } else { | 1027 } else { |
1016 gain *= ctx->dynrng; | 1028 gain *= ctx->dialnorm[0] * ctx->dynrng; |
1017 } | 1029 } |
1018 for(i=0; i<ctx->endmant[ch]; i++) { | 1030 for(i=0; i<ctx->endmant[ch]; i++) { |
1019 ctx->transform_coeffs[ch][i] *= gain; | 1031 ctx->transform_coeffs[ch][i] *= gain; |
1020 } | 1032 } |
1021 } | 1033 } |