FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac/aacdec_dsp_template.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 332 335 99.1%
Functions: 26 28 92.9%
Branches: 196 204 96.1%

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 93936 static void AAC_RENAME(dequant_scalefactors)(SingleChannelElement *sce)
42 {
43 93936 IndividualChannelStream *ics = &sce->ics;
44 93936 const enum BandType *band_type = sce->band_type;
45 93936 const int *band_type_run_end = sce->band_type_run_end;
46 93936 const int *sfo = sce->sfo;
47 93936 INTFLOAT *sf = sce->AAC_RENAME(sf);
48
49 93936 int g, i, idx = 0;
50
2/2
✓ Branch 0 taken 99174 times.
✓ Branch 1 taken 93936 times.
193110 for (g = 0; g < ics->num_window_groups; g++) {
51
2/2
✓ Branch 0 taken 464655 times.
✓ Branch 1 taken 99174 times.
563829 for (i = 0; i < ics->max_sfb;) {
52 464655 int run_end = band_type_run_end[idx];
53
4/4
✓ Branch 0 taken 63440 times.
✓ Branch 1 taken 9583 times.
✓ Branch 2 taken 7825 times.
✓ Branch 3 taken 383807 times.
464655 switch (band_type[idx]) {
54 63440 case ZERO_BT:
55
2/2
✓ Branch 0 taken 537005 times.
✓ Branch 1 taken 63440 times.
600445 for (; i < run_end; i++, idx++)
56 537005 sf[idx] = FIXR(0.);
57 63440 break;
58 9583 case INTENSITY_BT: /* fallthrough */
59 case INTENSITY_BT2:
60
2/2
✓ Branch 0 taken 66207 times.
✓ Branch 1 taken 9583 times.
75790 for (; i < run_end; i++, idx++) {
61 #if USE_FIXED
62 17856 sf[idx] = 100 - sfo[idx];
63 #else
64 48351 sf[idx] = ff_aac_pow2sf_tab[-sfo[idx] + POW_SF2_ZERO];
65 #endif /* USE_FIXED */
66 }
67 9583 break;
68 7825 case NOISE_BT:
69
2/2
✓ Branch 0 taken 281615 times.
✓ Branch 1 taken 7825 times.
289440 for (; i < run_end; i++, idx++) {
70 #if USE_FIXED
71 137931 sf[idx] = -(100 + sfo[idx]);
72 #else
73 143684 sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
74 #endif /* USE_FIXED */
75 }
76 7825 break;
77 383807 default:
78
2/2
✓ Branch 0 taken 2593829 times.
✓ Branch 1 taken 383807 times.
2977636 for (; i < run_end; i++, idx++) {
79 #if USE_FIXED
80 783227 sf[idx] = -sfo[idx];
81 #else
82 1810602 sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] - 100 + POW_SF2_ZERO];
83 #endif /* USE_FIXED */
84 }
85 383807 break;
86 }
87 }
88 }
89 93936 }
90
91 /**
92 * Mid/Side stereo decoding; reference: 4.6.8.1.3.
93 */
94 27052 static void AAC_RENAME(apply_mid_side_stereo)(AACDecContext *ac, ChannelElement *cpe)
95 {
96 27052 const IndividualChannelStream *ics = &cpe->ch[0].ics;
97 27052 INTFLOAT *ch0 = cpe->ch[0].AAC_RENAME(coeffs);
98 27052 INTFLOAT *ch1 = cpe->ch[1].AAC_RENAME(coeffs);
99 27052 int g, i, group, idx = 0;
100 27052 const uint16_t *offsets = ics->swb_offset;
101
2/2
✓ Branch 0 taken 28757 times.
✓ Branch 1 taken 27052 times.
55809 for (g = 0; g < ics->num_window_groups; g++) {
102
2/2
✓ Branch 0 taken 1016649 times.
✓ Branch 1 taken 28757 times.
1045406 for (i = 0; i < ics->max_sfb; i++, idx++) {
103
2/2
✓ Branch 0 taken 798983 times.
✓ Branch 1 taken 217666 times.
1016649 if (cpe->ms_mask[idx] &&
104
1/2
✓ Branch 0 taken 798983 times.
✗ Branch 1 not taken.
798983 cpe->ch[0].band_type[idx] < NOISE_BT &&
105
2/2
✓ Branch 0 taken 796607 times.
✓ Branch 1 taken 2376 times.
798983 cpe->ch[1].band_type[idx] < NOISE_BT) {
106 #if USE_FIXED
107
2/2
✓ Branch 0 taken 256654 times.
✓ Branch 1 taken 250955 times.
507609 for (group = 0; group < ics->group_len[g]; group++) {
108 256654 ac->fdsp->butterflies_fixed(ch0 + group * 128 + offsets[i],
109 256654 ch1 + group * 128 + offsets[i],
110 256654 offsets[i+1] - offsets[i]);
111 #else
112
2/2
✓ Branch 0 taken 570140 times.
✓ Branch 1 taken 545652 times.
1115792 for (group = 0; group < ics->group_len[g]; group++) {
113 570140 ac->fdsp->butterflies_float(ch0 + group * 128 + offsets[i],
114 570140 ch1 + group * 128 + offsets[i],
115 570140 offsets[i+1] - offsets[i]);
116 #endif /* USE_FIXED */
117 }
118 }
119 }
120 28757 ch0 += ics->group_len[g] * 128;
121 28757 ch1 += ics->group_len[g] * 128;
122 }
123 27052 }
124
125 /**
126 * intensity stereo decoding; reference: 4.6.8.2.3
127 *
128 * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
129 * [1] mask is decoded from bitstream; [2] mask is all 1s;
130 * [3] reserved for scalable AAC
131 */
132 30786 static void AAC_RENAME(apply_intensity_stereo)(AACDecContext *ac,
133 ChannelElement *cpe, int ms_present)
134 {
135 30786 const IndividualChannelStream *ics = &cpe->ch[1].ics;
136 30786 SingleChannelElement *sce1 = &cpe->ch[1];
137 30786 INTFLOAT *coef0 = cpe->ch[0].AAC_RENAME(coeffs), *coef1 = cpe->ch[1].AAC_RENAME(coeffs);
138 30786 const uint16_t *offsets = ics->swb_offset;
139 30786 int g, group, i, idx = 0;
140 int c;
141 INTFLOAT scale;
142
2/2
✓ Branch 0 taken 32714 times.
✓ Branch 1 taken 30786 times.
63500 for (g = 0; g < ics->num_window_groups; g++) {
143
2/2
✓ Branch 0 taken 161018 times.
✓ Branch 1 taken 32714 times.
193732 for (i = 0; i < ics->max_sfb;) {
144
2/2
✓ Branch 0 taken 151546 times.
✓ Branch 1 taken 9472 times.
161018 if (sce1->band_type[idx] == INTENSITY_BT ||
145
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 151435 times.
161129 sce1->band_type[idx] == INTENSITY_BT2) {
146 9583 const int bt_run_end = sce1->band_type_run_end[idx];
147
2/2
✓ Branch 0 taken 66207 times.
✓ Branch 1 taken 9583 times.
75790 for (; i < bt_run_end; i++, idx++) {
148 66207 c = -1 + 2 * (sce1->band_type[idx] - 14);
149
2/2
✓ Branch 0 taken 61324 times.
✓ Branch 1 taken 4883 times.
66207 if (ms_present)
150 61324 c *= 1 - 2 * cpe->ms_mask[idx];
151 66207 scale = c * sce1->AAC_RENAME(sf)[idx];
152
2/2
✓ Branch 0 taken 66538 times.
✓ Branch 1 taken 66207 times.
132745 for (group = 0; group < ics->group_len[g]; group++)
153 #if USE_FIXED
154 17955 subband_scale(coef1 + group * 128 + offsets[i],
155 17955 coef0 + group * 128 + offsets[i],
156 scale,
157 23,
158 17955 offsets[i + 1] - offsets[i] ,ac->avctx);
159 #else
160 48583 ac->fdsp->vector_fmul_scalar(coef1 + group * 128 + offsets[i],
161 48583 coef0 + group * 128 + offsets[i],
162 scale,
163 48583 offsets[i + 1] - offsets[i]);
164 #endif /* USE_FIXED */
165 }
166 } else {
167 151435 int bt_run_end = sce1->band_type_run_end[idx];
168 151435 idx += bt_run_end - i;
169 151435 i = bt_run_end;
170 }
171 }
172 32714 coef0 += ics->group_len[g] * 128;
173 32714 coef1 += ics->group_len[g] * 128;
174 }
175 30786 }
176
177 /**
178 * Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4.6.9.3.
179 *
180 * @param decode 1 if tool is used normally, 0 if tool is used in LTP.
181 * @param coef spectral coefficients
182 */
183 6961 static void AAC_RENAME(apply_tns)(void *_coef_param, TemporalNoiseShaping *tns,
184 IndividualChannelStream *ics, int decode)
185 {
186 6961 const int mmm = FFMIN(ics->tns_max_bands, ics->max_sfb);
187 int w, filt, m, i;
188 int bottom, top, order, start, end, size, inc;
189 6961 INTFLOAT *coef_param = _coef_param;
190 INTFLOAT lpc[TNS_MAX_ORDER];
191 INTFLOAT tmp[TNS_MAX_ORDER+1];
192 6961 UINTFLOAT *coef = coef_param;
193
194
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6955 times.
6961 if(!mmm)
195 6 return;
196
197
2/2
✓ Branch 0 taken 11568 times.
✓ Branch 1 taken 6955 times.
18523 for (w = 0; w < ics->num_windows; w++) {
198 11568 bottom = ics->num_swb;
199
2/2
✓ Branch 0 taken 9407 times.
✓ Branch 1 taken 11568 times.
20975 for (filt = 0; filt < tns->n_filt[w]; filt++) {
200 9407 top = bottom;
201 9407 bottom = FFMAX(0, top - tns->length[w][filt]);
202 9407 order = tns->order[w][filt];
203
2/2
✓ Branch 0 taken 520 times.
✓ Branch 1 taken 8887 times.
9407 if (order == 0)
204 520 continue;
205
206 // tns_decode_coef
207 8887 compute_lpc_coefs(tns->AAC_RENAME(coef)[w][filt], order, lpc, 0, 0, 0);
208
209
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8881 times.
8887 start = ics->swb_offset[FFMIN(bottom, mmm)];
210
2/2
✓ Branch 0 taken 7089 times.
✓ Branch 1 taken 1798 times.
8887 end = ics->swb_offset[FFMIN( top, mmm)];
211
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8879 times.
8887 if ((size = end - start) <= 0)
212 8 continue;
213
2/2
✓ Branch 0 taken 3614 times.
✓ Branch 1 taken 5265 times.
8879 if (tns->direction[w][filt]) {
214 3614 inc = -1;
215 3614 start = end - 1;
216 } else {
217 5265 inc = 1;
218 }
219 8879 start += w * 128;
220
221
2/2
✓ Branch 0 taken 8873 times.
✓ Branch 1 taken 6 times.
8879 if (decode) {
222 // ar filter
223
2/2
✓ Branch 0 taken 2747532 times.
✓ Branch 1 taken 8873 times.
2756405 for (m = 0; m < size; m++, start += inc)
224
2/2
✓ Branch 0 taken 21302901 times.
✓ Branch 1 taken 2747532 times.
24050433 for (i = 1; i <= FFMIN(m, order); i++)
225 21302901 coef[start] -= AAC_MUL26((INTFLOAT)coef[start - i * inc], lpc[i - 1]);
226 } else {
227 // ma filter
228
2/2
✓ Branch 0 taken 3696 times.
✓ Branch 1 taken 6 times.
3702 for (m = 0; m < size; m++, start += inc) {
229 3696 tmp[0] = coef[start];
230
2/2
✓ Branch 0 taken 35416 times.
✓ Branch 1 taken 3696 times.
39112 for (i = 1; i <= FFMIN(m, order); i++)
231 35416 coef[start] += AAC_MUL26(tmp[i], lpc[i - 1]);
232
2/2
✓ Branch 0 taken 35728 times.
✓ Branch 1 taken 3696 times.
39424 for (i = order; i > 0; i--)
233 35728 tmp[i] = tmp[i - 1];
234 }
235 }
236 }
237 }
238 }
239
240 /**
241 * Apply windowing and MDCT to obtain the spectral
242 * coefficient from the predicted sample by LTP.
243 */
244 786 static inline void AAC_RENAME(windowing_and_mdct_ltp)(AACDecContext *ac,
245 INTFLOAT *out, INTFLOAT *in,
246 IndividualChannelStream *ics)
247 {
248
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);
249
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);
250
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);
251
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);
252
253
2/2
✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2 times.
786 if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) {
254 784 ac->fdsp->vector_fmul(in, in, lwindow_prev, 1024);
255 } else {
256 2 memset(in, 0, 448 * sizeof(*in));
257 2 ac->fdsp->vector_fmul(in + 448, in + 448, swindow_prev, 128);
258 }
259
1/2
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
786 if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
260 786 ac->fdsp->vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
261 } else {
262 ac->fdsp->vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
263 memset(in + 1024 + 576, 0, 448 * sizeof(*in));
264 }
265 786 ac->mdct_ltp_fn(ac->mdct_ltp, out, in, sizeof(INTFLOAT));
266 786 }
267
268 /**
269 * Apply the long term prediction
270 */
271 786 static void AAC_RENAME(apply_ltp)(AACDecContext *ac, SingleChannelElement *sce)
272 {
273 786 const LongTermPrediction *ltp = &sce->ics.ltp;
274 786 const uint16_t *offsets = sce->ics.swb_offset;
275 int i, sfb;
276
277
1/2
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
786 if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
278 786 INTFLOAT *predTime = sce->AAC_RENAME(output);
279 786 INTFLOAT *predFreq = ac->AAC_RENAME(buf_mdct);
280 786 int16_t num_samples = 2048;
281
282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
786 if (ltp->lag < 1024)
283 num_samples = ltp->lag + 1024;
284
2/2
✓ Branch 0 taken 1609728 times.
✓ Branch 1 taken 786 times.
1610514 for (i = 0; i < num_samples; i++)
285 1609728 predTime[i] = AAC_MUL30(sce->AAC_RENAME(ltp_state)[i + 2048 - ltp->lag], ltp->AAC_RENAME(coef));
286 786 memset(&predTime[i], 0, (2048 - i) * sizeof(*predTime));
287
288 786 AAC_RENAME(windowing_and_mdct_ltp)(ac, predFreq, predTime, &sce->ics);
289
290
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 780 times.
786 if (sce->tns.present)
291 6 AAC_RENAME(apply_tns)(predFreq, &sce->tns, &sce->ics, 0);
292
293
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++)
294
2/2
✓ Branch 0 taken 22868 times.
✓ Branch 1 taken 8572 times.
31440 if (ltp->used[sfb])
295
2/2
✓ Branch 0 taken 347544 times.
✓ Branch 1 taken 22868 times.
370412 for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
296 347544 sce->AAC_RENAME(coeffs)[i] += (UINTFLOAT)predFreq[i];
297 }
298 786 }
299
300 /**
301 * Update the LTP buffer for next frame
302 */
303 3568 static void AAC_RENAME(update_ltp)(AACDecContext *ac, SingleChannelElement *sce)
304 {
305 3568 IndividualChannelStream *ics = &sce->ics;
306 3568 INTFLOAT *saved = sce->AAC_RENAME(saved);
307 3568 INTFLOAT *saved_ltp = sce->AAC_RENAME(coeffs);
308
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);
309
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);
310 int i;
311
312
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3564 times.
3568 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
313 4 memcpy(saved_ltp, saved, 512 * sizeof(*saved_ltp));
314 4 memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
315 4 ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->AAC_RENAME(buf_mdct) + 960, &swindow[64], 64);
316
317
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
260 for (i = 0; i < 64; i++)
318 256 saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], swindow[63 - i]);
319
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3560 times.
3564 } else if (1 && ics->window_sequence[0] == LONG_START_SEQUENCE) {
320 4 memcpy(saved_ltp, ac->AAC_RENAME(buf_mdct) + 512, 448 * sizeof(*saved_ltp));
321 4 memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
322 4 ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->AAC_RENAME(buf_mdct) + 960, &swindow[64], 64);
323
324
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 4 times.
260 for (i = 0; i < 64; i++)
325 256 saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], swindow[63 - i]);
326 } else if (1) { // LONG_STOP or ONLY_LONG
327 3560 ac->fdsp->vector_fmul_reverse(saved_ltp, ac->AAC_RENAME(buf_mdct) + 512, &lwindow[512], 512);
328
329
2/2
✓ Branch 0 taken 1822720 times.
✓ Branch 1 taken 3560 times.
1826280 for (i = 0; i < 512; i++)
330 1822720 saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], lwindow[511 - i]);
331 }
332
333 3568 memcpy(sce->AAC_RENAME(ltp_state), sce->AAC_RENAME(ltp_state)+1024,
334 1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
335 3568 memcpy(sce->AAC_RENAME(ltp_state) + 1024, sce->AAC_RENAME(output),
336 1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
337 3568 memcpy(sce->AAC_RENAME(ltp_state) + 2048, saved_ltp,
338 1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
339 3568 }
340
341 /**
342 * Conduct IMDCT and windowing.
343 */
344 62534 static void AAC_RENAME(imdct_and_windowing)(AACDecContext *ac, SingleChannelElement *sce)
345 {
346 62534 IndividualChannelStream *ics = &sce->ics;
347 62534 INTFLOAT *in = sce->AAC_RENAME(coeffs);
348 62534 INTFLOAT *out = sce->AAC_RENAME(output);
349 62534 INTFLOAT *saved = sce->AAC_RENAME(saved);
350
2/2
✓ Branch 0 taken 40470 times.
✓ Branch 1 taken 22064 times.
62534 const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
351
2/2
✓ Branch 0 taken 40317 times.
✓ Branch 1 taken 22217 times.
62534 const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
352
2/2
✓ Branch 0 taken 40317 times.
✓ Branch 1 taken 22217 times.
62534 const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
353 62534 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
354 62534 INTFLOAT *temp = ac->AAC_RENAME(temp);
355 int i;
356
357 // imdct
358
2/2
✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 60446 times.
62534 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
359
2/2
✓ Branch 0 taken 16704 times.
✓ Branch 1 taken 2088 times.
18792 for (i = 0; i < 1024; i += 128)
360 16704 ac->mdct128_fn(ac->mdct128, buf + i, in + i, sizeof(INTFLOAT));
361 } else {
362 60446 ac->mdct1024_fn(ac->mdct1024, buf, in, sizeof(INTFLOAT));
363 }
364
365 /* window overlapping
366 * NOTE: To simplify the overlapping code, all 'meaningless' short to long
367 * and long to short transitions are considered to be short to short
368 * transitions. This leaves just two cases (long to long and short to short)
369 * with a little special sauce for EIGHT_SHORT_SEQUENCE.
370 */
371
4/4
✓ Branch 0 taken 4249 times.
✓ Branch 1 taken 58285 times.
✓ Branch 2 taken 1079 times.
✓ Branch 3 taken 3170 times.
62534 if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
372
4/4
✓ Branch 0 taken 1223 times.
✓ Branch 1 taken 58141 times.
✓ Branch 2 taken 1221 times.
✓ Branch 3 taken 2 times.
59364 (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
373 59362 ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 512);
374 } else {
375 3172 memcpy( out, saved, 448 * sizeof(*out));
376
377
2/2
✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 1084 times.
3172 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
378 2088 ac->fdsp->vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64);
379 2088 ac->fdsp->vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64);
380 2088 ac->fdsp->vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64);
381 2088 ac->fdsp->vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64);
382 2088 ac->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64);
383 2088 memcpy( out + 448 + 4*128, temp, 64 * sizeof(*out));
384 } else {
385 1084 ac->fdsp->vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64);
386 1084 memcpy( out + 576, buf + 64, 448 * sizeof(*out));
387 }
388 }
389
390 // buffer update
391
2/2
✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 60446 times.
62534 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
392 2088 memcpy( saved, temp + 64, 64 * sizeof(*saved));
393 2088 ac->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64);
394 2088 ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
395 2088 ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
396 2088 memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
397
2/2
✓ Branch 0 taken 1221 times.
✓ Branch 1 taken 59225 times.
60446 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
398 1221 memcpy( saved, buf + 512, 448 * sizeof(*saved));
399 1221 memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
400 } else { // LONG_STOP or ONLY_LONG
401 59225 memcpy( saved, buf + 512, 512 * sizeof(*saved));
402 }
403 62534 }
404
405 /**
406 * Conduct IMDCT and windowing.
407 */
408 387 static void AAC_RENAME(imdct_and_windowing_960)(AACDecContext *ac, SingleChannelElement *sce)
409 {
410 387 IndividualChannelStream *ics = &sce->ics;
411 387 INTFLOAT *in = sce->AAC_RENAME(coeffs);
412 387 INTFLOAT *out = sce->AAC_RENAME(output);
413 387 INTFLOAT *saved = sce->AAC_RENAME(saved);
414
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);
415
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);
416
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);
417 387 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
418 387 INTFLOAT *temp = ac->AAC_RENAME(temp);
419 int i;
420
421 // imdct
422
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 386 times.
387 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
423
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (i = 0; i < 8; i++)
424 8 ac->mdct120_fn(ac->mdct120, buf + i * 120, in + i * 128, sizeof(INTFLOAT));
425 } else {
426 386 ac->mdct960_fn(ac->mdct960, buf, in, sizeof(INTFLOAT));
427 }
428
429 /* window overlapping
430 * NOTE: To simplify the overlapping code, all 'meaningless' short to long
431 * and long to short transitions are considered to be short to short
432 * transitions. This leaves just two cases (long to long and short to short)
433 * with a little special sauce for EIGHT_SHORT_SEQUENCE.
434 */
435
436
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) &&
437
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)) {
438 385 ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 480);
439 } else {
440 2 memcpy( out, saved, 420 * sizeof(*out));
441
442
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
443 1 ac->fdsp->vector_fmul_window(out + 420 + 0*120, saved + 420, buf + 0*120, swindow_prev, 60);
444 1 ac->fdsp->vector_fmul_window(out + 420 + 1*120, buf + 0*120 + 60, buf + 1*120, swindow, 60);
445 1 ac->fdsp->vector_fmul_window(out + 420 + 2*120, buf + 1*120 + 60, buf + 2*120, swindow, 60);
446 1 ac->fdsp->vector_fmul_window(out + 420 + 3*120, buf + 2*120 + 60, buf + 3*120, swindow, 60);
447 1 ac->fdsp->vector_fmul_window(temp, buf + 3*120 + 60, buf + 4*120, swindow, 60);
448 1 memcpy( out + 420 + 4*120, temp, 60 * sizeof(*out));
449 } else {
450 1 ac->fdsp->vector_fmul_window(out + 420, saved + 420, buf, swindow_prev, 60);
451 1 memcpy( out + 540, buf + 60, 420 * sizeof(*out));
452 }
453 }
454
455 // buffer update
456
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 386 times.
387 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
457 1 memcpy( saved, temp + 60, 60 * sizeof(*saved));
458 1 ac->fdsp->vector_fmul_window(saved + 60, buf + 4*120 + 60, buf + 5*120, swindow, 60);
459 1 ac->fdsp->vector_fmul_window(saved + 180, buf + 5*120 + 60, buf + 6*120, swindow, 60);
460 1 ac->fdsp->vector_fmul_window(saved + 300, buf + 6*120 + 60, buf + 7*120, swindow, 60);
461 1 memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
462
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 384 times.
386 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
463 2 memcpy( saved, buf + 480, 420 * sizeof(*saved));
464 2 memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
465 } else { // LONG_STOP or ONLY_LONG
466 384 memcpy( saved, buf + 480, 480 * sizeof(*saved));
467 }
468 387 }
469 3636 static void AAC_RENAME(imdct_and_windowing_ld)(AACDecContext *ac, SingleChannelElement *sce)
470 {
471 3636 IndividualChannelStream *ics = &sce->ics;
472 3636 INTFLOAT *in = sce->AAC_RENAME(coeffs);
473 3636 INTFLOAT *out = sce->AAC_RENAME(output);
474 3636 INTFLOAT *saved = sce->AAC_RENAME(saved);
475 3636 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
476
477 // imdct
478 3636 ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
479
480 // window overlapping
481
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 3574 times.
3636 if (ics->use_kb_window[1]) {
482 // AAC LD uses a low overlap sine window instead of a KBD window
483 62 memcpy(out, saved, 192 * sizeof(*out));
484 62 ac->fdsp->vector_fmul_window(out + 192, saved + 192, buf, AAC_RENAME2(sine_128), 64);
485 62 memcpy( out + 320, buf + 64, 192 * sizeof(*out));
486 } else {
487 3574 ac->fdsp->vector_fmul_window(out, saved, buf, AAC_RENAME2(sine_512), 256);
488 }
489
490 // buffer update
491 3636 memcpy(saved, buf + 256, 256 * sizeof(*saved));
492 3636 }
493
494 26598 static void AAC_RENAME(imdct_and_windowing_eld)(AACDecContext *ac, SingleChannelElement *sce)
495 {
496 26598 UINTFLOAT *in = sce->AAC_RENAME(coeffs);
497 26598 INTFLOAT *out = sce->AAC_RENAME(output);
498 26598 INTFLOAT *saved = sce->AAC_RENAME(saved);
499 26598 INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
500 int i;
501
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;
502 26598 const int n2 = n >> 1;
503 26598 const int n4 = n >> 2;
504
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) :
505 AAC_RENAME(ff_aac_eld_window_512);
506
507 // Inverse transform, mapped to the conventional IMDCT by
508 // Chivukula, R.K.; Reznik, Y.A.; Devarajan, V.,
509 // "Efficient algorithms for MPEG-4 AAC-ELD, AAC-LD and AAC-LC filterbanks,"
510 // International Conference on Audio, Language and Image Processing, ICALIP 2008.
511 // URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4590245&isnumber=4589950
512
2/2
✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
3374198 for (i = 0; i < n2; i+=2) {
513 INTFLOAT temp;
514 3347600 temp = in[i ]; in[i ] = -in[n - 1 - i]; in[n - 1 - i] = temp;
515 3347600 temp = -in[i + 1]; in[i + 1] = in[n - 2 - i]; in[n - 2 - i] = temp;
516 }
517
518
2/2
✓ Branch 0 taken 7118 times.
✓ Branch 1 taken 19480 times.
26598 if (n == 480)
519 7118 ac->mdct480_fn(ac->mdct480, buf, in, sizeof(INTFLOAT));
520 else
521 19480 ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
522
523
2/2
✓ Branch 0 taken 6695200 times.
✓ Branch 1 taken 26598 times.
6721798 for (i = 0; i < n; i+=2) {
524 6695200 buf[i + 0] = -(UINTFLOAT)(USE_FIXED + 1)*buf[i + 0];
525 6695200 buf[i + 1] = (UINTFLOAT)(USE_FIXED + 1)*buf[i + 1];
526 }
527 // Like with the regular IMDCT at this point we still have the middle half
528 // of a transform but with even symmetry on the left and odd symmetry on
529 // the right
530
531 // window overlapping
532 // The spec says to use samples [0..511] but the reference decoder uses
533 // samples [128..639].
534
2/2
✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
3374198 for (i = n4; i < n2; i ++) {
535 3347600 out[i - n4] = AAC_MUL31( buf[ n2 - 1 - i] , window[i - n4]) +
536 3347600 AAC_MUL31( saved[ i + n2] , window[i + n - n4]) +
537 3347600 AAC_MUL31(-saved[n + n2 - 1 - i] , window[i + 2*n - n4]) +
538 3347600 AAC_MUL31(-saved[ 2*n + n2 + i] , window[i + 3*n - n4]);
539 }
540
2/2
✓ Branch 0 taken 6695200 times.
✓ Branch 1 taken 26598 times.
6721798 for (i = 0; i < n2; i ++) {
541 6695200 out[n4 + i] = AAC_MUL31( buf[ i] , window[i + n2 - n4]) +
542 6695200 AAC_MUL31(-saved[ n - 1 - i] , window[i + n2 + n - n4]) +
543 6695200 AAC_MUL31(-saved[ n + i] , window[i + n2 + 2*n - n4]) +
544 6695200 AAC_MUL31( saved[2*n + n - 1 - i] , window[i + n2 + 3*n - n4]);
545 }
546
2/2
✓ Branch 0 taken 3347600 times.
✓ Branch 1 taken 26598 times.
3374198 for (i = 0; i < n4; i ++) {
547 3347600 out[n2 + n4 + i] = AAC_MUL31( buf[ i + n2] , window[i + n - n4]) +
548 3347600 AAC_MUL31(-saved[n2 - 1 - i] , window[i + 2*n - n4]) +
549 3347600 AAC_MUL31(-saved[n + n2 + i] , window[i + 3*n - n4]);
550 }
551
552 // buffer update
553 26598 memmove(saved + n, saved, 2 * n * sizeof(*saved));
554 26598 memcpy( saved, buf, n * sizeof(*saved));
555 26598 }
556
557 63150 static void AAC_RENAME(clip_output)(AACDecContext *ac, ChannelElement *che,
558 int type, int samples)
559 {
560 #if USE_FIXED
561 /* preparation for resampler */
562
2/2
✓ Branch 0 taken 19978752 times.
✓ Branch 1 taken 19545 times.
19998297 for (int j = 0; j < samples; j++){
563 19978752 che->ch[0].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[0].output_fixed[j]*128,
564 19978752 INT32_MIN, INT32_MAX-0x8000)+0x8000;
565
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))
566 10032128 che->ch[1].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[1].output_fixed[j]*128,
567 10032128 INT32_MIN, INT32_MAX-0x8000)+0x8000;
568 }
569 #endif
570 63150 }
571
572 40 static inline void reset_all_predictors(PredictorState *ps)
573 {
574 int i;
575
2/2
✓ Branch 0 taken 26880 times.
✓ Branch 1 taken 40 times.
26920 for (i = 0; i < MAX_PREDICTORS; i++)
576 26880 reset_predict_state(&ps[i]);
577 40 }
578
579 518 static inline void reset_predictor_group(PredictorState *ps, int group_num)
580 {
581 int i;
582
2/2
✓ Branch 0 taken 11662 times.
✓ Branch 1 taken 518 times.
12180 for (i = group_num - 1; i < MAX_PREDICTORS; i += 30)
583 11662 reset_predict_state(&ps[i]);
584 518 }
585
586 /**
587 * Apply AAC-Main style frequency domain prediction.
588 */
589 7388 static void AAC_RENAME(apply_prediction)(AACDecContext *ac, SingleChannelElement *sce)
590 {
591 int sfb, k;
592
593
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 7368 times.
7388 if (!sce->ics.predictor_initialized) {
594 20 reset_all_predictors(sce->AAC_RENAME(predictor_state));
595 20 sce->ics.predictor_initialized = 1;
596 }
597
598
2/2
✓ Branch 0 taken 7368 times.
✓ Branch 1 taken 20 times.
7388 if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
599 7368 for (sfb = 0;
600
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];
601 255198 sfb++) {
602 255198 for (k = sce->ics.swb_offset[sfb];
603
2/2
✓ Branch 0 taken 4047936 times.
✓ Branch 1 taken 255198 times.
4303134 k < sce->ics.swb_offset[sfb + 1];
604 4047936 k++) {
605 4047936 predict(&sce->AAC_RENAME(predictor_state)[k],
606 &sce->AAC_RENAME(coeffs)[k],
607
2/2
✓ Branch 0 taken 892992 times.
✓ Branch 1 taken 3154944 times.
4047936 sce->ics.predictor_present &&
608
2/2
✓ Branch 0 taken 271896 times.
✓ Branch 1 taken 621096 times.
892992 sce->ics.prediction_used[sfb]);
609 }
610 }
611
2/2
✓ Branch 0 taken 518 times.
✓ Branch 1 taken 6850 times.
7368 if (sce->ics.predictor_reset_group)
612 518 reset_predictor_group(sce->AAC_RENAME(predictor_state),
613 sce->ics.predictor_reset_group);
614 } else
615 20 reset_all_predictors(sce->AAC_RENAME(predictor_state));
616 7388 }
617
618 const AACDecDSP AAC_RENAME(aac_dsp) = {
619 .init = &AAC_RENAME(init),
620
621 .dequant_scalefactors = &AAC_RENAME(dequant_scalefactors),
622 .apply_mid_side_stereo = &AAC_RENAME(apply_mid_side_stereo),
623 .apply_intensity_stereo = &AAC_RENAME(apply_intensity_stereo),
624 .apply_tns = &AAC_RENAME(apply_tns),
625 .apply_ltp = &AAC_RENAME(apply_ltp),
626 .update_ltp = &AAC_RENAME(update_ltp),
627
628 .apply_prediction = AAC_RENAME(apply_prediction),
629
630 .imdct_and_windowing = AAC_RENAME(imdct_and_windowing),
631 .imdct_and_windowing_960 = AAC_RENAME(imdct_and_windowing_960),
632 .imdct_and_windowing_ld = AAC_RENAME(imdct_and_windowing_ld),
633 .imdct_and_windowing_eld = AAC_RENAME(imdct_and_windowing_eld),
634
635 .apply_dependent_coupling = AAC_RENAME(apply_dependent_coupling),
636 .apply_independent_coupling = AAC_RENAME(apply_independent_coupling),
637
638 .clip_output = AAC_RENAME(clip_output),
639 };
640