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 enum BandType *band_type = sce->band_type;
45  const int *band_type_run_end = sce->band_type_run_end;
46  const int *sfo = sce->sfo;
47  INTFLOAT *sf = sce->AAC_RENAME(sf);
48 
49  int g, i, idx = 0;
50  for (g = 0; g < ics->num_window_groups; g++) {
51  for (i = 0; i < ics->max_sfb;) {
52  int run_end = band_type_run_end[idx];
53  switch (band_type[idx]) {
54  case ZERO_BT:
55  for (; i < run_end; i++, idx++)
56  sf[idx] = FIXR(0.);
57  break;
58  case INTENSITY_BT: /* fallthrough */
59  case INTENSITY_BT2:
60  for (; i < run_end; i++, idx++) {
61 #if USE_FIXED
62  sf[idx] = 100 - sfo[idx];
63 #else
64  sf[idx] = ff_aac_pow2sf_tab[-sfo[idx] + POW_SF2_ZERO];
65 #endif /* USE_FIXED */
66  }
67  break;
68  case NOISE_BT:
69  for (; i < run_end; i++, idx++) {
70 #if USE_FIXED
71  sf[idx] = -(100 + sfo[idx]);
72 #else
73  sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
74 #endif /* USE_FIXED */
75  }
76  break;
77  default:
78  for (; i < run_end; i++, idx++) {
79 #if USE_FIXED
80  sf[idx] = -sfo[idx];
81 #else
82  sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] - 100 + POW_SF2_ZERO];
83 #endif /* USE_FIXED */
84  }
85  break;
86  }
87  }
88  }
89 }
90 
91 /**
92  * Mid/Side stereo decoding; reference: 4.6.8.1.3.
93  */
95 {
96  const IndividualChannelStream *ics = &cpe->ch[0].ics;
97  INTFLOAT *ch0 = cpe->ch[0].AAC_RENAME(coeffs);
98  INTFLOAT *ch1 = cpe->ch[1].AAC_RENAME(coeffs);
99  int g, i, group, idx = 0;
100  const uint16_t *offsets = ics->swb_offset;
101  for (g = 0; g < ics->num_window_groups; g++) {
102  for (i = 0; i < ics->max_sfb; i++, idx++) {
103  if (cpe->ms_mask[idx] &&
104  cpe->ch[0].band_type[idx] < NOISE_BT &&
105  cpe->ch[1].band_type[idx] < NOISE_BT) {
106 #if USE_FIXED
107  for (group = 0; group < ics->group_len[g]; group++) {
108  ac->fdsp->butterflies_fixed(ch0 + group * 128 + offsets[i],
109  ch1 + group * 128 + offsets[i],
110  offsets[i+1] - offsets[i]);
111 #else
112  for (group = 0; group < ics->group_len[g]; group++) {
113  ac->fdsp->butterflies_float(ch0 + group * 128 + offsets[i],
114  ch1 + group * 128 + offsets[i],
115  offsets[i+1] - offsets[i]);
116 #endif /* USE_FIXED */
117  }
118  }
119  }
120  ch0 += ics->group_len[g] * 128;
121  ch1 += ics->group_len[g] * 128;
122  }
123 }
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  */
133  ChannelElement *cpe, int ms_present)
134 {
135  const IndividualChannelStream *ics = &cpe->ch[1].ics;
136  SingleChannelElement *sce1 = &cpe->ch[1];
137  INTFLOAT *coef0 = cpe->ch[0].AAC_RENAME(coeffs), *coef1 = cpe->ch[1].AAC_RENAME(coeffs);
138  const uint16_t *offsets = ics->swb_offset;
139  int g, group, i, idx = 0;
140  int c;
141  INTFLOAT scale;
142  for (g = 0; g < ics->num_window_groups; g++) {
143  for (i = 0; i < ics->max_sfb;) {
144  if (sce1->band_type[idx] == INTENSITY_BT ||
145  sce1->band_type[idx] == INTENSITY_BT2) {
146  const int bt_run_end = sce1->band_type_run_end[idx];
147  for (; i < bt_run_end; i++, idx++) {
148  c = -1 + 2 * (sce1->band_type[idx] - 14);
149  if (ms_present)
150  c *= 1 - 2 * cpe->ms_mask[idx];
151  scale = c * sce1->AAC_RENAME(sf)[idx];
152  for (group = 0; group < ics->group_len[g]; group++)
153 #if USE_FIXED
154  subband_scale(coef1 + group * 128 + offsets[i],
155  coef0 + group * 128 + offsets[i],
156  scale,
157  23,
158  offsets[i + 1] - offsets[i] ,ac->avctx);
159 #else
160  ac->fdsp->vector_fmul_scalar(coef1 + group * 128 + offsets[i],
161  coef0 + group * 128 + offsets[i],
162  scale,
163  offsets[i + 1] - offsets[i]);
164 #endif /* USE_FIXED */
165  }
166  } else {
167  int bt_run_end = sce1->band_type_run_end[idx];
168  idx += bt_run_end - i;
169  i = bt_run_end;
170  }
171  }
172  coef0 += ics->group_len[g] * 128;
173  coef1 += ics->group_len[g] * 128;
174  }
175 }
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 static void AAC_RENAME(apply_tns)(void *_coef_param, TemporalNoiseShaping *tns,
185 {
186  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  INTFLOAT *coef_param = _coef_param;
190  INTFLOAT lpc[TNS_MAX_ORDER];
192  UINTFLOAT *coef = coef_param;
193 
194  if(!mmm)
195  return;
196 
197  for (w = 0; w < ics->num_windows; w++) {
198  bottom = ics->num_swb;
199  for (filt = 0; filt < tns->n_filt[w]; filt++) {
200  top = bottom;
201  bottom = FFMAX(0, top - tns->length[w][filt]);
202  order = tns->order[w][filt];
203  if (order == 0)
204  continue;
205 
206  // tns_decode_coef
207  compute_lpc_coefs(tns->AAC_RENAME(coef)[w][filt], order, lpc, 0, 0, 0);
208 
209  start = ics->swb_offset[FFMIN(bottom, mmm)];
210  end = ics->swb_offset[FFMIN( top, mmm)];
211  if ((size = end - start) <= 0)
212  continue;
213  if (tns->direction[w][filt]) {
214  inc = -1;
215  start = end - 1;
216  } else {
217  inc = 1;
218  }
219  start += w * 128;
220 
221  if (decode) {
222  // ar filter
223  for (m = 0; m < size; m++, start += inc)
224  for (i = 1; i <= FFMIN(m, order); i++)
225  coef[start] -= AAC_MUL26((INTFLOAT)coef[start - i * inc], lpc[i - 1]);
226  } else {
227  // ma filter
228  for (m = 0; m < size; m++, start += inc) {
229  tmp[0] = coef[start];
230  for (i = 1; i <= FFMIN(m, order); i++)
231  coef[start] += AAC_MUL26(tmp[i], lpc[i - 1]);
232  for (i = order; i > 0; i--)
233  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  */
245  INTFLOAT *out, INTFLOAT *in,
247 {
248  const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
249  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
250  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
251  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
252 
253  if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) {
254  ac->fdsp->vector_fmul(in, in, lwindow_prev, 1024);
255  } else {
256  memset(in, 0, 448 * sizeof(*in));
257  ac->fdsp->vector_fmul(in + 448, in + 448, swindow_prev, 128);
258  }
259  if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
260  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  ac->mdct_ltp_fn(ac->mdct_ltp, out, in, sizeof(INTFLOAT));
266 }
267 
268 /**
269  * Apply the long term prediction
270  */
272 {
273  const LongTermPrediction *ltp = &sce->ics.ltp;
274  const uint16_t *offsets = sce->ics.swb_offset;
275  int i, sfb;
276 
277  if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
278  INTFLOAT *predTime = sce->AAC_RENAME(output);
279  INTFLOAT *predFreq = ac->AAC_RENAME(buf_mdct);
280  int16_t num_samples = 2048;
281 
282  if (ltp->lag < 1024)
283  num_samples = ltp->lag + 1024;
284  for (i = 0; i < num_samples; i++)
285  predTime[i] = AAC_MUL30(sce->AAC_RENAME(ltp_state)[i + 2048 - ltp->lag], ltp->AAC_RENAME(coef));
286  memset(&predTime[i], 0, (2048 - i) * sizeof(*predTime));
287 
288  AAC_RENAME(windowing_and_mdct_ltp)(ac, predFreq, predTime, &sce->ics);
289 
290  if (sce->tns.present)
291  AAC_RENAME(apply_tns)(predFreq, &sce->tns, &sce->ics, 0);
292 
293  for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++)
294  if (ltp->used[sfb])
295  for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
296  sce->AAC_RENAME(coeffs)[i] += (UINTFLOAT)predFreq[i];
297  }
298 }
299 
300 /**
301  * Update the LTP buffer for next frame
302  */
304 {
305  IndividualChannelStream *ics = &sce->ics;
306  INTFLOAT *saved = sce->AAC_RENAME(saved);
307  INTFLOAT *saved_ltp = sce->AAC_RENAME(coeffs);
308  const INTFLOAT *lwindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
309  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
310  int i;
311 
312  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
313  memcpy(saved_ltp, saved, 512 * sizeof(*saved_ltp));
314  memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
315  ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->AAC_RENAME(buf_mdct) + 960, &swindow[64], 64);
316 
317  for (i = 0; i < 64; i++)
318  saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], swindow[63 - i]);
319  } else if (1 && ics->window_sequence[0] == LONG_START_SEQUENCE) {
320  memcpy(saved_ltp, ac->AAC_RENAME(buf_mdct) + 512, 448 * sizeof(*saved_ltp));
321  memset(saved_ltp + 576, 0, 448 * sizeof(*saved_ltp));
322  ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->AAC_RENAME(buf_mdct) + 960, &swindow[64], 64);
323 
324  for (i = 0; i < 64; i++)
325  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  ac->fdsp->vector_fmul_reverse(saved_ltp, ac->AAC_RENAME(buf_mdct) + 512, &lwindow[512], 512);
328 
329  for (i = 0; i < 512; i++)
330  saved_ltp[i + 512] = AAC_MUL31(ac->AAC_RENAME(buf_mdct)[1023 - i], lwindow[511 - i]);
331  }
332 
333  memcpy(sce->AAC_RENAME(ltp_state), sce->AAC_RENAME(ltp_state)+1024,
334  1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
335  memcpy(sce->AAC_RENAME(ltp_state) + 1024, sce->AAC_RENAME(output),
336  1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
337  memcpy(sce->AAC_RENAME(ltp_state) + 2048, saved_ltp,
338  1024 * sizeof(*sce->AAC_RENAME(ltp_state)));
339 }
340 
341 /**
342  * Conduct IMDCT and windowing.
343  */
345 {
346  IndividualChannelStream *ics = &sce->ics;
347  INTFLOAT *in = sce->AAC_RENAME(coeffs);
348  INTFLOAT *out = sce->AAC_RENAME(output);
349  INTFLOAT *saved = sce->AAC_RENAME(saved);
350  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
351  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_long_1024) : AAC_RENAME2(sine_1024);
352  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME2(aac_kbd_short_128) : AAC_RENAME2(sine_128);
353  INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
354  INTFLOAT *temp = ac->AAC_RENAME(temp);
355  int i;
356 
357  // imdct
358  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
359  for (i = 0; i < 1024; i += 128)
360  ac->mdct128_fn(ac->mdct128, buf + i, in + i, sizeof(INTFLOAT));
361  } else {
362  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  if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
373  ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 512);
374  } else {
375  memcpy( out, saved, 448 * sizeof(*out));
376 
377  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
378  ac->fdsp->vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64);
379  ac->fdsp->vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64);
380  ac->fdsp->vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64);
381  ac->fdsp->vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64);
382  ac->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64);
383  memcpy( out + 448 + 4*128, temp, 64 * sizeof(*out));
384  } else {
385  ac->fdsp->vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64);
386  memcpy( out + 576, buf + 64, 448 * sizeof(*out));
387  }
388  }
389 
390  // buffer update
391  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
392  memcpy( saved, temp + 64, 64 * sizeof(*saved));
393  ac->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64);
394  ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
395  ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
396  memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
397  } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
398  memcpy( saved, buf + 512, 448 * sizeof(*saved));
399  memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(*saved));
400  } else { // LONG_STOP or ONLY_LONG
401  memcpy( saved, buf + 512, 512 * sizeof(*saved));
402  }
403 }
404 
405 /**
406  * Conduct IMDCT and windowing.
407  */
409 {
410  IndividualChannelStream *ics = &sce->ics;
411  INTFLOAT *in = sce->AAC_RENAME(coeffs);
412  INTFLOAT *out = sce->AAC_RENAME(output);
413  INTFLOAT *saved = sce->AAC_RENAME(saved);
414  const INTFLOAT *swindow = ics->use_kb_window[0] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120);
415  const INTFLOAT *lwindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_long_960) : AAC_RENAME(sine_960);
416  const INTFLOAT *swindow_prev = ics->use_kb_window[1] ? AAC_RENAME(aac_kbd_short_120) : AAC_RENAME(sine_120);
417  INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
418  INTFLOAT *temp = ac->AAC_RENAME(temp);
419  int i;
420 
421  // imdct
422  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
423  for (i = 0; i < 8; i++)
424  ac->mdct120_fn(ac->mdct120, buf + i * 120, in + i * 128, sizeof(INTFLOAT));
425  } else {
426  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  if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
438  ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 480);
439  } else {
440  memcpy( out, saved, 420 * sizeof(*out));
441 
442  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
443  ac->fdsp->vector_fmul_window(out + 420 + 0*120, saved + 420, buf + 0*120, swindow_prev, 60);
444  ac->fdsp->vector_fmul_window(out + 420 + 1*120, buf + 0*120 + 60, buf + 1*120, swindow, 60);
445  ac->fdsp->vector_fmul_window(out + 420 + 2*120, buf + 1*120 + 60, buf + 2*120, swindow, 60);
446  ac->fdsp->vector_fmul_window(out + 420 + 3*120, buf + 2*120 + 60, buf + 3*120, swindow, 60);
447  ac->fdsp->vector_fmul_window(temp, buf + 3*120 + 60, buf + 4*120, swindow, 60);
448  memcpy( out + 420 + 4*120, temp, 60 * sizeof(*out));
449  } else {
450  ac->fdsp->vector_fmul_window(out + 420, saved + 420, buf, swindow_prev, 60);
451  memcpy( out + 540, buf + 60, 420 * sizeof(*out));
452  }
453  }
454 
455  // buffer update
456  if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
457  memcpy( saved, temp + 60, 60 * sizeof(*saved));
458  ac->fdsp->vector_fmul_window(saved + 60, buf + 4*120 + 60, buf + 5*120, swindow, 60);
459  ac->fdsp->vector_fmul_window(saved + 180, buf + 5*120 + 60, buf + 6*120, swindow, 60);
460  ac->fdsp->vector_fmul_window(saved + 300, buf + 6*120 + 60, buf + 7*120, swindow, 60);
461  memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
462  } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
463  memcpy( saved, buf + 480, 420 * sizeof(*saved));
464  memcpy( saved + 420, buf + 7*120 + 60, 60 * sizeof(*saved));
465  } else { // LONG_STOP or ONLY_LONG
466  memcpy( saved, buf + 480, 480 * sizeof(*saved));
467  }
468 }
470 {
471  IndividualChannelStream *ics = &sce->ics;
472  INTFLOAT *in = sce->AAC_RENAME(coeffs);
473  INTFLOAT *out = sce->AAC_RENAME(output);
474  INTFLOAT *saved = sce->AAC_RENAME(saved);
475  INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
476 
477  // imdct
478  ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
479 
480  // window overlapping
481  if (ics->use_kb_window[1]) {
482  // AAC LD uses a low overlap sine window instead of a KBD window
483  memcpy(out, saved, 192 * sizeof(*out));
484  ac->fdsp->vector_fmul_window(out + 192, saved + 192, buf, AAC_RENAME2(sine_128), 64);
485  memcpy( out + 320, buf + 64, 192 * sizeof(*out));
486  } else {
487  ac->fdsp->vector_fmul_window(out, saved, buf, AAC_RENAME2(sine_512), 256);
488  }
489 
490  // buffer update
491  memcpy(saved, buf + 256, 256 * sizeof(*saved));
492 }
493 
495 {
496  UINTFLOAT *in = sce->AAC_RENAME(coeffs);
497  INTFLOAT *out = sce->AAC_RENAME(output);
498  INTFLOAT *saved = sce->AAC_RENAME(saved);
499  INTFLOAT *buf = ac->AAC_RENAME(buf_mdct);
500  int i;
501  const int n = ac->oc[1].m4ac.frame_length_short ? 480 : 512;
502  const int n2 = n >> 1;
503  const int n4 = n >> 2;
504  const INTFLOAT *const window = n == 480 ? AAC_RENAME(ff_aac_eld_window_480) :
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  for (i = 0; i < n2; i+=2) {
513  INTFLOAT temp;
514  temp = in[i ]; in[i ] = -in[n - 1 - i]; in[n - 1 - i] = temp;
515  temp = -in[i + 1]; in[i + 1] = in[n - 2 - i]; in[n - 2 - i] = temp;
516  }
517 
518  if (n == 480)
519  ac->mdct480_fn(ac->mdct480, buf, in, sizeof(INTFLOAT));
520  else
521  ac->mdct512_fn(ac->mdct512, buf, in, sizeof(INTFLOAT));
522 
523  for (i = 0; i < n; i+=2) {
524  buf[i + 0] = -(UINTFLOAT)(USE_FIXED + 1)*buf[i + 0];
525  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  for (i = n4; i < n2; i ++) {
535  out[i - n4] = AAC_MUL31( buf[ n2 - 1 - i] , window[i - n4]) +
536  AAC_MUL31( saved[ i + n2] , window[i + n - n4]) +
537  AAC_MUL31(-saved[n + n2 - 1 - i] , window[i + 2*n - n4]) +
538  AAC_MUL31(-saved[ 2*n + n2 + i] , window[i + 3*n - n4]);
539  }
540  for (i = 0; i < n2; i ++) {
541  out[n4 + i] = AAC_MUL31( buf[ i] , window[i + n2 - n4]) +
542  AAC_MUL31(-saved[ n - 1 - i] , window[i + n2 + n - n4]) +
543  AAC_MUL31(-saved[ n + i] , window[i + n2 + 2*n - n4]) +
544  AAC_MUL31( saved[2*n + n - 1 - i] , window[i + n2 + 3*n - n4]);
545  }
546  for (i = 0; i < n4; i ++) {
547  out[n2 + n4 + i] = AAC_MUL31( buf[ i + n2] , window[i + n - n4]) +
548  AAC_MUL31(-saved[n2 - 1 - i] , window[i + 2*n - n4]) +
549  AAC_MUL31(-saved[n + n2 + i] , window[i + 3*n - n4]);
550  }
551 
552  // buffer update
553  memmove(saved + n, saved, 2 * n * sizeof(*saved));
554  memcpy( saved, buf, n * sizeof(*saved));
555 }
556 
558  int type, int samples)
559 {
560 #if USE_FIXED
561  /* preparation for resampler */
562  for (int j = 0; j < samples; j++){
563  che->ch[0].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[0].output_fixed[j]*128,
564  INT32_MIN, INT32_MAX-0x8000)+0x8000;
565  if (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1))
566  che->ch[1].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[1].output_fixed[j]*128,
567  INT32_MIN, INT32_MAX-0x8000)+0x8000;
568  }
569 #endif
570 }
571 
572 static inline void reset_all_predictors(PredictorState *ps)
573 {
574  int i;
575  for (i = 0; i < MAX_PREDICTORS; i++)
576  reset_predict_state(&ps[i]);
577 }
578 
579 static inline void reset_predictor_group(PredictorState *ps, int group_num)
580 {
581  int i;
582  for (i = group_num - 1; i < MAX_PREDICTORS; i += 30)
583  reset_predict_state(&ps[i]);
584 }
585 
586 /**
587  * Apply AAC-Main style frequency domain prediction.
588  */
590 {
591  int sfb, k;
592 
593  if (!sce->ics.predictor_initialized) {
594  reset_all_predictors(sce->AAC_RENAME(predictor_state));
595  sce->ics.predictor_initialized = 1;
596  }
597 
598  if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
599  for (sfb = 0;
600  sfb < ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index];
601  sfb++) {
602  for (k = sce->ics.swb_offset[sfb];
603  k < sce->ics.swb_offset[sfb + 1];
604  k++) {
605  predict(&sce->AAC_RENAME(predictor_state)[k],
606  &sce->AAC_RENAME(coeffs)[k],
607  sce->ics.predictor_present &&
608  sce->ics.prediction_used[sfb]);
609  }
610  }
611  if (sce->ics.predictor_reset_group)
612  reset_predictor_group(sce->AAC_RENAME(predictor_state),
613  sce->ics.predictor_reset_group);
614  } else
615  reset_all_predictors(sce->AAC_RENAME(predictor_state));
616 }
617 
618 const AACDecDSP AAC_RENAME(aac_dsp) = {
619  .init = &AAC_RENAME(init),
620 
627 
629 
634 
637 
639 };
imdct_and_windowing_eld
static void AAC_RENAME() imdct_and_windowing_eld(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec_dsp_template.c:494
imdct_and_windowing_ld
static void AAC_RENAME() imdct_and_windowing_ld(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec_dsp_template.c:469
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
AACDecDSP::apply_intensity_stereo
void(* apply_intensity_stereo)(AACDecContext *ac, ChannelElement *cpe, int ms_present)
Definition: aacdec.h:224
sine_120
static float sine_120[120]
Definition: aacdec_float.c:47
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:589
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:92
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
AACDecDSP::apply_tns
void(* apply_tns)(void *_coef_param, TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode)
Definition: aacdec.h:227
apply_ltp
static void AAC_RENAME() apply_ltp(AACDecContext *ac, SingleChannelElement *sce)
Apply the long term prediction.
Definition: aacdec_dsp_template.c:271
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AACDecDSP::apply_prediction
void(* apply_prediction)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:233
window
static SDL_Window * window
Definition: ffplay.c:361
TYPE_CPE
@ TYPE_CPE
Definition: aac.h:41
AAC_RENAME
const AACDecDSP AAC_RENAME(aac_dsp)
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:94
av_clip64
#define av_clip64
Definition: common.h:102
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
AACDecDSP::dequant_scalefactors
void(* dequant_scalefactors)(SingleChannelElement *sce)
Definition: aacdec.h:221
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
AACDecDSP::apply_mid_side_stereo
void(* apply_mid_side_stereo)(AACDecContext *ac, ChannelElement *cpe)
Definition: aacdec.h:223
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
AACDecDSP::imdct_and_windowing_ld
void(* imdct_and_windowing_ld)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:244
IndividualChannelStream
Individual Channel Stream.
Definition: aacdec.h:98
AACDecDSP::init
int(* init)(AACDecContext *ac)
Definition: aacdec.h:219
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:101
ff_aac_eld_window_480
const float ff_aac_eld_window_480[1800]
Definition: aactab.c:2475
sine_960
static float sine_960[960]
Definition: aacdec_float.c:48
IndividualChannelStream::num_window_groups
int num_window_groups
Definition: aacdec.h:102
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
SingleChannelElement::band_type_run_end
int band_type_run_end[120]
band type run end points
Definition: aacdec.h:149
AACDecDSP
DSP-specific primitives.
Definition: aacdec.h:218
AACDecDSP::update_ltp
void(* update_ltp)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:231
reset_predict_state
static av_always_inline void reset_predict_state(PredictorState *ps)
Definition: aacdec_fixed_prediction.h:135
AACDecDSP::apply_independent_coupling
void(* apply_independent_coupling)(AACDecContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Definition: aacdec.h:238
ff_aac_pred_sfb_max
const uint8_t ff_aac_pred_sfb_max[]
Definition: aactab.c:173
IndividualChannelStream::window_sequence
enum WindowSequence window_sequence[2]
Definition: aacdec.h:100
AACDecDSP::clip_output
void(* clip_output)(AACDecContext *ac, ChannelElement *che, int type, int samples)
Definition: aacdec.h:247
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
AACDecDSP::apply_dependent_coupling
void(* apply_dependent_coupling)(AACDecContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Definition: aacdec.h:235
ONLY_LONG_SEQUENCE
@ ONLY_LONG_SEQUENCE
Definition: aac.h:60
BandType
BandType
Definition: aac.h:66
AACDecDSP::imdct_and_windowing
void(* imdct_and_windowing)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:242
aac_kbd_long_960
static float aac_kbd_long_960[960]
Definition: aacdec_float.c:49
size
int size
Definition: twinvq_data.h:10344
aac_dsp
const AACDecDSP aac_dsp
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
SingleChannelElement::band_type
enum BandType band_type[128]
band types
Definition: aacdec.h:148
AACDecDSP::apply_ltp
void(* apply_ltp)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:230
AACDecDSP::imdct_and_windowing_960
void(* imdct_and_windowing_960)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:243
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aacdec.h:145
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:1508
LONG_STOP_SEQUENCE
@ LONG_STOP_SEQUENCE
Definition: aac.h:63
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aacdec.h:169
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:105
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:90
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:408
AACDecDSP::imdct_and_windowing_eld
void(* imdct_and_windowing_eld)(AACDecContext *ac, SingleChannelElement *sce)
Definition: aacdec.h:245
LONG_START_SEQUENCE
@ LONG_START_SEQUENCE
Definition: aac.h:61
aacdec.h
AACDecContext
main AAC decoding context
Definition: aacdec.h:253
reset_predictor_group
static void reset_predictor_group(PredictorState *ps, int group_num)
Definition: aacdec_dsp_template.c:579
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:132
LongTermPrediction
Long Term Prediction.
Definition: aacdec.h:88
lpc_functions.h
TemporalNoiseShaping
Temporal Noise Shaping.
Definition: aacdec.h:119
update_ltp
static void AAC_RENAME() update_ltp(AACDecContext *ac, SingleChannelElement *sce)
Update the LTP buffer for next frame.
Definition: aacdec_dsp_template.c:303
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:344
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:244
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:99
ff_aac_pow2sf_tab
float ff_aac_pow2sf_tab[428]
IndividualChannelStream::group_len
uint8_t group_len[8]
Definition: aacdec.h:103
clip_output
static void AAC_RENAME() clip_output(AACDecContext *ac, ChannelElement *che, int type, int samples)
Definition: aacdec_dsp_template.c:557
INTFLOAT
float INTFLOAT
Definition: aac_defines.h:101
aac_kbd_short_120
static float aac_kbd_short_120[120]
Definition: aacdec_float.c:50
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:183
FIXR
#define FIXR(x)
Definition: aac_defines.h:107
reset_all_predictors
static void reset_all_predictors(PredictorState *ps)
Definition: aacdec_dsp_template.c:572