Signed-off-by: Justin Ruggles <justin.ruggles@gmail.com>
Chris Berov authored on 2011/12/03 00:46:01... | ... |
@@ -44,7 +44,6 @@ |
44 | 44 |
*/ |
45 | 45 |
static uint8_t ungroup_3_in_7_bits_tab[128][3]; |
46 | 46 |
|
47 |
- |
|
48 | 47 |
/** tables for ungrouping mantissas */ |
49 | 48 |
static int b1_mantissas[32][3]; |
50 | 49 |
static int b2_mantissas[128][3]; |
... | ... |
@@ -124,7 +123,7 @@ static av_cold void ac3_tables_init(void) |
124 | 124 |
|
125 | 125 |
/* generate table for ungrouping 3 values in 7 bits |
126 | 126 |
reference: Section 7.1.3 Exponent Decoding */ |
127 |
- for(i=0; i<128; i++) { |
|
127 |
+ for (i = 0; i < 128; i++) { |
|
128 | 128 |
ungroup_3_in_7_bits_tab[i][0] = i / 25; |
129 | 129 |
ungroup_3_in_7_bits_tab[i][1] = (i % 25) / 5; |
130 | 130 |
ungroup_3_in_7_bits_tab[i][2] = (i % 25) % 5; |
... | ... |
@@ -132,13 +131,13 @@ static av_cold void ac3_tables_init(void) |
132 | 132 |
|
133 | 133 |
/* generate grouped mantissa tables |
134 | 134 |
reference: Section 7.3.5 Ungrouping of Mantissas */ |
135 |
- for(i=0; i<32; i++) { |
|
135 |
+ for (i = 0; i < 32; i++) { |
|
136 | 136 |
/* bap=1 mantissas */ |
137 | 137 |
b1_mantissas[i][0] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][0], 3); |
138 | 138 |
b1_mantissas[i][1] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][1], 3); |
139 | 139 |
b1_mantissas[i][2] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][2], 3); |
140 | 140 |
} |
141 |
- for(i=0; i<128; i++) { |
|
141 |
+ for (i = 0; i < 128; i++) { |
|
142 | 142 |
/* bap=2 mantissas */ |
143 | 143 |
b2_mantissas[i][0] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][0], 5); |
144 | 144 |
b2_mantissas[i][1] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][1], 5); |
... | ... |
@@ -150,24 +149,23 @@ static av_cold void ac3_tables_init(void) |
150 | 150 |
} |
151 | 151 |
/* generate ungrouped mantissa tables |
152 | 152 |
reference: Tables 7.21 and 7.23 */ |
153 |
- for(i=0; i<7; i++) { |
|
153 |
+ for (i = 0; i < 7; i++) { |
|
154 | 154 |
/* bap=3 mantissas */ |
155 | 155 |
b3_mantissas[i] = symmetric_dequant(i, 7); |
156 | 156 |
} |
157 |
- for(i=0; i<15; i++) { |
|
157 |
+ for (i = 0; i < 15; i++) { |
|
158 | 158 |
/* bap=5 mantissas */ |
159 | 159 |
b5_mantissas[i] = symmetric_dequant(i, 15); |
160 | 160 |
} |
161 | 161 |
|
162 | 162 |
/* generate dynamic range table |
163 | 163 |
reference: Section 7.7.1 Dynamic Range Control */ |
164 |
- for(i=0; i<256; i++) { |
|
164 |
+ for (i = 0; i < 256; i++) { |
|
165 | 165 |
int v = (i >> 5) - ((i >> 7) << 3) - 5; |
166 | 166 |
dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); |
167 | 167 |
} |
168 | 168 |
} |
169 | 169 |
|
170 |
- |
|
171 | 170 |
/** |
172 | 171 |
* AVCodec initialization |
173 | 172 |
*/ |
... | ... |
@@ -250,7 +248,7 @@ static int ac3_parse_header(AC3DecodeContext *s) |
250 | 250 |
i = get_bits(gbc, 6); |
251 | 251 |
do { |
252 | 252 |
skip_bits(gbc, 8); |
253 |
- } while(i--); |
|
253 |
+ } while (i--); |
|
254 | 254 |
} |
255 | 255 |
|
256 | 256 |
return 0; |
... | ... |
@@ -265,7 +263,7 @@ static int parse_frame_header(AC3DecodeContext *s) |
265 | 265 |
int err; |
266 | 266 |
|
267 | 267 |
err = avpriv_ac3_parse_header(&s->gbc, &hdr); |
268 |
- if(err) |
|
268 |
+ if (err) |
|
269 | 269 |
return err; |
270 | 270 |
|
271 | 271 |
/* get decoding parameters from header info */ |
... | ... |
@@ -287,9 +285,9 @@ static int parse_frame_header(AC3DecodeContext *s) |
287 | 287 |
s->frame_type = hdr.frame_type; |
288 | 288 |
s->substreamid = hdr.substreamid; |
289 | 289 |
|
290 |
- if(s->lfe_on) { |
|
291 |
- s->start_freq[s->lfe_ch] = 0; |
|
292 |
- s->end_freq[s->lfe_ch] = 7; |
|
290 |
+ if (s->lfe_on) { |
|
291 |
+ s->start_freq[s->lfe_ch] = 0; |
|
292 |
+ s->end_freq[s->lfe_ch] = 7; |
|
293 | 293 |
s->num_exp_groups[s->lfe_ch] = 2; |
294 | 294 |
s->channel_in_cpl[s->lfe_ch] = 0; |
295 | 295 |
} |
... | ... |
@@ -326,38 +324,39 @@ static void set_downmix_coeffs(AC3DecodeContext *s) |
326 | 326 |
float smix = gain_levels[surround_levels[s->surround_mix_level]]; |
327 | 327 |
float norm0, norm1; |
328 | 328 |
|
329 |
- for(i=0; i<s->fbw_channels; i++) { |
|
329 |
+ for (i = 0; i < s->fbw_channels; i++) { |
|
330 | 330 |
s->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]]; |
331 | 331 |
s->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]]; |
332 | 332 |
} |
333 |
- if(s->channel_mode > 1 && s->channel_mode & 1) { |
|
333 |
+ if (s->channel_mode > 1 && s->channel_mode & 1) { |
|
334 | 334 |
s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = cmix; |
335 | 335 |
} |
336 |
- if(s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) { |
|
336 |
+ if (s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) { |
|
337 | 337 |
int nf = s->channel_mode - 2; |
338 | 338 |
s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = smix * LEVEL_MINUS_3DB; |
339 | 339 |
} |
340 |
- if(s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) { |
|
340 |
+ if (s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) { |
|
341 | 341 |
int nf = s->channel_mode - 4; |
342 | 342 |
s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = smix; |
343 | 343 |
} |
344 | 344 |
|
345 | 345 |
/* renormalize */ |
346 | 346 |
norm0 = norm1 = 0.0; |
347 |
- for(i=0; i<s->fbw_channels; i++) { |
|
347 |
+ for (i = 0; i < s->fbw_channels; i++) { |
|
348 | 348 |
norm0 += s->downmix_coeffs[i][0]; |
349 | 349 |
norm1 += s->downmix_coeffs[i][1]; |
350 | 350 |
} |
351 | 351 |
norm0 = 1.0f / norm0; |
352 | 352 |
norm1 = 1.0f / norm1; |
353 |
- for(i=0; i<s->fbw_channels; i++) { |
|
353 |
+ for (i = 0; i < s->fbw_channels; i++) { |
|
354 | 354 |
s->downmix_coeffs[i][0] *= norm0; |
355 | 355 |
s->downmix_coeffs[i][1] *= norm1; |
356 | 356 |
} |
357 | 357 |
|
358 |
- if(s->output_mode == AC3_CHMODE_MONO) { |
|
359 |
- for(i=0; i<s->fbw_channels; i++) |
|
360 |
- s->downmix_coeffs[i][0] = (s->downmix_coeffs[i][0] + s->downmix_coeffs[i][1]) * LEVEL_MINUS_3DB; |
|
358 |
+ if (s->output_mode == AC3_CHMODE_MONO) { |
|
359 |
+ for (i = 0; i < s->fbw_channels; i++) |
|
360 |
+ s->downmix_coeffs[i][0] = (s->downmix_coeffs[i][0] + |
|
361 |
+ s->downmix_coeffs[i][1]) * LEVEL_MINUS_3DB; |
|
361 | 362 |
} |
362 | 363 |
} |
363 | 364 |
|
... | ... |
@@ -374,7 +373,7 @@ static int decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps, |
374 | 374 |
|
375 | 375 |
/* unpack groups */ |
376 | 376 |
group_size = exp_strategy + (exp_strategy == EXP_D45); |
377 |
- for(grp=0,i=0; grp<ngrps; grp++) { |
|
377 |
+ for (grp = 0, i = 0; grp < ngrps; grp++) { |
|
378 | 378 |
expacc = get_bits(gbc, 7); |
379 | 379 |
dexp[i++] = ungroup_3_in_7_bits_tab[expacc][0]; |
380 | 380 |
dexp[i++] = ungroup_3_in_7_bits_tab[expacc][1]; |
... | ... |
@@ -383,15 +382,15 @@ static int decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps, |
383 | 383 |
|
384 | 384 |
/* convert to absolute exps and expand groups */ |
385 | 385 |
prevexp = absexp; |
386 |
- for(i=0,j=0; i<ngrps*3; i++) { |
|
386 |
+ for (i = 0, j = 0; i < ngrps * 3; i++) { |
|
387 | 387 |
prevexp += dexp[i] - 2; |
388 | 388 |
if (prevexp > 24U) |
389 | 389 |
return -1; |
390 | 390 |
switch (group_size) { |
391 |
- case 4: dexps[j++] = prevexp; |
|
392 |
- dexps[j++] = prevexp; |
|
393 |
- case 2: dexps[j++] = prevexp; |
|
394 |
- case 1: dexps[j++] = prevexp; |
|
391 |
+ case 4: dexps[j++] = prevexp; |
|
392 |
+ dexps[j++] = prevexp; |
|
393 |
+ case 2: dexps[j++] = prevexp; |
|
394 |
+ case 1: dexps[j++] = prevexp; |
|
395 | 395 |
} |
396 | 396 |
} |
397 | 397 |
return 0; |
... | ... |
@@ -414,7 +413,8 @@ static void calc_transform_coeffs_cpl(AC3DecodeContext *s) |
414 | 414 |
if (s->channel_in_cpl[ch]) { |
415 | 415 |
int cpl_coord = s->cpl_coords[ch][band] << 5; |
416 | 416 |
for (bin = band_start; bin < band_end; bin++) { |
417 |
- s->fixed_coeffs[ch][bin] = MULH(s->fixed_coeffs[CPL_CH][bin] << 4, cpl_coord); |
|
417 |
+ s->fixed_coeffs[ch][bin] = |
|
418 |
+ MULH(s->fixed_coeffs[CPL_CH][bin] << 4, cpl_coord); |
|
418 | 419 |
} |
419 | 420 |
if (ch == 2 && s->phase_flags[band]) { |
420 | 421 |
for (bin = band_start; bin < band_end; bin++) |
... | ... |
@@ -445,73 +445,70 @@ typedef struct { |
445 | 445 |
static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, mant_groups *m) |
446 | 446 |
{ |
447 | 447 |
int start_freq = s->start_freq[ch_index]; |
448 |
- int end_freq = s->end_freq[ch_index]; |
|
449 |
- uint8_t *baps = s->bap[ch_index]; |
|
450 |
- int8_t *exps = s->dexps[ch_index]; |
|
451 |
- int *coeffs = s->fixed_coeffs[ch_index]; |
|
452 |
- int dither = (ch_index == CPL_CH) || s->dither_flag[ch_index]; |
|
448 |
+ int end_freq = s->end_freq[ch_index]; |
|
449 |
+ uint8_t *baps = s->bap[ch_index]; |
|
450 |
+ int8_t *exps = s->dexps[ch_index]; |
|
451 |
+ int *coeffs = s->fixed_coeffs[ch_index]; |
|
452 |
+ int dither = (ch_index == CPL_CH) || s->dither_flag[ch_index]; |
|
453 | 453 |
GetBitContext *gbc = &s->gbc; |
454 | 454 |
int freq; |
455 | 455 |
|
456 |
- for(freq = start_freq; freq < end_freq; freq++){ |
|
456 |
+ for (freq = start_freq; freq < end_freq; freq++) { |
|
457 | 457 |
int bap = baps[freq]; |
458 | 458 |
int mantissa; |
459 |
- switch(bap){ |
|
460 |
- case 0: |
|
461 |
- if (dither) |
|
462 |
- mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; |
|
463 |
- else |
|
464 |
- mantissa = 0; |
|
465 |
- break; |
|
466 |
- case 1: |
|
467 |
- if(m->b1){ |
|
468 |
- m->b1--; |
|
469 |
- mantissa = m->b1_mant[m->b1]; |
|
470 |
- } |
|
471 |
- else{ |
|
472 |
- int bits = get_bits(gbc, 5); |
|
473 |
- mantissa = b1_mantissas[bits][0]; |
|
474 |
- m->b1_mant[1] = b1_mantissas[bits][1]; |
|
475 |
- m->b1_mant[0] = b1_mantissas[bits][2]; |
|
476 |
- m->b1 = 2; |
|
477 |
- } |
|
478 |
- break; |
|
479 |
- case 2: |
|
480 |
- if(m->b2){ |
|
481 |
- m->b2--; |
|
482 |
- mantissa = m->b2_mant[m->b2]; |
|
483 |
- } |
|
484 |
- else{ |
|
485 |
- int bits = get_bits(gbc, 7); |
|
486 |
- mantissa = b2_mantissas[bits][0]; |
|
487 |
- m->b2_mant[1] = b2_mantissas[bits][1]; |
|
488 |
- m->b2_mant[0] = b2_mantissas[bits][2]; |
|
489 |
- m->b2 = 2; |
|
490 |
- } |
|
491 |
- break; |
|
492 |
- case 3: |
|
493 |
- mantissa = b3_mantissas[get_bits(gbc, 3)]; |
|
494 |
- break; |
|
495 |
- case 4: |
|
496 |
- if(m->b4){ |
|
497 |
- m->b4 = 0; |
|
498 |
- mantissa = m->b4_mant; |
|
499 |
- } |
|
500 |
- else{ |
|
501 |
- int bits = get_bits(gbc, 7); |
|
502 |
- mantissa = b4_mantissas[bits][0]; |
|
503 |
- m->b4_mant = b4_mantissas[bits][1]; |
|
504 |
- m->b4 = 1; |
|
505 |
- } |
|
506 |
- break; |
|
507 |
- case 5: |
|
508 |
- mantissa = b5_mantissas[get_bits(gbc, 4)]; |
|
509 |
- break; |
|
510 |
- default: /* 6 to 15 */ |
|
511 |
- /* Shift mantissa and sign-extend it. */ |
|
512 |
- mantissa = get_sbits(gbc, quantization_tab[bap]); |
|
513 |
- mantissa <<= 24 - quantization_tab[bap]; |
|
514 |
- break; |
|
459 |
+ switch (bap) { |
|
460 |
+ case 0: |
|
461 |
+ if (dither) |
|
462 |
+ mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; |
|
463 |
+ else |
|
464 |
+ mantissa = 0; |
|
465 |
+ break; |
|
466 |
+ case 1: |
|
467 |
+ if (m->b1) { |
|
468 |
+ m->b1--; |
|
469 |
+ mantissa = m->b1_mant[m->b1]; |
|
470 |
+ } else { |
|
471 |
+ int bits = get_bits(gbc, 5); |
|
472 |
+ mantissa = b1_mantissas[bits][0]; |
|
473 |
+ m->b1_mant[1] = b1_mantissas[bits][1]; |
|
474 |
+ m->b1_mant[0] = b1_mantissas[bits][2]; |
|
475 |
+ m->b1 = 2; |
|
476 |
+ } |
|
477 |
+ break; |
|
478 |
+ case 2: |
|
479 |
+ if (m->b2) { |
|
480 |
+ m->b2--; |
|
481 |
+ mantissa = m->b2_mant[m->b2]; |
|
482 |
+ } else { |
|
483 |
+ int bits = get_bits(gbc, 7); |
|
484 |
+ mantissa = b2_mantissas[bits][0]; |
|
485 |
+ m->b2_mant[1] = b2_mantissas[bits][1]; |
|
486 |
+ m->b2_mant[0] = b2_mantissas[bits][2]; |
|
487 |
+ m->b2 = 2; |
|
488 |
+ } |
|
489 |
+ break; |
|
490 |
+ case 3: |
|
491 |
+ mantissa = b3_mantissas[get_bits(gbc, 3)]; |
|
492 |
+ break; |
|
493 |
+ case 4: |
|
494 |
+ if (m->b4) { |
|
495 |
+ m->b4 = 0; |
|
496 |
+ mantissa = m->b4_mant; |
|
497 |
+ } else { |
|
498 |
+ int bits = get_bits(gbc, 7); |
|
499 |
+ mantissa = b4_mantissas[bits][0]; |
|
500 |
+ m->b4_mant = b4_mantissas[bits][1]; |
|
501 |
+ m->b4 = 1; |
|
502 |
+ } |
|
503 |
+ break; |
|
504 |
+ case 5: |
|
505 |
+ mantissa = b5_mantissas[get_bits(gbc, 4)]; |
|
506 |
+ break; |
|
507 |
+ default: /* 6 to 15 */ |
|
508 |
+ /* Shift mantissa and sign-extend it. */ |
|
509 |
+ mantissa = get_sbits(gbc, quantization_tab[bap]); |
|
510 |
+ mantissa <<= 24 - quantization_tab[bap]; |
|
511 |
+ break; |
|
515 | 512 |
} |
516 | 513 |
coeffs[freq] = mantissa >> exps[freq]; |
517 | 514 |
} |
... | ... |
@@ -525,10 +522,10 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma |
525 | 525 |
static void remove_dithering(AC3DecodeContext *s) { |
526 | 526 |
int ch, i; |
527 | 527 |
|
528 |
- for(ch=1; ch<=s->fbw_channels; ch++) { |
|
529 |
- if(!s->dither_flag[ch] && s->channel_in_cpl[ch]) { |
|
530 |
- for(i = s->start_freq[CPL_CH]; i<s->end_freq[CPL_CH]; i++) { |
|
531 |
- if(!s->bap[CPL_CH][i]) |
|
528 |
+ for (ch = 1; ch <= s->fbw_channels; ch++) { |
|
529 |
+ if (!s->dither_flag[ch] && s->channel_in_cpl[ch]) { |
|
530 |
+ for (i = s->start_freq[CPL_CH]; i < s->end_freq[CPL_CH]; i++) { |
|
531 |
+ if (!s->bap[CPL_CH][i]) |
|
532 | 532 |
s->fixed_coeffs[ch][i] = 0; |
533 | 533 |
} |
534 | 534 |
} |
... | ... |
@@ -536,7 +533,7 @@ static void remove_dithering(AC3DecodeContext *s) { |
536 | 536 |
} |
537 | 537 |
|
538 | 538 |
static void decode_transform_coeffs_ch(AC3DecodeContext *s, int blk, int ch, |
539 |
- mant_groups *m) |
|
539 |
+ mant_groups *m) |
|
540 | 540 |
{ |
541 | 541 |
if (!s->channel_uses_aht[ch]) { |
542 | 542 |
ac3_decode_transform_coeffs_ch(s, ch, m); |
... | ... |
@@ -580,7 +577,7 @@ static void decode_transform_coeffs(AC3DecodeContext *s, int blk) |
580 | 580 |
} |
581 | 581 |
do |
582 | 582 |
s->fixed_coeffs[ch][end] = 0; |
583 |
- while(++end < 256); |
|
583 |
+ while (++end < 256); |
|
584 | 584 |
} |
585 | 585 |
|
586 | 586 |
/* zero the dithered coefficients for appropriate channels */ |
... | ... |
@@ -598,10 +595,10 @@ static void do_rematrixing(AC3DecodeContext *s) |
598 | 598 |
|
599 | 599 |
end = FFMIN(s->end_freq[1], s->end_freq[2]); |
600 | 600 |
|
601 |
- for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) { |
|
602 |
- if(s->rematrixing_flags[bnd]) { |
|
603 |
- bndend = FFMIN(end, ff_ac3_rematrix_band_tab[bnd+1]); |
|
604 |
- for(i=ff_ac3_rematrix_band_tab[bnd]; i<bndend; i++) { |
|
601 |
+ for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++) { |
|
602 |
+ if (s->rematrixing_flags[bnd]) { |
|
603 |
+ bndend = FFMIN(end, ff_ac3_rematrix_band_tab[bnd + 1]); |
|
604 |
+ for (i = ff_ac3_rematrix_band_tab[bnd]; i < bndend; i++) { |
|
605 | 605 |
int tmp0 = s->fixed_coeffs[1][i]; |
606 | 606 |
s->fixed_coeffs[1][i] += s->fixed_coeffs[2][i]; |
607 | 607 |
s->fixed_coeffs[2][i] = tmp0 - s->fixed_coeffs[2][i]; |
... | ... |
@@ -619,21 +616,23 @@ static inline void do_imdct(AC3DecodeContext *s, int channels) |
619 | 619 |
{ |
620 | 620 |
int ch; |
621 | 621 |
|
622 |
- for (ch=1; ch<=channels; ch++) { |
|
622 |
+ for (ch = 1; ch <= channels; ch++) { |
|
623 | 623 |
if (s->block_switch[ch]) { |
624 | 624 |
int i; |
625 |
- float *x = s->tmp_output+128; |
|
626 |
- for(i=0; i<128; i++) |
|
627 |
- x[i] = s->transform_coeffs[ch][2*i]; |
|
625 |
+ float *x = s->tmp_output + 128; |
|
626 |
+ for (i = 0; i < 128; i++) |
|
627 |
+ x[i] = s->transform_coeffs[ch][2 * i]; |
|
628 | 628 |
s->imdct_256.imdct_half(&s->imdct_256, s->tmp_output, x); |
629 |
- s->dsp.vector_fmul_window(s->output[ch-1], s->delay[ch-1], s->tmp_output, s->window, 128); |
|
630 |
- for(i=0; i<128; i++) |
|
631 |
- x[i] = s->transform_coeffs[ch][2*i+1]; |
|
632 |
- s->imdct_256.imdct_half(&s->imdct_256, s->delay[ch-1], x); |
|
629 |
+ s->dsp.vector_fmul_window(s->output[ch - 1], s->delay[ch - 1], |
|
630 |
+ s->tmp_output, s->window, 128); |
|
631 |
+ for (i = 0; i < 128; i++) |
|
632 |
+ x[i] = s->transform_coeffs[ch][2 * i + 1]; |
|
633 |
+ s->imdct_256.imdct_half(&s->imdct_256, s->delay[ch - 1], x); |
|
633 | 634 |
} else { |
634 | 635 |
s->imdct_512.imdct_half(&s->imdct_512, s->tmp_output, s->transform_coeffs[ch]); |
635 |
- s->dsp.vector_fmul_window(s->output[ch-1], s->delay[ch-1], s->tmp_output, s->window, 128); |
|
636 |
- memcpy(s->delay[ch-1], s->tmp_output+128, 128*sizeof(float)); |
|
636 |
+ s->dsp.vector_fmul_window(s->output[ch - 1], s->delay[ch - 1], |
|
637 |
+ s->tmp_output, s->window, 128); |
|
638 |
+ memcpy(s->delay[ch - 1], s->tmp_output + 128, 128 * sizeof(float)); |
|
637 | 639 |
} |
638 | 640 |
} |
639 | 641 |
} |
... | ... |
@@ -641,24 +640,25 @@ static inline void do_imdct(AC3DecodeContext *s, int channels) |
641 | 641 |
/** |
642 | 642 |
* Downmix the output to mono or stereo. |
643 | 643 |
*/ |
644 |
-void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len) |
|
644 |
+void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], |
|
645 |
+ int out_ch, int in_ch, int len) |
|
645 | 646 |
{ |
646 | 647 |
int i, j; |
647 | 648 |
float v0, v1; |
648 |
- if(out_ch == 2) { |
|
649 |
- for(i=0; i<len; i++) { |
|
649 |
+ if (out_ch == 2) { |
|
650 |
+ for (i = 0; i < len; i++) { |
|
650 | 651 |
v0 = v1 = 0.0f; |
651 |
- for(j=0; j<in_ch; j++) { |
|
652 |
+ for (j = 0; j < in_ch; j++) { |
|
652 | 653 |
v0 += samples[j][i] * matrix[j][0]; |
653 | 654 |
v1 += samples[j][i] * matrix[j][1]; |
654 | 655 |
} |
655 | 656 |
samples[0][i] = v0; |
656 | 657 |
samples[1][i] = v1; |
657 | 658 |
} |
658 |
- } else if(out_ch == 1) { |
|
659 |
- for(i=0; i<len; i++) { |
|
659 |
+ } else if (out_ch == 1) { |
|
660 |
+ for (i = 0; i < len; i++) { |
|
660 | 661 |
v0 = 0.0f; |
661 |
- for(j=0; j<in_ch; j++) |
|
662 |
+ for (j = 0; j < in_ch; j++) |
|
662 | 663 |
v0 += samples[j][i] * matrix[j][0]; |
663 | 664 |
samples[0][i] = v0; |
664 | 665 |
} |
... | ... |
@@ -671,25 +671,25 @@ void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], int out_ch, int |
671 | 671 |
static void ac3_upmix_delay(AC3DecodeContext *s) |
672 | 672 |
{ |
673 | 673 |
int channel_data_size = sizeof(s->delay[0]); |
674 |
- switch(s->channel_mode) { |
|
675 |
- case AC3_CHMODE_DUALMONO: |
|
676 |
- case AC3_CHMODE_STEREO: |
|
677 |
- /* upmix mono to stereo */ |
|
678 |
- memcpy(s->delay[1], s->delay[0], channel_data_size); |
|
679 |
- break; |
|
680 |
- case AC3_CHMODE_2F2R: |
|
681 |
- memset(s->delay[3], 0, channel_data_size); |
|
682 |
- case AC3_CHMODE_2F1R: |
|
683 |
- memset(s->delay[2], 0, channel_data_size); |
|
684 |
- break; |
|
685 |
- case AC3_CHMODE_3F2R: |
|
686 |
- memset(s->delay[4], 0, channel_data_size); |
|
687 |
- case AC3_CHMODE_3F1R: |
|
688 |
- memset(s->delay[3], 0, channel_data_size); |
|
689 |
- case AC3_CHMODE_3F: |
|
690 |
- memcpy(s->delay[2], s->delay[1], channel_data_size); |
|
691 |
- memset(s->delay[1], 0, channel_data_size); |
|
692 |
- break; |
|
674 |
+ switch (s->channel_mode) { |
|
675 |
+ case AC3_CHMODE_DUALMONO: |
|
676 |
+ case AC3_CHMODE_STEREO: |
|
677 |
+ /* upmix mono to stereo */ |
|
678 |
+ memcpy(s->delay[1], s->delay[0], channel_data_size); |
|
679 |
+ break; |
|
680 |
+ case AC3_CHMODE_2F2R: |
|
681 |
+ memset(s->delay[3], 0, channel_data_size); |
|
682 |
+ case AC3_CHMODE_2F1R: |
|
683 |
+ memset(s->delay[2], 0, channel_data_size); |
|
684 |
+ break; |
|
685 |
+ case AC3_CHMODE_3F2R: |
|
686 |
+ memset(s->delay[4], 0, channel_data_size); |
|
687 |
+ case AC3_CHMODE_3F1R: |
|
688 |
+ memset(s->delay[3], 0, channel_data_size); |
|
689 |
+ case AC3_CHMODE_3F: |
|
690 |
+ memcpy(s->delay[2], s->delay[1], channel_data_size); |
|
691 |
+ memset(s->delay[1], 0, channel_data_size); |
|
692 |
+ break; |
|
693 | 693 |
} |
694 | 694 |
} |
695 | 695 |
|
... | ... |
@@ -742,7 +742,7 @@ static void decode_band_structure(GetBitContext *gbc, int blk, int eac3, |
742 | 742 |
bnd_sz[0] = ecpl ? 6 : 12; |
743 | 743 |
for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) { |
744 | 744 |
int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12; |
745 |
- if (band_struct[subbnd-1]) { |
|
745 |
+ if (band_struct[subbnd - 1]) { |
|
746 | 746 |
n_bands--; |
747 | 747 |
bnd_sz[bnd] += subbnd_size; |
748 | 748 |
} else { |
... | ... |
@@ -779,7 +779,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
779 | 779 |
if (s->block_switch_syntax) { |
780 | 780 |
for (ch = 1; ch <= fbw_channels; ch++) { |
781 | 781 |
s->block_switch[ch] = get_bits1(gbc); |
782 |
- if(ch > 1 && s->block_switch[ch] != s->block_switch[1]) |
|
782 |
+ if (ch > 1 && s->block_switch[ch] != s->block_switch[1]) |
|
783 | 783 |
different_transforms = 1; |
784 | 784 |
} |
785 | 785 |
} |
... | ... |
@@ -794,13 +794,13 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
794 | 794 |
/* dynamic range */ |
795 | 795 |
i = !(s->channel_mode); |
796 | 796 |
do { |
797 |
- if(get_bits1(gbc)) { |
|
798 |
- s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) * |
|
799 |
- s->drc_scale)+1.0; |
|
800 |
- } else if(blk == 0) { |
|
797 |
+ if (get_bits1(gbc)) { |
|
798 |
+ s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)] - 1.0) * |
|
799 |
+ s->drc_scale) + 1.0; |
|
800 |
+ } else if (blk == 0) { |
|
801 | 801 |
s->dynamic_range[i] = 1.0f; |
802 | 802 |
} |
803 |
- } while(i--); |
|
803 |
+ } while (i--); |
|
804 | 804 |
|
805 | 805 |
/* spectral extension strategy */ |
806 | 806 |
if (s->eac3 && (!blk || get_bits1(gbc))) { |
... | ... |
@@ -881,7 +881,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
881 | 881 |
bandsize = s->spx_band_sizes[bnd]; |
882 | 882 |
nratio = ((float)((bin + (bandsize >> 1))) / s->spx_dst_end_freq) - spx_blend; |
883 | 883 |
nratio = av_clipf(nratio, 0.0f, 1.0f); |
884 |
- nblend = sqrtf(3.0f * nratio); // noise is scaled by sqrt(3) to give unity variance |
|
884 |
+ nblend = sqrtf(3.0f * nratio); // noise is scaled by sqrt(3) |
|
885 |
+ // to give unity variance |
|
885 | 886 |
sblend = sqrtf(1.0f - nratio); |
886 | 887 |
bin += bandsize; |
887 | 888 |
|
... | ... |
@@ -891,7 +892,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
891 | 891 |
if (spx_coord_exp == 15) spx_coord_mant <<= 1; |
892 | 892 |
else spx_coord_mant += 4; |
893 | 893 |
spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord); |
894 |
- spx_coord = spx_coord_mant * (1.0f/(1<<23)); |
|
894 |
+ spx_coord = spx_coord_mant * (1.0f / (1 << 23)); |
|
895 | 895 |
|
896 | 896 |
/* multiply noise and signal blending factors by spx coordinate */ |
897 | 897 |
s->spx_noise_blend [ch][bnd] = nblend * spx_coord; |
... | ... |
@@ -964,8 +965,9 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
964 | 964 |
s->phase_flags_in_use = 0; |
965 | 965 |
} |
966 | 966 |
} else if (!s->eac3) { |
967 |
- if(!blk) { |
|
968 |
- av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must be present in block 0\n"); |
|
967 |
+ if (!blk) { |
|
968 |
+ av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must " |
|
969 |
+ "be present in block 0\n"); |
|
969 | 970 |
return -1; |
970 | 971 |
} else { |
971 | 972 |
s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; |
... | ... |
@@ -994,7 +996,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
994 | 994 |
s->cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord); |
995 | 995 |
} |
996 | 996 |
} else if (!blk) { |
997 |
- av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must be present in block 0\n"); |
|
997 |
+ av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must " |
|
998 |
+ "be present in block 0\n"); |
|
998 | 999 |
return -1; |
999 | 1000 |
} |
1000 | 1001 |
} else { |
... | ... |
@@ -1019,10 +1022,11 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1019 | 1019 |
} else if (s->spx_in_use && s->spx_src_start_freq <= 61) { |
1020 | 1020 |
s->num_rematrixing_bands--; |
1021 | 1021 |
} |
1022 |
- for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) |
|
1022 |
+ for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++) |
|
1023 | 1023 |
s->rematrixing_flags[bnd] = get_bits1(gbc); |
1024 | 1024 |
} else if (!blk) { |
1025 |
- av_log(s->avctx, AV_LOG_WARNING, "Warning: new rematrixing strategy not present in block 0\n"); |
|
1025 |
+ av_log(s->avctx, AV_LOG_WARNING, "Warning: " |
|
1026 |
+ "new rematrixing strategy not present in block 0\n"); |
|
1026 | 1027 |
s->num_rematrixing_bands = 0; |
1027 | 1028 |
} |
1028 | 1029 |
} |
... | ... |
@@ -1031,7 +1035,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1031 | 1031 |
for (ch = !cpl_in_use; ch <= s->channels; ch++) { |
1032 | 1032 |
if (!s->eac3) |
1033 | 1033 |
s->exp_strategy[blk][ch] = get_bits(gbc, 2 - (ch == s->lfe_ch)); |
1034 |
- if(s->exp_strategy[blk][ch] != EXP_REUSE) |
|
1034 |
+ if (s->exp_strategy[blk][ch] != EXP_REUSE) |
|
1035 | 1035 |
bit_alloc_stages[ch] = 3; |
1036 | 1036 |
} |
1037 | 1037 |
|
... | ... |
@@ -1054,8 +1058,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1054 | 1054 |
s->end_freq[ch] = bandwidth_code * 3 + 73; |
1055 | 1055 |
} |
1056 | 1056 |
group_size = 3 << (s->exp_strategy[blk][ch] - 1); |
1057 |
- s->num_exp_groups[ch] = (s->end_freq[ch]+group_size-4) / group_size; |
|
1058 |
- if(blk > 0 && s->end_freq[ch] != prev) |
|
1057 |
+ s->num_exp_groups[ch] = (s->end_freq[ch] + group_size-4) / group_size; |
|
1058 |
+ if (blk > 0 && s->end_freq[ch] != prev) |
|
1059 | 1059 |
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
1060 | 1060 |
} |
1061 | 1061 |
} |
... | ... |
@@ -1074,7 +1078,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1074 | 1074 |
av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n"); |
1075 | 1075 |
return -1; |
1076 | 1076 |
} |
1077 |
- if(ch != CPL_CH && ch != s->lfe_ch) |
|
1077 |
+ if (ch != CPL_CH && ch != s->lfe_ch) |
|
1078 | 1078 |
skip_bits(gbc, 2); /* skip gainrng */ |
1079 | 1079 |
} |
1080 | 1080 |
} |
... | ... |
@@ -1087,17 +1091,18 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1087 | 1087 |
s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; |
1088 | 1088 |
s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; |
1089 | 1089 |
s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)]; |
1090 |
- for(ch=!cpl_in_use; ch<=s->channels; ch++) |
|
1090 |
+ for (ch = !cpl_in_use; ch <= s->channels; ch++) |
|
1091 | 1091 |
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
1092 | 1092 |
} else if (!blk) { |
1093 |
- av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must be present in block 0\n"); |
|
1093 |
+ av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must " |
|
1094 |
+ "be present in block 0\n"); |
|
1094 | 1095 |
return -1; |
1095 | 1096 |
} |
1096 | 1097 |
} |
1097 | 1098 |
|
1098 | 1099 |
/* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ |
1099 |
- if(!s->eac3 || !blk){ |
|
1100 |
- if(s->snr_offset_strategy && get_bits1(gbc)) { |
|
1100 |
+ if (!s->eac3 || !blk) { |
|
1101 |
+ if (s->snr_offset_strategy && get_bits1(gbc)) { |
|
1101 | 1102 |
int snr = 0; |
1102 | 1103 |
int csnr; |
1103 | 1104 |
csnr = (get_bits(gbc, 6) - 15) << 4; |
... | ... |
@@ -1106,7 +1111,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1106 | 1106 |
if (ch == i || s->snr_offset_strategy == 2) |
1107 | 1107 |
snr = (csnr + get_bits(gbc, 4)) << 2; |
1108 | 1108 |
/* run at least last bit allocation stage if snr offset changes */ |
1109 |
- if(blk && s->snr_offset[ch] != snr) { |
|
1109 |
+ if (blk && s->snr_offset[ch] != snr) { |
|
1110 | 1110 |
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 1); |
1111 | 1111 |
} |
1112 | 1112 |
s->snr_offset[ch] = snr; |
... | ... |
@@ -1116,7 +1121,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1116 | 1116 |
int prev = s->fast_gain[ch]; |
1117 | 1117 |
s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; |
1118 | 1118 |
/* run last 2 bit allocation stages if fast gain changes */ |
1119 |
- if(blk && prev != s->fast_gain[ch]) |
|
1119 |
+ if (blk && prev != s->fast_gain[ch]) |
|
1120 | 1120 |
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
1121 | 1121 |
} |
1122 | 1122 |
} |
... | ... |
@@ -1132,7 +1137,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1132 | 1132 |
int prev = s->fast_gain[ch]; |
1133 | 1133 |
s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; |
1134 | 1134 |
/* run last 2 bit allocation stages if fast gain changes */ |
1135 |
- if(blk && prev != s->fast_gain[ch]) |
|
1135 |
+ if (blk && prev != s->fast_gain[ch]) |
|
1136 | 1136 |
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
1137 | 1137 |
} |
1138 | 1138 |
} else if (s->eac3 && !blk) { |
... | ... |
@@ -1152,14 +1157,15 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1152 | 1152 |
int sl = get_bits(gbc, 3); |
1153 | 1153 |
/* run last 2 bit allocation stages for coupling channel if |
1154 | 1154 |
coupling leak changes */ |
1155 |
- if(blk && (fl != s->bit_alloc_params.cpl_fast_leak || |
|
1156 |
- sl != s->bit_alloc_params.cpl_slow_leak)) { |
|
1155 |
+ if (blk && (fl != s->bit_alloc_params.cpl_fast_leak || |
|
1156 |
+ sl != s->bit_alloc_params.cpl_slow_leak)) { |
|
1157 | 1157 |
bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); |
1158 | 1158 |
} |
1159 | 1159 |
s->bit_alloc_params.cpl_fast_leak = fl; |
1160 | 1160 |
s->bit_alloc_params.cpl_slow_leak = sl; |
1161 | 1161 |
} else if (!s->eac3 && !blk) { |
1162 |
- av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must be present in block 0\n"); |
|
1162 |
+ av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must " |
|
1163 |
+ "be present in block 0\n"); |
|
1163 | 1164 |
return -1; |
1164 | 1165 |
} |
1165 | 1166 |
s->first_cpl_leak = 0; |
... | ... |
@@ -1183,40 +1189,40 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1183 | 1183 |
for (seg = 0; seg < s->dba_nsegs[ch]; seg++) { |
1184 | 1184 |
s->dba_offsets[ch][seg] = get_bits(gbc, 5); |
1185 | 1185 |
s->dba_lengths[ch][seg] = get_bits(gbc, 4); |
1186 |
- s->dba_values[ch][seg] = get_bits(gbc, 3); |
|
1186 |
+ s->dba_values[ch][seg] = get_bits(gbc, 3); |
|
1187 | 1187 |
} |
1188 | 1188 |
/* run last 2 bit allocation stages if new dba values */ |
1189 | 1189 |
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
1190 | 1190 |
} |
1191 | 1191 |
} |
1192 |
- } else if(blk == 0) { |
|
1193 |
- for(ch=0; ch<=s->channels; ch++) { |
|
1192 |
+ } else if (blk == 0) { |
|
1193 |
+ for (ch = 0; ch <= s->channels; ch++) { |
|
1194 | 1194 |
s->dba_mode[ch] = DBA_NONE; |
1195 | 1195 |
} |
1196 | 1196 |
} |
1197 | 1197 |
|
1198 | 1198 |
/* Bit allocation */ |
1199 |
- for(ch=!cpl_in_use; ch<=s->channels; ch++) { |
|
1200 |
- if(bit_alloc_stages[ch] > 2) { |
|
1199 |
+ for (ch = !cpl_in_use; ch <= s->channels; ch++) { |
|
1200 |
+ if (bit_alloc_stages[ch] > 2) { |
|
1201 | 1201 |
/* Exponent mapping into PSD and PSD integration */ |
1202 | 1202 |
ff_ac3_bit_alloc_calc_psd(s->dexps[ch], |
1203 | 1203 |
s->start_freq[ch], s->end_freq[ch], |
1204 | 1204 |
s->psd[ch], s->band_psd[ch]); |
1205 | 1205 |
} |
1206 |
- if(bit_alloc_stages[ch] > 1) { |
|
1206 |
+ if (bit_alloc_stages[ch] > 1) { |
|
1207 | 1207 |
/* Compute excitation function, Compute masking curve, and |
1208 | 1208 |
Apply delta bit allocation */ |
1209 | 1209 |
if (ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params, s->band_psd[ch], |
1210 |
- s->start_freq[ch], s->end_freq[ch], |
|
1211 |
- s->fast_gain[ch], (ch == s->lfe_ch), |
|
1212 |
- s->dba_mode[ch], s->dba_nsegs[ch], |
|
1210 |
+ s->start_freq[ch], s->end_freq[ch], |
|
1211 |
+ s->fast_gain[ch], (ch == s->lfe_ch), |
|
1212 |
+ s->dba_mode[ch], s->dba_nsegs[ch], |
|
1213 | 1213 |
s->dba_offsets[ch], s->dba_lengths[ch], |
1214 |
- s->dba_values[ch], s->mask[ch])) { |
|
1214 |
+ s->dba_values[ch], s->mask[ch])) { |
|
1215 | 1215 |
av_log(s->avctx, AV_LOG_ERROR, "error in bit allocation\n"); |
1216 | 1216 |
return -1; |
1217 | 1217 |
} |
1218 | 1218 |
} |
1219 |
- if(bit_alloc_stages[ch] > 0) { |
|
1219 |
+ if (bit_alloc_stages[ch] > 0) { |
|
1220 | 1220 |
/* Compute bit allocation */ |
1221 | 1221 |
const uint8_t *bap_tab = s->channel_uses_aht[ch] ? |
1222 | 1222 |
ff_eac3_hebap_tab : ff_ac3_bap_tab; |
... | ... |
@@ -1231,7 +1237,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1231 | 1231 |
/* unused dummy data */ |
1232 | 1232 |
if (s->skip_syntax && get_bits1(gbc)) { |
1233 | 1233 |
int skipl = get_bits(gbc, 9); |
1234 |
- while(skipl--) |
|
1234 |
+ while (skipl--) |
|
1235 | 1235 |
skip_bits(gbc, 8); |
1236 | 1236 |
} |
1237 | 1237 |
|
... | ... |
@@ -1242,18 +1248,19 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1242 | 1242 |
/* TODO: generate enhanced coupling coordinates and uncouple */ |
1243 | 1243 |
|
1244 | 1244 |
/* recover coefficients if rematrixing is in use */ |
1245 |
- if(s->channel_mode == AC3_CHMODE_STEREO) |
|
1245 |
+ if (s->channel_mode == AC3_CHMODE_STEREO) |
|
1246 | 1246 |
do_rematrixing(s); |
1247 | 1247 |
|
1248 | 1248 |
/* apply scaling to coefficients (headroom, dynrng) */ |
1249 |
- for(ch=1; ch<=s->channels; ch++) { |
|
1249 |
+ for (ch = 1; ch <= s->channels; ch++) { |
|
1250 | 1250 |
float gain = s->mul_bias / 4194304.0f; |
1251 |
- if(s->channel_mode == AC3_CHMODE_DUALMONO) { |
|
1252 |
- gain *= s->dynamic_range[2-ch]; |
|
1251 |
+ if (s->channel_mode == AC3_CHMODE_DUALMONO) { |
|
1252 |
+ gain *= s->dynamic_range[2 - ch]; |
|
1253 | 1253 |
} else { |
1254 | 1254 |
gain *= s->dynamic_range[0]; |
1255 | 1255 |
} |
1256 |
- s->fmt_conv.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); |
|
1256 |
+ s->fmt_conv.int32_to_float_fmul_scalar(s->transform_coeffs[ch], |
|
1257 |
+ s->fixed_coeffs[ch], gain, 256); |
|
1257 | 1258 |
} |
1258 | 1259 |
|
1259 | 1260 |
/* apply spectral extension to high frequency bins */ |
... | ... |
@@ -1267,27 +1274,30 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) |
1267 | 1267 |
downmix_output = s->channels != s->out_channels && |
1268 | 1268 |
!((s->output_mode & AC3_OUTPUT_LFEON) && |
1269 | 1269 |
s->fbw_channels == s->out_channels); |
1270 |
- if(different_transforms) { |
|
1270 |
+ if (different_transforms) { |
|
1271 | 1271 |
/* the delay samples have already been downmixed, so we upmix the delay |
1272 | 1272 |
samples in order to reconstruct all channels before downmixing. */ |
1273 |
- if(s->downmixed) { |
|
1273 |
+ if (s->downmixed) { |
|
1274 | 1274 |
s->downmixed = 0; |
1275 | 1275 |
ac3_upmix_delay(s); |
1276 | 1276 |
} |
1277 | 1277 |
|
1278 | 1278 |
do_imdct(s, s->channels); |
1279 | 1279 |
|
1280 |
- if(downmix_output) { |
|
1281 |
- s->dsp.ac3_downmix(s->output, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256); |
|
1280 |
+ if (downmix_output) { |
|
1281 |
+ s->dsp.ac3_downmix(s->output, s->downmix_coeffs, |
|
1282 |
+ s->out_channels, s->fbw_channels, 256); |
|
1282 | 1283 |
} |
1283 | 1284 |
} else { |
1284 |
- if(downmix_output) { |
|
1285 |
- s->dsp.ac3_downmix(s->transform_coeffs+1, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256); |
|
1285 |
+ if (downmix_output) { |
|
1286 |
+ s->dsp.ac3_downmix(s->transform_coeffs + 1, s->downmix_coeffs, |
|
1287 |
+ s->out_channels, s->fbw_channels, 256); |
|
1286 | 1288 |
} |
1287 | 1289 |
|
1288 |
- if(downmix_output && !s->downmixed) { |
|
1290 |
+ if (downmix_output && !s->downmixed) { |
|
1289 | 1291 |
s->downmixed = 1; |
1290 |
- s->dsp.ac3_downmix(s->delay, s->downmix_coeffs, s->out_channels, s->fbw_channels, 128); |
|
1292 |
+ s->dsp.ac3_downmix(s->delay, s->downmix_coeffs, s->out_channels, |
|
1293 |
+ s->fbw_channels, 128); |
|
1291 | 1294 |
} |
1292 | 1295 |
|
1293 | 1296 |
do_imdct(s, s->out_channels); |
... | ... |
@@ -1327,33 +1337,34 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, |
1327 | 1327 |
err = parse_frame_header(s); |
1328 | 1328 |
|
1329 | 1329 |
if (err) { |
1330 |
- switch(err) { |
|
1331 |
- case AAC_AC3_PARSE_ERROR_SYNC: |
|
1332 |
- av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); |
|
1333 |
- return -1; |
|
1334 |
- case AAC_AC3_PARSE_ERROR_BSID: |
|
1335 |
- av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n"); |
|
1336 |
- break; |
|
1337 |
- case AAC_AC3_PARSE_ERROR_SAMPLE_RATE: |
|
1338 |
- av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); |
|
1339 |
- break; |
|
1340 |
- case AAC_AC3_PARSE_ERROR_FRAME_SIZE: |
|
1341 |
- av_log(avctx, AV_LOG_ERROR, "invalid frame size\n"); |
|
1342 |
- break; |
|
1343 |
- case AAC_AC3_PARSE_ERROR_FRAME_TYPE: |
|
1344 |
- /* skip frame if CRC is ok. otherwise use error concealment. */ |
|
1345 |
- /* TODO: add support for substreams and dependent frames */ |
|
1346 |
- if(s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) { |
|
1347 |
- av_log(avctx, AV_LOG_ERROR, "unsupported frame type : skipping frame\n"); |
|
1348 |
- *got_frame_ptr = 0; |
|
1349 |
- return s->frame_size; |
|
1350 |
- } else { |
|
1351 |
- av_log(avctx, AV_LOG_ERROR, "invalid frame type\n"); |
|
1352 |
- } |
|
1353 |
- break; |
|
1354 |
- default: |
|
1355 |
- av_log(avctx, AV_LOG_ERROR, "invalid header\n"); |
|
1356 |
- break; |
|
1330 |
+ switch (err) { |
|
1331 |
+ case AAC_AC3_PARSE_ERROR_SYNC: |
|
1332 |
+ av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); |
|
1333 |
+ return -1; |
|
1334 |
+ case AAC_AC3_PARSE_ERROR_BSID: |
|
1335 |
+ av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n"); |
|
1336 |
+ break; |
|
1337 |
+ case AAC_AC3_PARSE_ERROR_SAMPLE_RATE: |
|
1338 |
+ av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); |
|
1339 |
+ break; |
|
1340 |
+ case AAC_AC3_PARSE_ERROR_FRAME_SIZE: |
|
1341 |
+ av_log(avctx, AV_LOG_ERROR, "invalid frame size\n"); |
|
1342 |
+ break; |
|
1343 |
+ case AAC_AC3_PARSE_ERROR_FRAME_TYPE: |
|
1344 |
+ /* skip frame if CRC is ok. otherwise use error concealment. */ |
|
1345 |
+ /* TODO: add support for substreams and dependent frames */ |
|
1346 |
+ if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) { |
|
1347 |
+ av_log(avctx, AV_LOG_ERROR, "unsupported frame type : " |
|
1348 |
+ "skipping frame\n"); |
|
1349 |
+ *got_frame_ptr = 0; |
|
1350 |
+ return s->frame_size; |
|
1351 |
+ } else { |
|
1352 |
+ av_log(avctx, AV_LOG_ERROR, "invalid frame type\n"); |
|
1353 |
+ } |
|
1354 |
+ break; |
|
1355 |
+ default: |
|
1356 |
+ av_log(avctx, AV_LOG_ERROR, "invalid header\n"); |
|
1357 |
+ break; |
|
1357 | 1358 |
} |
1358 | 1359 |
} else { |
1359 | 1360 |
/* check that reported frame size fits in input buffer */ |
... | ... |
@@ -1362,7 +1373,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, |
1362 | 1362 |
err = AAC_AC3_PARSE_ERROR_FRAME_SIZE; |
1363 | 1363 |
} else if (avctx->err_recognition & AV_EF_CRCCHECK) { |
1364 | 1364 |
/* check for crc mismatch */ |
1365 |
- if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) { |
|
1365 |
+ if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], |
|
1366 |
+ s->frame_size - 2)) { |
|
1366 | 1367 |
av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); |
1367 | 1368 |
err = AAC_AC3_PARSE_ERROR_CRC; |
1368 | 1369 |
} |
... | ... |
@@ -1372,12 +1384,12 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, |
1372 | 1372 |
/* if frame is ok, set audio parameters */ |
1373 | 1373 |
if (!err) { |
1374 | 1374 |
avctx->sample_rate = s->sample_rate; |
1375 |
- avctx->bit_rate = s->bit_rate; |
|
1375 |
+ avctx->bit_rate = s->bit_rate; |
|
1376 | 1376 |
|
1377 | 1377 |
/* channel config */ |
1378 | 1378 |
s->out_channels = s->channels; |
1379 |
- s->output_mode = s->channel_mode; |
|
1380 |
- if(s->lfe_on) |
|
1379 |
+ s->output_mode = s->channel_mode; |
|
1380 |
+ if (s->lfe_on) |
|
1381 | 1381 |
s->output_mode |= AC3_OUTPUT_LFEON; |
1382 | 1382 |
if (avctx->request_channels > 0 && avctx->request_channels <= 2 && |
1383 | 1383 |
avctx->request_channels < s->channels) { |
... | ... |
@@ -1385,17 +1397,17 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, |
1385 | 1385 |
s->output_mode = avctx->request_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO; |
1386 | 1386 |
s->channel_layout = ff_ac3_channel_layout_tab[s->output_mode]; |
1387 | 1387 |
} |
1388 |
- avctx->channels = s->out_channels; |
|
1388 |
+ avctx->channels = s->out_channels; |
|
1389 | 1389 |
avctx->channel_layout = s->channel_layout; |
1390 | 1390 |
|
1391 | 1391 |
/* set downmixing coefficients if needed */ |
1392 |
- if(s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) && |
|
1392 |
+ if (s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) && |
|
1393 | 1393 |
s->fbw_channels == s->out_channels)) { |
1394 | 1394 |
set_downmix_coeffs(s); |
1395 | 1395 |
} |
1396 | 1396 |
} else if (!s->out_channels) { |
1397 | 1397 |
s->out_channels = avctx->channels; |
1398 |
- if(s->out_channels < s->channels) |
|
1398 |
+ if (s->out_channels < s->channels) |
|
1399 | 1399 |
s->output_mode = s->out_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO; |
1400 | 1400 |
} |
1401 | 1401 |
/* set audio service type based on bitstream mode for AC-3 */ |
... | ... |
@@ -1465,19 +1477,19 @@ static const AVClass ac3_decoder_class = { |
1465 | 1465 |
}; |
1466 | 1466 |
|
1467 | 1467 |
AVCodec ff_ac3_decoder = { |
1468 |
- .name = "ac3", |
|
1469 |
- .type = AVMEDIA_TYPE_AUDIO, |
|
1470 |
- .id = CODEC_ID_AC3, |
|
1468 |
+ .name = "ac3", |
|
1469 |
+ .type = AVMEDIA_TYPE_AUDIO, |
|
1470 |
+ .id = CODEC_ID_AC3, |
|
1471 | 1471 |
.priv_data_size = sizeof (AC3DecodeContext), |
1472 |
- .init = ac3_decode_init, |
|
1473 |
- .close = ac3_decode_end, |
|
1474 |
- .decode = ac3_decode_frame, |
|
1475 |
- .capabilities = CODEC_CAP_DR1, |
|
1476 |
- .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), |
|
1477 |
- .sample_fmts = (const enum AVSampleFormat[]) { |
|
1478 |
- AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE |
|
1479 |
- }, |
|
1480 |
- .priv_class = &ac3_decoder_class, |
|
1472 |
+ .init = ac3_decode_init, |
|
1473 |
+ .close = ac3_decode_end, |
|
1474 |
+ .decode = ac3_decode_frame, |
|
1475 |
+ .capabilities = CODEC_CAP_DR1, |
|
1476 |
+ .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), |
|
1477 |
+ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, |
|
1478 |
+ AV_SAMPLE_FMT_S16, |
|
1479 |
+ AV_SAMPLE_FMT_NONE }, |
|
1480 |
+ .priv_class = &ac3_decoder_class, |
|
1481 | 1481 |
}; |
1482 | 1482 |
|
1483 | 1483 |
#if CONFIG_EAC3_DECODER |
... | ... |
@@ -1487,19 +1499,20 @@ static const AVClass eac3_decoder_class = { |
1487 | 1487 |
.option = options, |
1488 | 1488 |
.version = LIBAVUTIL_VERSION_INT, |
1489 | 1489 |
}; |
1490 |
+ |
|
1490 | 1491 |
AVCodec ff_eac3_decoder = { |
1491 |
- .name = "eac3", |
|
1492 |
- .type = AVMEDIA_TYPE_AUDIO, |
|
1493 |
- .id = CODEC_ID_EAC3, |
|
1492 |
+ .name = "eac3", |
|
1493 |
+ .type = AVMEDIA_TYPE_AUDIO, |
|
1494 |
+ .id = CODEC_ID_EAC3, |
|
1494 | 1495 |
.priv_data_size = sizeof (AC3DecodeContext), |
1495 |
- .init = ac3_decode_init, |
|
1496 |
- .close = ac3_decode_end, |
|
1497 |
- .decode = ac3_decode_frame, |
|
1498 |
- .capabilities = CODEC_CAP_DR1, |
|
1499 |
- .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), |
|
1500 |
- .sample_fmts = (const enum AVSampleFormat[]) { |
|
1501 |
- AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE |
|
1502 |
- }, |
|
1503 |
- .priv_class = &eac3_decoder_class, |
|
1496 |
+ .init = ac3_decode_init, |
|
1497 |
+ .close = ac3_decode_end, |
|
1498 |
+ .decode = ac3_decode_frame, |
|
1499 |
+ .capabilities = CODEC_CAP_DR1, |
|
1500 |
+ .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), |
|
1501 |
+ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, |
|
1502 |
+ AV_SAMPLE_FMT_S16, |
|
1503 |
+ AV_SAMPLE_FMT_NONE }, |
|
1504 |
+ .priv_class = &eac3_decoder_class, |
|
1504 | 1505 |
}; |
1505 | 1506 |
#endif |