FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac/aacdec_dsp_template.c
Date: 2024-07-16 12:46:59
Exec Total Coverage
Lines: 336 377 89.1%
Functions: 28 32 87.5%
Branches: 184 216 85.2%

Line Branch Exec Source
1 /*
2 * AAC decoder
3 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
4 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
5 * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com>
6 *
7 * AAC LATM decoder
8 * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
9 * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net>
10 *
11 * AAC decoder fixed-point implementation
12 * Copyright (c) 2013
13 * MIPS Technologies, Inc., California.
14 *
15 * This file is part of FFmpeg.
16 *
17 * FFmpeg is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * FFmpeg is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with FFmpeg; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 */
31
32 #include "aacdec.h"
33 #include "libavcodec/lpc_functions.h"
34
35 #include "libavcodec/aactab.h"
36
37 /**
38 * Convert integer scalefactors to the decoder's native expected
39 * scalefactor values.
40 */
41 101704 static void AAC_RENAME(dequant_scalefactors)(SingleChannelElement *sce)
42 {
43 101704 IndividualChannelStream *ics = &sce->ics;
44 101704 const int *sfo = sce->sfo;
45 101704 INTFLOAT *sf = sce->AAC_RENAME(sf);
46
47 101704 int idx = 0;
48
2/2
✓ Branch 0 taken 106942 times.
✓ Branch 1 taken 101704 times.
208646 for (int g = 0; g < ics->num_window_groups; g++) {
49
2/2
✓ Branch 0 taken 3817880 times.
✓ Branch 1 taken 106942 times.
3924822 for (int sfb = 0; sfb < ics->max_sfb; sfb++, idx++) {
50
4/4
✓ Branch 0 taken 537005 times.
✓ Branch 1 taken 66207 times.
✓ Branch 2 taken 281615 times.
✓ Branch 3 taken 2933053 times.
3817880 switch (sce->band_type[g*ics->max_sfb + sfb]) {
51 537005 case ZERO_BT:
52 537005 sf[idx] = FIXR(0.);
53 537005 break;
54 66207 case INTENSITY_BT: /* fallthrough */
55 case INTENSITY_BT2:
56 #if USE_FIXED
57 17856 sf[idx] = 100 - (sfo[idx] + 100);
58 #else
59 48351 sf[idx] = ff_aac_pow2sf_tab[-sfo[idx] - 100 + POW_SF2_ZERO];
60 #endif /* USE_FIXED */
61 66207 break;
62 281615 case NOISE_BT:
63 #if USE_FIXED
64 137931 sf[idx] = -(100 + sfo[idx]);
65 #else
66 143684 sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
67 #endif /* USE_FIXED */
68 281615 break;
69 2933053 default:
70 #if USE_FIXED
71 783227 sf[idx] = -sfo[idx] - 100;
72 #else
73 2149826 sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
74 #endif /* USE_FIXED */
75 2933053 break;
76 }
77 }
78 }
79 101704 }
80
81 /**
82 * Mid/Side stereo decoding; reference: 4.6.8.1.3.
83 */
84 30850 static void AAC_RENAME(apply_mid_side_stereo)(AACDecContext *ac, ChannelElement *cpe)
85 {
86 30850 const IndividualChannelStream *ics = &cpe->ch[0].ics;
87 30850 INTFLOAT *ch0 = cpe->ch[0].AAC_RENAME(coeffs);
88 30850 INTFLOAT *ch1 = cpe->ch[1].AAC_RENAME(coeffs);
89 30850 const uint16_t *offsets = ics->swb_offset;
90
2/2
✓ Branch 0 taken 32555 times.
✓ Branch 1 taken 30850 times.
63405 for (int g = 0; g < ics->num_window_groups; g++) {
91
2/2
✓ Branch 0 taken 1182527 times.
✓ Branch 1 taken 32555 times.
1215082 for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++) {
92 1182527 const int idx = g*cpe->max_sfb_ste + sfb;
93
2/2
✓ Branch 0 taken 883483 times.
✓ Branch 1 taken 299044 times.
1182527 if (cpe->ms_mask[idx] &&
94
1/2
✓ Branch 0 taken 883483 times.
✗ Branch 1 not taken.
883483 cpe->ch[0].band_type[idx] < NOISE_BT &&
95
2/2
✓ Branch 0 taken 881107 times.
✓ Branch 1 taken 2376 times.
883483 cpe->ch[1].band_type[idx] < NOISE_BT) {
96
2/2
✓ Branch 0 taken 911294 times.
✓ Branch 1 taken 881107 times.
1792401 for (int group = 0; group < ics->group_len[g]; group++)
97 #if USE_FIXED
98 256654 ac->fdsp->butterflies_fixed(ch0 + group * 128 + offsets[sfb],
99 256654 ch1 + group * 128 + offsets[sfb],
100 256654 offsets[sfb+1] - offsets[sfb]);
101 #else
102 654640 ac->fdsp->butterflies_float(ch0 + group * 128 + offsets[sfb],
103 654640 ch1 + group * 128 + offsets[sfb],
104 654640 offsets[sfb+1] - offsets[sfb]);
105 #endif /* USE_FIXED */
106 }
107 }
108 32555 ch0 += ics->group_len[g] * 128;
109 32555 ch1 += ics->group_len[g] * 128;
110 }
111 30850 }
112
113 /**
114 * intensity stereo decoding; reference: 4.6.8.2.3
115 *
116 * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
117 * [1] mask is decoded from bitstream; [2] mask is all 1s;
118 * [3] reserved for scalable AAC
119 */
120 30786 static void AAC_RENAME(apply_intensity_stereo)(AACDecContext *ac,
121 ChannelElement *cpe, int ms_present)
122 {
123 30786 const IndividualChannelStream *ics = &cpe->ch[1].ics;
124 30786 SingleChannelElement *sce1 = &cpe->ch[1];
125 30786 INTFLOAT *coef0 = cpe->ch[0].AAC_RENAME(coeffs), *coef1 = cpe->ch[1].AAC_RENAME(coeffs);
126 30786 const uint16_t *offsets = ics->swb_offset;
127 int c;
128 INTFLOAT scale;
129
2/2
✓ Branch 0 taken 32714 times.
✓ Branch 1 taken 30786 times.
63500 for (int g = 0; g < ics->num_window_groups; g++) {
130
2/2
✓ Branch 0 taken 1165449 times.
✓ Branch 1 taken 32714 times.
1198163 for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
131 1165449 const int idx = g*ics->max_sfb + sfb;
132
2/2
✓ Branch 0 taken 1101485 times.
✓ Branch 1 taken 63964 times.
1165449 if (sce1->band_type[idx] == INTENSITY_BT ||
133
2/2
✓ Branch 0 taken 2243 times.
✓ Branch 1 taken 1099242 times.
1101485 sce1->band_type[idx] == INTENSITY_BT2) {
134 66207 c = -1 + 2 * (sce1->band_type[idx] - 14);
135
2/2
✓ Branch 0 taken 61324 times.
✓ Branch 1 taken 4883 times.
66207 if (ms_present)
136 61324 c *= 1 - 2 * cpe->ms_mask[idx];
137 66207 scale = c * sce1->AAC_RENAME(sf)[idx];
138
2/2
✓ Branch 0 taken 66538 times.
✓ Branch 1 taken 66207 times.
132745 for (int group = 0; group < ics->group_len[g]; group++)
139 #if USE_FIXED
140 17955 subband_scale(coef1 + group * 128 + offsets[sfb],
141 17955 coef0 + group * 128 + offsets[sfb],
142 scale,
143 23,
144 17955 offsets[sfb + 1] - offsets[sfb], ac->avctx);
145 #else
146 48583 ac->fdsp->vector_fmul_scalar(coef1 + group * 128 + offsets[sfb],
147 48583 coef0 + group * 128 + offsets[sfb],
148 scale,
149 48583 offsets[sfb + 1] - offsets[sfb]);
150 #endif /* USE_FIXED */
151 }
152 }
153 32714 coef0 += ics->group_len[g] * 128;
154 32714 coef1 += ics->group_len[g] * 128;
155 }
156 30786 }
157
158 /**
159 * Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4.6.9.3.
160 *
161 * @param decode 1 if tool is used normally, 0 if tool is used in LTP.
162 * @param coef spectral coefficients
163 */
164 6961 static void AAC_RENAME(apply_tns)(void *_coef_param, TemporalNoiseShaping *tns,
165 IndividualChannelStream *ics, int decode)
166 {
167 6961 const int mmm = FFMIN(ics->tns_max_bands, ics->max_sfb);
168 int w, filt, m, i;
169 int bottom, top, order, start, end, size, inc;
170 6961 INTFLOAT *coef_param = _coef_param;
171 INTFLOAT lpc[TNS_MAX_ORDER];
172 INTFLOAT tmp[TNS_MAX_ORDER+1];
173 6961 UINTFLOAT *coef = coef_param;
174
175
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6955 times.
6961 if(!mmm)
176 6 return;
177
178
2/2
✓ Branch 0 taken 11568 times.
✓ Branch 1 taken 6955 times.
18523 for (w = 0; w < ics->num_windows; w++) {
179 11568 bottom = ics->num_swb;
180
2/2
✓ Branch 0 taken 9407 times.
✓ Branch 1 taken 11568 times.
20975 for (filt = 0; filt < tns->n_filt[w]; filt++) {
181 9407 top = bottom;
182 9407 bottom = FFMAX(0, top - tns->length[w][filt]);
183 9407 order = tns->order[w][filt];
184
2/2
✓ Branch 0 taken 520 times.
✓ Branch 1 taken 8887 times.
9407 if (order == 0)
185 520 continue;
186
187 // tns_decode_coef
188 8887 compute_lpc_coefs(tns->AAC_RENAME(coef)[w][filt], order, lpc, 0, 0, 0);
189
190
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8881 times.
8887 start = ics->swb_offset[FFMIN(bottom, mmm)];
191
2/2
✓ Branch 0 taken 7089 times.
✓ Branch 1 taken 1798 times.
8887 end = ics->swb_offset[FFMIN( top, mmm)];
192
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8879 times.
8887 if ((size = end - start) <= 0)
193 8 continue;
194
2/2
✓ Branch 0 taken 3614 times.
✓ Branch 1 taken 5265 times.
8879 if (tns->direction[w][filt]) {
195 3614 inc = -1;
196 3614 start = end - 1;
197 } else {
198 5265 inc = 1;
199 }
200 8879 start += w * 128;
201
202
2/2
✓ Branch 0 taken 8873 times.
✓ Branch 1 taken 6 times.
8879 if (decode) {
203 // ar filter
204
2/2
✓ Branch 0 taken 2747532 times.
✓ Branch 1 taken 8873 times.
2756405 for (m = 0; m < size; m++, start += inc)
205
2/2
✓ Branch 0 taken 21302901 times.
✓ Branch 1 taken 2747532 times.
24050433 for (i = 1; i <= FFMIN(m, order); i++)
206 21302901 coef[start] -= AAC_MUL26((INTFLOAT)coef[start - i * inc], lpc[i - 1]);
207 } else {
208 // ma filter
209
2/2
✓ Branch 0 taken 3696 times.
✓ Branch 1 taken 6 times.
3702 for (m = 0; m < size; m++, start += inc) {
210 3696 tmp[0] = coef[start];
211
2/2
✓ Branch 0 taken 35416 times.
✓ Branch 1 taken 3696 times.
39112 for (i = 1; i <= FFMIN(m, order); i++)
212 35416 coef[start] += AAC_MUL26(tmp[i], lpc[i - 1]);
213
2/2
✓ Branch 0 taken 35728 times.
✓ Branch 1 taken 3696 times.
39424 for (i = order; i > 0; i--)
214 35728 tmp[i] = tmp[i - 1];
215 }
216 }
217 }
218 }
219 }
220
221 /**
222 * Apply windowing and MDCT to obtain the spectral
223 * coefficient from the predicted sample by LTP.
224 */
225 786 static inline void AAC_RENAME(windowing_and_mdct_ltp)(AACDecContext *ac,
226 INTFLOAT *out, INTFLOAT *in,
227 IndividualChannelStream *ics)
228 {
229
1/2
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
786 const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
230
1/2
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
786 const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
231
2/2
✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2 times.
786 const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
232
2/2
✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2 times.
786 const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
233
234
2/2
✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2 times.
786 if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) {
235 784 ac->fdsp->vector_fmul(in, in, lwindow_prev, 1024);
236 } else {
237 2 memset(in, 0, 448 * sizeof(*in));
238 2 ac->fdsp->vector_fmul(in + 448, in + 448, swindow_prev, 128);
239 }
240
1/2
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
786 if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
241 786 ac->fdsp->vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
242 } else {
243 ac->fdsp->vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
244 memset(in + 1024 + 576, 0, 448 * sizeof(*in));
245 }
246 786 ac->mdct_ltp_fn(ac->mdct_ltp, out, in, sizeof(INTFLOAT));
247 786 }
248
249 /**
250 * Apply the long term prediction
251 */
252 786 static void AAC_RENAME(apply_ltp)(AACDecContext *ac, SingleChannelElement *sce)
253 {
254 786 const LongTermPrediction *ltp = &sce->ics.ltp;
255 786 const uint16_t *offsets = sce->ics.swb_offset;
256 int i, sfb;
257
258
1/2
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
786 if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
259 786 INTFLOAT *predTime = sce->AAC_RENAME(output);
260 786 INTFLOAT *predFreq = ac->AAC_RENAME(buf_mdct);
261 786 int16_t num_samples = 2048;
262
263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
786 if (ltp->lag < 1024)
264 num_samples = ltp->lag + 1024;
265
2/2
✓ Branch 0 taken 1609728 times.
✓ Branch 1 taken 786 times.
1610514 for (i = 0; i < num_samples; i++)
266 1609728 predTime[i] = AAC_MUL30(sce->AAC_RENAME(ltp_state)[i + 2048 - ltp->lag], ltp->AAC_RENAME(coef));
267 786 memset(&predTime[i], 0, (2048 - i) * sizeof(*predTime));
268
269 786 AAC_RENAME(windowing_and_mdct_ltp)(ac, predFreq, predTime, &sce->ics);
270
271
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 780 times.
786 if (sce->tns.present)
272 6 AAC_RENAME(apply_tns)(predFreq, &sce->tns, &sce->ics, 0);
273
274
2/2
✓ Branch 0 taken 31440 times.
✓ Branch 1 taken 786 times.
32226 for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++)
275
2/2
✓ Branch 0 taken 22868 times.
✓ Branch 1 taken 8572 times.
31440 if (ltp->used[sfb])
276
2/2
✓ Branch 0 taken 347544 times.
✓ Branch 1 taken 22868 times.
370412 for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
277 347544 sce->AAC_RENAME(coeffs)[i] += (UINTFLOAT)predFreq[i];
278 }
279 786 }
280
281 /**
282 * Update the LTP buffer for next frame
283 */
284 3568 static void AAC_RENAME(update_ltp)(AACDecContext *ac, SingleChannelElement *sce)
285 {
286 3568 IndividualChannelStream *ics = &sce->ics;
287 3568 INTFLOAT *saved = sce->AAC_RENAME(saved);
288 3568 INTFLOAT *saved_ltp = sce->AAC_RENAME(coeffs);
289
2/2
✓ Branch 0 taken 3560 times.
✓ Branch 1 taken 8 times.
3568 const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
290
2/2
✓ Branch 0 taken 3560 times.
✓ Branch 1 taken 8 times.
3568 const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
291 int i;
292
293
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3564 times.
3568 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
294 4 memcpy(saved_ltp, saved, 512 * sizeof(*saved_ltp));
295 4 memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
296 4 ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->AAC_RENAME(buf_mdct) + 960, &swindow[64], 64);
297
298
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
260 for (i = 0; i < 64; i++)
299 256 saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], swindow[63 - i]);
300
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3560 times.
3564 } else if (1 && ics->window_sequence[0] == LONG_START_SEQUENCE) {
301 4 memcpy(saved_ltp, ac->AAC_RENAME(buf_mdct) + 512, 448 * sizeof(*saved_ltp));
302 4 memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
303 4 ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->AAC_RENAME(buf_mdct) + 960, &swindow[64], 64);
304
305
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
260 for (i = 0; i < 64; i++)
306 256 saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], swindow[63 - i]);
307 } else if (1) { // LONG_STOP or ONLY_LONG
308 3560 ac->fdsp->vector_fmul_reverse(saved_ltp, ac->AAC_RENAME(buf_mdct) + 512, &lwindow[512], 512);
309
310
2/2
✓ Branch 0 taken 1822720 times.
✓ Branch 1 taken 3560 times.
1826280 for (i = 0; i < 512; i++)
311 1822720 saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], lwindow[511 - i]);
312 }
313
314 3568 memcpy(sce->AAC_RENAME(ltp_state), sce->AAC_RENAME(ltp_state)+1024,
315 1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
316 3568 memcpy(sce->AAC_RENAME(ltp_state) + 1024, sce->AAC_RENAME(output),
317 1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
318 3568 memcpy(sce->AAC_RENAME(ltp_state) + 2048, saved_ltp,
319 1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
320 3568 }
321
322 /**
323 * Conduct IMDCT and windowing.
324 */
325 70302 static void AAC_RENAME(imdct_and_windowing)(AACDecContext *ac, SingleChannelElement *sce)
326 {
327 70302 IndividualChannelStream *ics = &sce->ics;
328 70302 INTFLOAT *in = sce->AAC_RENAME(coeffs);
329 70302 INTFLOAT *out = sce->AAC_RENAME(output);
330 70302 INTFLOAT *saved = sce->AAC_RENAME(saved);
331
2/2
✓ Branch 0 taken 48238 times.
✓ Branch 1 taken 22064 times.
70302 const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
332
2/2
✓ Branch 0 taken 48077 times.
✓ Branch 1 taken 22225 times.
70302 const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
333
2/2
✓ Branch 0 taken 48077 times.
✓ Branch 1 taken 22225 times.
70302 const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
334 70302 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
335 70302 INTFLOAT *temp = ac->AAC_RENAME(temp);
336 int i;
337
338 // imdct
339
2/2
✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 68214 times.
70302 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
340
2/2
✓ Branch 0 taken 16704 times.
✓ Branch 1 taken 2088 times.
18792 for (i = 0; i < 1024; i += 128)
341 16704 ac->mdct128_fn(ac->mdct128, buf + i, in + i, sizeof(INTFLOAT));
342 } else {
343 68214 ac->mdct1024_fn(ac->mdct1024, buf, in, sizeof(INTFLOAT));
344 }
345
346 /* window overlapping
347 * NOTE: To simplify the overlapping code, all 'meaningless' short to long
348 * and long to short transitions are considered to be short to short
349 * transitions. This leaves just two cases (long to long and short to short)
350 * with a little special sauce for EIGHT_SHORT_SEQUENCE.
351 */
352
4/4
✓ Branch 0 taken 4249 times.
✓ Branch 1 taken 66053 times.
✓ Branch 2 taken 1079 times.
✓ Branch 3 taken 3170 times.
70302 if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
353
4/4
✓ Branch 0 taken 1223 times.
✓ Branch 1 taken 65909 times.
✓ Branch 2 taken 1221 times.
✓ Branch 3 taken 2 times.
67132 (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
354 67130 ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 512);
355 } else {
356 3172 memcpy( out, saved, 448 * sizeof(*out));
357
358
2/2
✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 1084 times.
3172 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
359 2088 ac->fdsp->vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64);
360 2088 ac->fdsp->vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64);
361 2088 ac->fdsp->vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64);
362 2088 ac->fdsp->vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64);
363 2088 ac->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64);
364 2088 memcpy( out + 448 + 4*128, temp, 64 * sizeof(*out));
365 } else {
366 1084 ac->fdsp->vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64);
367 1084 memcpy( out + 576, buf + 64, 448 * sizeof(*out));
368 }
369 }
370
371 // buffer update
372
2/2
✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 68214 times.
70302 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
373 2088 memcpy( saved, temp + 64, 64 * sizeof(*saved));
374 2088 ac->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64);
375 2088 ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
376 2088 ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
377 2088 memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
378
2/2
✓ Branch 0 taken 1221 times.
✓ Branch 1 taken 66993 times.
68214 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
379 1221 memcpy( saved, buf + 512, 448 * sizeof(*saved));
380 1221 memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
381 } else { // LONG_STOP or ONLY_LONG
382 66993 memcpy( saved, buf + 512, 512 * sizeof(*saved));
383 }
384 70302 }
385
386 /**
387 * Conduct IMDCT and windowing for 768-point frames.
388 */
389 static void AAC_RENAME(imdct_and_windowing_768)(AACDecContext *ac, SingleChannelElement *sce)
390 {
391 IndividualChannelStream *ics = &sce->ics;
392 INTFLOAT *in = sce->AAC_RENAME(coeffs);
393 INTFLOAT *out = sce->AAC_RENAME(output);
394 INTFLOAT *saved = sce->AAC_RENAME(saved);
395 const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME(aac_kbd_short_96) : AAC_RENAME(sine_96);
396 const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_long_768) : AAC_RENAME(sine_768);
397 const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_short_96) : AAC_RENAME(sine_96);
398 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
399 INTFLOAT *temp = ac->AAC_RENAME(temp);
400 int i;
401
402 // imdct
403 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
404 for (i = 0; i < 8; i++)
405 ac->mdct96_fn(ac->mdct96, buf + i * 96, in + i * 96, sizeof(INTFLOAT));
406 } else {
407 ac->mdct768_fn(ac->mdct768, buf, in, sizeof(INTFLOAT));
408 }
409
410 /* window overlapping
411 * NOTE: To simplify the overlapping code, all 'meaningless' short to long
412 * and long to short transitions are considered to be short to short
413 * transitions. This leaves just two cases (long to long and short to short)
414 * with a little special sauce for EIGHT_SHORT_SEQUENCE.
415 */
416
417 if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
418 (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
419 ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 384);
420 } else {
421 memcpy( out, saved, 336 * sizeof(*out));
422
423 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
424 ac->fdsp->vector_fmul_window(out + 336 + 0*96, saved + 336, buf + 0*96, swindow_prev, 48);
425 ac->fdsp->vector_fmul_window(out + 336 + 1*96, buf + 0*96 + 48, buf + 1*96, swindow, 48);
426 ac->fdsp->vector_fmul_window(out + 336 + 2*96, buf + 1*96 + 48, buf + 2*96, swindow, 48);
427 ac->fdsp->vector_fmul_window(out + 336 + 3*96, buf + 2*96 + 48, buf + 3*96, swindow, 48);
428 ac->fdsp->vector_fmul_window(temp, buf + 3*96 + 48, buf + 4*96, swindow, 48);
429 memcpy( out + 336 + 4*96, temp, 48 * sizeof(*out));
430 } else {
431 ac->fdsp->vector_fmul_window(out + 336, saved + 336, buf, swindow_prev, 48);
432 memcpy( out + 432, buf + 48, 336 * sizeof(*out));
433 }
434 }
435
436 // buffer update
437 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
438 memcpy( saved, temp + 48, 48 * sizeof(*saved));
439 ac->fdsp->vector_fmul_window(saved + 48, buf + 4*96 + 48, buf + 5*96, swindow, 48);
440 ac->fdsp->vector_fmul_window(saved + 144, buf + 5*96 + 48, buf + 6*96, swindow, 48);
441 ac->fdsp->vector_fmul_window(saved + 240, buf + 6*96 + 48, buf + 7*96, swindow, 48);
442 memcpy( saved + 336, buf + 7*96 + 48, 48 * sizeof(*saved));
443 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
444 memcpy( saved, buf + 384, 336 * sizeof(*saved));
445 memcpy( saved + 336, buf + 7*96 + 48, 48 * sizeof(*saved));
446 } else { // LONG_STOP or ONLY_LONG
447 memcpy( saved, buf + 384, 384 * sizeof(*saved));
448 }
449 }
450
451 /**
452 * Conduct IMDCT and windowing.
453 */
454 387 static void AAC_RENAME(imdct_and_windowing_960)(AACDecContext *ac, SingleChannelElement *sce)
455 {
456 387 IndividualChannelStream *ics = &sce->ics;
457 387 INTFLOAT *in = sce->AAC_RENAME(coeffs);
458 387 INTFLOAT *out = sce->AAC_RENAME(output);
459 387 INTFLOAT *saved = sce->AAC_RENAME(saved);
460
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 373 times.
387 const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120);
461
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 373 times.
387 const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_long_960) : AAC_RENAME(sine_960);
462
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 373 times.
387 const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120);
463 387 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
464 387 INTFLOAT *temp = ac->AAC_RENAME(temp);
465 int i;
466
467 // imdct
468
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 386 times.
387 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
469
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (i = 0; i < 8; i++)
470 8 ac->mdct120_fn(ac->mdct120, buf + i * 120, in + i * 128, sizeof(INTFLOAT));
471 } else {
472 386 ac->mdct960_fn(ac->mdct960, buf, in, sizeof(INTFLOAT));
473 }
474
475 /* window overlapping
476 * NOTE: To simplify the overlapping code, all 'meaningless' short to long
477 * and long to short transitions are considered to be short to short
478 * transitions. This leaves just two cases (long to long and short to short)
479 * with a little special sauce for EIGHT_SHORT_SEQUENCE.
480 */
481
482
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 384 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
387 if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
483
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 383 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
385 (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
484 385 ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 480);
485 } else {
486 2 memcpy( out, saved, 420 * sizeof(*out));
487
488
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
489 1 ac->fdsp->vector_fmul_window(out + 420 + 0*120, saved + 420, buf + 0*120, swindow_prev, 60);
490 1 ac->fdsp->vector_fmul_window(out + 420 + 1*120, buf + 0*120 + 60, buf + 1*120, swindow, 60);
491 1 ac->fdsp->vector_fmul_window(out + 420 + 2*120, buf + 1*120 + 60, buf + 2*120, swindow, 60);
492 1 ac->fdsp->vector_fmul_window(out + 420 + 3*120, buf + 2*120 + 60, buf + 3*120, swindow, 60);
493 1 ac->fdsp->vector_fmul_window(temp, buf + 3*120 + 60, buf + 4*120, swindow, 60);
494 1 memcpy( out + 420 + 4*120, temp, 60 * sizeof(*out));
495 } else {
496 1 ac->fdsp->vector_fmul_window(out + 420, saved + 420, buf, swindow_prev, 60);
497 1 memcpy( out + 540, buf + 60, 420 * sizeof(*out));
498 }
499 }
500
501 // buffer update
502
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 386 times.
387 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
503 1 memcpy( saved, temp + 60, 60 * sizeof(*saved));
504 1 ac->fdsp->vector_fmul_window(saved + 60, buf + 4*120 + 60, buf + 5*120, swindow, 60);
505 1 ac->fdsp->vector_fmul_window(saved + 180, buf + 5*120 + 60, buf + 6*120, swindow, 60);
506 1 ac->fdsp->vector_fmul_window(saved + 300, buf + 6*120 + 60, buf + 7*120, swindow, 60);
507 1 memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
508
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 384 times.
386 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
509 2 memcpy( saved, buf + 480, 420 * sizeof(*saved));
510 2 memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
511 } else { // LONG_STOP or ONLY_LONG
512 384 memcpy( saved, buf + 480, 480 * sizeof(*saved));
513 }
514 387 }
515
516 3636 static void AAC_RENAME(imdct_and_windowing_ld)(AACDecContext *ac, SingleChannelElement *sce)
517 {
518 3636 IndividualChannelStream *ics = &sce->ics;
519 3636 INTFLOAT *in = sce->AAC_RENAME(coeffs);
520 3636 INTFLOAT *out = sce->AAC_RENAME(output);
521 3636 INTFLOAT *saved = sce->AAC_RENAME(saved);
522 3636 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
523
524 // imdct
525 3636 ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
526
527 // window overlapping
528
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 3574 times.
3636 if (ics->use_kb_window[1]) {
529 // AAC LD uses a low overlap sine window instead of a KBD window
530 62 memcpy(out, saved, 192 * sizeof(*out));
531 62 ac->fdsp->vector_fmul_window(out + 192, saved + 192, buf, AAC_RENAME2(sine_128), 64);
532 62 memcpy( out + 320, buf + 64, 192 * sizeof(*out));
533 } else {
534 3574 ac->fdsp->vector_fmul_window(out, saved, buf, AAC_RENAME2(sine_512), 256);
535 }
536
537 // buffer update
538 3636 memcpy(saved, buf + 256, 256 * sizeof(*saved));
539 3636 }
540
541 26598 static void AAC_RENAME(imdct_and_windowing_eld)(AACDecContext *ac, SingleChannelElement *sce)
542 {
543 26598 UINTFLOAT *in = sce->AAC_RENAME(coeffs);
544 26598 INTFLOAT *out = sce->AAC_RENAME(output);
545 26598 INTFLOAT *saved = sce->AAC_RENAME(saved);
546 26598 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
547 int i;
548
2/2
✓ Branch 0 taken 7118 times.
✓ Branch 1 taken 19480 times.
26598 const int n = ac->oc[1].m4ac.frame_length_short ? 480 : 512;
549 26598 const int n2 = n >> 1;
550 26598 const int n4 = n >> 2;
551
2/2
✓ Branch 0 taken 7118 times.
✓ Branch 1 taken 19480 times.
26598 const INTFLOAT *const window = n == 480 ? AAC_RENAME(ff_aac_eld_window_480) :
552 AAC_RENAME(ff_aac_eld_window_512);
553
554 // Inverse transform, mapped to the conventional IMDCT by
555 // Chivukula, R.K.; Reznik, Y.A.; Devarajan, V.,
556 // "Efficient algorithms for MPEG-4 AAC-ELD, AAC-LD and AAC-LC filterbanks,"
557 // International Conference on Audio, Language and Image Processing, ICALIP 2008.
558 // URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4590245&isnumber=4589950
559
2/2
✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
3374198 for (i = 0; i < n2; i+=2) {
560 INTFLOAT temp;
561 3347600 temp = in[i ]; in[i ] = -in[n - 1 - i]; in[n - 1 - i] = temp;
562 3347600 temp = -in[i + 1]; in[i + 1] = in[n - 2 - i]; in[n - 2 - i] = temp;
563 }
564
565
2/2
✓ Branch 0 taken 7118 times.
✓ Branch 1 taken 19480 times.
26598 if (n == 480)
566 7118 ac->mdct480_fn(ac->mdct480, buf, in, sizeof(INTFLOAT));
567 else
568 19480 ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
569
570
2/2
✓ Branch 0 taken 6695200 times.
✓ Branch 1 taken 26598 times.
6721798 for (i = 0; i < n; i+=2) {
571 6695200 buf[i + 0] = -(UINTFLOAT)(USE_FIXED + 1)*buf[i + 0];
572 6695200 buf[i + 1] = (UINTFLOAT)(USE_FIXED + 1)*buf[i + 1];
573 }
574 // Like with the regular IMDCT at this point we still have the middle half
575 // of a transform but with even symmetry on the left and odd symmetry on
576 // the right
577
578 // window overlapping
579 // The spec says to use samples [0..511] but the reference decoder uses
580 // samples [128..639].
581
2/2
✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
3374198 for (i = n4; i < n2; i ++) {
582 3347600 out[i - n4] = AAC_MUL31( buf[ n2 - 1 - i] , window[i - n4]) +
583 3347600 AAC_MUL31( saved[ i + n2] , window[i + n - n4]) +
584 3347600 AAC_MUL31(-saved[n + n2 - 1 - i] , window[i + 2*n - n4]) +
585 3347600 AAC_MUL31(-saved[ 2*n + n2 + i] , window[i + 3*n - n4]);
586 }
587
2/2
✓ Branch 0 taken 6695200 times.
✓ Branch 1 taken 26598 times.
6721798 for (i = 0; i < n2; i ++) {
588 6695200 out[n4 + i] = AAC_MUL31( buf[ i] , window[i + n2 - n4]) +
589 6695200 AAC_MUL31(-saved[ n - 1 - i] , window[i + n2 + n - n4]) +
590 6695200 AAC_MUL31(-saved[ n + i] , window[i + n2 + 2*n - n4]) +
591 6695200 AAC_MUL31( saved[2*n + n - 1 - i] , window[i + n2 + 3*n - n4]);
592 }
593
2/2
✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
3374198 for (i = 0; i < n4; i ++) {
594 3347600 out[n2 + n4 + i] = AAC_MUL31( buf[ i + n2] , window[i + n - n4]) +
595 3347600 AAC_MUL31(-saved[n2 - 1 - i] , window[i + 2*n - n4]) +
596 3347600 AAC_MUL31(-saved[n + n2 + i] , window[i + 3*n - n4]);
597 }
598
599 // buffer update
600 26598 memmove(saved + n, saved, 2 * n * sizeof(*saved));
601 26598 memcpy( saved, buf, n * sizeof(*saved));
602 26598 }
603
604 63150 static void AAC_RENAME(clip_output)(AACDecContext *ac, ChannelElement *che,
605 int type, int samples)
606 {
607 #if USE_FIXED
608 /* preparation for resampler */
609
2/2
✓ Branch 0 taken 19978752 times.
✓ Branch 1 taken 19545 times.
19998297 for (int j = 0; j < samples; j++){
610 19978752 che->ch[0].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[0].output_fixed[j]*128,
611 19978752 INT32_MIN, INT32_MAX-0x8000)+0x8000;
612
5/6
✓ Branch 0 taken 9946624 times.
✓ Branch 1 taken 10032128 times.
✓ Branch 2 taken 7981568 times.
✓ Branch 3 taken 1965056 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7981568 times.
19978752 if (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1))
613 10032128 che->ch[1].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[1].output_fixed[j]*128,
614 10032128 INT32_MIN, INT32_MAX-0x8000)+0x8000;
615 }
616 #endif
617 63150 }
618
619 40 static inline void reset_all_predictors(PredictorState *ps)
620 {
621 int i;
622
2/2
✓ Branch 0 taken 26880 times.
✓ Branch 1 taken 40 times.
26920 for (i = 0; i < MAX_PREDICTORS; i++)
623 26880 reset_predict_state(&ps[i]);
624 40 }
625
626 518 static inline void reset_predictor_group(PredictorState *ps, int group_num)
627 {
628 int i;
629
2/2
✓ Branch 0 taken 11662 times.
✓ Branch 1 taken 518 times.
12180 for (i = group_num - 1; i < MAX_PREDICTORS; i += 30)
630 11662 reset_predict_state(&ps[i]);
631 518 }
632
633 /**
634 * Apply AAC-Main style frequency domain prediction.
635 */
636 7388 static void AAC_RENAME(apply_prediction)(AACDecContext *ac, SingleChannelElement *sce)
637 {
638 int sfb, k;
639
640
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 7368 times.
7388 if (!sce->ics.predictor_initialized) {
641 20 reset_all_predictors(sce->AAC_RENAME(predictor_state));
642 20 sce->ics.predictor_initialized = 1;
643 }
644
645
2/2
✓ Branch 0 taken 7368 times.
✓ Branch 1 taken 20 times.
7388 if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
646 7368 for (sfb = 0;
647
2/2
✓ Branch 0 taken 255198 times.
✓ Branch 1 taken 7368 times.
262566 sfb < ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index];
648 255198 sfb++) {
649 255198 for (k = sce->ics.swb_offset[sfb];
650
2/2
✓ Branch 0 taken 4047936 times.
✓ Branch 1 taken 255198 times.
4303134 k < sce->ics.swb_offset[sfb + 1];
651 4047936 k++) {
652 4047936 predict(&sce->AAC_RENAME(predictor_state)[k],
653 &sce->AAC_RENAME(coeffs)[k],
654
2/2
✓ Branch 0 taken 892992 times.
✓ Branch 1 taken 3154944 times.
4047936 sce->ics.predictor_present &&
655
2/2
✓ Branch 0 taken 271896 times.
✓ Branch 1 taken 621096 times.
892992 sce->ics.prediction_used[sfb]);
656 }
657 }
658
2/2
✓ Branch 0 taken 518 times.
✓ Branch 1 taken 6850 times.
7368 if (sce->ics.predictor_reset_group)
659 518 reset_predictor_group(sce->AAC_RENAME(predictor_state),
660 sce->ics.predictor_reset_group);
661 } else
662 20 reset_all_predictors(sce->AAC_RENAME(predictor_state));
663 7388 }
664
665 295 static av_cold void AAC_RENAME(aac_dsp_init)(AACDecDSP *aac_dsp)
666 {
667 #define SET(member) aac_dsp->member = AAC_RENAME(member)
668 295 SET(dequant_scalefactors);
669 295 SET(apply_mid_side_stereo);
670 295 SET(apply_intensity_stereo);
671 295 SET(apply_tns);
672 295 SET(apply_ltp);
673 295 SET(update_ltp);
674
675 295 SET(apply_prediction);
676
677 295 SET(imdct_and_windowing);
678 295 SET(imdct_and_windowing_768);
679 295 SET(imdct_and_windowing_960);
680 295 SET(imdct_and_windowing_ld);
681 295 SET(imdct_and_windowing_eld);
682
683 295 SET(apply_dependent_coupling);
684 295 SET(apply_independent_coupling);
685
686 295 SET(clip_output);
687 #undef SET
688 295 }
689