comparison ac3dec.c @ 6032:f74202e7e896 libavcodec

Skip dialog normalization. It shouldn't be used by the decoder, and there is not currently a clean way to pass the value to the user.
author jbr
date Mon, 17 Dec 2007 01:09:00 +0000
parents 9d3f52380cb3
children 2f9c17454842
comparison
equal deleted inserted replaced
6031:9d3f52380cb3 6032:f74202e7e896
71 }; 71 };
72 72
73 /** dynamic range table. converts codes to scale factors. */ 73 /** dynamic range table. converts codes to scale factors. */
74 static float dynamic_range_tab[256]; 74 static float dynamic_range_tab[256];
75 75
76 /** dialog normalization table */
77 static float dialog_norm_tab[32];
78
79 /** Adjustments in dB gain */ 76 /** Adjustments in dB gain */
80 #define LEVEL_MINUS_3DB 0.7071067811865476 77 #define LEVEL_MINUS_3DB 0.7071067811865476
81 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605 78 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605
82 #define LEVEL_MINUS_6DB 0.5000000000000000 79 #define LEVEL_MINUS_6DB 0.5000000000000000
83 #define LEVEL_MINUS_9DB 0.3535533905932738 80 #define LEVEL_MINUS_9DB 0.3535533905932738
159 int lfe_ch; ///< index of LFE channel 156 int lfe_ch; ///< index of LFE channel
160 int output_mode; ///< output channel configuration 157 int output_mode; ///< output channel configuration
161 int out_channels; ///< number of output channels 158 int out_channels; ///< number of output channels
162 159
163 float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients 160 float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients
164 float dialog_norm[2]; ///< dialog normalization
165 float dynamic_range[2]; ///< dynamic range 161 float dynamic_range[2]; ///< dynamic range
166 float cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates 162 float cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates
167 int num_cpl_bands; ///< number of coupling bands 163 int num_cpl_bands; ///< number of coupling bands
168 int num_cpl_subbands; ///< number of coupling sub bands 164 int num_cpl_subbands; ///< number of coupling sub bands
169 int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin 165 int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin
273 reference: Section 7.7.1 Dynamic Range Control */ 269 reference: Section 7.7.1 Dynamic Range Control */
274 for(i=0; i<256; i++) { 270 for(i=0; i<256; i++) {
275 int v = (i >> 5) - ((i >> 7) << 3) - 5; 271 int v = (i >> 5) - ((i >> 7) << 3) - 5;
276 dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); 272 dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20);
277 } 273 }
278
279 /* generate dialog normalization table
280 references: Section 5.4.2.8 dialnorm
281 Section 7.6 Dialogue Normalization */
282 for(i=1; i<32; i++) {
283 dialog_norm_tab[i] = expf((i-31) * M_LN10 / 20.0f);
284 }
285 dialog_norm_tab[0] = dialog_norm_tab[31];
286 274
287 /* generate scale factors for exponents and asymmetrical dequantization 275 /* generate scale factors for exponents and asymmetrical dequantization
288 reference: Section 7.3.2 Expansion of Mantissas for Asymmetric Quantization */ 276 reference: Section 7.3.2 Expansion of Mantissas for Asymmetric Quantization */
289 for (i = 0; i < 25; i++) 277 for (i = 0; i < 25; i++)
290 scale_factors[i] = pow(2.0, -i); 278 scale_factors[i] = pow(2.0, -i);
380 skip_bits1(gb); // skip lfeon 368 skip_bits1(gb); // skip lfeon
381 369
382 /* read the rest of the bsi. read twice for dual mono mode. */ 370 /* read the rest of the bsi. read twice for dual mono mode. */
383 i = !(ctx->channel_mode); 371 i = !(ctx->channel_mode);
384 do { 372 do {
385 ctx->dialog_norm[i] = dialog_norm_tab[get_bits(gb, 5)]; // dialog normalization 373 skip_bits(gb, 5); // skip dialog normalization
386 if (get_bits1(gb)) 374 if (get_bits1(gb))
387 skip_bits(gb, 8); //skip compression 375 skip_bits(gb, 8); //skip compression
388 if (get_bits1(gb)) 376 if (get_bits1(gb))
389 skip_bits(gb, 8); //skip language code 377 skip_bits(gb, 8); //skip language code
390 if (get_bits1(gb)) 378 if (get_bits1(gb))
1047 1035
1048 /* recover coefficients if rematrixing is in use */ 1036 /* recover coefficients if rematrixing is in use */
1049 if(ctx->channel_mode == AC3_CHMODE_STEREO) 1037 if(ctx->channel_mode == AC3_CHMODE_STEREO)
1050 do_rematrixing(ctx); 1038 do_rematrixing(ctx);
1051 1039
1052 /* apply scaling to coefficients (headroom, dialnorm, dynrng) */ 1040 /* apply scaling to coefficients (headroom, dynrng) */
1053 for(ch=1; ch<=ctx->channels; ch++) { 1041 for(ch=1; ch<=ctx->channels; ch++) {
1054 float gain = 2.0f * ctx->mul_bias; 1042 float gain = 2.0f * ctx->mul_bias;
1055 if(ctx->channel_mode == AC3_CHMODE_DUALMONO) { 1043 if(ctx->channel_mode == AC3_CHMODE_DUALMONO) {
1056 gain *= ctx->dialog_norm[ch-1] * ctx->dynamic_range[ch-1]; 1044 gain *= ctx->dynamic_range[ch-1];
1057 } else { 1045 } else {
1058 gain *= ctx->dialog_norm[0] * ctx->dynamic_range[0]; 1046 gain *= ctx->dynamic_range[0];
1059 } 1047 }
1060 for(i=0; i<ctx->end_freq[ch]; i++) { 1048 for(i=0; i<ctx->end_freq[ch]; i++) {
1061 ctx->transform_coeffs[ch][i] *= gain; 1049 ctx->transform_coeffs[ch][i] *= gain;
1062 } 1050 }
1063 } 1051 }