Coverage Report

Created: 2025-12-31 07:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/eac3dec.c
Line
Count
Source
1
/*
2
 * E-AC-3 decoder
3
 * Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
4
 * Copyright (c) 2008 Justin Ruggles
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22
23
/*
24
 * There are several features of E-AC-3 that this decoder does not yet support.
25
 *
26
 * Enhanced Coupling
27
 *     No known samples exist.  If any ever surface, this feature should not be
28
 *     too difficult to implement.
29
 *
30
 * Reduced Sample Rates
31
 *     No known samples exist.  The spec also does not give clear information
32
 *     on how this is to be implemented.
33
 *
34
 * Transient Pre-noise Processing
35
 *     This is side information which a decoder should use to reduce artifacts
36
 *     caused by transients.  There are samples which are known to have this
37
 *     information, but this decoder currently ignores it.
38
 */
39
40
41
#include "avcodec.h"
42
#include "ac3.h"
43
#include "ac3_parser_internal.h"
44
#include "ac3dec.h"
45
#include "ac3dec_data.h"
46
#include "eac3_data.h"
47
48
/** gain adaptive quantization mode */
49
typedef enum {
50
    EAC3_GAQ_NO =0,
51
    EAC3_GAQ_12,
52
    EAC3_GAQ_14,
53
    EAC3_GAQ_124
54
} EAC3GaqMode;
55
56
static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
57
277k
{
58
277k
    int bin, bnd, ch, i;
59
277k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
277k
    float rms_energy[SPX_MAX_BANDS];
61
62
    /* Set copy index mapping table. Set wrap flags to apply a notch filter at
63
       wrap points later on. */
64
277k
    bin = s->spx_dst_start_freq;
65
277k
    num_copy_sections = 0;
66
977k
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
699k
        int copysize;
68
699k
        int bandsize = s->spx_band_sizes[bnd];
69
699k
        if (bin + bandsize > s->spx_src_start_freq) {
70
315k
            copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71
315k
            bin = s->spx_dst_start_freq;
72
315k
            wrapflag[bnd] = 1;
73
315k
        }
74
1.46M
        for (i = 0; i < bandsize; i += copysize) {
75
766k
            if (bin == s->spx_src_start_freq) {
76
66.6k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
66.6k
                bin = s->spx_dst_start_freq;
78
66.6k
            }
79
766k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
766k
            bin += copysize;
81
766k
        }
82
699k
    }
83
277k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
853k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
575k
        if (!s->channel_uses_spx[ch])
87
124k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
451k
        bin = s->spx_src_start_freq;
91
1.31M
        for (i = 0; i < num_copy_sections; i++) {
92
858k
            memcpy(&s->transform_coeffs[ch][bin],
93
858k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
858k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
858k
            bin += copy_sizes[i];
96
858k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
451k
        bin = s->spx_src_start_freq;
100
1.36M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
913k
            int bandsize = s->spx_band_sizes[bnd];
102
913k
            float accum = 0.0f;
103
34.6M
            for (i = 0; i < bandsize; i++) {
104
33.7M
                float coeff = s->transform_coeffs[ch][bin++];
105
33.7M
                accum += coeff * coeff;
106
33.7M
            }
107
913k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
913k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
451k
        if (s->spx_atten_code[ch] >= 0) {
113
112k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
112k
            bin = s->spx_src_start_freq - 2;
115
265k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
152k
                if (wrapflag[bnd]) {
117
126k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
126k
                    coeffs[0] *= atten_tab[0];
119
126k
                    coeffs[1] *= atten_tab[1];
120
126k
                    coeffs[2] *= atten_tab[2];
121
126k
                    coeffs[3] *= atten_tab[1];
122
126k
                    coeffs[4] *= atten_tab[0];
123
126k
                }
124
152k
                bin += s->spx_band_sizes[bnd];
125
152k
            }
126
112k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
451k
        bin = s->spx_src_start_freq;
132
1.36M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
913k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
913k
            float sscale = s->spx_signal_blend[ch][bnd];
135
#if USE_FIXED
136
            // spx_noise_blend and spx_signal_blend are both FP.23
137
            nscale *= 1.0 / (1<<23);
138
            sscale *= 1.0 / (1<<23);
139
114k
            if (nscale < -1.0)
140
1.00k
                nscale = -1.0;
141
#endif
142
34.6M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
33.7M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
33.7M
                s->transform_coeffs[ch][bin]   *= sscale;
145
33.7M
                s->transform_coeffs[ch][bin++] += noise;
146
33.7M
            }
147
913k
        }
148
451k
    }
149
277k
}
ac3dec_float.c:ff_eac3_apply_spectral_extension
Line
Count
Source
57
244k
{
58
244k
    int bin, bnd, ch, i;
59
244k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
244k
    float rms_energy[SPX_MAX_BANDS];
61
62
    /* Set copy index mapping table. Set wrap flags to apply a notch filter at
63
       wrap points later on. */
64
244k
    bin = s->spx_dst_start_freq;
65
244k
    num_copy_sections = 0;
66
845k
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
600k
        int copysize;
68
600k
        int bandsize = s->spx_band_sizes[bnd];
69
600k
        if (bin + bandsize > s->spx_src_start_freq) {
70
275k
            copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71
275k
            bin = s->spx_dst_start_freq;
72
275k
            wrapflag[bnd] = 1;
73
275k
        }
74
1.25M
        for (i = 0; i < bandsize; i += copysize) {
75
655k
            if (bin == s->spx_src_start_freq) {
76
54.9k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
54.9k
                bin = s->spx_dst_start_freq;
78
54.9k
            }
79
655k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
655k
            bin += copysize;
81
655k
        }
82
600k
    }
83
244k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
742k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
497k
        if (!s->channel_uses_spx[ch])
87
95.2k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
402k
        bin = s->spx_src_start_freq;
91
1.16M
        for (i = 0; i < num_copy_sections; i++) {
92
761k
            memcpy(&s->transform_coeffs[ch][bin],
93
761k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
761k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
761k
            bin += copy_sizes[i];
96
761k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
402k
        bin = s->spx_src_start_freq;
100
1.20M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
798k
            int bandsize = s->spx_band_sizes[bnd];
102
798k
            float accum = 0.0f;
103
31.1M
            for (i = 0; i < bandsize; i++) {
104
30.3M
                float coeff = s->transform_coeffs[ch][bin++];
105
30.3M
                accum += coeff * coeff;
106
30.3M
            }
107
798k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
798k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
402k
        if (s->spx_atten_code[ch] >= 0) {
113
109k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
109k
            bin = s->spx_src_start_freq - 2;
115
256k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
146k
                if (wrapflag[bnd]) {
117
122k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
122k
                    coeffs[0] *= atten_tab[0];
119
122k
                    coeffs[1] *= atten_tab[1];
120
122k
                    coeffs[2] *= atten_tab[2];
121
122k
                    coeffs[3] *= atten_tab[1];
122
122k
                    coeffs[4] *= atten_tab[0];
123
122k
                }
124
146k
                bin += s->spx_band_sizes[bnd];
125
146k
            }
126
109k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
402k
        bin = s->spx_src_start_freq;
132
1.20M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
798k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
798k
            float sscale = s->spx_signal_blend[ch][bnd];
135
#if USE_FIXED
136
            // spx_noise_blend and spx_signal_blend are both FP.23
137
            nscale *= 1.0 / (1<<23);
138
            sscale *= 1.0 / (1<<23);
139
            if (nscale < -1.0)
140
                nscale = -1.0;
141
#endif
142
31.1M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
30.3M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
30.3M
                s->transform_coeffs[ch][bin]   *= sscale;
145
30.3M
                s->transform_coeffs[ch][bin++] += noise;
146
30.3M
            }
147
798k
        }
148
402k
    }
149
244k
}
ac3dec_fixed.c:ff_eac3_apply_spectral_extension
Line
Count
Source
57
32.8k
{
58
32.8k
    int bin, bnd, ch, i;
59
32.8k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
32.8k
    float rms_energy[SPX_MAX_BANDS];
61
62
    /* Set copy index mapping table. Set wrap flags to apply a notch filter at
63
       wrap points later on. */
64
32.8k
    bin = s->spx_dst_start_freq;
65
32.8k
    num_copy_sections = 0;
66
131k
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
98.7k
        int copysize;
68
98.7k
        int bandsize = s->spx_band_sizes[bnd];
69
98.7k
        if (bin + bandsize > s->spx_src_start_freq) {
70
39.8k
            copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71
39.8k
            bin = s->spx_dst_start_freq;
72
39.8k
            wrapflag[bnd] = 1;
73
39.8k
        }
74
209k
        for (i = 0; i < bandsize; i += copysize) {
75
110k
            if (bin == s->spx_src_start_freq) {
76
11.7k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
11.7k
                bin = s->spx_dst_start_freq;
78
11.7k
            }
79
110k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
110k
            bin += copysize;
81
110k
        }
82
98.7k
    }
83
32.8k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
110k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
77.8k
        if (!s->channel_uses_spx[ch])
87
29.1k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
48.7k
        bin = s->spx_src_start_freq;
91
146k
        for (i = 0; i < num_copy_sections; i++) {
92
97.3k
            memcpy(&s->transform_coeffs[ch][bin],
93
97.3k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
97.3k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
97.3k
            bin += copy_sizes[i];
96
97.3k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
48.7k
        bin = s->spx_src_start_freq;
100
163k
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
114k
            int bandsize = s->spx_band_sizes[bnd];
102
114k
            float accum = 0.0f;
103
3.53M
            for (i = 0; i < bandsize; i++) {
104
3.42M
                float coeff = s->transform_coeffs[ch][bin++];
105
3.42M
                accum += coeff * coeff;
106
3.42M
            }
107
114k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
114k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
48.7k
        if (s->spx_atten_code[ch] >= 0) {
113
3.04k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
3.04k
            bin = s->spx_src_start_freq - 2;
115
9.03k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
5.99k
                if (wrapflag[bnd]) {
117
4.40k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
4.40k
                    coeffs[0] *= atten_tab[0];
119
4.40k
                    coeffs[1] *= atten_tab[1];
120
4.40k
                    coeffs[2] *= atten_tab[2];
121
4.40k
                    coeffs[3] *= atten_tab[1];
122
4.40k
                    coeffs[4] *= atten_tab[0];
123
4.40k
                }
124
5.99k
                bin += s->spx_band_sizes[bnd];
125
5.99k
            }
126
3.04k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
48.7k
        bin = s->spx_src_start_freq;
132
163k
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
114k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
114k
            float sscale = s->spx_signal_blend[ch][bnd];
135
114k
#if USE_FIXED
136
            // spx_noise_blend and spx_signal_blend are both FP.23
137
114k
            nscale *= 1.0 / (1<<23);
138
114k
            sscale *= 1.0 / (1<<23);
139
114k
            if (nscale < -1.0)
140
1.00k
                nscale = -1.0;
141
114k
#endif
142
3.53M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
3.42M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
3.42M
                s->transform_coeffs[ch][bin]   *= sscale;
145
3.42M
                s->transform_coeffs[ch][bin++] += noise;
146
3.42M
            }
147
114k
        }
148
48.7k
    }
149
32.8k
}
150
151
152
/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
153
5.90M
#define COEFF_0 10273905LL
154
155
/** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
156
5.90M
#define COEFF_1 11863283LL
157
158
/** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
159
5.90M
#define COEFF_2  3070444LL
160
161
/**
162
 * Calculate 6-point IDCT of the pre-mantissas.
163
 * All calculations are 24-bit fixed-point.
164
 */
165
static void idct6(int pre_mant[6])
166
5.90M
{
167
5.90M
    int tmp;
168
5.90M
    int even0, even1, even2, odd0, odd1, odd2;
169
170
5.90M
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
5.90M
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
5.90M
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
5.90M
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
5.90M
    even0 = pre_mant[0] + (tmp >> 1);
177
5.90M
    even1 = pre_mant[0] - tmp;
178
179
5.90M
    tmp = even0;
180
5.90M
    even0 = tmp + even2;
181
5.90M
    even2 = tmp - even2;
182
183
5.90M
    tmp = odd0;
184
5.90M
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
5.90M
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
5.90M
    pre_mant[0] = even0 + odd0;
188
5.90M
    pre_mant[1] = even1 + odd1;
189
5.90M
    pre_mant[2] = even2 + odd2;
190
5.90M
    pre_mant[3] = even2 - odd2;
191
5.90M
    pre_mant[4] = even1 - odd1;
192
5.90M
    pre_mant[5] = even0 - odd0;
193
5.90M
}
ac3dec_float.c:idct6
Line
Count
Source
166
4.83M
{
167
4.83M
    int tmp;
168
4.83M
    int even0, even1, even2, odd0, odd1, odd2;
169
170
4.83M
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
4.83M
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
4.83M
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
4.83M
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
4.83M
    even0 = pre_mant[0] + (tmp >> 1);
177
4.83M
    even1 = pre_mant[0] - tmp;
178
179
4.83M
    tmp = even0;
180
4.83M
    even0 = tmp + even2;
181
4.83M
    even2 = tmp - even2;
182
183
4.83M
    tmp = odd0;
184
4.83M
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
4.83M
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
4.83M
    pre_mant[0] = even0 + odd0;
188
4.83M
    pre_mant[1] = even1 + odd1;
189
4.83M
    pre_mant[2] = even2 + odd2;
190
4.83M
    pre_mant[3] = even2 - odd2;
191
4.83M
    pre_mant[4] = even1 - odd1;
192
4.83M
    pre_mant[5] = even0 - odd0;
193
4.83M
}
ac3dec_fixed.c:idct6
Line
Count
Source
166
1.06M
{
167
1.06M
    int tmp;
168
1.06M
    int even0, even1, even2, odd0, odd1, odd2;
169
170
1.06M
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
1.06M
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
1.06M
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
1.06M
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
1.06M
    even0 = pre_mant[0] + (tmp >> 1);
177
1.06M
    even1 = pre_mant[0] - tmp;
178
179
1.06M
    tmp = even0;
180
1.06M
    even0 = tmp + even2;
181
1.06M
    even2 = tmp - even2;
182
183
1.06M
    tmp = odd0;
184
1.06M
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
1.06M
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
1.06M
    pre_mant[0] = even0 + odd0;
188
1.06M
    pre_mant[1] = even1 + odd1;
189
1.06M
    pre_mant[2] = even2 + odd2;
190
1.06M
    pre_mant[3] = even2 - odd2;
191
1.06M
    pre_mant[4] = even1 - odd1;
192
1.06M
    pre_mant[5] = even0 - odd0;
193
1.06M
}
194
195
static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
196
87.7k
{
197
87.7k
    int bin, blk, gs;
198
87.7k
    int end_bap, gaq_mode;
199
87.7k
    GetBitContext *gbc = &s->gbc;
200
87.7k
    int gaq_gain[AC3_MAX_COEFS];
201
202
87.7k
    gaq_mode = get_bits(gbc, 2);
203
87.7k
    end_bap = (gaq_mode < 2) ? 12 : 17;
204
205
    /* if GAQ gain is used, decode gain codes for bins with hebap between
206
       8 and end_bap */
207
87.7k
    gs = 0;
208
87.7k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
2.73M
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
2.69M
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212
156k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
2.69M
        }
214
47.4k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
16.1k
        int gc = 2;
217
1.02M
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
1.00M
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
116k
                if (gc++ == 2) {
220
39.8k
                    int group_code = get_bits(gbc, 5);
221
39.8k
                    if (group_code > 26) {
222
18.0k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
18.0k
                        group_code = 26;
224
18.0k
                    }
225
39.8k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
39.8k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
39.8k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
39.8k
                    gc = 0;
229
39.8k
                }
230
116k
            }
231
1.00M
        }
232
16.1k
    }
233
234
87.7k
    gs=0;
235
5.98M
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
5.90M
        int hebap = s->bap[ch][bin];
237
5.90M
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
5.90M
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
7.76M
            for (blk = 0; blk < 6; blk++) {
241
6.65M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
6.65M
            }
243
4.79M
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
103k
            int v = get_bits(gbc, bits);
246
726k
            for (blk = 0; blk < 6; blk++) {
247
622k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
622k
            }
249
4.68M
        } else {
250
            /* Gain Adaptive Quantization */
251
4.68M
            int gbits, log_gain;
252
4.68M
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
273k
                log_gain = gaq_gain[gs++];
254
4.41M
            } else {
255
4.41M
                log_gain = 0;
256
4.41M
            }
257
4.68M
            gbits = bits - log_gain;
258
259
32.8M
            for (blk = 0; blk < 6; blk++) {
260
28.1M
                int mant = get_sbits(gbc, gbits);
261
28.1M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
158k
                    int b;
264
158k
                    int mbits = bits - (2 - log_gain);
265
158k
                    mant = get_sbits(gbc, mbits);
266
158k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
158k
                    if (mant >= 0)
269
26.2k
                        b = 1 << (23 - log_gain);
270
132k
                    else
271
132k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
158k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
27.9M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
27.9M
                    mant *= (1 << 24 - bits);
276
27.9M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
27.1M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
27.1M
                    }
280
27.9M
                }
281
28.1M
                s->pre_mantissa[ch][bin][blk] = mant;
282
28.1M
            }
283
4.68M
        }
284
5.90M
        idct6(s->pre_mantissa[ch][bin]);
285
5.90M
    }
286
87.7k
}
ac3dec_float.c:ff_eac3_decode_transform_coeffs_aht_ch
Line
Count
Source
196
71.6k
{
197
71.6k
    int bin, blk, gs;
198
71.6k
    int end_bap, gaq_mode;
199
71.6k
    GetBitContext *gbc = &s->gbc;
200
71.6k
    int gaq_gain[AC3_MAX_COEFS];
201
202
71.6k
    gaq_mode = get_bits(gbc, 2);
203
71.6k
    end_bap = (gaq_mode < 2) ? 12 : 17;
204
205
    /* if GAQ gain is used, decode gain codes for bins with hebap between
206
       8 and end_bap */
207
71.6k
    gs = 0;
208
71.6k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
2.36M
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
2.32M
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212
128k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
2.32M
        }
214
36.6k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
12.5k
        int gc = 2;
217
776k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
763k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
83.6k
                if (gc++ == 2) {
220
28.7k
                    int group_code = get_bits(gbc, 5);
221
28.7k
                    if (group_code > 26) {
222
13.6k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
13.6k
                        group_code = 26;
224
13.6k
                    }
225
28.7k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
28.7k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
28.7k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
28.7k
                    gc = 0;
229
28.7k
                }
230
83.6k
            }
231
763k
        }
232
12.5k
    }
233
234
71.6k
    gs=0;
235
4.90M
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
4.83M
        int hebap = s->bap[ch][bin];
237
4.83M
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
4.83M
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
3.02M
            for (blk = 0; blk < 6; blk++) {
241
2.59M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
2.59M
            }
243
4.40M
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
80.7k
            int v = get_bits(gbc, bits);
246
565k
            for (blk = 0; blk < 6; blk++) {
247
484k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
484k
            }
249
4.32M
        } else {
250
            /* Gain Adaptive Quantization */
251
4.32M
            int gbits, log_gain;
252
4.32M
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
211k
                log_gain = gaq_gain[gs++];
254
4.11M
            } else {
255
4.11M
                log_gain = 0;
256
4.11M
            }
257
4.32M
            gbits = bits - log_gain;
258
259
30.2M
            for (blk = 0; blk < 6; blk++) {
260
25.9M
                int mant = get_sbits(gbc, gbits);
261
25.9M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
134k
                    int b;
264
134k
                    int mbits = bits - (2 - log_gain);
265
134k
                    mant = get_sbits(gbc, mbits);
266
134k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
134k
                    if (mant >= 0)
269
19.5k
                        b = 1 << (23 - log_gain);
270
115k
                    else
271
115k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
134k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
25.8M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
25.8M
                    mant *= (1 << 24 - bits);
276
25.8M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
25.1M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
25.1M
                    }
280
25.8M
                }
281
25.9M
                s->pre_mantissa[ch][bin][blk] = mant;
282
25.9M
            }
283
4.32M
        }
284
4.83M
        idct6(s->pre_mantissa[ch][bin]);
285
4.83M
    }
286
71.6k
}
ac3dec_fixed.c:ff_eac3_decode_transform_coeffs_aht_ch
Line
Count
Source
196
16.0k
{
197
16.0k
    int bin, blk, gs;
198
16.0k
    int end_bap, gaq_mode;
199
16.0k
    GetBitContext *gbc = &s->gbc;
200
16.0k
    int gaq_gain[AC3_MAX_COEFS];
201
202
16.0k
    gaq_mode = get_bits(gbc, 2);
203
16.0k
    end_bap = (gaq_mode < 2) ? 12 : 17;
204
205
    /* if GAQ gain is used, decode gain codes for bins with hebap between
206
       8 and end_bap */
207
16.0k
    gs = 0;
208
16.0k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
371k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
366k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212
28.6k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
366k
        }
214
10.7k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
3.62k
        int gc = 2;
217
244k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
240k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
32.7k
                if (gc++ == 2) {
220
11.1k
                    int group_code = get_bits(gbc, 5);
221
11.1k
                    if (group_code > 26) {
222
4.46k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
4.46k
                        group_code = 26;
224
4.46k
                    }
225
11.1k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
11.1k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
11.1k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
11.1k
                    gc = 0;
229
11.1k
                }
230
32.7k
            }
231
240k
        }
232
3.62k
    }
233
234
16.0k
    gs=0;
235
1.07M
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
1.06M
        int hebap = s->bap[ch][bin];
237
1.06M
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
1.06M
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
4.74M
            for (blk = 0; blk < 6; blk++) {
241
4.06M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
4.06M
            }
243
678k
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
22.9k
            int v = get_bits(gbc, bits);
246
160k
            for (blk = 0; blk < 6; blk++) {
247
137k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
137k
            }
249
362k
        } else {
250
            /* Gain Adaptive Quantization */
251
362k
            int gbits, log_gain;
252
362k
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
61.3k
                log_gain = gaq_gain[gs++];
254
301k
            } else {
255
301k
                log_gain = 0;
256
301k
            }
257
362k
            gbits = bits - log_gain;
258
259
2.53M
            for (blk = 0; blk < 6; blk++) {
260
2.17M
                int mant = get_sbits(gbc, gbits);
261
2.17M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
23.7k
                    int b;
264
23.7k
                    int mbits = bits - (2 - log_gain);
265
23.7k
                    mant = get_sbits(gbc, mbits);
266
23.7k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
23.7k
                    if (mant >= 0)
269
6.68k
                        b = 1 << (23 - log_gain);
270
17.1k
                    else
271
17.1k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
23.7k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
2.15M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
2.15M
                    mant *= (1 << 24 - bits);
276
2.15M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
1.93M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
1.93M
                    }
280
2.15M
                }
281
2.17M
                s->pre_mantissa[ch][bin][blk] = mant;
282
2.17M
            }
283
362k
        }
284
1.06M
        idct6(s->pre_mantissa[ch][bin]);
285
1.06M
    }
286
16.0k
}
287
288
static int ff_eac3_parse_header(AC3DecodeContext *s, const AC3HeaderInfo *hdr)
289
2.52M
{
290
2.52M
    int i, blk, ch;
291
2.52M
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
2.52M
    int parse_transient_proc_info;
293
2.52M
    int num_cpl_blocks;
294
2.52M
    GetBitContext *gbc = &s->gbc;
295
296
    /* An E-AC-3 stream can have multiple independent streams which the
297
       application can select from. each independent stream can also contain
298
       dependent streams which are used to add or replace channels. */
299
2.52M
    if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
300
0
        av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
301
0
        return AC3_PARSE_ERROR_FRAME_TYPE;
302
0
    }
303
304
    /* The substream id indicates which substream this frame belongs to. each
305
       independent stream has its own substream id, and the dependent streams
306
       associated to an independent stream have matching substream id's. */
307
2.52M
    if (s->substreamid) {
308
        /* only decode substream with id=0. skip any additional substreams. */
309
0
        if (!s->eac3_subsbtreamid_found) {
310
0
            s->eac3_subsbtreamid_found = 1;
311
0
            avpriv_request_sample(s->avctx, "Additional substreams");
312
0
        }
313
0
        return AC3_PARSE_ERROR_FRAME_TYPE;
314
0
    }
315
316
2.52M
    if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
317
        /* The E-AC-3 specification does not tell how to handle reduced sample
318
           rates in bit allocation.  The best assumption would be that it is
319
           handled like AC-3 DolbyNet, but we cannot be sure until we have a
320
           sample which utilizes this feature. */
321
8.57k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
8.57k
        return AVERROR_PATCHWELCOME;
323
8.57k
    }
324
325
    /* volume control params */
326
5.62M
    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327
3.11M
        s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
3.11M
        if (s->dialog_normalization[i] == 0) {
329
221k
            s->dialog_normalization[i] = -31;
330
221k
        }
331
3.11M
        if (s->target_level != 0) {
332
0
            s->level_gain[i] = powf(2.0f,
333
0
                (float)(s->target_level - s->dialog_normalization[i])/6.0f);
334
0
        }
335
3.11M
        if (hdr->compression_exists[i]) {
336
1.69M
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
1.69M
        }
338
3.11M
    }
339
340
2.51M
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
2.51M
    s->preferred_downmix       = hdr->preferred_downmix;
344
2.51M
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
2.51M
    s->center_mix_level        = hdr->center_mix_level;
346
2.51M
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
2.51M
    s->surround_mix_level      = hdr->surround_mix_level;
348
2.51M
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
2.51M
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
2.51M
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
2.51M
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
2.51M
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
2.51M
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
2.51M
    s->eac3_extension_type_a = hdr->eac3_extension_type_a;
359
360
    /* audio frame syntax flags, strategy data, and per-frame data */
361
362
2.51M
    if (s->num_blocks == 6) {
363
1.14M
        ac3_exponent_strategy = get_bits1(gbc);
364
1.14M
        parse_aht_info        = get_bits1(gbc);
365
1.36M
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
1.36M
        ac3_exponent_strategy = 1;
369
1.36M
        parse_aht_info = 0;
370
1.36M
    }
371
372
2.51M
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
2.51M
    parse_transient_proc_info = get_bits1(gbc);
374
375
2.51M
    s->block_switch_syntax = get_bits1(gbc);
376
2.51M
    if (!s->block_switch_syntax)
377
1.83M
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
2.51M
    s->dither_flag_syntax = get_bits1(gbc);
380
2.51M
    if (!s->dither_flag_syntax) {
381
7.66M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
5.71M
            s->dither_flag[ch] = 1;
383
1.95M
    }
384
2.51M
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
2.51M
    s->bit_allocation_syntax = get_bits1(gbc);
387
2.51M
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
1.98M
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
1.98M
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
1.98M
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
1.98M
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
1.98M
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
1.98M
    }
395
396
2.51M
    s->fast_gain_syntax  = get_bits1(gbc);
397
2.51M
    s->dba_syntax        = get_bits1(gbc);
398
2.51M
    s->skip_syntax       = get_bits1(gbc);
399
2.51M
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
2.51M
    num_cpl_blocks = 0;
403
2.51M
    if (s->channel_mode > 1) {
404
9.02M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
7.44M
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
7.44M
            if (s->cpl_strategy_exists[blk]) {
407
3.58M
                s->cpl_in_use[blk] = get_bits1(gbc);
408
3.86M
            } else {
409
3.86M
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
3.86M
            }
411
7.44M
            num_cpl_blocks += s->cpl_in_use[blk];
412
7.44M
        }
413
1.58M
    } else {
414
934k
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
934k
    }
416
417
    /* exponent strategy data */
418
2.51M
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
6.63M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
19.8M
            for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422
14.8M
                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423
14.8M
            }
424
4.91M
        }
425
1.72M
    } else {
426
        /* LUT-based exponent strategy syntax */
427
4.27M
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
3.48M
            int frmchexpstr = get_bits(gbc, 5);
429
24.4M
            for (blk = 0; blk < 6; blk++) {
430
20.9M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
20.9M
            }
432
3.48M
        }
433
792k
    }
434
    /* LFE exponent strategy */
435
2.51M
    if (s->lfe_on) {
436
7.30M
        for (blk = 0; blk < s->num_blocks; blk++) {
437
5.89M
            s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438
5.89M
        }
439
1.41M
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
2.51M
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
1.53M
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
1.03M
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
1.03M
    }
445
446
    /* determine which channels use AHT */
447
2.51M
    if (parse_aht_info) {
448
        /* For AHT to be used, all non-zero blocks must reuse exponents from
449
           the first block.  Furthermore, for AHT to be used in the coupling
450
           channel, all blocks must use coupling and use the same coupling
451
           strategy. */
452
323k
        s->channel_uses_aht[CPL_CH]=0;
453
1.66M
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
1.34M
            int use_aht = 1;
455
4.89M
            for (blk = 1; blk < 6; blk++) {
456
4.27M
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
3.55M
                        (!ch && s->cpl_strategy_exists[blk])) {
458
732k
                    use_aht = 0;
459
732k
                    break;
460
732k
                }
461
4.27M
            }
462
1.34M
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
1.34M
        }
464
2.19M
    } else {
465
2.19M
        memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466
2.19M
    }
467
468
    /* per-frame SNR offset */
469
2.51M
    if (!s->snr_offset_strategy) {
470
1.37M
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
1.37M
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
7.45M
        for (ch = 0; ch <= s->channels; ch++)
473
6.08M
            s->snr_offset[ch] = snroffst;
474
1.37M
    }
475
476
    /* transient pre-noise processing data */
477
2.51M
    if (parse_transient_proc_info) {
478
1.60M
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
1.20M
            if (get_bits1(gbc)) { // channel in transient processing
480
516k
                skip_bits(gbc, 10); // skip transient processing location
481
516k
                skip_bits(gbc, 8);  // skip transient processing length
482
516k
            }
483
1.20M
        }
484
398k
    }
485
486
    /* spectral extension attenuation data */
487
10.1M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
7.59M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
636k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
6.95M
        } else {
491
6.95M
            s->spx_atten_code[ch] = -1;
492
6.95M
        }
493
7.59M
    }
494
495
    /* block start information */
496
2.51M
    if (s->num_blocks > 1 && get_bits1(gbc)) {
497
        /* reference: Section E2.3.2.27
498
           nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
499
           The spec does not say what this data is or what it's used for.
500
           It is likely the offset of each block within the frame. */
501
368k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
368k
        skip_bits_long(gbc, block_start_bits);
503
368k
        avpriv_request_sample(s->avctx, "Block start info");
504
368k
    }
505
506
    /* syntax state initialization */
507
10.1M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
7.59M
        s->first_spx_coords[ch] = 1;
509
7.59M
        s->first_cpl_coords[ch] = 1;
510
7.59M
    }
511
2.51M
    s->first_cpl_leak = 1;
512
513
2.51M
    return 0;
514
2.52M
}
ac3dec_float.c:ff_eac3_parse_header
Line
Count
Source
289
1.81M
{
290
1.81M
    int i, blk, ch;
291
1.81M
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
1.81M
    int parse_transient_proc_info;
293
1.81M
    int num_cpl_blocks;
294
1.81M
    GetBitContext *gbc = &s->gbc;
295
296
    /* An E-AC-3 stream can have multiple independent streams which the
297
       application can select from. each independent stream can also contain
298
       dependent streams which are used to add or replace channels. */
299
1.81M
    if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
300
0
        av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
301
0
        return AC3_PARSE_ERROR_FRAME_TYPE;
302
0
    }
303
304
    /* The substream id indicates which substream this frame belongs to. each
305
       independent stream has its own substream id, and the dependent streams
306
       associated to an independent stream have matching substream id's. */
307
1.81M
    if (s->substreamid) {
308
        /* only decode substream with id=0. skip any additional substreams. */
309
0
        if (!s->eac3_subsbtreamid_found) {
310
0
            s->eac3_subsbtreamid_found = 1;
311
0
            avpriv_request_sample(s->avctx, "Additional substreams");
312
0
        }
313
0
        return AC3_PARSE_ERROR_FRAME_TYPE;
314
0
    }
315
316
1.81M
    if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
317
        /* The E-AC-3 specification does not tell how to handle reduced sample
318
           rates in bit allocation.  The best assumption would be that it is
319
           handled like AC-3 DolbyNet, but we cannot be sure until we have a
320
           sample which utilizes this feature. */
321
1.49k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
1.49k
        return AVERROR_PATCHWELCOME;
323
1.49k
    }
324
325
    /* volume control params */
326
3.97M
    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327
2.16M
        s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
2.16M
        if (s->dialog_normalization[i] == 0) {
329
47.6k
            s->dialog_normalization[i] = -31;
330
47.6k
        }
331
2.16M
        if (s->target_level != 0) {
332
0
            s->level_gain[i] = powf(2.0f,
333
0
                (float)(s->target_level - s->dialog_normalization[i])/6.0f);
334
0
        }
335
2.16M
        if (hdr->compression_exists[i]) {
336
1.20M
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
1.20M
        }
338
2.16M
    }
339
340
1.81M
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
1.81M
    s->preferred_downmix       = hdr->preferred_downmix;
344
1.81M
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
1.81M
    s->center_mix_level        = hdr->center_mix_level;
346
1.81M
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
1.81M
    s->surround_mix_level      = hdr->surround_mix_level;
348
1.81M
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
1.81M
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
1.81M
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
1.81M
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
1.81M
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
1.81M
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
1.81M
    s->eac3_extension_type_a = hdr->eac3_extension_type_a;
359
360
    /* audio frame syntax flags, strategy data, and per-frame data */
361
362
1.81M
    if (s->num_blocks == 6) {
363
983k
        ac3_exponent_strategy = get_bits1(gbc);
364
983k
        parse_aht_info        = get_bits1(gbc);
365
983k
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
831k
        ac3_exponent_strategy = 1;
369
831k
        parse_aht_info = 0;
370
831k
    }
371
372
1.81M
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
1.81M
    parse_transient_proc_info = get_bits1(gbc);
374
375
1.81M
    s->block_switch_syntax = get_bits1(gbc);
376
1.81M
    if (!s->block_switch_syntax)
377
1.25M
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
1.81M
    s->dither_flag_syntax = get_bits1(gbc);
380
1.81M
    if (!s->dither_flag_syntax) {
381
5.58M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
4.20M
            s->dither_flag[ch] = 1;
383
1.37M
    }
384
1.81M
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
1.81M
    s->bit_allocation_syntax = get_bits1(gbc);
387
1.81M
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
1.40M
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
1.40M
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
1.40M
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
1.40M
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
1.40M
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
1.40M
    }
395
396
1.81M
    s->fast_gain_syntax  = get_bits1(gbc);
397
1.81M
    s->dba_syntax        = get_bits1(gbc);
398
1.81M
    s->skip_syntax       = get_bits1(gbc);
399
1.81M
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
1.81M
    num_cpl_blocks = 0;
403
1.81M
    if (s->channel_mode > 1) {
404
7.49M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
6.21M
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
6.21M
            if (s->cpl_strategy_exists[blk]) {
407
2.99M
                s->cpl_in_use[blk] = get_bits1(gbc);
408
3.22M
            } else {
409
3.22M
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
3.22M
            }
411
6.21M
            num_cpl_blocks += s->cpl_in_use[blk];
412
6.21M
        }
413
1.27M
    } else {
414
541k
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
541k
    }
416
417
    /* exponent strategy data */
418
1.81M
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
4.47M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
14.4M
            for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422
11.0M
                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423
11.0M
            }
424
3.32M
        }
425
1.14M
    } else {
426
        /* LUT-based exponent strategy syntax */
427
3.52M
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
2.85M
            int frmchexpstr = get_bits(gbc, 5);
429
19.9M
            for (blk = 0; blk < 6; blk++) {
430
17.1M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
17.1M
            }
432
2.85M
        }
433
667k
    }
434
    /* LFE exponent strategy */
435
1.81M
    if (s->lfe_on) {
436
4.83M
        for (blk = 0; blk < s->num_blocks; blk++) {
437
3.97M
            s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438
3.97M
        }
439
857k
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
1.81M
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
1.31M
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
942k
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
942k
    }
445
446
    /* determine which channels use AHT */
447
1.81M
    if (parse_aht_info) {
448
        /* For AHT to be used, all non-zero blocks must reuse exponents from
449
           the first block.  Furthermore, for AHT to be used in the coupling
450
           channel, all blocks must use coupling and use the same coupling
451
           strategy. */
452
274k
        s->channel_uses_aht[CPL_CH]=0;
453
1.40M
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
1.12M
            int use_aht = 1;
455
4.31M
            for (blk = 1; blk < 6; blk++) {
456
3.75M
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
3.19M
                        (!ch && s->cpl_strategy_exists[blk])) {
458
564k
                    use_aht = 0;
459
564k
                    break;
460
564k
                }
461
3.75M
            }
462
1.12M
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
1.12M
        }
464
1.54M
    } else {
465
1.54M
        memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466
1.54M
    }
467
468
    /* per-frame SNR offset */
469
1.81M
    if (!s->snr_offset_strategy) {
470
861k
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
861k
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
4.73M
        for (ch = 0; ch <= s->channels; ch++)
473
3.87M
            s->snr_offset[ch] = snroffst;
474
861k
    }
475
476
    /* transient pre-noise processing data */
477
1.81M
    if (parse_transient_proc_info) {
478
1.05M
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
779k
            if (get_bits1(gbc)) { // channel in transient processing
480
358k
                skip_bits(gbc, 10); // skip transient processing location
481
358k
                skip_bits(gbc, 8);  // skip transient processing length
482
358k
            }
483
779k
        }
484
280k
    }
485
486
    /* spectral extension attenuation data */
487
7.55M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
5.74M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
423k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
5.32M
        } else {
491
5.32M
            s->spx_atten_code[ch] = -1;
492
5.32M
        }
493
5.74M
    }
494
495
    /* block start information */
496
1.81M
    if (s->num_blocks > 1 && get_bits1(gbc)) {
497
        /* reference: Section E2.3.2.27
498
           nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
499
           The spec does not say what this data is or what it's used for.
500
           It is likely the offset of each block within the frame. */
501
273k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
273k
        skip_bits_long(gbc, block_start_bits);
503
273k
        avpriv_request_sample(s->avctx, "Block start info");
504
273k
    }
505
506
    /* syntax state initialization */
507
7.55M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
5.74M
        s->first_spx_coords[ch] = 1;
509
5.74M
        s->first_cpl_coords[ch] = 1;
510
5.74M
    }
511
1.81M
    s->first_cpl_leak = 1;
512
513
1.81M
    return 0;
514
1.81M
}
ac3dec_fixed.c:ff_eac3_parse_header
Line
Count
Source
289
707k
{
290
707k
    int i, blk, ch;
291
707k
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
707k
    int parse_transient_proc_info;
293
707k
    int num_cpl_blocks;
294
707k
    GetBitContext *gbc = &s->gbc;
295
296
    /* An E-AC-3 stream can have multiple independent streams which the
297
       application can select from. each independent stream can also contain
298
       dependent streams which are used to add or replace channels. */
299
707k
    if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
300
0
        av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
301
0
        return AC3_PARSE_ERROR_FRAME_TYPE;
302
0
    }
303
304
    /* The substream id indicates which substream this frame belongs to. each
305
       independent stream has its own substream id, and the dependent streams
306
       associated to an independent stream have matching substream id's. */
307
707k
    if (s->substreamid) {
308
        /* only decode substream with id=0. skip any additional substreams. */
309
0
        if (!s->eac3_subsbtreamid_found) {
310
0
            s->eac3_subsbtreamid_found = 1;
311
0
            avpriv_request_sample(s->avctx, "Additional substreams");
312
0
        }
313
0
        return AC3_PARSE_ERROR_FRAME_TYPE;
314
0
    }
315
316
707k
    if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
317
        /* The E-AC-3 specification does not tell how to handle reduced sample
318
           rates in bit allocation.  The best assumption would be that it is
319
           handled like AC-3 DolbyNet, but we cannot be sure until we have a
320
           sample which utilizes this feature. */
321
7.07k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
7.07k
        return AVERROR_PATCHWELCOME;
323
7.07k
    }
324
325
    /* volume control params */
326
1.64M
    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327
949k
        s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
949k
        if (s->dialog_normalization[i] == 0) {
329
173k
            s->dialog_normalization[i] = -31;
330
173k
        }
331
949k
        if (s->target_level != 0) {
332
0
            s->level_gain[i] = powf(2.0f,
333
0
                (float)(s->target_level - s->dialog_normalization[i])/6.0f);
334
0
        }
335
949k
        if (hdr->compression_exists[i]) {
336
487k
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
487k
        }
338
949k
    }
339
340
700k
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
700k
    s->preferred_downmix       = hdr->preferred_downmix;
344
700k
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
700k
    s->center_mix_level        = hdr->center_mix_level;
346
700k
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
700k
    s->surround_mix_level      = hdr->surround_mix_level;
348
700k
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
700k
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
700k
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
700k
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
700k
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
700k
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
700k
    s->eac3_extension_type_a = hdr->eac3_extension_type_a;
359
360
    /* audio frame syntax flags, strategy data, and per-frame data */
361
362
700k
    if (s->num_blocks == 6) {
363
163k
        ac3_exponent_strategy = get_bits1(gbc);
364
163k
        parse_aht_info        = get_bits1(gbc);
365
537k
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
537k
        ac3_exponent_strategy = 1;
369
537k
        parse_aht_info = 0;
370
537k
    }
371
372
700k
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
700k
    parse_transient_proc_info = get_bits1(gbc);
374
375
700k
    s->block_switch_syntax = get_bits1(gbc);
376
700k
    if (!s->block_switch_syntax)
377
585k
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
700k
    s->dither_flag_syntax = get_bits1(gbc);
380
700k
    if (!s->dither_flag_syntax) {
381
2.08M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
1.50M
            s->dither_flag[ch] = 1;
383
578k
    }
384
700k
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
700k
    s->bit_allocation_syntax = get_bits1(gbc);
387
700k
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
577k
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
577k
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
577k
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
577k
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
577k
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
577k
    }
395
396
700k
    s->fast_gain_syntax  = get_bits1(gbc);
397
700k
    s->dba_syntax        = get_bits1(gbc);
398
700k
    s->skip_syntax       = get_bits1(gbc);
399
700k
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
700k
    num_cpl_blocks = 0;
403
700k
    if (s->channel_mode > 1) {
404
1.53M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
1.22M
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
1.22M
            if (s->cpl_strategy_exists[blk]) {
407
595k
                s->cpl_in_use[blk] = get_bits1(gbc);
408
634k
            } else {
409
634k
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
634k
            }
411
1.22M
            num_cpl_blocks += s->cpl_in_use[blk];
412
1.22M
        }
413
392k
    } else {
414
392k
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
392k
    }
416
417
    /* exponent strategy data */
418
700k
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
2.16M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
5.38M
            for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422
3.78M
                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423
3.78M
            }
424
1.59M
        }
425
575k
    } else {
426
        /* LUT-based exponent strategy syntax */
427
757k
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
631k
            int frmchexpstr = get_bits(gbc, 5);
429
4.42M
            for (blk = 0; blk < 6; blk++) {
430
3.79M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
3.79M
            }
432
631k
        }
433
125k
    }
434
    /* LFE exponent strategy */
435
700k
    if (s->lfe_on) {
436
2.47M
        for (blk = 0; blk < s->num_blocks; blk++) {
437
1.91M
            s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438
1.91M
        }
439
553k
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
700k
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
225k
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
91.2k
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
91.2k
    }
445
446
    /* determine which channels use AHT */
447
700k
    if (parse_aht_info) {
448
        /* For AHT to be used, all non-zero blocks must reuse exponents from
449
           the first block.  Furthermore, for AHT to be used in the coupling
450
           channel, all blocks must use coupling and use the same coupling
451
           strategy. */
452
48.7k
        s->channel_uses_aht[CPL_CH]=0;
453
269k
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
220k
            int use_aht = 1;
455
578k
            for (blk = 1; blk < 6; blk++) {
456
525k
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
359k
                        (!ch && s->cpl_strategy_exists[blk])) {
458
168k
                    use_aht = 0;
459
168k
                    break;
460
168k
                }
461
525k
            }
462
220k
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
220k
        }
464
652k
    } else {
465
652k
        memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466
652k
    }
467
468
    /* per-frame SNR offset */
469
700k
    if (!s->snr_offset_strategy) {
470
509k
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
509k
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
2.71M
        for (ch = 0; ch <= s->channels; ch++)
473
2.20M
            s->snr_offset[ch] = snroffst;
474
509k
    }
475
476
    /* transient pre-noise processing data */
477
700k
    if (parse_transient_proc_info) {
478
542k
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
423k
            if (get_bits1(gbc)) { // channel in transient processing
480
157k
                skip_bits(gbc, 10); // skip transient processing location
481
157k
                skip_bits(gbc, 8);  // skip transient processing length
482
157k
            }
483
423k
        }
484
118k
    }
485
486
    /* spectral extension attenuation data */
487
2.55M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
1.85M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
212k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
1.63M
        } else {
491
1.63M
            s->spx_atten_code[ch] = -1;
492
1.63M
        }
493
1.85M
    }
494
495
    /* block start information */
496
700k
    if (s->num_blocks > 1 && get_bits1(gbc)) {
497
        /* reference: Section E2.3.2.27
498
           nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
499
           The spec does not say what this data is or what it's used for.
500
           It is likely the offset of each block within the frame. */
501
95.3k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
95.3k
        skip_bits_long(gbc, block_start_bits);
503
95.3k
        avpriv_request_sample(s->avctx, "Block start info");
504
95.3k
    }
505
506
    /* syntax state initialization */
507
2.55M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
1.85M
        s->first_spx_coords[ch] = 1;
509
1.85M
        s->first_cpl_coords[ch] = 1;
510
1.85M
    }
511
700k
    s->first_cpl_leak = 1;
512
513
700k
    return 0;
514
707k
}