Coverage Report

Created: 2025-08-28 07:12

/src/ffmpeg/libavcodec/eac3dec.c
Line
Count
Source (jump to first uncovered line)
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
240k
{
58
240k
    int bin, bnd, ch, i;
59
240k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
240k
    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
240k
    bin = s->spx_dst_start_freq;
65
240k
    num_copy_sections = 0;
66
903k
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
663k
        int copysize;
68
663k
        int bandsize = s->spx_band_sizes[bnd];
69
663k
        if (bin + bandsize > s->spx_src_start_freq) {
70
331k
            copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71
331k
            bin = s->spx_dst_start_freq;
72
331k
            wrapflag[bnd] = 1;
73
331k
        }
74
1.40M
        for (i = 0; i < bandsize; i += copysize) {
75
737k
            if (bin == s->spx_src_start_freq) {
76
73.8k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
73.8k
                bin = s->spx_dst_start_freq;
78
73.8k
            }
79
737k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
737k
            bin += copysize;
81
737k
        }
82
663k
    }
83
240k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
722k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
482k
        if (!s->channel_uses_spx[ch])
87
127k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
355k
        bin = s->spx_src_start_freq;
91
1.15M
        for (i = 0; i < num_copy_sections; i++) {
92
796k
            memcpy(&s->transform_coeffs[ch][bin],
93
796k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
796k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
796k
            bin += copy_sizes[i];
96
796k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
355k
        bin = s->spx_src_start_freq;
100
1.17M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
817k
            int bandsize = s->spx_band_sizes[bnd];
102
817k
            float accum = 0.0f;
103
27.7M
            for (i = 0; i < bandsize; i++) {
104
26.9M
                float coeff = s->transform_coeffs[ch][bin++];
105
26.9M
                accum += coeff * coeff;
106
26.9M
            }
107
817k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
817k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
355k
        if (s->spx_atten_code[ch] >= 0) {
113
85.9k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
85.9k
            bin = s->spx_src_start_freq - 2;
115
202k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
116k
                if (wrapflag[bnd]) {
117
98.0k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
98.0k
                    coeffs[0] *= atten_tab[0];
119
98.0k
                    coeffs[1] *= atten_tab[1];
120
98.0k
                    coeffs[2] *= atten_tab[2];
121
98.0k
                    coeffs[3] *= atten_tab[1];
122
98.0k
                    coeffs[4] *= atten_tab[0];
123
98.0k
                }
124
116k
                bin += s->spx_band_sizes[bnd];
125
116k
            }
126
85.9k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
355k
        bin = s->spx_src_start_freq;
132
1.17M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
817k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
817k
            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
103k
            if (nscale < -1.0)
140
562
                nscale = -1.0;
141
#endif
142
27.7M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
26.9M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
26.9M
                s->transform_coeffs[ch][bin]   *= sscale;
145
26.9M
                s->transform_coeffs[ch][bin++] += noise;
146
26.9M
            }
147
817k
        }
148
355k
    }
149
240k
}
ac3dec_float.c:ff_eac3_apply_spectral_extension
Line
Count
Source
57
211k
{
58
211k
    int bin, bnd, ch, i;
59
211k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
211k
    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
211k
    bin = s->spx_dst_start_freq;
65
211k
    num_copy_sections = 0;
66
789k
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
578k
        int copysize;
68
578k
        int bandsize = s->spx_band_sizes[bnd];
69
578k
        if (bin + bandsize > s->spx_src_start_freq) {
70
297k
            copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71
297k
            bin = s->spx_dst_start_freq;
72
297k
            wrapflag[bnd] = 1;
73
297k
        }
74
1.21M
        for (i = 0; i < bandsize; i += copysize) {
75
640k
            if (bin == s->spx_src_start_freq) {
76
61.6k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
61.6k
                bin = s->spx_dst_start_freq;
78
61.6k
            }
79
640k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
640k
            bin += copysize;
81
640k
        }
82
578k
    }
83
211k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
625k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
414k
        if (!s->channel_uses_spx[ch])
87
101k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
313k
        bin = s->spx_src_start_freq;
91
1.01M
        for (i = 0; i < num_copy_sections; i++) {
92
699k
            memcpy(&s->transform_coeffs[ch][bin],
93
699k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
699k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
699k
            bin += copy_sizes[i];
96
699k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
313k
        bin = s->spx_src_start_freq;
100
1.02M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
714k
            int bandsize = s->spx_band_sizes[bnd];
102
714k
            float accum = 0.0f;
103
24.6M
            for (i = 0; i < bandsize; i++) {
104
23.9M
                float coeff = s->transform_coeffs[ch][bin++];
105
23.9M
                accum += coeff * coeff;
106
23.9M
            }
107
714k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
714k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
313k
        if (s->spx_atten_code[ch] >= 0) {
113
81.9k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
81.9k
            bin = s->spx_src_start_freq - 2;
115
191k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
109k
                if (wrapflag[bnd]) {
117
92.9k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
92.9k
                    coeffs[0] *= atten_tab[0];
119
92.9k
                    coeffs[1] *= atten_tab[1];
120
92.9k
                    coeffs[2] *= atten_tab[2];
121
92.9k
                    coeffs[3] *= atten_tab[1];
122
92.9k
                    coeffs[4] *= atten_tab[0];
123
92.9k
                }
124
109k
                bin += s->spx_band_sizes[bnd];
125
109k
            }
126
81.9k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
313k
        bin = s->spx_src_start_freq;
132
1.02M
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
714k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
714k
            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
24.6M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
23.9M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
23.9M
                s->transform_coeffs[ch][bin]   *= sscale;
145
23.9M
                s->transform_coeffs[ch][bin++] += noise;
146
23.9M
            }
147
714k
        }
148
313k
    }
149
211k
}
ac3dec_fixed.c:ff_eac3_apply_spectral_extension
Line
Count
Source
57
28.9k
{
58
28.9k
    int bin, bnd, ch, i;
59
28.9k
    uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
60
28.9k
    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
28.9k
    bin = s->spx_dst_start_freq;
65
28.9k
    num_copy_sections = 0;
66
113k
    for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
67
84.7k
        int copysize;
68
84.7k
        int bandsize = s->spx_band_sizes[bnd];
69
84.7k
        if (bin + bandsize > s->spx_src_start_freq) {
70
34.2k
            copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
71
34.2k
            bin = s->spx_dst_start_freq;
72
34.2k
            wrapflag[bnd] = 1;
73
34.2k
        }
74
181k
        for (i = 0; i < bandsize; i += copysize) {
75
96.8k
            if (bin == s->spx_src_start_freq) {
76
12.1k
                copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
77
12.1k
                bin = s->spx_dst_start_freq;
78
12.1k
            }
79
96.8k
            copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
80
96.8k
            bin += copysize;
81
96.8k
        }
82
84.7k
    }
83
28.9k
    copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
84
85
96.8k
    for (ch = 1; ch <= s->fbw_channels; ch++) {
86
67.9k
        if (!s->channel_uses_spx[ch])
87
25.7k
            continue;
88
89
        /* Copy coeffs from normal bands to extension bands */
90
42.1k
        bin = s->spx_src_start_freq;
91
138k
        for (i = 0; i < num_copy_sections; i++) {
92
96.6k
            memcpy(&s->transform_coeffs[ch][bin],
93
96.6k
                   &s->transform_coeffs[ch][s->spx_dst_start_freq],
94
96.6k
                   copy_sizes[i]*sizeof(INTFLOAT));
95
96.6k
            bin += copy_sizes[i];
96
96.6k
        }
97
98
        /* Calculate RMS energy for each SPX band. */
99
42.1k
        bin = s->spx_src_start_freq;
100
145k
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
101
103k
            int bandsize = s->spx_band_sizes[bnd];
102
103k
            float accum = 0.0f;
103
3.14M
            for (i = 0; i < bandsize; i++) {
104
3.04M
                float coeff = s->transform_coeffs[ch][bin++];
105
3.04M
                accum += coeff * coeff;
106
3.04M
            }
107
103k
            rms_energy[bnd] = sqrtf(accum / bandsize);
108
103k
        }
109
110
        /* Apply a notch filter at transitions between normal and extension
111
           bands and at all wrap points. */
112
42.1k
        if (s->spx_atten_code[ch] >= 0) {
113
4.00k
            const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
114
4.00k
            bin = s->spx_src_start_freq - 2;
115
10.4k
            for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
116
6.39k
                if (wrapflag[bnd]) {
117
5.13k
                    INTFLOAT *coeffs = &s->transform_coeffs[ch][bin];
118
5.13k
                    coeffs[0] *= atten_tab[0];
119
5.13k
                    coeffs[1] *= atten_tab[1];
120
5.13k
                    coeffs[2] *= atten_tab[2];
121
5.13k
                    coeffs[3] *= atten_tab[1];
122
5.13k
                    coeffs[4] *= atten_tab[0];
123
5.13k
                }
124
6.39k
                bin += s->spx_band_sizes[bnd];
125
6.39k
            }
126
4.00k
        }
127
128
        /* Apply noise-blended coefficient scaling based on previously
129
           calculated RMS energy, blending factors, and SPX coordinates for
130
           each band. */
131
42.1k
        bin = s->spx_src_start_freq;
132
145k
        for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
133
103k
            float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
134
103k
            float sscale = s->spx_signal_blend[ch][bnd];
135
103k
#if USE_FIXED
136
            // spx_noise_blend and spx_signal_blend are both FP.23
137
103k
            nscale *= 1.0 / (1<<23);
138
103k
            sscale *= 1.0 / (1<<23);
139
103k
            if (nscale < -1.0)
140
562
                nscale = -1.0;
141
103k
#endif
142
3.14M
            for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
143
3.04M
                UINTFLOAT noise = (INTFLOAT)(nscale * (int32_t)av_lfg_get(&s->dith_state));
144
3.04M
                s->transform_coeffs[ch][bin]   *= sscale;
145
3.04M
                s->transform_coeffs[ch][bin++] += noise;
146
3.04M
            }
147
103k
        }
148
42.1k
    }
149
28.9k
}
150
151
152
/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
153
3.85M
#define COEFF_0 10273905LL
154
155
/** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
156
3.85M
#define COEFF_1 11863283LL
157
158
/** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
159
3.85M
#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
3.85M
{
167
3.85M
    int tmp;
168
3.85M
    int even0, even1, even2, odd0, odd1, odd2;
169
170
3.85M
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
3.85M
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
3.85M
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
3.85M
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
3.85M
    even0 = pre_mant[0] + (tmp >> 1);
177
3.85M
    even1 = pre_mant[0] - tmp;
178
179
3.85M
    tmp = even0;
180
3.85M
    even0 = tmp + even2;
181
3.85M
    even2 = tmp - even2;
182
183
3.85M
    tmp = odd0;
184
3.85M
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
3.85M
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
3.85M
    pre_mant[0] = even0 + odd0;
188
3.85M
    pre_mant[1] = even1 + odd1;
189
3.85M
    pre_mant[2] = even2 + odd2;
190
3.85M
    pre_mant[3] = even2 - odd2;
191
3.85M
    pre_mant[4] = even1 - odd1;
192
3.85M
    pre_mant[5] = even0 - odd0;
193
3.85M
}
ac3dec_float.c:idct6
Line
Count
Source
166
2.88M
{
167
2.88M
    int tmp;
168
2.88M
    int even0, even1, even2, odd0, odd1, odd2;
169
170
2.88M
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
2.88M
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
2.88M
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
2.88M
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
2.88M
    even0 = pre_mant[0] + (tmp >> 1);
177
2.88M
    even1 = pre_mant[0] - tmp;
178
179
2.88M
    tmp = even0;
180
2.88M
    even0 = tmp + even2;
181
2.88M
    even2 = tmp - even2;
182
183
2.88M
    tmp = odd0;
184
2.88M
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
2.88M
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
2.88M
    pre_mant[0] = even0 + odd0;
188
2.88M
    pre_mant[1] = even1 + odd1;
189
2.88M
    pre_mant[2] = even2 + odd2;
190
2.88M
    pre_mant[3] = even2 - odd2;
191
2.88M
    pre_mant[4] = even1 - odd1;
192
2.88M
    pre_mant[5] = even0 - odd0;
193
2.88M
}
ac3dec_fixed.c:idct6
Line
Count
Source
166
972k
{
167
972k
    int tmp;
168
972k
    int even0, even1, even2, odd0, odd1, odd2;
169
170
972k
    odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
171
172
972k
    even2 = ( pre_mant[2]                * COEFF_0) >> 23;
173
972k
    tmp   = ( pre_mant[4]                * COEFF_1) >> 23;
174
972k
    odd0  = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
175
176
972k
    even0 = pre_mant[0] + (tmp >> 1);
177
972k
    even1 = pre_mant[0] - tmp;
178
179
972k
    tmp = even0;
180
972k
    even0 = tmp + even2;
181
972k
    even2 = tmp - even2;
182
183
972k
    tmp = odd0;
184
972k
    odd0 = tmp + pre_mant[1] + pre_mant[3];
185
972k
    odd2 = tmp + pre_mant[5] - pre_mant[3];
186
187
972k
    pre_mant[0] = even0 + odd0;
188
972k
    pre_mant[1] = even1 + odd1;
189
972k
    pre_mant[2] = even2 + odd2;
190
972k
    pre_mant[3] = even2 - odd2;
191
972k
    pre_mant[4] = even1 - odd1;
192
972k
    pre_mant[5] = even0 - odd0;
193
972k
}
194
195
static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
196
65.3k
{
197
65.3k
    int bin, blk, gs;
198
65.3k
    int end_bap, gaq_mode;
199
65.3k
    GetBitContext *gbc = &s->gbc;
200
65.3k
    int gaq_gain[AC3_MAX_COEFS];
201
202
65.3k
    gaq_mode = get_bits(gbc, 2);
203
65.3k
    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
65.3k
    gs = 0;
208
65.3k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
1.80M
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
1.77M
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212
112k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
1.77M
        }
214
37.1k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
11.7k
        int gc = 2;
217
607k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
595k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
106k
                if (gc++ == 2) {
220
36.5k
                    int group_code = get_bits(gbc, 5);
221
36.5k
                    if (group_code > 26) {
222
13.7k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
13.7k
                        group_code = 26;
224
13.7k
                    }
225
36.5k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
36.5k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
36.5k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
36.5k
                    gc = 0;
229
36.5k
                }
230
106k
            }
231
595k
        }
232
11.7k
    }
233
234
65.3k
    gs=0;
235
3.92M
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
3.85M
        int hebap = s->bap[ch][bin];
237
3.85M
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
3.85M
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
5.24M
            for (blk = 0; blk < 6; blk++) {
241
4.49M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
4.49M
            }
243
3.10M
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
99.3k
            int v = get_bits(gbc, bits);
246
695k
            for (blk = 0; blk < 6; blk++) {
247
596k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
596k
            }
249
3.00M
        } else {
250
            /* Gain Adaptive Quantization */
251
3.00M
            int gbits, log_gain;
252
3.00M
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
218k
                log_gain = gaq_gain[gs++];
254
2.79M
            } else {
255
2.79M
                log_gain = 0;
256
2.79M
            }
257
3.00M
            gbits = bits - log_gain;
258
259
21.0M
            for (blk = 0; blk < 6; blk++) {
260
18.0M
                int mant = get_sbits(gbc, gbits);
261
18.0M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
114k
                    int b;
264
114k
                    int mbits = bits - (2 - log_gain);
265
114k
                    mant = get_sbits(gbc, mbits);
266
114k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
114k
                    if (mant >= 0)
269
21.1k
                        b = 1 << (23 - log_gain);
270
93.6k
                    else
271
93.6k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
114k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
17.9M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
17.9M
                    mant *= (1 << 24 - bits);
276
17.9M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
17.2M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
17.2M
                    }
280
17.9M
                }
281
18.0M
                s->pre_mantissa[ch][bin][blk] = mant;
282
18.0M
            }
283
3.00M
        }
284
3.85M
        idct6(s->pre_mantissa[ch][bin]);
285
3.85M
    }
286
65.3k
}
ac3dec_float.c:ff_eac3_decode_transform_coeffs_aht_ch
Line
Count
Source
196
48.1k
{
197
48.1k
    int bin, blk, gs;
198
48.1k
    int end_bap, gaq_mode;
199
48.1k
    GetBitContext *gbc = &s->gbc;
200
48.1k
    int gaq_gain[AC3_MAX_COEFS];
201
202
48.1k
    gaq_mode = get_bits(gbc, 2);
203
48.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
48.1k
    gs = 0;
208
48.1k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
1.47M
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
211
1.45M
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
212
87.3k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
1.45M
        }
214
24.6k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
7.97k
        int gc = 2;
217
350k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
342k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
68.2k
                if (gc++ == 2) {
220
23.6k
                    int group_code = get_bits(gbc, 5);
221
23.6k
                    if (group_code > 26) {
222
9.12k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
9.12k
                        group_code = 26;
224
9.12k
                    }
225
23.6k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
23.6k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
23.6k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
23.6k
                    gc = 0;
229
23.6k
                }
230
68.2k
            }
231
342k
        }
232
7.97k
    }
233
234
48.1k
    gs=0;
235
2.93M
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
2.88M
        int hebap = s->bap[ch][bin];
237
2.88M
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
2.88M
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
2.25M
            for (blk = 0; blk < 6; blk++) {
241
1.92M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
1.92M
            }
243
2.56M
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
73.4k
            int v = get_bits(gbc, bits);
246
514k
            for (blk = 0; blk < 6; blk++) {
247
440k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
440k
            }
249
2.49M
        } else {
250
            /* Gain Adaptive Quantization */
251
2.49M
            int gbits, log_gain;
252
2.49M
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
155k
                log_gain = gaq_gain[gs++];
254
2.33M
            } else {
255
2.33M
                log_gain = 0;
256
2.33M
            }
257
2.49M
            gbits = bits - log_gain;
258
259
17.4M
            for (blk = 0; blk < 6; blk++) {
260
14.9M
                int mant = get_sbits(gbc, gbits);
261
14.9M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
83.3k
                    int b;
264
83.3k
                    int mbits = bits - (2 - log_gain);
265
83.3k
                    mant = get_sbits(gbc, mbits);
266
83.3k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
83.3k
                    if (mant >= 0)
269
13.9k
                        b = 1 << (23 - log_gain);
270
69.3k
                    else
271
69.3k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
83.3k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
14.8M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
14.8M
                    mant *= (1 << 24 - bits);
276
14.8M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
14.3M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
14.3M
                    }
280
14.8M
                }
281
14.9M
                s->pre_mantissa[ch][bin][blk] = mant;
282
14.9M
            }
283
2.49M
        }
284
2.88M
        idct6(s->pre_mantissa[ch][bin]);
285
2.88M
    }
286
48.1k
}
ac3dec_fixed.c:ff_eac3_decode_transform_coeffs_aht_ch
Line
Count
Source
196
17.1k
{
197
17.1k
    int bin, blk, gs;
198
17.1k
    int end_bap, gaq_mode;
199
17.1k
    GetBitContext *gbc = &s->gbc;
200
17.1k
    int gaq_gain[AC3_MAX_COEFS];
201
202
17.1k
    gaq_mode = get_bits(gbc, 2);
203
17.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
17.1k
    gs = 0;
208
17.1k
    if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
209
        /* read 1-bit GAQ gain codes */
210
324k
        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
24.6k
                gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
213
320k
        }
214
12.4k
    } else if (gaq_mode == EAC3_GAQ_124) {
215
        /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
216
3.77k
        int gc = 2;
217
257k
        for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218
253k
            if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
219
38.2k
                if (gc++ == 2) {
220
12.9k
                    int group_code = get_bits(gbc, 5);
221
12.9k
                    if (group_code > 26) {
222
4.65k
                        av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
223
4.65k
                        group_code = 26;
224
4.65k
                    }
225
12.9k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
226
12.9k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
227
12.9k
                    gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
228
12.9k
                    gc = 0;
229
12.9k
                }
230
38.2k
            }
231
253k
        }
232
3.77k
    }
233
234
17.1k
    gs=0;
235
989k
    for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
236
972k
        int hebap = s->bap[ch][bin];
237
972k
        int bits = ff_eac3_bits_vs_hebap[hebap];
238
972k
        if (!hebap) {
239
            /* zero-mantissa dithering */
240
2.98M
            for (blk = 0; blk < 6; blk++) {
241
2.56M
                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
242
2.56M
            }
243
545k
        } else if (hebap < 8) {
244
            /* Vector Quantization */
245
25.8k
            int v = get_bits(gbc, bits);
246
180k
            for (blk = 0; blk < 6; blk++) {
247
155k
                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] * (1 << 8);
248
155k
            }
249
519k
        } else {
250
            /* Gain Adaptive Quantization */
251
519k
            int gbits, log_gain;
252
519k
            if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
253
62.8k
                log_gain = gaq_gain[gs++];
254
456k
            } else {
255
456k
                log_gain = 0;
256
456k
            }
257
519k
            gbits = bits - log_gain;
258
259
3.63M
            for (blk = 0; blk < 6; blk++) {
260
3.11M
                int mant = get_sbits(gbc, gbits);
261
3.11M
                if (log_gain && mant == -(1 << (gbits-1))) {
262
                    /* large mantissa */
263
31.4k
                    int b;
264
31.4k
                    int mbits = bits - (2 - log_gain);
265
31.4k
                    mant = get_sbits(gbc, mbits);
266
31.4k
                    mant = ((unsigned)mant) << (23 - (mbits - 1));
267
                    /* remap mantissa value to correct for asymmetric quantization */
268
31.4k
                    if (mant >= 0)
269
7.13k
                        b = 1 << (23 - log_gain);
270
24.3k
                    else
271
24.3k
                        b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] * (1 << 8);
272
31.4k
                    mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
273
3.08M
                } else {
274
                    /* small mantissa, no GAQ, or Gk=1 */
275
3.08M
                    mant *= (1 << 24 - bits);
276
3.08M
                    if (!log_gain) {
277
                        /* remap mantissa value for no GAQ or Gk=1 */
278
2.85M
                        mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
279
2.85M
                    }
280
3.08M
                }
281
3.11M
                s->pre_mantissa[ch][bin][blk] = mant;
282
3.11M
            }
283
519k
        }
284
972k
        idct6(s->pre_mantissa[ch][bin]);
285
972k
    }
286
17.1k
}
287
288
static int ff_eac3_parse_header(AC3DecodeContext *s, const AC3HeaderInfo *hdr)
289
2.15M
{
290
2.15M
    int i, blk, ch;
291
2.15M
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
2.15M
    int parse_transient_proc_info;
293
2.15M
    int num_cpl_blocks;
294
2.15M
    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.15M
    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.15M
    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.15M
    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.82k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
8.82k
        return AVERROR_PATCHWELCOME;
323
8.82k
    }
324
325
    /* volume control params */
326
4.82M
    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327
2.67M
        s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
2.67M
        if (s->dialog_normalization[i] == 0) {
329
280k
            s->dialog_normalization[i] = -31;
330
280k
        }
331
2.67M
        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.67M
        if (hdr->compression_exists[i]) {
336
1.42M
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
1.42M
        }
338
2.67M
    }
339
340
2.14M
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
2.14M
    s->preferred_downmix       = hdr->preferred_downmix;
344
2.14M
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
2.14M
    s->center_mix_level        = hdr->center_mix_level;
346
2.14M
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
2.14M
    s->surround_mix_level      = hdr->surround_mix_level;
348
2.14M
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
2.14M
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
2.14M
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
2.14M
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
2.14M
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
2.14M
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
2.14M
    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.14M
    if (s->num_blocks == 6) {
363
912k
        ac3_exponent_strategy = get_bits1(gbc);
364
912k
        parse_aht_info        = get_bits1(gbc);
365
1.23M
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
1.23M
        ac3_exponent_strategy = 1;
369
1.23M
        parse_aht_info = 0;
370
1.23M
    }
371
372
2.14M
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
2.14M
    parse_transient_proc_info = get_bits1(gbc);
374
375
2.14M
    s->block_switch_syntax = get_bits1(gbc);
376
2.14M
    if (!s->block_switch_syntax)
377
1.49M
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
2.14M
    s->dither_flag_syntax = get_bits1(gbc);
380
2.14M
    if (!s->dither_flag_syntax) {
381
6.26M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
4.60M
            s->dither_flag[ch] = 1;
383
1.65M
    }
384
2.14M
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
2.14M
    s->bit_allocation_syntax = get_bits1(gbc);
387
2.14M
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
1.56M
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
1.56M
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
1.56M
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
1.56M
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
1.56M
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
1.56M
    }
395
396
2.14M
    s->fast_gain_syntax  = get_bits1(gbc);
397
2.14M
    s->dba_syntax        = get_bits1(gbc);
398
2.14M
    s->skip_syntax       = get_bits1(gbc);
399
2.14M
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
2.14M
    num_cpl_blocks = 0;
403
2.14M
    if (s->channel_mode > 1) {
404
7.15M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
5.85M
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
5.85M
            if (s->cpl_strategy_exists[blk]) {
407
2.87M
                s->cpl_in_use[blk] = get_bits1(gbc);
408
2.97M
            } else {
409
2.97M
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
2.97M
            }
411
5.85M
            num_cpl_blocks += s->cpl_in_use[blk];
412
5.85M
        }
413
1.29M
    } else {
414
848k
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
848k
    }
416
417
    /* exponent strategy data */
418
2.14M
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
6.44M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
19.8M
            for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422
15.0M
                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423
15.0M
            }
424
4.82M
        }
425
1.61M
    } else {
426
        /* LUT-based exponent strategy syntax */
427
2.63M
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
2.10M
            int frmchexpstr = get_bits(gbc, 5);
429
14.7M
            for (blk = 0; blk < 6; blk++) {
430
12.6M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
12.6M
            }
432
2.10M
        }
433
529k
    }
434
    /* LFE exponent strategy */
435
2.14M
    if (s->lfe_on) {
436
6.53M
        for (blk = 0; blk < s->num_blocks; blk++) {
437
5.22M
            s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438
5.22M
        }
439
1.31M
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
2.14M
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
2.14M
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
816k
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
816k
    }
445
446
    /* determine which channels use AHT */
447
2.14M
    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
242k
        s->channel_uses_aht[CPL_CH]=0;
453
1.19M
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
956k
            int use_aht = 1;
455
2.91M
            for (blk = 1; blk < 6; blk++) {
456
2.60M
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
2.60M
                        (!ch && s->cpl_strategy_exists[blk])) {
458
645k
                    use_aht = 0;
459
645k
                    break;
460
645k
                }
461
2.60M
            }
462
956k
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
956k
        }
464
1.90M
    } else {
465
1.90M
        memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466
1.90M
    }
467
468
    /* per-frame SNR offset */
469
2.14M
    if (!s->snr_offset_strategy) {
470
1.20M
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
1.20M
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
6.51M
        for (ch = 0; ch <= s->channels; ch++)
473
5.31M
            s->snr_offset[ch] = snroffst;
474
1.20M
    }
475
476
    /* transient pre-noise processing data */
477
2.14M
    if (parse_transient_proc_info) {
478
1.60M
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
1.19M
            if (get_bits1(gbc)) { // channel in transient processing
480
512k
                skip_bits(gbc, 10); // skip transient processing location
481
512k
                skip_bits(gbc, 8);  // skip transient processing length
482
512k
            }
483
1.19M
        }
484
411k
    }
485
486
    /* spectral extension attenuation data */
487
8.30M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
6.16M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
662k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
5.50M
        } else {
491
5.50M
            s->spx_atten_code[ch] = -1;
492
5.50M
        }
493
6.16M
    }
494
495
    /* block start information */
496
2.14M
    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
347k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
347k
        skip_bits_long(gbc, block_start_bits);
503
347k
        avpriv_request_sample(s->avctx, "Block start info");
504
347k
    }
505
506
    /* syntax state initialization */
507
8.30M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
6.16M
        s->first_spx_coords[ch] = 1;
509
6.16M
        s->first_cpl_coords[ch] = 1;
510
6.16M
    }
511
2.14M
    s->first_cpl_leak = 1;
512
513
2.14M
    return 0;
514
2.15M
}
ac3dec_float.c:ff_eac3_parse_header
Line
Count
Source
289
1.56M
{
290
1.56M
    int i, blk, ch;
291
1.56M
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
1.56M
    int parse_transient_proc_info;
293
1.56M
    int num_cpl_blocks;
294
1.56M
    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.56M
    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.56M
    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.56M
    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.69k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
1.69k
        return AVERROR_PATCHWELCOME;
323
1.69k
    }
324
325
    /* volume control params */
326
3.44M
    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327
1.87M
        s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
1.87M
        if (s->dialog_normalization[i] == 0) {
329
108k
            s->dialog_normalization[i] = -31;
330
108k
        }
331
1.87M
        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.87M
        if (hdr->compression_exists[i]) {
336
1.01M
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
1.01M
        }
338
1.87M
    }
339
340
1.56M
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
1.56M
    s->preferred_downmix       = hdr->preferred_downmix;
344
1.56M
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
1.56M
    s->center_mix_level        = hdr->center_mix_level;
346
1.56M
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
1.56M
    s->surround_mix_level      = hdr->surround_mix_level;
348
1.56M
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
1.56M
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
1.56M
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
1.56M
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
1.56M
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
1.56M
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
1.56M
    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.56M
    if (s->num_blocks == 6) {
363
762k
        ac3_exponent_strategy = get_bits1(gbc);
364
762k
        parse_aht_info        = get_bits1(gbc);
365
805k
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
805k
        ac3_exponent_strategy = 1;
369
805k
        parse_aht_info = 0;
370
805k
    }
371
372
1.56M
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
1.56M
    parse_transient_proc_info = get_bits1(gbc);
374
375
1.56M
    s->block_switch_syntax = get_bits1(gbc);
376
1.56M
    if (!s->block_switch_syntax)
377
1.00M
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
1.56M
    s->dither_flag_syntax = get_bits1(gbc);
380
1.56M
    if (!s->dither_flag_syntax) {
381
4.59M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
3.42M
            s->dither_flag[ch] = 1;
383
1.17M
    }
384
1.56M
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
1.56M
    s->bit_allocation_syntax = get_bits1(gbc);
387
1.56M
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
1.07M
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
1.07M
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
1.07M
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
1.07M
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
1.07M
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
1.07M
    }
395
396
1.56M
    s->fast_gain_syntax  = get_bits1(gbc);
397
1.56M
    s->dba_syntax        = get_bits1(gbc);
398
1.56M
    s->skip_syntax       = get_bits1(gbc);
399
1.56M
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
1.56M
    num_cpl_blocks = 0;
403
1.56M
    if (s->channel_mode > 1) {
404
5.97M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
4.89M
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
4.89M
            if (s->cpl_strategy_exists[blk]) {
407
2.47M
                s->cpl_in_use[blk] = get_bits1(gbc);
408
2.47M
            } else {
409
2.42M
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
2.42M
            }
411
4.89M
            num_cpl_blocks += s->cpl_in_use[blk];
412
4.89M
        }
413
1.08M
    } else {
414
483k
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
483k
    }
416
417
    /* exponent strategy data */
418
1.56M
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
4.64M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
15.5M
            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.49M
        }
425
1.14M
    } else {
426
        /* LUT-based exponent strategy syntax */
427
1.98M
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
1.56M
            int frmchexpstr = get_bits(gbc, 5);
429
10.9M
            for (blk = 0; blk < 6; blk++) {
430
9.37M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
9.37M
            }
432
1.56M
        }
433
419k
    }
434
    /* LFE exponent strategy */
435
1.56M
    if (s->lfe_on) {
436
4.33M
        for (blk = 0; blk < s->num_blocks; blk++) {
437
3.50M
            s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438
3.50M
        }
439
833k
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
1.56M
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
1.56M
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
708k
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
708k
    }
445
446
    /* determine which channels use AHT */
447
1.56M
    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
200k
        s->channel_uses_aht[CPL_CH]=0;
453
974k
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
773k
            int use_aht = 1;
455
2.39M
            for (blk = 1; blk < 6; blk++) {
456
2.13M
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
2.13M
                        (!ch && s->cpl_strategy_exists[blk])) {
458
512k
                    use_aht = 0;
459
512k
                    break;
460
512k
                }
461
2.13M
            }
462
773k
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
773k
        }
464
1.36M
    } else {
465
1.36M
        memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466
1.36M
    }
467
468
    /* per-frame SNR offset */
469
1.56M
    if (!s->snr_offset_strategy) {
470
767k
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
767k
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
4.21M
        for (ch = 0; ch <= s->channels; ch++)
473
3.44M
            s->snr_offset[ch] = snroffst;
474
767k
    }
475
476
    /* transient pre-noise processing data */
477
1.56M
    if (parse_transient_proc_info) {
478
1.18M
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
871k
            if (get_bits1(gbc)) { // channel in transient processing
480
390k
                skip_bits(gbc, 10); // skip transient processing location
481
390k
                skip_bits(gbc, 8);  // skip transient processing length
482
390k
            }
483
871k
        }
484
311k
    }
485
486
    /* spectral extension attenuation data */
487
6.26M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
4.69M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
519k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
4.17M
        } else {
491
4.17M
            s->spx_atten_code[ch] = -1;
492
4.17M
        }
493
4.69M
    }
494
495
    /* block start information */
496
1.56M
    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
281k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
281k
        skip_bits_long(gbc, block_start_bits);
503
281k
        avpriv_request_sample(s->avctx, "Block start info");
504
281k
    }
505
506
    /* syntax state initialization */
507
6.26M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
4.69M
        s->first_spx_coords[ch] = 1;
509
4.69M
        s->first_cpl_coords[ch] = 1;
510
4.69M
    }
511
1.56M
    s->first_cpl_leak = 1;
512
513
1.56M
    return 0;
514
1.56M
}
ac3dec_fixed.c:ff_eac3_parse_header
Line
Count
Source
289
584k
{
290
584k
    int i, blk, ch;
291
584k
    int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
292
584k
    int parse_transient_proc_info;
293
584k
    int num_cpl_blocks;
294
584k
    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
584k
    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
584k
    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
584k
    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.13k
        avpriv_request_sample(s->avctx, "Reduced sampling rate");
322
7.13k
        return AVERROR_PATCHWELCOME;
323
7.13k
    }
324
325
    /* volume control params */
326
1.37M
    for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
327
802k
        s->dialog_normalization[i] = hdr->dialog_normalization[i];
328
802k
        if (s->dialog_normalization[i] == 0) {
329
172k
            s->dialog_normalization[i] = -31;
330
172k
        }
331
802k
        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
802k
        if (hdr->compression_exists[i]) {
336
409k
            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(hdr->heavy_dynamic_range[i]);
337
409k
        }
338
802k
    }
339
340
577k
    s->channel_map = hdr->channel_map;
341
342
    /* mixing metadata */
343
577k
    s->preferred_downmix       = hdr->preferred_downmix;
344
577k
    s->center_mix_level_ltrt   = hdr->center_mix_level_ltrt;
345
577k
    s->center_mix_level        = hdr->center_mix_level;
346
577k
    s->surround_mix_level_ltrt = hdr->surround_mix_level_ltrt;
347
577k
    s->surround_mix_level      = hdr->surround_mix_level;
348
577k
    s->lfe_mix_level_exists    = hdr->lfe_mix_level_exists;
349
577k
    s->lfe_mix_level           = hdr->lfe_mix_level;
350
577k
    s->dolby_surround_mode     = hdr->dolby_surround_mode;
351
577k
    s->dolby_headphone_mode    = hdr->dolby_headphone_mode;
352
577k
    s->dolby_surround_ex_mode  = hdr->dolby_surround_ex_mode;
353
354
    /* informational metadata */
355
577k
    s->bitstream_mode = hdr->bitstream_mode;
356
357
    /* additional bitstream info */
358
577k
    s->eac3_extension_type_a = hdr->eac3_extension_type_a;
359
360
    /* audio frame syntax flags, strategy data, and per-frame data */
361
362
577k
    if (s->num_blocks == 6) {
363
149k
        ac3_exponent_strategy = get_bits1(gbc);
364
149k
        parse_aht_info        = get_bits1(gbc);
365
427k
    } else {
366
        /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
367
           do not use AHT */
368
427k
        ac3_exponent_strategy = 1;
369
427k
        parse_aht_info = 0;
370
427k
    }
371
372
577k
    s->snr_offset_strategy    = get_bits(gbc, 2);
373
577k
    parse_transient_proc_info = get_bits1(gbc);
374
375
577k
    s->block_switch_syntax = get_bits1(gbc);
376
577k
    if (!s->block_switch_syntax)
377
483k
        memset(s->block_switch, 0, sizeof(s->block_switch));
378
379
577k
    s->dither_flag_syntax = get_bits1(gbc);
380
577k
    if (!s->dither_flag_syntax) {
381
1.67M
        for (ch = 1; ch <= s->fbw_channels; ch++)
382
1.18M
            s->dither_flag[ch] = 1;
383
484k
    }
384
577k
    s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
385
386
577k
    s->bit_allocation_syntax = get_bits1(gbc);
387
577k
    if (!s->bit_allocation_syntax) {
388
        /* set default bit allocation parameters */
389
488k
        s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
390
488k
        s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
391
488k
        s->bit_alloc_params.slow_gain  = ff_ac3_slow_gain_tab [1];
392
488k
        s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
393
488k
        s->bit_alloc_params.floor      = ff_ac3_floor_tab     [7];
394
488k
    }
395
396
577k
    s->fast_gain_syntax  = get_bits1(gbc);
397
577k
    s->dba_syntax        = get_bits1(gbc);
398
577k
    s->skip_syntax       = get_bits1(gbc);
399
577k
    parse_spx_atten_data = get_bits1(gbc);
400
401
    /* coupling strategy occurrence and coupling use per block */
402
577k
    num_cpl_blocks = 0;
403
577k
    if (s->channel_mode > 1) {
404
1.17M
        for (blk = 0; blk < s->num_blocks; blk++) {
405
963k
            s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
406
963k
            if (s->cpl_strategy_exists[blk]) {
407
407k
                s->cpl_in_use[blk] = get_bits1(gbc);
408
555k
            } else {
409
555k
                s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
410
555k
            }
411
963k
            num_cpl_blocks += s->cpl_in_use[blk];
412
963k
        }
413
365k
    } else {
414
365k
        memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
415
365k
    }
416
417
    /* exponent strategy data */
418
577k
    if (ac3_exponent_strategy) {
419
        /* AC-3-style exponent strategy syntax */
420
1.80M
        for (blk = 0; blk < s->num_blocks; blk++) {
421
4.30M
            for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
422
2.97M
                s->exp_strategy[blk][ch] = get_bits(gbc, 2);
423
2.97M
            }
424
1.33M
        }
425
467k
    } else {
426
        /* LUT-based exponent strategy syntax */
427
649k
        for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
428
539k
            int frmchexpstr = get_bits(gbc, 5);
429
3.77M
            for (blk = 0; blk < 6; blk++) {
430
3.23M
                s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
431
3.23M
            }
432
539k
        }
433
110k
    }
434
    /* LFE exponent strategy */
435
577k
    if (s->lfe_on) {
436
2.19M
        for (blk = 0; blk < s->num_blocks; blk++) {
437
1.71M
            s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
438
1.71M
        }
439
477k
    }
440
    /* original exponent strategies if this stream was converted from AC-3 */
441
577k
    if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
442
577k
            (s->num_blocks == 6 || get_bits1(gbc))) {
443
107k
        skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
444
107k
    }
445
446
    /* determine which channels use AHT */
447
577k
    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
41.8k
        s->channel_uses_aht[CPL_CH]=0;
453
224k
        for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
454
183k
            int use_aht = 1;
455
512k
            for (blk = 1; blk < 6; blk++) {
456
462k
                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
457
462k
                        (!ch && s->cpl_strategy_exists[blk])) {
458
133k
                    use_aht = 0;
459
133k
                    break;
460
133k
                }
461
462k
            }
462
183k
            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
463
183k
        }
464
535k
    } else {
465
535k
        memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
466
535k
    }
467
468
    /* per-frame SNR offset */
469
577k
    if (!s->snr_offset_strategy) {
470
438k
        int csnroffst = (get_bits(gbc, 6) - 15) << 4;
471
438k
        int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
472
2.30M
        for (ch = 0; ch <= s->channels; ch++)
473
1.86M
            s->snr_offset[ch] = snroffst;
474
438k
    }
475
476
    /* transient pre-noise processing data */
477
577k
    if (parse_transient_proc_info) {
478
423k
        for (ch = 1; ch <= s->fbw_channels; ch++) {
479
324k
            if (get_bits1(gbc)) { // channel in transient processing
480
121k
                skip_bits(gbc, 10); // skip transient processing location
481
121k
                skip_bits(gbc, 8);  // skip transient processing length
482
121k
            }
483
324k
        }
484
99.3k
    }
485
486
    /* spectral extension attenuation data */
487
2.04M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
488
1.46M
        if (parse_spx_atten_data && get_bits1(gbc)) {
489
142k
            s->spx_atten_code[ch] = get_bits(gbc, 5);
490
1.32M
        } else {
491
1.32M
            s->spx_atten_code[ch] = -1;
492
1.32M
        }
493
1.46M
    }
494
495
    /* block start information */
496
577k
    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
66.3k
        int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
502
66.3k
        skip_bits_long(gbc, block_start_bits);
503
66.3k
        avpriv_request_sample(s->avctx, "Block start info");
504
66.3k
    }
505
506
    /* syntax state initialization */
507
2.04M
    for (ch = 1; ch <= s->fbw_channels; ch++) {
508
1.46M
        s->first_spx_coords[ch] = 1;
509
1.46M
        s->first_cpl_coords[ch] = 1;
510
1.46M
    }
511
577k
    s->first_cpl_leak = 1;
512
513
577k
    return 0;
514
584k
}