annotate eac3dec.c @ 11600:2b35577e49db libavcodec

DECLARE_ALIGNED usage requires #inclusion of 'mem.h'.
author jai_menon
date Sun, 11 Apr 2010 15:54:45 +0000
parents 444f4b594fdb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
1 /*
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
2 * E-AC-3 decoder
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
3 * Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
4 * Copyright (c) 2008 Justin Ruggles
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
5 *
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
6 * This file is part of FFmpeg.
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
7 *
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
7679
e27395cc7321 change eac3dec.c license to LGPL
jbr
parents: 7666
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
7679
e27395cc7321 change eac3dec.c license to LGPL
jbr
parents: 7666
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
12 *
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7679
e27395cc7321 change eac3dec.c license to LGPL
jbr
parents: 7666
diff changeset
16 * Lesser General Public License for more details.
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
17 *
7679
e27395cc7321 change eac3dec.c license to LGPL
jbr
parents: 7666
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
21 */
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
22
9181
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
23 /*
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
24 * There are several features of E-AC-3 that this decoder does not yet support.
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
25 *
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
26 * Enhanced Coupling
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
27 * No known samples exist. If any ever surface, this feature should not be
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
28 * too difficult to implement.
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
29 *
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
30 * Reduced Sample Rates
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
31 * No known samples exist. The spec also does not give clear information
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
32 * on how this is to be implemented.
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
33 *
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
34 * Dependent Streams
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
35 * Only the independent stream is currently decoded. Any dependent
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
36 * streams are skipped. We have only come across two examples of this, and
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
37 * they are both just test streams, one for HD-DVD and the other for
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
38 * Blu-ray.
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
39 *
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
40 * Transient Pre-noise Processing
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
41 * This is side information which a decoder should use to reduce artifacts
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
42 * caused by transients. There are samples which are known to have this
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
43 * information, but this decoder currently ignores it.
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
44 */
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
45
323e4f591d7a Add documentation about missing E-AC-3 features.
jbr
parents: 8545
diff changeset
46
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
47 #include "avcodec.h"
8281
f93efc084e41 Make av_log_missing_feature an internal function, and change its name
stefano
parents: 8273
diff changeset
48 #include "internal.h"
8545
a5402e89a80c Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that
superdump
parents: 8281
diff changeset
49 #include "aac_ac3_parser.h"
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
50 #include "ac3.h"
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
51 #include "ac3_parser.h"
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
52 #include "ac3dec.h"
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
53 #include "ac3dec_data.h"
9983
68de5143aa45 refactoring: properly separate AC-3 and E-AC-3 code
diego
parents: 9891
diff changeset
54 #include "eac3dec_data.h"
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
55
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
56 /** gain adaptive quantization mode */
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
57 typedef enum {
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
58 EAC3_GAQ_NO =0,
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
59 EAC3_GAQ_12,
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
60 EAC3_GAQ_14,
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
61 EAC3_GAQ_124
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
62 } EAC3GaqMode;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
63
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
64 #define EAC3_SR_CODE_REDUCED 3
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
65
11559
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
66 void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
67 {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
68 int bin, bnd, ch, i;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
69 uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
70 float rms_energy[SPX_MAX_BANDS];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
71
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
72 /* Set copy index mapping table. Set wrap flags to apply a notch filter at
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
73 wrap points later on. */
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
74 bin = s->spx_dst_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
75 num_copy_sections = 0;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
76 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
77 int copysize;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
78 int bandsize = s->spx_band_sizes[bnd];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
79 if (bin + bandsize > s->spx_src_start_freq) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
80 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
81 bin = s->spx_dst_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
82 wrapflag[bnd] = 1;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
83 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
84 for (i = 0; i < bandsize; i += copysize) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
85 if (bin == s->spx_src_start_freq) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
86 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
87 bin = s->spx_dst_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
88 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
89 copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
90 bin += copysize;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
91 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
92 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
93 copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
94
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
95 for (ch = 1; ch <= s->fbw_channels; ch++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
96 if (!s->channel_uses_spx[ch])
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
97 continue;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
98
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
99 /* Copy coeffs from normal bands to extension bands */
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
100 bin = s->spx_src_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
101 for (i = 0; i < num_copy_sections; i++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
102 memcpy(&s->transform_coeffs[ch][bin],
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
103 &s->transform_coeffs[ch][s->spx_dst_start_freq],
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
104 copy_sizes[i]*sizeof(float));
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
105 bin += copy_sizes[i];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
106 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
107
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
108 /* Calculate RMS energy for each SPX band. */
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
109 bin = s->spx_src_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
110 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
111 int bandsize = s->spx_band_sizes[bnd];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
112 float accum = 0.0f;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
113 for (i = 0; i < bandsize; i++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
114 float coeff = s->transform_coeffs[ch][bin++];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
115 accum += coeff * coeff;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
116 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
117 rms_energy[bnd] = sqrtf(accum / bandsize);
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
118 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
119
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
120 /* Apply a notch filter at transitions between normal and extension
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
121 bands and at all wrap points. */
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
122 if (s->spx_atten_code[ch] >= 0) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
123 const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
124 bin = s->spx_src_start_freq - 2;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
125 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
126 if (wrapflag[bnd]) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
127 float *coeffs = &s->transform_coeffs[ch][bin];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
128 coeffs[0] *= atten_tab[0];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
129 coeffs[1] *= atten_tab[1];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
130 coeffs[2] *= atten_tab[2];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
131 coeffs[3] *= atten_tab[1];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
132 coeffs[4] *= atten_tab[0];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
133 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
134 bin += s->spx_band_sizes[bnd];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
135 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
136 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
137
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
138 /* Apply noise-blended coefficient scaling based on previously
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
139 calculated RMS energy, blending factors, and SPX coordinates for
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
140 each band. */
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
141 bin = s->spx_src_start_freq;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
142 for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
143 float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f/(1<<31));
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
144 float sscale = s->spx_signal_blend[ch][bnd];
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
145 for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
146 float noise = nscale * (int32_t)av_lfg_get(&s->dith_state);
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
147 s->transform_coeffs[ch][bin] *= sscale;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
148 s->transform_coeffs[ch][bin++] += noise;
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
149 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
150 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
151 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
152 }
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
153
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
154
9680
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
155 /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
156 #define COEFF_0 10273905LL
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
157
9680
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
158 /** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
159 #define COEFF_1 11863283LL
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
160
9680
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
161 /** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
162 #define COEFF_2 3070444LL
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
163
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
164 /**
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
165 * Calculate 6-point IDCT of the pre-mantissas.
9680
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
166 * All calculations are 24-bit fixed-point.
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
167 */
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
168 static void idct6(int pre_mant[6])
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
169 {
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
170 int tmp;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
171 int even0, even1, even2, odd0, odd1, odd2;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
172
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
173 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
174
9680
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
175 even2 = ( pre_mant[2] * COEFF_0) >> 23;
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
176 tmp = ( pre_mant[4] * COEFF_1) >> 23;
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
177 odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
7666
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
178
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
179 even0 = pre_mant[0] + (tmp >> 1);
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
180 even1 = pre_mant[0] - tmp;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
181
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
182 tmp = even0;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
183 even0 = tmp + even2;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
184 even2 = tmp - even2;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
185
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
186 tmp = odd0;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
187 odd0 = tmp + pre_mant[1] + pre_mant[3];
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
188 odd2 = tmp + pre_mant[5] - pre_mant[3];
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
189
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
190 pre_mant[0] = even0 + odd0;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
191 pre_mant[1] = even1 + odd1;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
192 pre_mant[2] = even2 + odd2;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
193 pre_mant[3] = even2 - odd2;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
194 pre_mant[4] = even1 - odd1;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
195 pre_mant[5] = even0 - odd0;
d407738f9a71 add more OKed parts of the E-AC-3 decoder
jbr
parents:
diff changeset
196 }
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
197
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
198 void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
199 {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
200 int bin, blk, gs;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
201 int end_bap, gaq_mode;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
202 GetBitContext *gbc = &s->gbc;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
203 int gaq_gain[AC3_MAX_COEFS];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
204
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
205 gaq_mode = get_bits(gbc, 2);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
206 end_bap = (gaq_mode < 2) ? 12 : 17;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
207
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
208 /* if GAQ gain is used, decode gain codes for bins with hebap between
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
209 8 and end_bap */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
210 gs = 0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
211 if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
212 /* read 1-bit GAQ gain codes */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
213 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
214 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
215 gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
216 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
217 } else if (gaq_mode == EAC3_GAQ_124) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
218 /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
219 int gc = 2;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
220 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
221 if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
222 if (gc++ == 2) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
223 int group_code = get_bits(gbc, 5);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
224 if (group_code > 26) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
225 av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
226 group_code = 26;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
227 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
228 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
229 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
230 gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
231 gc = 0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
232 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
233 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
234 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
235 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
236
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
237 gs=0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
238 for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
239 int hebap = s->bap[ch][bin];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
240 int bits = ff_eac3_bits_vs_hebap[hebap];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
241 if (!hebap) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
242 /* zero-mantissa dithering */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
243 for (blk = 0; blk < 6; blk++) {
9680
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
244 s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
245 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
246 } else if (hebap < 8) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
247 /* Vector Quantization */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
248 int v = get_bits(gbc, bits);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
249 for (blk = 0; blk < 6; blk++) {
9680
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
250 s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
251 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
252 } else {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
253 /* Gain Adaptive Quantization */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
254 int gbits, log_gain;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
255 if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
256 log_gain = gaq_gain[gs++];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
257 } else {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
258 log_gain = 0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
259 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
260 gbits = bits - log_gain;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
261
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
262 for (blk = 0; blk < 6; blk++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
263 int mant = get_sbits(gbc, gbits);
9682
0596729ae4af eac3dec: fix bug in GAQ dequantization. large mantissas should only be
jbr
parents: 9681
diff changeset
264 if (log_gain && mant == -(1 << (gbits-1))) {
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
265 /* large mantissa */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
266 int b;
9681
116836dbd25d eac3dec: make GAQ dequantization 24-bit
jbr
parents: 9680
diff changeset
267 int mbits = bits - (2 - log_gain);
116836dbd25d eac3dec: make GAQ dequantization 24-bit
jbr
parents: 9680
diff changeset
268 mant = get_sbits(gbc, mbits);
116836dbd25d eac3dec: make GAQ dequantization 24-bit
jbr
parents: 9680
diff changeset
269 mant <<= (23 - (mbits - 1));
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
270 /* remap mantissa value to correct for asymmetric quantization */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
271 if (mant >= 0)
9683
815664144471 10l: typing mistake in r18888
jbr
parents: 9682
diff changeset
272 b = 1 << (23 - log_gain);
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
273 else
9681
116836dbd25d eac3dec: make GAQ dequantization 24-bit
jbr
parents: 9680
diff changeset
274 b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8;
9708
d23332ab364f eac3dec: get rid of unnecessary left shifts in 16-bit * 24-bit
jbr
parents: 9683
diff changeset
275 mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
276 } else {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
277 /* small mantissa, no GAQ, or Gk=1 */
9680
debe2623a70a eac3dec: revert commit r18860. keep the AHT IDCT 24-bit. will make AHT GAQ
jbr
parents: 9661
diff changeset
278 mant <<= 24 - bits;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
279 if (!log_gain) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
280 /* remap mantissa value for no GAQ or Gk=1 */
9708
d23332ab364f eac3dec: get rid of unnecessary left shifts in 16-bit * 24-bit
jbr
parents: 9683
diff changeset
281 mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
282 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
283 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
284 s->pre_mantissa[ch][bin][blk] = mant;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
285 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
286 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
287 idct6(s->pre_mantissa[ch][bin]);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
288 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
289 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
290
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
291 int ff_eac3_parse_header(AC3DecodeContext *s)
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
292 {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
293 int i, blk, ch;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
294 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
295 int parse_transient_proc_info;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
296 int num_cpl_blocks;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
297 GetBitContext *gbc = &s->gbc;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
298
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
299 /* An E-AC-3 stream can have multiple independent streams which the
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
300 application can select from. each independent stream can also contain
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
301 dependent streams which are used to add or replace channels. */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
302 if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
9891
7ad7d4094d1f Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents: 9708
diff changeset
303 av_log_missing_feature(s->avctx, "Dependent substream decoding", 1);
8545
a5402e89a80c Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that
superdump
parents: 8281
diff changeset
304 return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
305 } else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
306 av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
8545
a5402e89a80c Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that
superdump
parents: 8281
diff changeset
307 return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
308 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
309
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
310 /* The substream id indicates which substream this frame belongs to. each
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
311 independent stream has its own substream id, and the dependent streams
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
312 associated to an independent stream have matching substream id's. */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
313 if (s->substreamid) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
314 /* only decode substream with id=0. skip any additional substreams. */
9891
7ad7d4094d1f Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents: 9708
diff changeset
315 av_log_missing_feature(s->avctx, "Additional substreams", 1);
8545
a5402e89a80c Factorise enum of AC3 error types to be usable by AAC in the ADTS patch that
superdump
parents: 8281
diff changeset
316 return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
317 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
318
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
319 if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
320 /* The E-AC-3 specification does not tell how to handle reduced sample
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
321 rates in bit allocation. The best assumption would be that it is
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
322 handled like AC-3 DolbyNet, but we cannot be sure until we have a
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
323 sample which utilizes this feature. */
9891
7ad7d4094d1f Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents: 9708
diff changeset
324 av_log_missing_feature(s->avctx, "Reduced sampling rates", 1);
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
325 return -1;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
326 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
327 skip_bits(gbc, 5); // skip bitstream id
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
328
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
329 /* volume control params */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
330 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
331 skip_bits(gbc, 5); // skip dialog normalization
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
332 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
333 skip_bits(gbc, 8); // skip compression gain word
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
334 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
335 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
336
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
337 /* dependent stream channel map */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
338 if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
339 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
340 skip_bits(gbc, 16); // skip custom channel map
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
341 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
342 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
343
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
344 /* mixing metadata */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
345 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
346 /* center and surround mix levels */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
347 if (s->channel_mode > AC3_CHMODE_STEREO) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
348 skip_bits(gbc, 2); // skip preferred stereo downmix mode
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
349 if (s->channel_mode & 1) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
350 /* if three front channels exist */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
351 skip_bits(gbc, 3); //skip Lt/Rt center mix level
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
352 s->center_mix_level = get_bits(gbc, 3);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
353 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
354 if (s->channel_mode & 4) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
355 /* if a surround channel exists */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
356 skip_bits(gbc, 3); //skip Lt/Rt surround mix level
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
357 s->surround_mix_level = get_bits(gbc, 3);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
358 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
359 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
360
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
361 /* lfe mix level */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
362 if (s->lfe_on && get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
363 // TODO: use LFE mix level
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
364 skip_bits(gbc, 5); // skip LFE mix level code
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
365 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
366
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
367 /* info for mixing with other streams and substreams */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
368 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
369 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
370 // TODO: apply program scale factor
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
371 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
372 skip_bits(gbc, 6); // skip program scale factor
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
373 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
374 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
375 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
376 skip_bits(gbc, 6); // skip external program scale factor
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
377 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
378 /* skip mixing parameter data */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
379 switch(get_bits(gbc, 2)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
380 case 1: skip_bits(gbc, 5); break;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
381 case 2: skip_bits(gbc, 12); break;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
382 case 3: {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
383 int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
384 skip_bits_long(gbc, mix_data_size);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
385 break;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
386 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
387 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
388 /* skip pan information for mono or dual mono source */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
389 if (s->channel_mode < AC3_CHMODE_STEREO) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
390 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
391 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
392 /* note: this is not in the ATSC A/52B specification
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
393 reference: ETSI TS 102 366 V1.1.1
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
394 section: E.1.3.1.25 */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
395 skip_bits(gbc, 8); // skip pan mean direction index
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
396 skip_bits(gbc, 6); // skip reserved paninfo bits
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
397 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
398 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
399 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
400 /* skip mixing configuration information */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
401 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
402 for (blk = 0; blk < s->num_blocks; blk++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
403 if (s->num_blocks == 1 || get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
404 skip_bits(gbc, 5);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
405 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
406 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
407 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
408 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
409 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
410
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
411 /* informational metadata */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
412 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
413 skip_bits(gbc, 3); // skip bit stream mode
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
414 skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
415 if (s->channel_mode == AC3_CHMODE_STEREO) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
416 skip_bits(gbc, 4); // skip Dolby surround and headphone mode
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
417 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
418 if (s->channel_mode >= AC3_CHMODE_2F2R) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
419 skip_bits(gbc, 2); // skip Dolby surround EX mode
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
420 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
421 for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
422 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
423 skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
424 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
425 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
426 if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
427 skip_bits1(gbc); // skip source sample rate code
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
428 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
429 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
430
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
431 /* converter synchronization flag
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
432 If frames are less than six blocks, this bit should be turned on
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
433 once every 6 blocks to indicate the start of a frame set.
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
434 reference: RFC 4598, Section 2.1.3 Frame Sets */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
435 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
436 skip_bits1(gbc); // skip converter synchronization flag
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
437 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
438
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
439 /* original frame size code if this stream was converted from AC-3 */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
440 if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT &&
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
441 (s->num_blocks == 6 || get_bits1(gbc))) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
442 skip_bits(gbc, 6); // skip frame size code
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
443 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
444
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
445 /* additional bitstream info */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
446 if (get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
447 int addbsil = get_bits(gbc, 6);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
448 for (i = 0; i < addbsil + 1; i++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
449 skip_bits(gbc, 8); // skip additional bit stream info
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
450 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
451 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
452
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
453 /* audio frame syntax flags, strategy data, and per-frame data */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
454
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
455 if (s->num_blocks == 6) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
456 ac3_exponent_strategy = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
457 parse_aht_info = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
458 } else {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
459 /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
460 do not use AHT */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
461 ac3_exponent_strategy = 1;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
462 parse_aht_info = 0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
463 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
464
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
465 s->snr_offset_strategy = get_bits(gbc, 2);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
466 parse_transient_proc_info = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
467
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
468 s->block_switch_syntax = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
469 if (!s->block_switch_syntax)
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
470 memset(s->block_switch, 0, sizeof(s->block_switch));
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
471
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
472 s->dither_flag_syntax = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
473 if (!s->dither_flag_syntax) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
474 for (ch = 1; ch <= s->fbw_channels; ch++)
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
475 s->dither_flag[ch] = 1;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
476 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
477 s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
478
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
479 s->bit_allocation_syntax = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
480 if (!s->bit_allocation_syntax) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
481 /* set default bit allocation parameters */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
482 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
483 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
484 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab [1];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
485 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
486 s->bit_alloc_params.floor = ff_ac3_floor_tab [7];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
487 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
488
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
489 s->fast_gain_syntax = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
490 s->dba_syntax = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
491 s->skip_syntax = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
492 parse_spx_atten_data = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
493
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
494 /* coupling strategy occurance and coupling use per block */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
495 num_cpl_blocks = 0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
496 if (s->channel_mode > 1) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
497 for (blk = 0; blk < s->num_blocks; blk++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
498 s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
499 if (s->cpl_strategy_exists[blk]) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
500 s->cpl_in_use[blk] = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
501 } else {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
502 s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
503 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
504 num_cpl_blocks += s->cpl_in_use[blk];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
505 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
506 } else {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
507 memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
508 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
509
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
510 /* exponent strategy data */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
511 if (ac3_exponent_strategy) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
512 /* AC-3-style exponent strategy syntax */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
513 for (blk = 0; blk < s->num_blocks; blk++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
514 for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
515 s->exp_strategy[blk][ch] = get_bits(gbc, 2);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
516 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
517 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
518 } else {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
519 /* LUT-based exponent strategy syntax */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
520 for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
7750
f9bd775992d4 merge declaration and init. variable is not used outside the loop.
jbr
parents: 7745
diff changeset
521 int frmchexpstr = get_bits(gbc, 5);
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
522 for (blk = 0; blk < 6; blk++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
523 s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
524 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
525 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
526 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
527 /* LFE exponent strategy */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
528 if (s->lfe_on) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
529 for (blk = 0; blk < s->num_blocks; blk++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
530 s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
531 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
532 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
533 /* original exponent strategies if this stream was converted from AC-3 */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
534 if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
535 (s->num_blocks == 6 || get_bits1(gbc))) {
7752
e3fb2606d5b5 skip converter exponent strategy for all channels at once
jbr
parents: 7750
diff changeset
536 skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
537 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
538
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
539 /* determine which channels use AHT */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
540 if (parse_aht_info) {
7755
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
541 /* For AHT to be used, all non-zero blocks must reuse exponents from
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
542 the first block. Furthermore, for AHT to be used in the coupling
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
543 channel, all blocks must use coupling and use the same coupling
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
544 strategy. */
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
545 s->channel_uses_aht[CPL_CH]=0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
546 for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
7755
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
547 int use_aht = 1;
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
548 for (blk = 1; blk < 6; blk++) {
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
549 if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
550 (!ch && s->cpl_strategy_exists[blk])) {
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
551 use_aht = 0;
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
552 break;
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
553 }
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
554 }
7755
1c0e498ac7bd simplify code and comment regarding determination whether or not AHT is used.
jbr
parents: 7754
diff changeset
555 s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
556 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
557 } else {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
558 memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
559 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
560
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
561 /* per-frame SNR offset */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
562 if (!s->snr_offset_strategy) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
563 int csnroffst = (get_bits(gbc, 6) - 15) << 4;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
564 int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
565 for (ch = 0; ch <= s->channels; ch++)
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
566 s->snr_offset[ch] = snroffst;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
567 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
568
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
569 /* transient pre-noise processing data */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
570 if (parse_transient_proc_info) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
571 for (ch = 1; ch <= s->fbw_channels; ch++) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
572 if (get_bits1(gbc)) { // channel in transient processing
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
573 skip_bits(gbc, 10); // skip transient processing location
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
574 skip_bits(gbc, 8); // skip transient processing length
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
575 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
576 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
577 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
578
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
579 /* spectral extension attenuation data */
11559
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
580 for (ch = 1; ch <= s->fbw_channels; ch++) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
581 if (parse_spx_atten_data && get_bits1(gbc)) {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
582 s->spx_atten_code[ch] = get_bits(gbc, 5);
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
583 } else {
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
584 s->spx_atten_code[ch] = -1;
8142
f17b1eb9ccd1 revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents: 8136
diff changeset
585 }
f17b1eb9ccd1 revert r15812 (E-AC-3 Spectral Extension) pending further review
jbr
parents: 8136
diff changeset
586 }
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
587
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
588 /* block start information */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
589 if (s->num_blocks > 1 && get_bits1(gbc)) {
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
590 /* reference: Section E2.3.2.27
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
591 nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
592 The spec does not say what this data is or what it's used for.
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
593 It is likely the offset of each block within the frame. */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
594 int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
8272
c15abcb0209a ac3dec: use skip_bits_long() for block start bits
jbr
parents: 8142
diff changeset
595 skip_bits_long(gbc, block_start_bits);
9891
7ad7d4094d1f Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents: 9708
diff changeset
596 av_log_missing_feature(s->avctx, "Block start info", 1);
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
597 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
598
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
599 /* syntax state initialization */
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
600 for (ch = 1; ch <= s->fbw_channels; ch++) {
11559
444f4b594fdb Add spectral extension to the E-AC-3 decoder.
cehoyos
parents: 9983
diff changeset
601 s->first_spx_coords[ch] = 1;
7745
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
602 s->first_cpl_coords[ch] = 1;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
603 }
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
604 s->first_cpl_leak = 1;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
605
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
606 return 0;
b09973d487e6 commit more OKed parts of the E-AC-3 decoder
jbr
parents: 7679
diff changeset
607 }