FFmpeg
aacdec_dsp_template.c
Go to the documentation of this file.
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"
34 
35 #include "libavcodec/aactab.h"
36 
37 /**
38  * Convert integer scalefactors to the decoder's native expected
39  * scalefactor values.
40  */
42 {
43  IndividualChannelStream *ics = &sce->ics;
44  const int *sfo = sce->sfo;
45  INTFLOAT *sf = sce->AAC_RENAME(sf);
46 
47  int idx = 0;
48  for (int g = 0; g < ics->num_window_groups; g++) {
49  for (int sfb = 0; sfb < ics->max_sfb; sfb++, idx++) {
50  switch (sce->band_type[g*ics->max_sfb + sfb]) {
51  case ZERO_BT:
52  sf[idx] = FIXR(0.);
53  break;
54  case INTENSITY_BT: /* fallthrough */
55  case INTENSITY_BT2:
56 #if USE_FIXED
57  sf[idx] = 100 - (sfo[idx] + 100);
58 #else
59  sf[idx] = ff_aac_pow2sf_tab[-sfo[idx] - 100 + POW_SF2_ZERO];
60 #endif /* USE_FIXED */
61  break;
62  case NOISE_BT:
63 #if USE_FIXED
64  sf[idx] = -(100 + sfo[idx]);
65 #else
66  sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
67 #endif /* USE_FIXED */
68  break;
69  default:
70 #if USE_FIXED
71  sf[idx] = -sfo[idx] - 100;
72 #else
73  sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
74 #endif /* USE_FIXED */
75  break;
76  }
77  }
78  }
79 }
80 
81 /**
82  * Mid/Side stereo decoding; reference: 4.6.8.1.3.
83  */
85 {
86  const IndividualChannelStream *ics = &cpe->ch[0].ics;
87  INTFLOAT *ch0 = cpe->ch[0].AAC_RENAME(coeffs);
88  INTFLOAT *ch1 = cpe->ch[1].AAC_RENAME(coeffs);
89  const uint16_t *offsets = ics->swb_offset;
90  for (int g = 0; g < ics->num_window_groups; g++) {
91  for (int sfb = 0; sfb < cpe->max_sfb_ste; sfb++) {
92  const int idx = g*cpe->max_sfb_ste + sfb;
93  if (cpe->ms_mask[idx] &&
94  cpe->ch[0].band_type[idx] < NOISE_BT &&
95  cpe->ch[1].band_type[idx] < NOISE_BT) {
96  for (int group = 0; group < ics->group_len[g]; group++)
97 #if USE_FIXED
98  ac->fdsp->butterflies_fixed(ch0 + group * 128 + offsets[sfb],
99  ch1 + group * 128 + offsets[sfb],
100  offsets[sfb+1] - offsets[sfb]);
101 #else
102  ac->fdsp->butterflies_float(ch0 + group * 128 + offsets[sfb],
103  ch1 + group * 128 + offsets[sfb],
104  offsets[sfb+1] - offsets[sfb]);
105 #endif /* USE_FIXED */
106  }
107  }
108  ch0 += ics->group_len[g] * 128;
109  ch1 += ics->group_len[g] * 128;
110  }
111 }
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  */
121  ChannelElement *cpe, int ms_present)
122 {
123  const IndividualChannelStream *ics = &cpe->ch[1].ics;
124  SingleChannelElement *sce1 = &cpe->ch[1];
125  INTFLOAT *coef0 = cpe->ch[0].AAC_RENAME(coeffs), *coef1 = cpe->ch[1].AAC_RENAME(coeffs);
126  const uint16_t *offsets = ics->swb_offset;
127  int c;
128  INTFLOAT scale;
129  for (int g = 0; g < ics->num_window_groups; g++) {
130  for (int sfb = 0; sfb < ics->max_sfb; sfb++) {
131  const int idx = g*ics->max_sfb + sfb;
132  if (sce1->band_type[idx] == INTENSITY_BT ||
133  sce1->band_type[idx] == INTENSITY_BT2) {
134  c = -1 + 2 * (sce1->band_type[idx] - 14);
135  if (ms_present)
136  c *= 1 - 2 * cpe->ms_mask[idx];
137  scale = c * sce1->AAC_RENAME(sf)[idx];
138  for (int group = 0; group < ics->group_len[g]; group++)
139 #if USE_FIXED
140  subband_scale(coef1 + group * 128 + offsets[sfb],
141  coef0 + group * 128 + offsets[sfb],
142  scale,
143  23,
144  offsets[sfb + 1] - offsets[sfb], ac->avctx);
145 #else
146  ac->fdsp->vector_fmul_scalar(coef1 + group * 128 + offsets[sfb],
147  coef0 + group * 128 + offsets[sfb],
148  scale,
149  offsets[sfb + 1] - offsets[sfb]);
150 #endif /* USE_FIXED */
151  }
152  }
153  coef0 += ics->group_len[g] * 128;
154  coef1 += ics->group_len[g] * 128;
155  }
156 }
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 static void AAC_RENAME(apply_tns)(void *_coef_param, TemporalNoiseShaping *tns,
166 {
167  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  INTFLOAT *coef_param = _coef_param;
171  INTFLOAT lpc[TNS_MAX_ORDER];
173  UINTFLOAT *coef = coef_param;
174 
175  if(!mmm)
176  return;
177 
178  for (w = 0; w < ics->num_windows; w++) {
179  bottom = ics->num_swb;
180  for (filt = 0; filt < tns->n_filt[w]; filt++) {
181  top = bottom;
182  bottom = FFMAX(0, top - tns->length[w][filt]);
183  order = tns->order[w][filt];
184  if (order == 0)
185  continue;
186 
187  // tns_decode_coef
188  compute_lpc_coefs(tns->AAC_RENAME(coef)[w][filt], order, lpc, 0, 0, 0);
189 
190  start = ics->swb_offset[FFMIN(bottom, mmm)];
191  end = ics->swb_offset[FFMIN( top, mmm)];
192  if ((size = end - start) <= 0)
193  continue;
194  if (tns->direction[w][filt]) {
195  inc = -1;
196  start = end - 1;
197  } else {
198  inc = 1;
199  }
200  start += w * 128;
201 
202  if (decode) {
203  // ar filter
204  for (m = 0; m < size; m++, start += inc)
205  for (i = 1; i <= FFMIN(m, order); i++)
206  coef[start] -= AAC_MUL26((INTFLOAT)coef[start - i * inc], lpc[i - 1]);
207  } else {
208  // ma filter
209  for (m = 0; m < size; m++, start += inc) {
210  tmp[0] = coef[start];
211  for (i = 1; i <= FFMIN(m, order); i++)
212  coef[start] += AAC_MUL26(tmp[i], lpc[i - 1]);
213  for (i = order; i > 0; i--)
214  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  */
226  INTFLOAT *out, INTFLOAT *in,
228 {
229  const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
230  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
231  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
232  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
233 
234  if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) {
235  ac->fdsp->vector_fmul(in, in, lwindow_prev, 1024);
236  } else {
237  memset(in, 0, 448 * sizeof(*in));
238  ac->fdsp->vector_fmul(in + 448, in + 448, swindow_prev, 128);
239  }
240  if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
241  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  ac->mdct_ltp_fn(ac->mdct_ltp, out, in, sizeof(INTFLOAT));
247 }
248 
249 /**
250  * Apply the long term prediction
251  */
253 {
254  const LongTermPrediction *ltp = &sce->ics.ltp;
255  const uint16_t *offsets = sce->ics.swb_offset;
256  int i, sfb;
257 
258  if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
259  INTFLOAT *predTime = sce->AAC_RENAME(output);
260  INTFLOAT *predFreq = ac->AAC_RENAME(buf_mdct);
261  int16_t num_samples = 2048;
262 
263  if (ltp->lag < 1024)
264  num_samples = ltp->lag + 1024;
265  for (i = 0; i < num_samples; i++)
266  predTime[i] = AAC_MUL30(sce->AAC_RENAME(ltp_state)[i + 2048 - ltp->lag], ltp->AAC_RENAME(coef));
267  memset(&predTime[i], 0, (2048 - i) * sizeof(*predTime));
268 
269  AAC_RENAME(windowing_and_mdct_ltp)(ac, predFreq, predTime, &sce->ics);
270 
271  if (sce->tns.present)
272  AAC_RENAME(apply_tns)(predFreq, &sce->tns, &sce->ics, 0);
273 
274  for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++)
275  if (ltp->used[sfb])
276  for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
277  sce->AAC_RENAME(coeffs)[i] += (UINTFLOAT)predFreq[i];
278  }
279 }
280 
281 /**
282  * Update the LTP buffer for next frame
283  */
285 {
286  IndividualChannelStream *ics = &sce->ics;
287  INTFLOAT *saved = sce->AAC_RENAME(saved);
288  INTFLOAT *saved_ltp = sce->AAC_RENAME(coeffs);
289  const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
290  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
291  int i;
292 
293  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
294  memcpy(saved_ltp, saved, 512 * sizeof(*saved_ltp));
295  memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
296  ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->AAC_RENAME(buf_mdct) + 960, &swindow[64], 64);
297 
298  for (i = 0; i < 64; i++)
299  saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], swindow[63 - i]);
300  } else if (1 && ics->window_sequence[0] == LONG_START_SEQUENCE) {
301  memcpy(saved_ltp, ac->AAC_RENAME(buf_mdct) + 512, 448 * sizeof(*saved_ltp));
302  memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
303  ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->AAC_RENAME(buf_mdct) + 960, &swindow[64], 64);
304 
305  for (i = 0; i < 64; i++)
306  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  ac->fdsp->vector_fmul_reverse(saved_ltp, ac->AAC_RENAME(buf_mdct) + 512, &lwindow[512], 512);
309 
310  for (i = 0; i < 512; i++)
311  saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], lwindow[511 - i]);
312  }
313 
314  memcpy(sce->AAC_RENAME(ltp_state), sce->AAC_RENAME(ltp_state)+1024,
315  1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
316  memcpy(sce->AAC_RENAME(ltp_state) + 1024, sce->AAC_RENAME(output),
317  1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
318  memcpy(sce->AAC_RENAME(ltp_state) + 2048, saved_ltp,
319  1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
320 }
321 
322 /**
323  * Conduct IMDCT and windowing.
324  */
326 {
327  IndividualChannelStream *ics = &sce->ics;
328  INTFLOAT *in = sce->AAC_RENAME(coeffs);
329  INTFLOAT *out = sce->AAC_RENAME(output);
330  INTFLOAT *saved = sce->AAC_RENAME(saved);
331  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
332  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
333  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
334  INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
335  INTFLOAT *temp = ac->AAC_RENAME(temp);
336  int i;
337 
338  // imdct
339  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
340  for (i = 0; i < 1024; i += 128)
341  ac->mdct128_fn(ac->mdct128, buf + i, in + i, sizeof(INTFLOAT));
342  } else {
343  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  if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
354  ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 512);
355  } else {
356  memcpy( out, saved, 448 * sizeof(*out));
357 
358  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
359  ac->fdsp->vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64);
360  ac->fdsp->vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64);
361  ac->fdsp->vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64);
362  ac->fdsp->vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64);
363  ac->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64);
364  memcpy( out + 448 + 4*128, temp, 64 * sizeof(*out));
365  } else {
366  ac->fdsp->vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64);
367  memcpy( out + 576, buf + 64, 448 * sizeof(*out));
368  }
369  }
370 
371  // buffer update
372  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
373  memcpy( saved, temp + 64, 64 * sizeof(*saved));
374  ac->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64);
375  ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
376  ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
377  memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
378  } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
379  memcpy( saved, buf + 512, 448 * sizeof(*saved));
380  memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
381  } else { // LONG_STOP or ONLY_LONG
382  memcpy( saved, buf + 512, 512 * sizeof(*saved));
383  }
384 }
385 
386 /**
387  * Conduct IMDCT and windowing for 768-point frames.
388  */
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) &&
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  */
455 {
456  IndividualChannelStream *ics = &sce->ics;
457  INTFLOAT *in = sce->AAC_RENAME(coeffs);
458  INTFLOAT *out = sce->AAC_RENAME(output);
459  INTFLOAT *saved = sce->AAC_RENAME(saved);
460  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120);
461  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_long_960) : AAC_RENAME(sine_960);
462  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120);
463  INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
464  INTFLOAT *temp = ac->AAC_RENAME(temp);
465  int i;
466 
467  // imdct
468  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
469  for (i = 0; i < 8; i++)
470  ac->mdct120_fn(ac->mdct120, buf + i * 120, in + i * 128, sizeof(INTFLOAT));
471  } else {
472  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  if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
484  ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 480);
485  } else {
486  memcpy( out, saved, 420 * sizeof(*out));
487 
488  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
489  ac->fdsp->vector_fmul_window(out + 420 + 0*120, saved + 420, buf + 0*120, swindow_prev, 60);
490  ac->fdsp->vector_fmul_window(out + 420 + 1*120, buf + 0*120 + 60, buf + 1*120, swindow, 60);
491  ac->fdsp->vector_fmul_window(out + 420 + 2*120, buf + 1*120 + 60, buf + 2*120, swindow, 60);
492  ac->fdsp->vector_fmul_window(out + 420 + 3*120, buf + 2*120 + 60, buf + 3*120, swindow, 60);
493  ac->fdsp->vector_fmul_window(temp, buf + 3*120 + 60, buf + 4*120, swindow, 60);
494  memcpy( out + 420 + 4*120, temp, 60 * sizeof(*out));
495  } else {
496  ac->fdsp->vector_fmul_window(out + 420, saved + 420, buf, swindow_prev, 60);
497  memcpy( out + 540, buf + 60, 420 * sizeof(*out));
498  }
499  }
500 
501  // buffer update
502  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
503  memcpy( saved, temp + 60, 60 * sizeof(*saved));
504  ac->fdsp->vector_fmul_window(saved + 60, buf + 4*120 + 60, buf + 5*120, swindow, 60);
505  ac->fdsp->vector_fmul_window(saved + 180, buf + 5*120 + 60, buf + 6*120, swindow, 60);
506  ac->fdsp->vector_fmul_window(saved + 300, buf + 6*120 + 60, buf + 7*120, swindow, 60);
507  memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
508  } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
509  memcpy( saved, buf + 480, 420 * sizeof(*saved));
510  memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
511  } else { // LONG_STOP or ONLY_LONG
512  memcpy( saved, buf + 480, 480 * sizeof(*saved));
513  }
514 }
515 
517 {
518  IndividualChannelStream *ics = &sce->ics;
519  INTFLOAT *in = sce->AAC_RENAME(coeffs);
520  INTFLOAT *out = sce->AAC_RENAME(output);
521  INTFLOAT *saved = sce->AAC_RENAME(saved);
522  INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
523 
524  // imdct
525  ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
526 
527  // window overlapping
528  if (ics->use_kb_window[1]) {
529  // AAC LD uses a low overlap sine window instead of a KBD window
530  memcpy(out, saved, 192 * sizeof(*out));
531  ac->fdsp->vector_fmul_window(out + 192, saved + 192, buf, AAC_RENAME2(sine_128), 64);
532  memcpy( out + 320, buf + 64, 192 * sizeof(*out));
533  } else {
534  ac->fdsp->vector_fmul_window(out, saved, buf, AAC_RENAME2(sine_512), 256);
535  }
536 
537  // buffer update
538  memcpy(saved, buf + 256, 256 * sizeof(*saved));
539 }
540 
542 {
543  UINTFLOAT *in = sce->AAC_RENAME(coeffs);
544  INTFLOAT *out = sce->AAC_RENAME(output);
545  INTFLOAT *saved = sce->AAC_RENAME(saved);
546  INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
547  int i;
548  const int n = ac->oc[1].m4ac.frame_length_short ? 480 : 512;
549  const int n2 = n >> 1;
550  const int n4 = n >> 2;
551  const INTFLOAT *const window = n == 480 ? AAC_RENAME(ff_aac_eld_window_480) :
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  for (i = 0; i < n2; i+=2) {
560  INTFLOAT temp;
561  temp = in[i ]; in[i ] = -in[n - 1 - i]; in[n - 1 - i] = temp;
562  temp = -in[i + 1]; in[i + 1] = in[n - 2 - i]; in[n - 2 - i] = temp;
563  }
564 
565  if (n == 480)
566  ac->mdct480_fn(ac->mdct480, buf, in, sizeof(INTFLOAT));
567  else
568  ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
569 
570  for (i = 0; i < n; i+=2) {
571  buf[i + 0] = -(UINTFLOAT)(USE_FIXED + 1)*buf[i + 0];
572  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  for (i = n4; i < n2; i ++) {
582  out[i - n4] = AAC_MUL31( buf[ n2 - 1 - i] , window[i - n4]) +
583  AAC_MUL31( saved[ i + n2] , window[i + n - n4]) +
584  AAC_MUL31(-saved[n + n2 - 1 - i] , window[i + 2*n - n4]) +
585  AAC_MUL31(-saved[ 2*n + n2 + i] , window[i + 3*n - n4]);
586  }
587  for (i = 0; i < n2; i ++) {
588  out[n4 + i] = AAC_MUL31( buf[ i] , window[i + n2 - n4]) +
589  AAC_MUL31(-saved[ n - 1 - i] , window[i + n2 + n - n4]) +
590  AAC_MUL31(-saved[ n + i] , window[i + n2 + 2*n - n4]) +
591  AAC_MUL31( saved[2*n + n - 1 - i] , window[i + n2 + 3*n - n4]);
592  }
593  for (i = 0; i < n4; i ++) {
594  out[n2 + n4 + i] = AAC_MUL31( buf[ i + n2] , window[i + n - n4]) +
595  AAC_MUL31(-saved[n2 - 1 - i] , window[i + 2*n - n4]) +
596  AAC_MUL31(-saved[n + n2 + i] , window[i + 3*n - n4]);
597  }
598 
599  // buffer update
600  memmove(saved + n, saved, 2 * n * sizeof(*saved));
601  memcpy( saved, buf, n * sizeof(*saved));
602 }
603 
605  int type, int samples)
606 {
607 #if USE_FIXED
608  /* preparation for resampler */
609  for (int j = 0; j < samples; j++){
610  che->ch[0].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[0].output_fixed[j]*128,
611  INT32_MIN, INT32_MAX-0x8000)+0x8000;
612  if (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1))
613  che->ch[1].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[1].output_fixed[j]*128,
614  INT32_MIN, INT32_MAX-0x8000)+0x8000;
615  }
616 #endif
617 }
618 
619 static inline void reset_all_predictors(PredictorState *ps)
620 {
621  int i;
622  for (i = 0; i < MAX_PREDICTORS; i++)
623  reset_predict_state(&ps[i]);
624 }
625 
626 static inline void reset_predictor_group(PredictorState *ps, int group_num)
627 {
628  int i;
629  for (i = group_num - 1; i < MAX_PREDICTORS; i += 30)
630  reset_predict_state(&ps[i]);
631 }
632 
633 /**
634  * Apply AAC-Main style frequency domain prediction.
635  */
637 {
638  int sfb, k;
639 
640  if (!sce->ics.predictor_initialized) {
641  reset_all_predictors(sce->AAC_RENAME(predictor_state));
642  sce->ics.predictor_initialized = 1;
643  }
644 
645  if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
646  for (sfb = 0;
647  sfb < ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index];
648  sfb++) {
649  for (k = sce->ics.swb_offset[sfb];
650  k < sce->ics.swb_offset[sfb + 1];
651  k++) {
652  predict(&sce->AAC_RENAME(predictor_state)[k],
653  &sce->AAC_RENAME(coeffs)[k],
654  sce->ics.predictor_present &&
655  sce->ics.prediction_used[sfb]);
656  }
657  }
658  if (sce->ics.predictor_reset_group)
659  reset_predictor_group(sce->AAC_RENAME(predictor_state),
660  sce->ics.predictor_reset_group);
661  } else
662  reset_all_predictors(sce->AAC_RENAME(predictor_state));
663 }
664 
665 static av_cold void AAC_RENAME(aac_dsp_init)(AACDecDSP *aac_dsp)
666 {
667 #define SET(member) aac_dsp->member = AAC_RENAME(member)
671  SET(apply_tns);
672  SET(apply_ltp);
673  SET(update_ltp);
674 
676 
682 
685 
686  SET(clip_output);
687 #undef SET
688 }
imdct_and_windowing_eld
static void AAC_RENAME() imdct_and_windowing_eld(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec_dsp_template.c:541
imdct_and_windowing_ld
static void AAC_RENAME() imdct_and_windowing_ld(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec_dsp_template.c:516
apply_independent_coupling
static void AAC_RENAME() apply_independent_coupling(AACDecContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply independent channel coupling (applied after IMDCT).
Definition: aacdec_fixed_coupling.h:106
sine_120
static float sine_120[120]
Definition: aacdec_float.c:48
dequant_scalefactors
static void AAC_RENAME() dequant_scalefactors(SingleChannelElement *sce)
Convert integer scalefactors to the decoder's native expected scalefactor values.
Definition: aacdec_dsp_template.c:41
out
FILE * out
Definition: movenc.c:55
apply_prediction
static void AAC_RENAME() apply_prediction(AACDecContext *ac, SingleChannelElement *sce)
Apply AAC-Main style frequency domain prediction.
Definition: aacdec_dsp_template.c:636
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
LongTermPrediction::used
int8_t used[MAX_LTP_LONG_SFB]
Definition: aacdec.h:121
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
w
uint8_t w
Definition: llviddspenc.c:38
MAX_PREDICTORS
#define MAX_PREDICTORS
Definition: aac.h:85
predict
static av_always_inline void predict(PredictorState *ps, int *coef, int output_enable)
Definition: aacdec_fixed_prediction.h:77
apply_ltp
static void AAC_RENAME() apply_ltp(AACDecContext *ac, SingleChannelElement *sce)
Apply the long term prediction.
Definition: aacdec_dsp_template.c:252
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
window
static SDL_Window * window
Definition: ffplay.c:361
TYPE_CPE
@ TYPE_CPE
Definition: aac.h:41
POW_SF2_ZERO
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0);
Definition: aac.h:93
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
apply_mid_side_stereo
static void AAC_RENAME() apply_mid_side_stereo(AACDecContext *ac, ChannelElement *cpe)
Mid/Side stereo decoding; reference: 4.6.8.1.3.
Definition: aacdec_dsp_template.c:84
av_clip64
#define av_clip64
Definition: common.h:103
MAX_LTP_LONG_SFB
#define MAX_LTP_LONG_SFB
Definition: aac.h:37
ZERO_BT
@ ZERO_BT
Scalefactors and spectral data are all zero.
Definition: aac.h:67
av_cold
#define av_cold
Definition: attributes.h:90
AAC_MUL31
#define AAC_MUL31(x, y)
Definition: aac_defines.h:116
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:72
NOISE_BT
@ NOISE_BT
Spectral data are scaled white noise not coded in the bitstream.
Definition: aac.h:71
AAC_MUL30
#define AAC_MUL30(x, y)
Definition: aac_defines.h:115
offsets
static const int offsets[]
Definition: hevc_pel.c:34
g
const char * g
Definition: vf_curves.c:128
EIGHT_SHORT_SEQUENCE
@ EIGHT_SHORT_SEQUENCE
Definition: aac.h:62
INTENSITY_BT2
@ INTENSITY_BT2
Scalefactor data are intensity stereo positions (out of phase).
Definition: aac.h:72
PredictorState
Predictor State.
Definition: aac_defines.h:130
IndividualChannelStream
Individual Channel Stream.
Definition: aacdec.h:162
INTENSITY_BT
@ INTENSITY_BT
Scalefactor data are intensity stereo positions (in phase).
Definition: aac.h:73
compute_lpc_coefs
static int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order, LPC_TYPE *lpc, int lpc_stride, int fail, int normalize)
Levinson-Durbin recursion.
Definition: lpc_functions.h:54
IndividualChannelStream::use_kb_window
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sine window.
Definition: aacdec.h:165
ff_aac_eld_window_480
const float ff_aac_eld_window_480[1800]
Definition: aactab.c:2981
sine_960
static float sine_960[960]
Definition: aacdec_float.c:50
IndividualChannelStream::num_window_groups
int num_window_groups
Definition: aacdec.h:166
aactab.h
USE_FIXED
#define USE_FIXED
Definition: aacdec.c:34
TNS_MAX_ORDER
#define TNS_MAX_ORDER
Definition: aac.h:36
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AACDecDSP
DSP-specific primitives.
Definition: aacdec.h:415
reset_predict_state
static av_always_inline void reset_predict_state(PredictorState *ps)
Definition: aacdec_fixed_prediction.h:135
ff_aac_pred_sfb_max
const uint8_t ff_aac_pred_sfb_max[]
Definition: aactab.c:181
IndividualChannelStream::window_sequence
enum WindowSequence window_sequence[2]
Definition: aacdec.h:164
ONLY_LONG_SEQUENCE
@ ONLY_LONG_SEQUENCE
Definition: aac.h:60
aac_dsp_init
static av_cold void AAC_RENAME() aac_dsp_init(AACDecDSP *aac_dsp)
Definition: aacdec_dsp_template.c:665
aac_kbd_long_960
static float aac_kbd_long_960[960]
Definition: aacdec_float.c:51
size
int size
Definition: twinvq_data.h:10344
AAC_RENAME2
#define AAC_RENAME2(x)
Definition: aac_defines.h:100
subband_scale
static void subband_scale(int *dst, int *src, int scale, int offset, int len, void *log_context)
Definition: aacdec_fixed_dequant.h:57
aac_kbd_short_96
static float aac_kbd_short_96[96]
Definition: aacdec_float.c:54
SET
#define SET(member)
SingleChannelElement::band_type
enum BandType band_type[128]
band types
Definition: aacdec.h:214
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aacdec.h:210
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_aac_eld_window_512
const float ff_aac_eld_window_512[1920]
Definition: aactab.c:2014
LONG_STOP_SEQUENCE
@ LONG_STOP_SEQUENCE
Definition: aac.h:63
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aacdec.h:260
IndividualChannelStream::swb_offset
const uint16_t * swb_offset
table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular wind...
Definition: aacdec.h:170
AAC_MUL26
#define AAC_MUL26(x, y)
Definition: aac_defines.h:114
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
LongTermPrediction::lag
int16_t lag
Definition: aacdec.h:119
AAC_RENAME
#define AAC_RENAME(x)
Definition: aac_defines.h:99
TYPE_SCE
@ TYPE_SCE
Definition: aac.h:40
filt
static const int8_t filt[NUMTAPS *2]
Definition: af_earwax.c:39
UINTFLOAT
float UINTFLOAT
Definition: aac_defines.h:102
imdct_and_windowing_960
static void AAC_RENAME() imdct_and_windowing_960(AACDecContext *ac, SingleChannelElement *sce)
Conduct IMDCT and windowing.
Definition: aacdec_dsp_template.c:454
sine_96
static float sine_96[96]
Definition: aacdec_float.c:47
LONG_START_SEQUENCE
@ LONG_START_SEQUENCE
Definition: aac.h:61
sine_768
static float sine_768[768]
Definition: aacdec_float.c:49
aacdec.h
AACDecContext
main AAC decoding context
Definition: aacdec.h:449
reset_predictor_group
static void reset_predictor_group(PredictorState *ps, int group_num)
Definition: aacdec_dsp_template.c:626
apply_intensity_stereo
static void AAC_RENAME() apply_intensity_stereo(AACDecContext *ac, ChannelElement *cpe, int ms_present)
intensity stereo decoding; reference: 4.6.8.2.3
Definition: aacdec_dsp_template.c:120
LongTermPrediction
Long Term Prediction.
Definition: aacdec.h:117
lpc_functions.h
TemporalNoiseShaping
Temporal Noise Shaping.
Definition: aacdec.h:184
update_ltp
static void AAC_RENAME() update_ltp(AACDecContext *ac, SingleChannelElement *sce)
Update the LTP buffer for next frame.
Definition: aacdec_dsp_template.c:284
temp
else temp
Definition: vf_mcdeint.c:263
imdct_and_windowing
static void AAC_RENAME() imdct_and_windowing(AACDecContext *ac, SingleChannelElement *sce)
Conduct IMDCT and windowing.
Definition: aacdec_dsp_template.c:325
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
windowing_and_mdct_ltp
static void AAC_RENAME() windowing_and_mdct_ltp(AACDecContext *ac, INTFLOAT *out, INTFLOAT *in, IndividualChannelStream *ics)
Apply windowing and MDCT to obtain the spectral coefficient from the predicted sample by LTP.
Definition: aacdec_dsp_template.c:225
aac_kbd_long_768
static float aac_kbd_long_768[768]
Definition: aacdec_float.c:53
apply_dependent_coupling
static void AAC_RENAME() apply_dependent_coupling(AACDecContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply dependent channel coupling (applied before IMDCT).
Definition: aacdec_fixed_coupling.h:42
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
int32_t
int32_t
Definition: audioconvert.c:56
IndividualChannelStream::max_sfb
uint8_t max_sfb
number of scalefactor bands per group
Definition: aacdec.h:163
imdct_and_windowing_768
static void AAC_RENAME() imdct_and_windowing_768(AACDecContext *ac, SingleChannelElement *sce)
Conduct IMDCT and windowing for 768-point frames.
Definition: aacdec_dsp_template.c:389
ff_aac_pow2sf_tab
float ff_aac_pow2sf_tab[428]
IndividualChannelStream::group_len
uint8_t group_len[8]
Definition: aacdec.h:168
clip_output
static void AAC_RENAME() clip_output(AACDecContext *ac, ChannelElement *che, int type, int samples)
Definition: aacdec_dsp_template.c:604
INTFLOAT
float INTFLOAT
Definition: aac_defines.h:101
aac_kbd_short_120
static float aac_kbd_short_120[120]
Definition: aacdec_float.c:52
apply_tns
static void AAC_RENAME() apply_tns(void *_coef_param, TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode)
Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4....
Definition: aacdec_dsp_template.c:164
FIXR
#define FIXR(x)
Definition: aac_defines.h:107
reset_all_predictors
static void reset_all_predictors(PredictorState *ps)
Definition: aacdec_dsp_template.c:619