Coverage Report

Created: 2025-11-16 07:20

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
323k
{
58
323k
    int bin, bnd, ch, i;
59
323k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
323k
    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
323k
    bin = s->spx_dst_start_freq;
65
323k
    num_copy_sections = 0;
66
1.07M
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
746k
        int copysize;
68
746k
        int bandsize = s->spx_band_sizes[bnd];
69
746k
        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.56M
        for (i = 0; i < bandsize; i += copysize) {
75
817k
            if (bin == s->spx_src_start_freq) {
76
70.8k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
70.8k
                bin = s->spx_dst_start_freq;
78
70.8k
            }
79
817k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
817k
            bin += copysize;
81
817k
        }
82
746k
    }
83
323k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
975k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
652k
        if (!s->channel_uses_spx[ch])
87
128k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
523k
        bin = s->spx_src_start_freq;
91
1.46M
        for (i = 0; i < num_copy_sections; i++) {
92
941k
            memcpy(&s->transform_coeffs[ch][bin],
93
941k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
941k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
941k
            bin += copy_sizes[i];
96
941k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
523k
        bin = s->spx_src_start_freq;
100
1.51M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
993k
            int bandsize = s->spx_band_sizes[bnd];
102
993k
            float accum = 0.0f;
103
39.4M
            for (i = 0; i < bandsize; i++) {
104
38.4M
                float coeff = s->transform_coeffs[ch][bin++];
105
38.4M
                accum += coeff * coeff;
106
38.4M
            }
107
993k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
993k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
523k
        if (s->spx_atten_code[ch] >= 0) {
113
151k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
151k
            bin = s->spx_src_start_freq - 2;
115
350k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
198k
                if (wrapflag[bnd]) {
117
168k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
168k
                    coeffs[0] *= atten_tab[0];
119
168k
                    coeffs[1] *= atten_tab[1];
120
168k
                    coeffs[2] *= atten_tab[2];
121
168k
                    coeffs[3] *= atten_tab[1];
122
168k
                    coeffs[4] *= atten_tab[0];
123
168k
                }
124
198k
                bin += s->spx_band_sizes[bnd];
125
198k
            }
126
151k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
523k
        bin = s->spx_src_start_freq;
132
1.51M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
993k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
993k
            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
104k
            if (nscale < -1.0)
140
611
                nscale = -1.0;
141
#endif
142
39.4M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
38.4M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
38.4M
                s->transform_coeffs[ch][bin]   *= sscale;
145
38.4M
                s->transform_coeffs[ch][bin++] += noise;
146
38.4M
            }
147
993k
        }
148
523k
    }
149
323k
}
ac3dec_float.c:ff_eac3_apply_spectral_extension
Line
Count
Source
57
293k
{
58
293k
    int bin, bnd, ch, i;
59
293k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
293k
    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
293k
    bin = s->spx_dst_start_freq;
65
293k
    num_copy_sections = 0;
66
960k
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
667k
        int copysize;
68
667k
        int bandsize = s->spx_band_sizes[bnd];
69
667k
        if (bin + bandsize > s->spx_src_start_freq) {
70
283k
            copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71
283k
            bin = s->spx_dst_start_freq;
72
283k
            wrapflag[bnd] = 1;
73
283k
        }
74
1.39M
        for (i = 0; i < bandsize; i += copysize) {
75
726k
            if (bin == s->spx_src_start_freq) {
76
59.4k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
59.4k
                bin = s->spx_dst_start_freq;
78
59.4k
            }
79
726k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
726k
            bin += copysize;
81
726k
        }
82
667k
    }
83
293k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
876k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
583k
        if (!s->channel_uses_spx[ch])
87
104k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
479k
        bin = s->spx_src_start_freq;
91
1.32M
        for (i = 0; i < num_copy_sections; i++) {
92
844k
            memcpy(&s->transform_coeffs[ch][bin],
93
844k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
844k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
844k
            bin += copy_sizes[i];
96
844k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
479k
        bin = s->spx_src_start_freq;
100
1.36M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
889k
            int bandsize = s->spx_band_sizes[bnd];
102
889k
            float accum = 0.0f;
103
36.2M
            for (i = 0; i < bandsize; i++) {
104
35.3M
                float coeff = s->transform_coeffs[ch][bin++];
105
35.3M
                accum += coeff * coeff;
106
35.3M
            }
107
889k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
889k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
479k
        if (s->spx_atten_code[ch] >= 0) {
113
148k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
148k
            bin = s->spx_src_start_freq - 2;
115
342k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
193k
                if (wrapflag[bnd]) {
117
164k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
164k
                    coeffs[0] *= atten_tab[0];
119
164k
                    coeffs[1] *= atten_tab[1];
120
164k
                    coeffs[2] *= atten_tab[2];
121
164k
                    coeffs[3] *= atten_tab[1];
122
164k
                    coeffs[4] *= atten_tab[0];
123
164k
                }
124
193k
                bin += s->spx_band_sizes[bnd];
125
193k
            }
126
148k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
479k
        bin = s->spx_src_start_freq;
132
1.36M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
889k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
889k
            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
36.2M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
35.3M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
35.3M
                s->transform_coeffs[ch][bin]   *= sscale;
145
35.3M
                s->transform_coeffs[ch][bin++] += noise;
146
35.3M
            }
147
889k
        }
148
479k
    }
149
293k
}
ac3dec_fixed.c:ff_eac3_apply_spectral_extension
Line
Count
Source
57
29.4k
{
58
29.4k
    int bin, bnd, ch, i;
59
29.4k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
29.4k
    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
29.4k
    bin = s->spx_dst_start_freq;
65
29.4k
    num_copy_sections = 0;
66
109k
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
79.8k
        int copysize;
68
79.8k
        int bandsize = s->spx_band_sizes[bnd];
69
79.8k
        if (bin + bandsize > s->spx_src_start_freq) {
70
31.6k
            copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71
31.6k
            bin = s->spx_dst_start_freq;
72
31.6k
            wrapflag[bnd] = 1;
73
31.6k
        }
74
170k
        for (i = 0; i < bandsize; i += copysize) {
75
91.1k
            if (bin == s->spx_src_start_freq) {
76
11.3k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
11.3k
                bin = s->spx_dst_start_freq;
78
11.3k
            }
79
91.1k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
91.1k
            bin += copysize;
81
91.1k
        }
82
79.8k
    }
83
29.4k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
98.5k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
69.0k
        if (!s->channel_uses_spx[ch])
87
24.4k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
44.5k
        bin = s->spx_src_start_freq;
91
140k
        for (i = 0; i < num_copy_sections; i++) {
92
96.3k
            memcpy(&s->transform_coeffs[ch][bin],
93
96.3k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
96.3k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
96.3k
            bin += copy_sizes[i];
96
96.3k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
44.5k
        bin = s->spx_src_start_freq;
100
148k
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
104k
            int bandsize = s->spx_band_sizes[bnd];
102
104k
            float accum = 0.0f;
103
3.15M
            for (i = 0; i < bandsize; i++) {
104
3.05M
                float coeff = s->transform_coeffs[ch][bin++];
105
3.05M
                accum += coeff * coeff;
106
3.05M
            }
107
104k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
104k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
44.5k
        if (s->spx_atten_code[ch] >= 0) {
113
2.67k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
2.67k
            bin = s->spx_src_start_freq - 2;
115
8.06k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
5.39k
                if (wrapflag[bnd]) {
117
3.91k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
3.91k
                    coeffs[0] *= atten_tab[0];
119
3.91k
                    coeffs[1] *= atten_tab[1];
120
3.91k
                    coeffs[2] *= atten_tab[2];
121
3.91k
                    coeffs[3] *= atten_tab[1];
122
3.91k
                    coeffs[4] *= atten_tab[0];
123
3.91k
                }
124
5.39k
                bin += s->spx_band_sizes[bnd];
125
5.39k
            }
126
2.67k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
44.5k
        bin = s->spx_src_start_freq;
132
148k
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
104k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
104k
            float sscale = s->spx_signal_blend[ch][bnd];
135
104k
#if USE_FIXED
136
            // spx_noise_blend and spx_signal_blend are both FP.23
137
104k
            nscale *= 1.0 / (1<<23);
138
104k
            sscale *= 1.0 / (1<<23);
139
104k
            if (nscale < -1.0)
140
611
                nscale = -1.0;
141
104k
#endif
142
3.15M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
3.05M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
3.05M
                s->transform_coeffs[ch][bin]   *= sscale;
145
3.05M
                s->transform_coeffs[ch][bin++] += noise;
146
3.05M
            }
147
104k
        }
148
44.5k
    }
149
29.4k
}
150
151
152
/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
153
6.37M
#define COEFF_0 10273905LL
154
155
/** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
156
6.37M
#define COEFF_1 11863283LL
157
158
/** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
159
6.37M
#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
6.37M
{
167
6.37M
    int tmp;
168
6.37M
    int even0, even1, even2, odd0, odd1, odd2;
169
170
6.37M
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
6.37M
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
6.37M
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
6.37M
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
6.37M
    even0 = pre_mant[0] + (tmp >> 1);
177
6.37M
    even1 = pre_mant[0] - tmp;
178
179
6.37M
    tmp = even0;
180
6.37M
    even0 = tmp + even2;
181
6.37M
    even2 = tmp - even2;
182
183
6.37M
    tmp = odd0;
184
6.37M
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
6.37M
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
6.37M
    pre_mant[0] = even0 + odd0;
188
6.37M
    pre_mant[1] = even1 + odd1;
189
6.37M
    pre_mant[2] = even2 + odd2;
190
6.37M
    pre_mant[3] = even2 - odd2;
191
6.37M
    pre_mant[4] = even1 - odd1;
192
6.37M
    pre_mant[5] = even0 - odd0;
193
6.37M
}
ac3dec_float.c:idct6
Line
Count
Source
166
5.45M
{
167
5.45M
    int tmp;
168
5.45M
    int even0, even1, even2, odd0, odd1, odd2;
169
170
5.45M
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
5.45M
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
5.45M
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
5.45M
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
5.45M
    even0 = pre_mant[0] + (tmp >> 1);
177
5.45M
    even1 = pre_mant[0] - tmp;
178
179
5.45M
    tmp = even0;
180
5.45M
    even0 = tmp + even2;
181
5.45M
    even2 = tmp - even2;
182
183
5.45M
    tmp = odd0;
184
5.45M
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
5.45M
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
5.45M
    pre_mant[0] = even0 + odd0;
188
5.45M
    pre_mant[1] = even1 + odd1;
189
5.45M
    pre_mant[2] = even2 + odd2;
190
5.45M
    pre_mant[3] = even2 - odd2;
191
5.45M
    pre_mant[4] = even1 - odd1;
192
5.45M
    pre_mant[5] = even0 - odd0;
193
5.45M
}
ac3dec_fixed.c:idct6
Line
Count
Source
166
916k
{
167
916k
    int tmp;
168
916k
    int even0, even1, even2, odd0, odd1, odd2;
169
170
916k
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
916k
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
916k
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
916k
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
916k
    even0 = pre_mant[0] + (tmp >> 1);
177
916k
    even1 = pre_mant[0] - tmp;
178
179
916k
    tmp = even0;
180
916k
    even0 = tmp + even2;
181
916k
    even2 = tmp - even2;
182
183
916k
    tmp = odd0;
184
916k
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
916k
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
916k
    pre_mant[0] = even0 + odd0;
188
916k
    pre_mant[1] = even1 + odd1;
189
916k
    pre_mant[2] = even2 + odd2;
190
916k
    pre_mant[3] = even2 - odd2;
191
916k
    pre_mant[4] = even1 - odd1;
192
916k
    pre_mant[5] = even0 - odd0;
193
916k
}
194
195
static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
196
102k
{
197
102k
    int bin, blk, gs;
198
102k
    int end_bap, gaq_mode;
199
102k
    GetBitContext *gbc = &s->gbc;
200
102k
    int gaq_gain[AC3_MAX_COEFS];
201
202
102k
    gaq_mode = get_bits(gbc, 2);
203
102k
    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
102k
    gs = 0;
208
102k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
3.23M
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
3.18M
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212
130k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
3.18M
        }
214
52.0k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
16.0k
        int gc = 2;
217
810k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
794k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
102k
                if (gc++ == 2) {
220
35.1k
                    int group_code = get_bits(gbc, 5);
221
35.1k
                    if (group_code > 26) {
222
14.6k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
14.6k
                        group_code = 26;
224
14.6k
                    }
225
35.1k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
35.1k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
35.1k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
35.1k
                    gc = 0;
229
35.1k
                }
230
102k
            }
231
794k
        }
232
16.0k
    }
233
234
102k
    gs=0;
235
6.47M
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
6.37M
        int hebap = s->bap[ch][bin];
237
6.37M
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
6.37M
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
8.03M
            for (blk = 0; blk < 6; blk++) {
241
6.88M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
6.88M
            }
243
5.22M
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
100k
            int v = get_bits(gbc, bits);
246
704k
            for (blk = 0; blk < 6; blk++) {
247
604k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
604k
            }
249
5.12M
        } else {
250
            /* Gain Adaptive Quantization */
251
5.12M
            int gbits, log_gain;
252
5.12M
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
232k
                log_gain = gaq_gain[gs++];
254
4.89M
            } else {
255
4.89M
                log_gain = 0;
256
4.89M
            }
257
5.12M
            gbits = bits - log_gain;
258
259
35.8M
            for (blk = 0; blk < 6; blk++) {
260
30.7M
                int mant = get_sbits(gbc, gbits);
261
30.7M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
120k
                    int b;
264
120k
                    int mbits = bits - (2 - log_gain);
265
120k
                    mant = get_sbits(gbc, mbits);
266
120k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
120k
                    if (mant >= 0)
269
23.0k
                        b = 1 << (23 - log_gain);
270
97.0k
                    else
271
97.0k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
120k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
30.6M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
30.6M
                    mant *= (1 << 24 - bits);
276
30.6M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
29.8M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
29.8M
                    }
280
30.6M
                }
281
30.7M
                s->pre_mantissa[ch][bin][blk] = mant;
282
30.7M
            }
283
5.12M
        }
284
6.37M
        idct6(s->pre_mantissa[ch][bin]);
285
6.37M
    }
286
102k
}
ac3dec_float.c:ff_eac3_decode_transform_coeffs_aht_ch
Line
Count
Source
196
87.2k
{
197
87.2k
    int bin, blk, gs;
198
87.2k
    int end_bap, gaq_mode;
199
87.2k
    GetBitContext *gbc = &s->gbc;
200
87.2k
    int gaq_gain[AC3_MAX_COEFS];
201
202
87.2k
    gaq_mode = get_bits(gbc, 2);
203
87.2k
    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.2k
    gs = 0;
208
87.2k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
2.91M
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
2.86M
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212
102k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
2.86M
        }
214
45.3k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
12.6k
        int gc = 2;
217
559k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
546k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
65.9k
                if (gc++ == 2) {
220
22.9k
                    int group_code = get_bits(gbc, 5);
221
22.9k
                    if (group_code > 26) {
222
10.0k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
10.0k
                        group_code = 26;
224
10.0k
                    }
225
22.9k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
22.9k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
22.9k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
22.9k
                    gc = 0;
229
22.9k
                }
230
65.9k
            }
231
546k
        }
232
12.6k
    }
233
234
87.2k
    gs=0;
235
5.54M
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
5.45M
        int hebap = s->bap[ch][bin];
237
5.45M
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
5.45M
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
4.28M
            for (blk = 0; blk < 6; blk++) {
241
3.67M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
3.67M
            }
243
4.84M
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
75.1k
            int v = get_bits(gbc, bits);
246
525k
            for (blk = 0; blk < 6; blk++) {
247
450k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
450k
            }
249
4.76M
        } else {
250
            /* Gain Adaptive Quantization */
251
4.76M
            int gbits, log_gain;
252
4.76M
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
168k
                log_gain = gaq_gain[gs++];
254
4.60M
            } else {
255
4.60M
                log_gain = 0;
256
4.60M
            }
257
4.76M
            gbits = bits - log_gain;
258
259
33.3M
            for (blk = 0; blk < 6; blk++) {
260
28.6M
                int mant = get_sbits(gbc, gbits);
261
28.6M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
95.3k
                    int b;
264
95.3k
                    int mbits = bits - (2 - log_gain);
265
95.3k
                    mant = get_sbits(gbc, mbits);
266
95.3k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
95.3k
                    if (mant >= 0)
269
15.9k
                        b = 1 << (23 - log_gain);
270
79.4k
                    else
271
79.4k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
95.3k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
28.5M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
28.5M
                    mant *= (1 << 24 - bits);
276
28.5M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
28.0M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
28.0M
                    }
280
28.5M
                }
281
28.6M
                s->pre_mantissa[ch][bin][blk] = mant;
282
28.6M
            }
283
4.76M
        }
284
5.45M
        idct6(s->pre_mantissa[ch][bin]);
285
5.45M
    }
286
87.2k
}
ac3dec_fixed.c:ff_eac3_decode_transform_coeffs_aht_ch
Line
Count
Source
196
15.1k
{
197
15.1k
    int bin, blk, gs;
198
15.1k
    int end_bap, gaq_mode;
199
15.1k
    GetBitContext *gbc = &s->gbc;
200
15.1k
    int gaq_gain[AC3_MAX_COEFS];
201
202
15.1k
    gaq_mode = get_bits(gbc, 2);
203
15.1k
    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
15.1k
    gs = 0;
208
15.1k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
325k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
320k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212
28.0k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
320k
        }
214
10.1k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
3.33k
        int gc = 2;
217
250k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
247k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
36.1k
                if (gc++ == 2) {
220
12.2k
                    int group_code = get_bits(gbc, 5);
221
12.2k
                    if (group_code > 26) {
222
4.52k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
4.52k
                        group_code = 26;
224
4.52k
                    }
225
12.2k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
12.2k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
12.2k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
12.2k
                    gc = 0;
229
12.2k
                }
230
36.1k
            }
231
247k
        }
232
3.33k
    }
233
234
15.1k
    gs=0;
235
931k
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
916k
        int hebap = s->bap[ch][bin];
237
916k
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
916k
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
3.74M
            for (blk = 0; blk < 6; blk++) {
241
3.20M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
3.20M
            }
243
534k
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
25.5k
            int v = get_bits(gbc, bits);
246
178k
            for (blk = 0; blk < 6; blk++) {
247
153k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
153k
            }
249
356k
        } else {
250
            /* Gain Adaptive Quantization */
251
356k
            int gbits, log_gain;
252
356k
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
64.2k
                log_gain = gaq_gain[gs++];
254
291k
            } else {
255
291k
                log_gain = 0;
256
291k
            }
257
356k
            gbits = bits - log_gain;
258
259
2.49M
            for (blk = 0; blk < 6; blk++) {
260
2.13M
                int mant = get_sbits(gbc, gbits);
261
2.13M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
24.6k
                    int b;
264
24.6k
                    int mbits = bits - (2 - log_gain);
265
24.6k
                    mant = get_sbits(gbc, mbits);
266
24.6k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
24.6k
                    if (mant >= 0)
269
7.05k
                        b = 1 << (23 - log_gain);
270
17.6k
                    else
271
17.6k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
24.6k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
2.11M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
2.11M
                    mant *= (1 << 24 - bits);
276
2.11M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
1.87M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
1.87M
                    }
280
2.11M
                }
281
2.13M
                s->pre_mantissa[ch][bin][blk] = mant;
282
2.13M
            }
283
356k
        }
284
916k
        idct6(s->pre_mantissa[ch][bin]);
285
916k
    }
286
15.1k
}
287
288
static int ff_eac3_parse_header(AC3DecodeContext *s, const AC3HeaderInfo *hdr)
289
2.50M
{
290
2.50M
    int i, blk, ch;
291
2.50M
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
2.50M
    int parse_transient_proc_info;
293
2.50M
    int num_cpl_blocks;
294
2.50M
    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.50M
    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.50M
    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.50M
    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
11.9k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
11.9k
        return AVERROR_PATCHWELCOME;
323
11.9k
    }
324
325
    /* volume control params */
326
5.60M
    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
292k
            s->dialog_normalization[i] = -31;
330
292k
        }
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.67M
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
1.67M
        }
338
3.11M
    }
339
340
2.49M
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
2.49M
    s->preferred_downmix       = hdr->preferred_downmix;
344
2.49M
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
2.49M
    s->center_mix_level        = hdr->center_mix_level;
346
2.49M
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
2.49M
    s->surround_mix_level      = hdr->surround_mix_level;
348
2.49M
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
2.49M
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
2.49M
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
2.49M
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
2.49M
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
2.49M
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
2.49M
    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.49M
    if (s->num_blocks == 6) {
363
968k
        ac3_exponent_strategy = get_bits1(gbc);
364
968k
        parse_aht_info        = get_bits1(gbc);
365
1.52M
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
1.52M
        ac3_exponent_strategy = 1;
369
1.52M
        parse_aht_info = 0;
370
1.52M
    }
371
372
2.49M
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
2.49M
    parse_transient_proc_info = get_bits1(gbc);
374
375
2.49M
    s->block_switch_syntax = get_bits1(gbc);
376
2.49M
    if (!s->block_switch_syntax)
377
1.78M
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
2.49M
    s->dither_flag_syntax = get_bits1(gbc);
380
2.49M
    if (!s->dither_flag_syntax) {
381
7.10M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
5.17M
            s->dither_flag[ch] = 1;
383
1.93M
    }
384
2.49M
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
2.49M
    s->bit_allocation_syntax = get_bits1(gbc);
387
2.49M
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
1.93M
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
1.93M
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
1.93M
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
1.93M
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
1.93M
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
1.93M
    }
395
396
2.49M
    s->fast_gain_syntax  = get_bits1(gbc);
397
2.49M
    s->dba_syntax        = get_bits1(gbc);
398
2.49M
    s->skip_syntax       = get_bits1(gbc);
399
2.49M
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
2.49M
    num_cpl_blocks = 0;
403
2.49M
    if (s->channel_mode > 1) {
404
8.17M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
6.67M
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
6.67M
            if (s->cpl_strategy_exists[blk]) {
407
3.38M
                s->cpl_in_use[blk] = get_bits1(gbc);
408
3.38M
            } else {
409
3.29M
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
3.29M
            }
411
6.67M
            num_cpl_blocks += s->cpl_in_use[blk];
412
6.67M
        }
413
1.49M
    } else {
414
1.00M
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
1.00M
    }
416
417
    /* exponent strategy data */
418
2.49M
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
7.66M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
22.4M
            for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422
16.7M
                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423
16.7M
            }
424
5.74M
        }
425
1.92M
    } else {
426
        /* LUT-based exponent strategy syntax */
427
2.91M
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
2.34M
            int frmchexpstr = get_bits(gbc, 5);
429
16.4M
            for (blk = 0; blk < 6; blk++) {
430
14.0M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
14.0M
            }
432
2.34M
        }
433
571k
    }
434
    /* LFE exponent strategy */
435
2.49M
    if (s->lfe_on) {
436
7.56M
        for (blk = 0; blk < s->num_blocks; blk++) {
437
6.01M
            s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438
6.01M
        }
439
1.55M
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
2.49M
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
1.30M
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
882k
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
882k
    }
445
446
    /* determine which channels use AHT */
447
2.49M
    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
297k
        s->channel_uses_aht[CPL_CH]=0;
453
1.46M
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
1.17M
            int use_aht = 1;
455
4.05M
            for (blk = 1; blk < 6; blk++) {
456
3.57M
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
2.89M
                        (!ch && s->cpl_strategy_exists[blk])) {
458
681k
                    use_aht = 0;
459
681k
                    break;
460
681k
                }
461
3.57M
            }
462
1.17M
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
1.17M
        }
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.49M
    if (!s->snr_offset_strategy) {
470
1.40M
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
1.40M
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
7.50M
        for (ch = 0; ch <= s->channels; ch++)
473
6.10M
            s->snr_offset[ch] = snroffst;
474
1.40M
    }
475
476
    /* transient pre-noise processing data */
477
2.49M
    if (parse_transient_proc_info) {
478
1.67M
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
1.24M
            if (get_bits1(gbc)) { // channel in transient processing
480
553k
                skip_bits(gbc, 10); // skip transient processing location
481
553k
                skip_bits(gbc, 8);  // skip transient processing length
482
553k
            }
483
1.24M
        }
484
433k
    }
485
486
    /* spectral extension attenuation data */
487
9.46M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
6.97M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
679k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
6.29M
        } else {
491
6.29M
            s->spx_atten_code[ch] = -1;
492
6.29M
        }
493
6.97M
    }
494
495
    /* block start information */
496
2.49M
    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
421k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
421k
        skip_bits_long(gbc, block_start_bits);
503
421k
        avpriv_request_sample(s->avctx, "Block start info");
504
421k
    }
505
506
    /* syntax state initialization */
507
9.46M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
6.97M
        s->first_spx_coords[ch] = 1;
509
6.97M
        s->first_cpl_coords[ch] = 1;
510
6.97M
    }
511
2.49M
    s->first_cpl_leak = 1;
512
513
2.49M
    return 0;
514
2.50M
}
ac3dec_float.c:ff_eac3_parse_header
Line
Count
Source
289
1.65M
{
290
1.65M
    int i, blk, ch;
291
1.65M
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
1.65M
    int parse_transient_proc_info;
293
1.65M
    int num_cpl_blocks;
294
1.65M
    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.65M
    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.65M
    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.65M
    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.16k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
1.16k
        return AVERROR_PATCHWELCOME;
323
1.16k
    }
324
325
    /* volume control params */
326
3.58M
    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327
1.93M
        s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
1.93M
        if (s->dialog_normalization[i] == 0) {
329
55.6k
            s->dialog_normalization[i] = -31;
330
55.6k
        }
331
1.93M
        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
1.93M
        if (hdr->compression_exists[i]) {
336
978k
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
978k
        }
338
1.93M
    }
339
340
1.64M
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
1.64M
    s->preferred_downmix       = hdr->preferred_downmix;
344
1.64M
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
1.64M
    s->center_mix_level        = hdr->center_mix_level;
346
1.64M
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
1.64M
    s->surround_mix_level      = hdr->surround_mix_level;
348
1.64M
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
1.64M
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
1.64M
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
1.64M
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
1.64M
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
1.64M
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
1.64M
    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.64M
    if (s->num_blocks == 6) {
363
860k
        ac3_exponent_strategy = get_bits1(gbc);
364
860k
        parse_aht_info        = get_bits1(gbc);
365
860k
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
788k
        ac3_exponent_strategy = 1;
369
788k
        parse_aht_info = 0;
370
788k
    }
371
372
1.64M
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
1.64M
    parse_transient_proc_info = get_bits1(gbc);
374
375
1.64M
    s->block_switch_syntax = get_bits1(gbc);
376
1.64M
    if (!s->block_switch_syntax)
377
1.08M
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
1.64M
    s->dither_flag_syntax = get_bits1(gbc);
380
1.64M
    if (!s->dither_flag_syntax) {
381
4.78M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
3.56M
            s->dither_flag[ch] = 1;
383
1.22M
    }
384
1.64M
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
1.64M
    s->bit_allocation_syntax = get_bits1(gbc);
387
1.64M
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
1.21M
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
1.21M
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
1.21M
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
1.21M
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
1.21M
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
1.21M
    }
395
396
1.64M
    s->fast_gain_syntax  = get_bits1(gbc);
397
1.64M
    s->dba_syntax        = get_bits1(gbc);
398
1.64M
    s->skip_syntax       = get_bits1(gbc);
399
1.64M
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
1.64M
    num_cpl_blocks = 0;
403
1.64M
    if (s->channel_mode > 1) {
404
6.83M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
5.65M
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
5.65M
            if (s->cpl_strategy_exists[blk]) {
407
2.83M
                s->cpl_in_use[blk] = get_bits1(gbc);
408
2.83M
            } else {
409
2.82M
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
2.82M
            }
411
5.65M
            num_cpl_blocks += s->cpl_in_use[blk];
412
5.65M
        }
413
1.18M
    } else {
414
467k
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
467k
    }
416
417
    /* exponent strategy data */
418
1.64M
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
4.73M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
15.6M
            for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422
12.0M
                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423
12.0M
            }
424
3.58M
        }
425
1.15M
    } else {
426
        /* LUT-based exponent strategy syntax */
427
2.49M
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
1.99M
            int frmchexpstr = get_bits(gbc, 5);
429
13.9M
            for (blk = 0; blk < 6; blk++) {
430
11.9M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
11.9M
            }
432
1.99M
        }
433
498k
    }
434
    /* LFE exponent strategy */
435
1.64M
    if (s->lfe_on) {
436
4.86M
        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
888k
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
1.64M
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
1.06M
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
805k
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
805k
    }
445
446
    /* determine which channels use AHT */
447
1.64M
    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
266k
        s->channel_uses_aht[CPL_CH]=0;
453
1.31M
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
1.04M
            int use_aht = 1;
455
3.67M
            for (blk = 1; blk < 6; blk++) {
456
3.22M
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
2.63M
                        (!ch && s->cpl_strategy_exists[blk])) {
458
597k
                    use_aht = 0;
459
597k
                    break;
460
597k
                }
461
3.22M
            }
462
1.04M
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
1.04M
        }
464
1.38M
    } else {
465
1.38M
        memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466
1.38M
    }
467
468
    /* per-frame SNR offset */
469
1.64M
    if (!s->snr_offset_strategy) {
470
757k
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
757k
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
4.17M
        for (ch = 0; ch <= s->channels; ch++)
473
3.41M
            s->snr_offset[ch] = snroffst;
474
757k
    }
475
476
    /* transient pre-noise processing data */
477
1.64M
    if (parse_transient_proc_info) {
478
1.32M
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
983k
            if (get_bits1(gbc)) { // channel in transient processing
480
455k
                skip_bits(gbc, 10); // skip transient processing location
481
455k
                skip_bits(gbc, 8);  // skip transient processing length
482
455k
            }
483
983k
        }
484
336k
    }
485
486
    /* spectral extension attenuation data */
487
6.66M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
5.01M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
479k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
4.53M
        } else {
491
4.53M
            s->spx_atten_code[ch] = -1;
492
4.53M
        }
493
5.01M
    }
494
495
    /* block start information */
496
1.64M
    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
325k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
325k
        skip_bits_long(gbc, block_start_bits);
503
325k
        avpriv_request_sample(s->avctx, "Block start info");
504
325k
    }
505
506
    /* syntax state initialization */
507
6.66M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
5.01M
        s->first_spx_coords[ch] = 1;
509
5.01M
        s->first_cpl_coords[ch] = 1;
510
5.01M
    }
511
1.64M
    s->first_cpl_leak = 1;
512
513
1.64M
    return 0;
514
1.65M
}
ac3dec_fixed.c:ff_eac3_parse_header
Line
Count
Source
289
858k
{
290
858k
    int i, blk, ch;
291
858k
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
858k
    int parse_transient_proc_info;
293
858k
    int num_cpl_blocks;
294
858k
    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
858k
    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
858k
    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
858k
    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
10.8k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
10.8k
        return AVERROR_PATCHWELCOME;
323
10.8k
    }
324
325
    /* volume control params */
326
2.02M
    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327
1.17M
        s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
1.17M
        if (s->dialog_normalization[i] == 0) {
329
237k
            s->dialog_normalization[i] = -31;
330
237k
        }
331
1.17M
        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
1.17M
        if (hdr->compression_exists[i]) {
336
695k
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
695k
        }
338
1.17M
    }
339
340
847k
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
847k
    s->preferred_downmix       = hdr->preferred_downmix;
344
847k
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
847k
    s->center_mix_level        = hdr->center_mix_level;
346
847k
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
847k
    s->surround_mix_level      = hdr->surround_mix_level;
348
847k
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
847k
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
847k
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
847k
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
847k
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
847k
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
847k
    s->eac3_extension_type_a = hdr->eac3_extension_type_a;
359
360
    /* audio frame syntax flags, strategy data, and per-frame data */
361
362
847k
    if (s->num_blocks == 6) {
363
107k
        ac3_exponent_strategy = get_bits1(gbc);
364
107k
        parse_aht_info        = get_bits1(gbc);
365
740k
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
740k
        ac3_exponent_strategy = 1;
369
740k
        parse_aht_info = 0;
370
740k
    }
371
372
847k
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
847k
    parse_transient_proc_info = get_bits1(gbc);
374
375
847k
    s->block_switch_syntax = get_bits1(gbc);
376
847k
    if (!s->block_switch_syntax)
377
699k
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
847k
    s->dither_flag_syntax = get_bits1(gbc);
380
847k
    if (!s->dither_flag_syntax) {
381
2.31M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
1.60M
            s->dither_flag[ch] = 1;
383
708k
    }
384
847k
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
847k
    s->bit_allocation_syntax = get_bits1(gbc);
387
847k
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
717k
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
717k
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
717k
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
717k
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
717k
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
717k
    }
395
396
847k
    s->fast_gain_syntax  = get_bits1(gbc);
397
847k
    s->dba_syntax        = get_bits1(gbc);
398
847k
    s->skip_syntax       = get_bits1(gbc);
399
847k
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
847k
    num_cpl_blocks = 0;
403
847k
    if (s->channel_mode > 1) {
404
1.33M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
1.02M
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
1.02M
            if (s->cpl_strategy_exists[blk]) {
407
549k
                s->cpl_in_use[blk] = get_bits1(gbc);
408
549k
            } else {
409
472k
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
472k
            }
411
1.02M
            num_cpl_blocks += s->cpl_in_use[blk];
412
1.02M
        }
413
538k
    } else {
414
538k
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
538k
    }
416
417
    /* exponent strategy data */
418
847k
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
2.93M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
6.81M
            for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422
4.65M
                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423
4.65M
            }
424
2.15M
        }
425
775k
    } else {
426
        /* LUT-based exponent strategy syntax */
427
422k
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
349k
            int frmchexpstr = get_bits(gbc, 5);
429
2.44M
            for (blk = 0; blk < 6; blk++) {
430
2.09M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
2.09M
            }
432
349k
        }
433
72.7k
    }
434
    /* LFE exponent strategy */
435
847k
    if (s->lfe_on) {
436
2.70M
        for (blk = 0; blk < s->num_blocks; blk++) {
437
2.04M
            s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438
2.04M
        }
439
664k
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
847k
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
240k
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
76.9k
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
76.9k
    }
445
446
    /* determine which channels use AHT */
447
847k
    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
30.7k
        s->channel_uses_aht[CPL_CH]=0;
453
155k
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
125k
            int use_aht = 1;
455
386k
            for (blk = 1; blk < 6; blk++) {
456
345k
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
263k
                        (!ch && s->cpl_strategy_exists[blk])) {
458
84.4k
                    use_aht = 0;
459
84.4k
                    break;
460
84.4k
                }
461
345k
            }
462
125k
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
125k
        }
464
817k
    } else {
465
817k
        memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466
817k
    }
467
468
    /* per-frame SNR offset */
469
847k
    if (!s->snr_offset_strategy) {
470
650k
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
650k
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
3.33M
        for (ch = 0; ch <= s->channels; ch++)
473
2.68M
            s->snr_offset[ch] = snroffst;
474
650k
    }
475
476
    /* transient pre-noise processing data */
477
847k
    if (parse_transient_proc_info) {
478
354k
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
258k
            if (get_bits1(gbc)) { // channel in transient processing
480
97.5k
                skip_bits(gbc, 10); // skip transient processing location
481
97.5k
                skip_bits(gbc, 8);  // skip transient processing length
482
97.5k
            }
483
258k
        }
484
96.3k
    }
485
486
    /* spectral extension attenuation data */
487
2.79M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
1.95M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
199k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
1.75M
        } else {
491
1.75M
            s->spx_atten_code[ch] = -1;
492
1.75M
        }
493
1.95M
    }
494
495
    /* block start information */
496
847k
    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.4k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
95.4k
        skip_bits_long(gbc, block_start_bits);
503
95.4k
        avpriv_request_sample(s->avctx, "Block start info");
504
95.4k
    }
505
506
    /* syntax state initialization */
507
2.79M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
1.95M
        s->first_spx_coords[ch] = 1;
509
1.95M
        s->first_cpl_coords[ch] = 1;
510
1.95M
    }
511
847k
    s->first_cpl_leak = 1;
512
513
847k
    return 0;
514
858k
}