FFmpeg
aacsbr_template.c
Go to the documentation of this file.
1 /*
2  * AAC Spectral Band Replication decoding functions
3  * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
4  * Copyright (c) 2009-2010 Alex Converse <alex.converse@gmail.com>
5  *
6  * Fixed point code
7  * Copyright (c) 2013
8  * MIPS Technologies, Inc., California.
9  *
10  * This file is part of FFmpeg.
11  *
12  * FFmpeg is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * FFmpeg is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with FFmpeg; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 /**
28  * @file
29  * AAC Spectral Band Replication decoding functions
30  * @author Robert Swain ( rob opendot cl )
31  * @author Stanislav Ocovaj ( stanislav.ocovaj@imgtec.com )
32  * @author Zoran Basaric ( zoran.basaric@imgtec.com )
33  */
34 
35 #include "aac/aacdec.h"
36 #include "aac/aacdec_tab.h"
37 #include "avcodec.h"
38 #include "libavutil/qsort.h"
39 #include "libavutil/mem.h"
40 
41 typedef struct ExtChannelElement {
46 
48 {
49  return &((ExtChannelElement*)ch)->sbr;
50 }
51 
53 {
55 }
56 
57 /** Places SBR in pure upsampling mode. */
59  sbr->start = 0;
60  sbr->ready_for_dequant = 0;
61  // Init defults used in pure upsampling mode
62  sbr->kx[1] = 32; //Typo in spec, kx' inits to 32
63  sbr->m[1] = 0;
64  // Reset values for first SBR header
65  sbr->data[0].e_a[1] = sbr->data[1].e_a[1] = -1;
66  memset(&sbr->spectrum_params, -1, sizeof(SpectrumParameters));
67 }
68 
70  ChannelElement **che, int id_aac)
71 {
73  ExtChannelElement *ext = av_mallocz(sizeof(*ext));
74  int ret;
75  float scale;
76 
77  if (!ext)
78  return AVERROR(ENOMEM);
79  *che = &ext->ch;
80  sbr = &ext->sbr;
81  ext->ch.ch[0].AAC_RENAME(predictor_state) = ext->predictor_state[0];
82  ext->ch.ch[1].AAC_RENAME(predictor_state) = ext->predictor_state[1];
83 
84  sbr->kx[0] = sbr->kx[1];
85  sbr->id_aac = id_aac;
86  sbr_turnoff(sbr);
89  /* SBR requires samples to be scaled to +/-32768.0 to work correctly.
90  * mdct scale factors are adjusted to scale up from +/-1.0 at analysis
91  * and scale back down at synthesis. */
92 
93  scale = USE_FIXED ? 1 : 1.0 / (64 * 32768);
94  ret = av_tx_init(&sbr->mdct, &sbr->mdct_fn,
96  1, 64, &scale, 0);
97  if (ret < 0)
98  return ret;
99 
100  scale = USE_FIXED ? -1.0 : -2.0 * 32768;
101  ret = av_tx_init(&sbr->mdct_ana, &sbr->mdct_ana_fn,
103  1, 64, &scale, 0);
104  if (ret < 0)
105  return ret;
106 
107  AAC_RENAME(ff_ps_ctx_init)(&sbr->ps);
108  AAC_RENAME(ff_sbrdsp_init)(&sbr->dsp);
109  aacsbr_func_ptr_init(&sbr->c);
110 
111  return 0;
112 }
113 
115 {
116  SpectralBandReplication *sbr = get_sbr(che);
117  av_tx_uninit(&sbr->mdct);
118  av_tx_uninit(&sbr->mdct_ana);
119 }
120 
121 static int qsort_comparison_function_int16(const void *a, const void *b)
122 {
123  return *(const int16_t *)a - *(const int16_t *)b;
124 }
125 
126 static inline int in_table_int16(const int16_t *table, int last_el, int16_t needle)
127 {
128  int i;
129  for (i = 0; i <= last_el; i++)
130  if (table[i] == needle)
131  return 1;
132  return 0;
133 }
134 
135 /// Limiter Frequency Band Table (14496-3 sp04 p198)
137 {
138  int k;
139  if (sbr->bs_limiter_bands > 0) {
140  static const INTFLOAT bands_warped[3] = { Q23(1.32715174233856803909f), //2^(0.49/1.2)
141  Q23(1.18509277094158210129f), //2^(0.49/2)
142  Q23(1.11987160404675912501f) }; //2^(0.49/3)
143  const INTFLOAT lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1];
144  int16_t patch_borders[7];
145  uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim;
146 
147  patch_borders[0] = sbr->kx[1];
148  for (k = 1; k <= sbr->num_patches; k++)
149  patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1];
150 
151  memcpy(sbr->f_tablelim, sbr->f_tablelow,
152  (sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0]));
153  if (sbr->num_patches > 1)
154  memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1,
155  (sbr->num_patches - 1) * sizeof(patch_borders[0]));
156 
157  AV_QSORT(sbr->f_tablelim, sbr->num_patches + sbr->n[0],
158  uint16_t,
160 
161  sbr->n_lim = sbr->n[0] + sbr->num_patches - 1;
162  while (out < sbr->f_tablelim + sbr->n_lim) {
163 #if USE_FIXED
164  if ((*in << 23) >= *out * lim_bands_per_octave_warped) {
165 #else
166  if (*in >= *out * lim_bands_per_octave_warped) {
167 #endif /* USE_FIXED */
168  *++out = *in++;
169  } else if (*in == *out ||
170  !in_table_int16(patch_borders, sbr->num_patches, *in)) {
171  in++;
172  sbr->n_lim--;
173  } else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) {
174  *out = *in++;
175  sbr->n_lim--;
176  } else {
177  *++out = *in++;
178  }
179  }
180  } else {
181  sbr->f_tablelim[0] = sbr->f_tablelow[0];
182  sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]];
183  sbr->n_lim = 1;
184  }
185 }
186 
188 {
189  unsigned int cnt = get_bits_count(gb);
190  uint8_t bs_header_extra_1;
191  uint8_t bs_header_extra_2;
192  int old_bs_limiter_bands = sbr->bs_limiter_bands;
193  SpectrumParameters old_spectrum_params;
194 
195  sbr->start = 1;
196  sbr->ready_for_dequant = 0;
197 
198  // Save last spectrum parameters variables to compare to new ones
199  memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters));
200 
201  sbr->bs_amp_res_header = get_bits1(gb);
202  sbr->spectrum_params.bs_start_freq = get_bits(gb, 4);
203  sbr->spectrum_params.bs_stop_freq = get_bits(gb, 4);
204  sbr->spectrum_params.bs_xover_band = get_bits(gb, 3);
205  skip_bits(gb, 2); // bs_reserved
206 
207  bs_header_extra_1 = get_bits1(gb);
208  bs_header_extra_2 = get_bits1(gb);
209 
210  if (bs_header_extra_1) {
211  sbr->spectrum_params.bs_freq_scale = get_bits(gb, 2);
214  } else {
218  }
219 
220  // Check if spectrum parameters changed
221  if (memcmp(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters)))
222  sbr->reset = 1;
223 
224  if (bs_header_extra_2) {
225  sbr->bs_limiter_bands = get_bits(gb, 2);
226  sbr->bs_limiter_gains = get_bits(gb, 2);
227  sbr->bs_interpol_freq = get_bits1(gb);
228  sbr->bs_smoothing_mode = get_bits1(gb);
229  } else {
230  sbr->bs_limiter_bands = 2;
231  sbr->bs_limiter_gains = 2;
232  sbr->bs_interpol_freq = 1;
233  sbr->bs_smoothing_mode = 1;
234  }
235 
236  if (sbr->bs_limiter_bands != old_bs_limiter_bands && !sbr->reset)
237  sbr_make_f_tablelim(sbr);
238 
239  return get_bits_count(gb) - cnt;
240 }
241 
242 static int array_min_int16(const int16_t *array, int nel)
243 {
244  int i, min = array[0];
245  for (i = 1; i < nel; i++)
246  min = FFMIN(array[i], min);
247  return min;
248 }
249 
250 static int check_n_master(AVCodecContext *avctx, int n_master, int bs_xover_band)
251 {
252  // Requirements (14496-3 sp04 p205)
253  if (n_master <= 0) {
254  av_log(avctx, AV_LOG_ERROR, "Invalid n_master: %d\n", n_master);
255  return -1;
256  }
257  if (bs_xover_band >= n_master) {
258  av_log(avctx, AV_LOG_ERROR,
259  "Invalid bitstream, crossover band index beyond array bounds: %d\n",
260  bs_xover_band);
261  return -1;
262  }
263  return 0;
264 }
265 
266 /// Master Frequency Band Table (14496-3 sp04 p194)
268  SpectrumParameters *spectrum)
269 {
270  unsigned int temp, max_qmf_subbands = 0;
271  unsigned int start_min, stop_min;
272  int k;
273  const int8_t *sbr_offset_ptr;
274  int16_t stop_dk[13];
275 
276  switch (sbr->sample_rate) {
277  case 16000:
278  sbr_offset_ptr = sbr_offset[0];
279  break;
280  case 22050:
281  sbr_offset_ptr = sbr_offset[1];
282  break;
283  case 24000:
284  sbr_offset_ptr = sbr_offset[2];
285  break;
286  case 32000:
287  sbr_offset_ptr = sbr_offset[3];
288  break;
289  case 44100: case 48000: case 64000:
290  sbr_offset_ptr = sbr_offset[4];
291  break;
292  case 88200: case 96000: case 128000: case 176400: case 192000:
293  sbr_offset_ptr = sbr_offset[5];
294  break;
295  default:
297  "Unsupported sample rate for SBR: %d\n", sbr->sample_rate);
298  return -1;
299  }
300 
301  if (sbr->sample_rate < 32000) {
302  temp = 3000;
303  } else if (sbr->sample_rate < 64000) {
304  temp = 4000;
305  } else
306  temp = 5000;
307 
308  start_min = ((temp << 7) + (sbr->sample_rate >> 1)) / sbr->sample_rate;
309  stop_min = ((temp << 8) + (sbr->sample_rate >> 1)) / sbr->sample_rate;
310 
311  sbr->k[0] = start_min + sbr_offset_ptr[spectrum->bs_start_freq];
312 
313  if (spectrum->bs_stop_freq < 14) {
314  sbr->k[2] = stop_min;
315  make_bands(stop_dk, stop_min, 64, 13);
316  AV_QSORT(stop_dk, 13, int16_t, qsort_comparison_function_int16);
317  for (k = 0; k < spectrum->bs_stop_freq; k++)
318  sbr->k[2] += stop_dk[k];
319  } else if (spectrum->bs_stop_freq == 14) {
320  sbr->k[2] = 2*sbr->k[0];
321  } else if (spectrum->bs_stop_freq == 15) {
322  sbr->k[2] = 3*sbr->k[0];
323  } else {
325  "Invalid bs_stop_freq: %d\n", spectrum->bs_stop_freq);
326  return -1;
327  }
328  sbr->k[2] = FFMIN(64, sbr->k[2]);
329 
330  // Requirements (14496-3 sp04 p205)
331  if (sbr->sample_rate <= 32000) {
332  max_qmf_subbands = 48;
333  } else if (sbr->sample_rate == 44100) {
334  max_qmf_subbands = 35;
335  } else if (sbr->sample_rate >= 48000)
336  max_qmf_subbands = 32;
337  else
338  av_assert0(0);
339 
340  if (sbr->k[2] - sbr->k[0] > max_qmf_subbands) {
342  "Invalid bitstream, too many QMF subbands: %d\n", sbr->k[2] - sbr->k[0]);
343  return -1;
344  }
345 
346  if (!spectrum->bs_freq_scale) {
347  int dk, k2diff;
348 
349  dk = spectrum->bs_alter_scale + 1;
350  sbr->n_master = ((sbr->k[2] - sbr->k[0] + (dk&2)) >> dk) << 1;
352  return -1;
353 
354  for (k = 1; k <= sbr->n_master; k++)
355  sbr->f_master[k] = dk;
356 
357  k2diff = sbr->k[2] - sbr->k[0] - sbr->n_master * dk;
358  if (k2diff < 0) {
359  sbr->f_master[1]--;
360  sbr->f_master[2]-= (k2diff < -1);
361  } else if (k2diff) {
362  sbr->f_master[sbr->n_master]++;
363  }
364 
365  sbr->f_master[0] = sbr->k[0];
366  for (k = 1; k <= sbr->n_master; k++)
367  sbr->f_master[k] += sbr->f_master[k - 1];
368 
369  } else {
370  int half_bands = 7 - spectrum->bs_freq_scale; // bs_freq_scale = {1,2,3}
371  int two_regions, num_bands_0;
372  int vdk0_max, vdk1_min;
373  int16_t vk0[49];
374 #if USE_FIXED
375  int tmp, nz = 0;
376 #endif /* USE_FIXED */
377 
378  if (49 * sbr->k[2] > 110 * sbr->k[0]) {
379  two_regions = 1;
380  sbr->k[1] = 2 * sbr->k[0];
381  } else {
382  two_regions = 0;
383  sbr->k[1] = sbr->k[2];
384  }
385 
386 #if USE_FIXED
387  tmp = (sbr->k[1] << 23) / sbr->k[0];
388  while (tmp < 0x40000000) {
389  tmp <<= 1;
390  nz++;
391  }
392  tmp = fixed_log(tmp - 0x80000000);
393  tmp = (int)(((int64_t)tmp * CONST_RECIP_LN2 + 0x20000000) >> 30);
394  tmp = (((tmp + 0x80) >> 8) + ((8 - nz) << 23)) * half_bands;
395  num_bands_0 = ((tmp + 0x400000) >> 23) * 2;
396 #else
397  num_bands_0 = lrintf(half_bands * log2f(sbr->k[1] / (float)sbr->k[0])) * 2;
398 #endif /* USE_FIXED */
399 
400  if (num_bands_0 <= 0) { // Requirements (14496-3 sp04 p205)
401  av_log(ac->avctx, AV_LOG_ERROR, "Invalid num_bands_0: %d\n", num_bands_0);
402  return -1;
403  }
404 
405  vk0[0] = 0;
406 
407  make_bands(vk0+1, sbr->k[0], sbr->k[1], num_bands_0);
408 
409  AV_QSORT(vk0 + 1, num_bands_0, int16_t, qsort_comparison_function_int16);
410  vdk0_max = vk0[num_bands_0];
411 
412  vk0[0] = sbr->k[0];
413  for (k = 1; k <= num_bands_0; k++) {
414  if (vk0[k] <= 0) { // Requirements (14496-3 sp04 p205)
415  av_log(ac->avctx, AV_LOG_ERROR, "Invalid vDk0[%d]: %d\n", k, vk0[k]);
416  return -1;
417  }
418  vk0[k] += vk0[k-1];
419  }
420 
421  if (two_regions) {
422  int16_t vk1[49];
423 #if USE_FIXED
424  int num_bands_1;
425 
426  tmp = (sbr->k[2] << 23) / sbr->k[1];
427  nz = 0;
428  while (tmp < 0x40000000) {
429  tmp <<= 1;
430  nz++;
431  }
432  tmp = fixed_log(tmp - 0x80000000);
433  tmp = (int)(((int64_t)tmp * CONST_RECIP_LN2 + 0x20000000) >> 30);
434  tmp = (((tmp + 0x80) >> 8) + ((8 - nz) << 23)) * half_bands;
435  if (spectrum->bs_alter_scale)
436  tmp = (int)(((int64_t)tmp * CONST_076923 + 0x40000000) >> 31);
437  num_bands_1 = ((tmp + 0x400000) >> 23) * 2;
438 #else
439  float invwarp = spectrum->bs_alter_scale ? 0.76923076923076923077f
440  : 1.0f; // bs_alter_scale = {0,1}
441  int num_bands_1 = lrintf(half_bands * invwarp *
442  log2f(sbr->k[2] / (float)sbr->k[1])) * 2;
443 #endif /* USE_FIXED */
444  make_bands(vk1+1, sbr->k[1], sbr->k[2], num_bands_1);
445 
446  vdk1_min = array_min_int16(vk1 + 1, num_bands_1);
447 
448  if (vdk1_min < vdk0_max) {
449  int change;
450  AV_QSORT(vk1 + 1, num_bands_1, int16_t, qsort_comparison_function_int16);
451  change = FFMIN(vdk0_max - vk1[1], (vk1[num_bands_1] - vk1[1]) >> 1);
452  vk1[1] += change;
453  vk1[num_bands_1] -= change;
454  }
455 
456  AV_QSORT(vk1 + 1, num_bands_1, int16_t, qsort_comparison_function_int16);
457 
458  vk1[0] = sbr->k[1];
459  for (k = 1; k <= num_bands_1; k++) {
460  if (vk1[k] <= 0) { // Requirements (14496-3 sp04 p205)
461  av_log(ac->avctx, AV_LOG_ERROR, "Invalid vDk1[%d]: %d\n", k, vk1[k]);
462  return -1;
463  }
464  vk1[k] += vk1[k-1];
465  }
466 
467  sbr->n_master = num_bands_0 + num_bands_1;
469  return -1;
470  memcpy(&sbr->f_master[0], vk0,
471  (num_bands_0 + 1) * sizeof(sbr->f_master[0]));
472  memcpy(&sbr->f_master[num_bands_0 + 1], vk1 + 1,
473  num_bands_1 * sizeof(sbr->f_master[0]));
474 
475  } else {
476  sbr->n_master = num_bands_0;
478  return -1;
479  memcpy(sbr->f_master, vk0, (num_bands_0 + 1) * sizeof(sbr->f_master[0]));
480  }
481  }
482 
483  return 0;
484 }
485 
486 /// High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46)
488 {
489  int i, k, last_k = -1, last_msb = -1, sb = 0;
490  int msb = sbr->k[0];
491  int usb = sbr->kx[1];
492  int goal_sb = ((1000 << 11) + (sbr->sample_rate >> 1)) / sbr->sample_rate;
493 
494  sbr->num_patches = 0;
495 
496  if (goal_sb < sbr->kx[1] + sbr->m[1]) {
497  for (k = 0; sbr->f_master[k] < goal_sb; k++) ;
498  } else
499  k = sbr->n_master;
500 
501  do {
502  int odd = 0;
503  if (k == last_k && msb == last_msb) {
504  av_log(ac->avctx, AV_LOG_ERROR, "patch construction failed\n");
505  return AVERROR_INVALIDDATA;
506  }
507  last_k = k;
508  last_msb = msb;
509  for (i = k; i == k || sb > (sbr->k[0] - 1 + msb - odd); i--) {
510  sb = sbr->f_master[i];
511  odd = (sb + sbr->k[0]) & 1;
512  }
513 
514  // Requirements (14496-3 sp04 p205) sets the maximum number of patches to 5.
515  // After this check the final number of patches can still be six which is
516  // illegal however the Coding Technologies decoder check stream has a final
517  // count of 6 patches
518  if (sbr->num_patches > 5) {
519  av_log(ac->avctx, AV_LOG_ERROR, "Too many patches: %d\n", sbr->num_patches);
520  return -1;
521  }
522 
523  sbr->patch_num_subbands[sbr->num_patches] = FFMAX(sb - usb, 0);
524  sbr->patch_start_subband[sbr->num_patches] = sbr->k[0] - odd - sbr->patch_num_subbands[sbr->num_patches];
525 
526  if (sbr->patch_num_subbands[sbr->num_patches] > 0) {
527  usb = sb;
528  msb = sb;
529  sbr->num_patches++;
530  } else
531  msb = sbr->kx[1];
532 
533  if (sbr->f_master[k] - sb < 3)
534  k = sbr->n_master;
535  } while (sb != sbr->kx[1] + sbr->m[1]);
536 
537  if (sbr->num_patches > 1 &&
538  sbr->patch_num_subbands[sbr->num_patches - 1] < 3)
539  sbr->num_patches--;
540 
541  return 0;
542 }
543 
544 /// Derived Frequency Band Tables (14496-3 sp04 p197)
546 {
547  int k, temp;
548 #if USE_FIXED
549  int nz = 0;
550 #endif /* USE_FIXED */
551 
552  sbr->n[1] = sbr->n_master - sbr->spectrum_params.bs_xover_band;
553  sbr->n[0] = (sbr->n[1] + 1) >> 1;
554 
555  memcpy(sbr->f_tablehigh, &sbr->f_master[sbr->spectrum_params.bs_xover_band],
556  (sbr->n[1] + 1) * sizeof(sbr->f_master[0]));
557  sbr->m[1] = sbr->f_tablehigh[sbr->n[1]] - sbr->f_tablehigh[0];
558  sbr->kx[1] = sbr->f_tablehigh[0];
559 
560  // Requirements (14496-3 sp04 p205)
561  if (sbr->kx[1] + sbr->m[1] > 64) {
563  "Stop frequency border too high: %d\n", sbr->kx[1] + sbr->m[1]);
564  return -1;
565  }
566  if (sbr->kx[1] > 32) {
567  av_log(ac->avctx, AV_LOG_ERROR, "Start frequency border too high: %d\n", sbr->kx[1]);
568  return -1;
569  }
570 
571  sbr->f_tablelow[0] = sbr->f_tablehigh[0];
572  temp = sbr->n[1] & 1;
573  for (k = 1; k <= sbr->n[0]; k++)
574  sbr->f_tablelow[k] = sbr->f_tablehigh[2 * k - temp];
575 #if USE_FIXED
576  temp = (sbr->k[2] << 23) / sbr->kx[1];
577  while (temp < 0x40000000) {
578  temp <<= 1;
579  nz++;
580  }
581  temp = fixed_log(temp - 0x80000000);
582  temp = (int)(((int64_t)temp * CONST_RECIP_LN2 + 0x20000000) >> 30);
583  temp = (((temp + 0x80) >> 8) + ((8 - nz) << 23)) * sbr->spectrum_params.bs_noise_bands;
584 
585  sbr->n_q = (temp + 0x400000) >> 23;
586  if (sbr->n_q < 1)
587  sbr->n_q = 1;
588 #else
590  log2f(sbr->k[2] / (float)sbr->kx[1]))); // 0 <= bs_noise_bands <= 3
591 #endif /* USE_FIXED */
592 
593  if (sbr->n_q > 5) {
594  av_log(ac->avctx, AV_LOG_ERROR, "Too many noise floor scale factors: %d\n", sbr->n_q);
595  return -1;
596  }
597 
598  sbr->f_tablenoise[0] = sbr->f_tablelow[0];
599  temp = 0;
600  for (k = 1; k <= sbr->n_q; k++) {
601  temp += (sbr->n[0] - temp) / (sbr->n_q + 1 - k);
602  sbr->f_tablenoise[k] = sbr->f_tablelow[temp];
603  }
604 
605  if (sbr_hf_calc_npatches(ac, sbr) < 0)
606  return -1;
607 
608  sbr_make_f_tablelim(sbr);
609 
610  sbr->data[0].f_indexnoise = 0;
611  sbr->data[1].f_indexnoise = 0;
612 
613  return 0;
614 }
615 
616 static av_always_inline void get_bits1_vector(GetBitContext *gb, uint8_t *vec,
617  int elements)
618 {
619  int i;
620  for (i = 0; i < elements; i++) {
621  vec[i] = get_bits1(gb);
622  }
623 }
624 
625 /** ceil(log2(index+1)) */
626 static const int8_t ceil_log2[] = {
627  0, 1, 2, 2, 3, 3,
628 };
629 
631  GetBitContext *gb, SBRData *ch_data)
632 {
633  int i;
634  int bs_pointer = 0;
635  // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots
636  int abs_bord_trail = 16;
637  int num_rel_lead, num_rel_trail;
638  unsigned bs_num_env_old = ch_data->bs_num_env;
639  int bs_frame_class, bs_num_env;
640 
641  ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env];
642  ch_data->bs_amp_res = sbr->bs_amp_res_header;
643  ch_data->t_env_num_env_old = ch_data->t_env[bs_num_env_old];
644 
645  switch (bs_frame_class = get_bits(gb, 2)) {
646  case FIXFIX:
647  bs_num_env = 1 << get_bits(gb, 2);
648  if (bs_num_env > 4) {
650  "Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\n",
651  bs_num_env);
652  return -1;
653  }
654  ch_data->bs_num_env = bs_num_env;
655  num_rel_lead = ch_data->bs_num_env - 1;
656  if (ch_data->bs_num_env == 1)
657  ch_data->bs_amp_res = 0;
658 
659 
660  ch_data->t_env[0] = 0;
661  ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
662 
663  abs_bord_trail = (abs_bord_trail + (ch_data->bs_num_env >> 1)) /
664  ch_data->bs_num_env;
665  for (i = 0; i < num_rel_lead; i++)
666  ch_data->t_env[i + 1] = ch_data->t_env[i] + abs_bord_trail;
667 
668  ch_data->bs_freq_res[1] = get_bits1(gb);
669  for (i = 1; i < ch_data->bs_num_env; i++)
670  ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1];
671  break;
672  case FIXVAR:
673  abs_bord_trail += get_bits(gb, 2);
674  num_rel_trail = get_bits(gb, 2);
675  ch_data->bs_num_env = num_rel_trail + 1;
676  ch_data->t_env[0] = 0;
677  ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
678 
679  for (i = 0; i < num_rel_trail; i++)
680  ch_data->t_env[ch_data->bs_num_env - 1 - i] =
681  ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2;
682 
683  bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
684 
685  for (i = 0; i < ch_data->bs_num_env; i++)
686  ch_data->bs_freq_res[ch_data->bs_num_env - i] = get_bits1(gb);
687  break;
688  case VARFIX:
689  ch_data->t_env[0] = get_bits(gb, 2);
690  num_rel_lead = get_bits(gb, 2);
691  ch_data->bs_num_env = num_rel_lead + 1;
692  ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
693 
694  for (i = 0; i < num_rel_lead; i++)
695  ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2;
696 
697  bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
698 
699  get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env);
700  break;
701  case VARVAR:
702  ch_data->t_env[0] = get_bits(gb, 2);
703  abs_bord_trail += get_bits(gb, 2);
704  num_rel_lead = get_bits(gb, 2);
705  num_rel_trail = get_bits(gb, 2);
706  bs_num_env = num_rel_lead + num_rel_trail + 1;
707 
708  if (bs_num_env > 5) {
710  "Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\n",
711  bs_num_env);
712  return -1;
713  }
714  ch_data->bs_num_env = bs_num_env;
715 
716  ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
717 
718  for (i = 0; i < num_rel_lead; i++)
719  ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2;
720  for (i = 0; i < num_rel_trail; i++)
721  ch_data->t_env[ch_data->bs_num_env - 1 - i] =
722  ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2;
723 
724  bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
725 
726  get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env);
727  break;
728  }
729  ch_data->bs_frame_class = bs_frame_class;
730 
731  av_assert0(bs_pointer >= 0);
732  if (bs_pointer > ch_data->bs_num_env + 1) {
734  "Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\n",
735  bs_pointer);
736  return -1;
737  }
738 
739  for (i = 1; i <= ch_data->bs_num_env; i++) {
740  if (ch_data->t_env[i-1] >= ch_data->t_env[i]) {
741  av_log(ac->avctx, AV_LOG_ERROR, "Not strictly monotone time borders\n");
742  return -1;
743  }
744  }
745 
746  ch_data->bs_num_noise = (ch_data->bs_num_env > 1) + 1;
747 
748  ch_data->t_q[0] = ch_data->t_env[0];
749  ch_data->t_q[ch_data->bs_num_noise] = ch_data->t_env[ch_data->bs_num_env];
750  if (ch_data->bs_num_noise > 1) {
751  int idx;
752  if (ch_data->bs_frame_class == FIXFIX) {
753  idx = ch_data->bs_num_env >> 1;
754  } else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
755  idx = ch_data->bs_num_env - FFMAX(bs_pointer - 1, 1);
756  } else { // VARFIX
757  if (!bs_pointer)
758  idx = 1;
759  else if (bs_pointer == 1)
760  idx = ch_data->bs_num_env - 1;
761  else // bs_pointer > 1
762  idx = bs_pointer - 1;
763  }
764  ch_data->t_q[1] = ch_data->t_env[idx];
765  }
766 
767  ch_data->e_a[0] = -(ch_data->e_a[1] != bs_num_env_old); // l_APrev
768  ch_data->e_a[1] = -1;
769  if ((ch_data->bs_frame_class & 1) && bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0
770  ch_data->e_a[1] = ch_data->bs_num_env + 1 - bs_pointer;
771  } else if ((ch_data->bs_frame_class == 2) && (bs_pointer > 1)) // VARFIX and bs_pointer > 1
772  ch_data->e_a[1] = bs_pointer - 1;
773 
774  return 0;
775 }
776 
777 static void copy_sbr_grid(SBRData *dst, const SBRData *src) {
778  //These variables are saved from the previous frame rather than copied
779  dst->bs_freq_res[0] = dst->bs_freq_res[dst->bs_num_env];
780  dst->t_env_num_env_old = dst->t_env[dst->bs_num_env];
781  dst->e_a[0] = -(dst->e_a[1] != dst->bs_num_env);
782 
783  //These variables are read from the bitstream and therefore copied
784  memcpy(dst->bs_freq_res+1, src->bs_freq_res+1, sizeof(dst->bs_freq_res)-sizeof(*dst->bs_freq_res));
785  memcpy(dst->t_env, src->t_env, sizeof(dst->t_env));
786  memcpy(dst->t_q, src->t_q, sizeof(dst->t_q));
787  dst->bs_num_env = src->bs_num_env;
788  dst->bs_amp_res = src->bs_amp_res;
789  dst->bs_num_noise = src->bs_num_noise;
790  dst->bs_frame_class = src->bs_frame_class;
791  dst->e_a[1] = src->e_a[1];
792 }
793 
794 /// Read how the envelope and noise floor data is delta coded
796  SBRData *ch_data)
797 {
798  get_bits1_vector(gb, ch_data->bs_df_env, ch_data->bs_num_env);
799  get_bits1_vector(gb, ch_data->bs_df_noise, ch_data->bs_num_noise);
800 }
801 
802 /// Read inverse filtering data
804  SBRData *ch_data)
805 {
806  int i;
807 
808  memcpy(ch_data->bs_invf_mode[1], ch_data->bs_invf_mode[0], 5 * sizeof(uint8_t));
809  for (i = 0; i < sbr->n_q; i++)
810  ch_data->bs_invf_mode[0][i] = get_bits(gb, 2);
811 }
812 
814  SBRData *ch_data, int ch)
815 {
816  int bits;
817  int i, j, k;
818  const VLCElem *t_huff, *f_huff;
819  const int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
820  const int odd = sbr->n[1] & 1;
821 
822  if (sbr->bs_coupling && ch) {
823  if (ch_data->bs_amp_res) {
824  bits = 5;
827  } else {
828  bits = 6;
831  }
832  } else {
833  if (ch_data->bs_amp_res) {
834  bits = 6;
837  } else {
838  bits = 7;
841  }
842  }
843 
844  for (i = 0; i < ch_data->bs_num_env; i++) {
845  if (ch_data->bs_df_env[i]) {
846  // bs_freq_res[0] == bs_freq_res[bs_num_env] from prev frame
847  if (ch_data->bs_freq_res[i + 1] == ch_data->bs_freq_res[i]) {
848  for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
849  ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][j] + delta * get_vlc2(gb, t_huff, 9, 3);
850  if (ch_data->env_facs_q[i + 1][j] > 127U) {
851  av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
852  return AVERROR_INVALIDDATA;
853  }
854  }
855  } else if (ch_data->bs_freq_res[i + 1]) {
856  for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
857  k = (j + odd) >> 1; // find k such that f_tablelow[k] <= f_tablehigh[j] < f_tablelow[k + 1]
858  ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * get_vlc2(gb, t_huff, 9, 3);
859  if (ch_data->env_facs_q[i + 1][j] > 127U) {
860  av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
861  return AVERROR_INVALIDDATA;
862  }
863  }
864  } else {
865  for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
866  k = j ? 2*j - odd : 0; // find k such that f_tablehigh[k] == f_tablelow[j]
867  ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * get_vlc2(gb, t_huff, 9, 3);
868  if (ch_data->env_facs_q[i + 1][j] > 127U) {
869  av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
870  return AVERROR_INVALIDDATA;
871  }
872  }
873  }
874  } else {
875  ch_data->env_facs_q[i + 1][0] = delta * get_bits(gb, bits); // bs_env_start_value_balance
876  for (j = 1; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
877  ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i + 1][j - 1] + delta * get_vlc2(gb, f_huff, 9, 3);
878  if (ch_data->env_facs_q[i + 1][j] > 127U) {
879  av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
880  return AVERROR_INVALIDDATA;
881  }
882  }
883  }
884  }
885 
886  //assign 0th elements of env_facs_q from last elements
887  memcpy(ch_data->env_facs_q[0], ch_data->env_facs_q[ch_data->bs_num_env],
888  sizeof(ch_data->env_facs_q[0]));
889 
890  return 0;
891 }
892 
894  SBRData *ch_data, int ch)
895 {
896  int i, j;
897  const VLCElem *t_huff, *f_huff;
898  int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
899 
900  if (sbr->bs_coupling && ch) {
903  } else {
906  }
907 
908  for (i = 0; i < ch_data->bs_num_noise; i++) {
909  if (ch_data->bs_df_noise[i]) {
910  for (j = 0; j < sbr->n_q; j++) {
911  ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i][j] + delta * get_vlc2(gb, t_huff, 9, 2);
912  if (ch_data->noise_facs_q[i + 1][j] > 30U) {
913  av_log(ac->avctx, AV_LOG_ERROR, "noise_facs_q %d is invalid\n", ch_data->noise_facs_q[i + 1][j]);
914  return AVERROR_INVALIDDATA;
915  }
916  }
917  } else {
918  ch_data->noise_facs_q[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level
919  for (j = 1; j < sbr->n_q; j++) {
920  ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i + 1][j - 1] + delta * get_vlc2(gb, f_huff, 9, 3);
921  if (ch_data->noise_facs_q[i + 1][j] > 30U) {
922  av_log(ac->avctx, AV_LOG_ERROR, "noise_facs_q %d is invalid\n", ch_data->noise_facs_q[i + 1][j]);
923  return AVERROR_INVALIDDATA;
924  }
925  }
926  }
927  }
928 
929  //assign 0th elements of noise_facs_q from last elements
930  memcpy(ch_data->noise_facs_q[0], ch_data->noise_facs_q[ch_data->bs_num_noise],
931  sizeof(ch_data->noise_facs_q[0]));
932  return 0;
933 }
934 
936  GetBitContext *gb,
937  int bs_extension_id, int *num_bits_left)
938 {
939  switch (bs_extension_id) {
940  case EXTENSION_ID_PS:
941  if (!ac->oc[1].m4ac.ps) {
942  av_log(ac->avctx, AV_LOG_ERROR, "Parametric Stereo signaled to be not-present but was found in the bitstream.\n");
943  skip_bits_long(gb, *num_bits_left); // bs_fill_bits
944  *num_bits_left = 0;
945  } else {
946  *num_bits_left -= ff_ps_read_data(ac->avctx, gb, &sbr->ps.common, *num_bits_left);
948  // ensure the warning is not printed if PS extension is present
949  ac->warned_he_aac_mono = 1;
950  }
951  break;
952  default:
953  // some files contain 0-padding
954  if (bs_extension_id || *num_bits_left > 16 || show_bits(gb, *num_bits_left))
955  avpriv_request_sample(ac->avctx, "Reserved SBR extensions");
956  skip_bits_long(gb, *num_bits_left); // bs_fill_bits
957  *num_bits_left = 0;
958  break;
959  }
960 }
961 
964  GetBitContext *gb)
965 {
966  int ret;
967 
968  if (get_bits1(gb)) // bs_data_extra
969  skip_bits(gb, 4); // bs_reserved
970 
971  if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]))
972  return -1;
973  read_sbr_dtdf(sbr, gb, &sbr->data[0]);
974  read_sbr_invf(sbr, gb, &sbr->data[0]);
975  if((ret = read_sbr_envelope(ac, sbr, gb, &sbr->data[0], 0)) < 0)
976  return ret;
977  if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[0], 0)) < 0)
978  return ret;
979 
980  if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb)))
981  get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]);
982 
983  return 0;
984 }
985 
988  GetBitContext *gb)
989 {
990  int ret;
991 
992  if (get_bits1(gb)) // bs_data_extra
993  skip_bits(gb, 8); // bs_reserved
994 
995  if ((sbr->bs_coupling = get_bits1(gb))) {
996  if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]))
997  return -1;
998  copy_sbr_grid(&sbr->data[1], &sbr->data[0]);
999  read_sbr_dtdf(sbr, gb, &sbr->data[0]);
1000  read_sbr_dtdf(sbr, gb, &sbr->data[1]);
1001  read_sbr_invf(sbr, gb, &sbr->data[0]);
1002  memcpy(sbr->data[1].bs_invf_mode[1], sbr->data[1].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0]));
1003  memcpy(sbr->data[1].bs_invf_mode[0], sbr->data[0].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0]));
1004  if((ret = read_sbr_envelope(ac, sbr, gb, &sbr->data[0], 0)) < 0)
1005  return ret;
1006  if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[0], 0)) < 0)
1007  return ret;
1008  if((ret = read_sbr_envelope(ac, sbr, gb, &sbr->data[1], 1)) < 0)
1009  return ret;
1010  if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[1], 1)) < 0)
1011  return ret;
1012  } else {
1013  if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]) ||
1014  read_sbr_grid(ac, sbr, gb, &sbr->data[1]))
1015  return -1;
1016  read_sbr_dtdf(sbr, gb, &sbr->data[0]);
1017  read_sbr_dtdf(sbr, gb, &sbr->data[1]);
1018  read_sbr_invf(sbr, gb, &sbr->data[0]);
1019  read_sbr_invf(sbr, gb, &sbr->data[1]);
1020  if((ret = read_sbr_envelope(ac, sbr, gb, &sbr->data[0], 0)) < 0)
1021  return ret;
1022  if((ret = read_sbr_envelope(ac, sbr, gb, &sbr->data[1], 1)) < 0)
1023  return ret;
1024  if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[0], 0)) < 0)
1025  return ret;
1026  if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[1], 1)) < 0)
1027  return ret;
1028  }
1029 
1030  if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb)))
1031  get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]);
1032  if ((sbr->data[1].bs_add_harmonic_flag = get_bits1(gb)))
1033  get_bits1_vector(gb, sbr->data[1].bs_add_harmonic, sbr->n[1]);
1034 
1035  return 0;
1036 }
1037 
1039  GetBitContext *gb, int id_aac)
1040 {
1041  unsigned int cnt = get_bits_count(gb);
1042 
1043  sbr->id_aac = id_aac;
1044  sbr->ready_for_dequant = 1;
1045 
1046  if (id_aac == TYPE_SCE || id_aac == TYPE_CCE) {
1047  if (read_sbr_single_channel_element(ac, sbr, gb)) {
1048  sbr_turnoff(sbr);
1049  return get_bits_count(gb) - cnt;
1050  }
1051  } else if (id_aac == TYPE_CPE) {
1052  if (read_sbr_channel_pair_element(ac, sbr, gb)) {
1053  sbr_turnoff(sbr);
1054  return get_bits_count(gb) - cnt;
1055  }
1056  } else {
1057  av_log(ac->avctx, AV_LOG_ERROR,
1058  "Invalid bitstream - cannot apply SBR to element type %d\n", id_aac);
1059  sbr_turnoff(sbr);
1060  return get_bits_count(gb) - cnt;
1061  }
1062  if (get_bits1(gb)) { // bs_extended_data
1063  int num_bits_left = get_bits(gb, 4); // bs_extension_size
1064  if (num_bits_left == 15)
1065  num_bits_left += get_bits(gb, 8); // bs_esc_count
1066 
1067  num_bits_left <<= 3;
1068  while (num_bits_left > 7) {
1069  num_bits_left -= 2;
1070  read_sbr_extension(ac, sbr, gb, get_bits(gb, 2), &num_bits_left); // bs_extension_id
1071  }
1072  if (num_bits_left < 0) {
1073  av_log(ac->avctx, AV_LOG_ERROR, "SBR Extension over read.\n");
1074  }
1075  if (num_bits_left > 0)
1076  skip_bits(gb, num_bits_left);
1077  }
1078 
1079  return get_bits_count(gb) - cnt;
1080 }
1081 
1083 {
1084  int err;
1085  err = sbr_make_f_master(ac, sbr, &sbr->spectrum_params);
1086  if (err >= 0)
1087  err = sbr_make_f_derived(ac, sbr);
1088  if (err < 0) {
1089  av_log(ac->avctx, AV_LOG_ERROR,
1090  "SBR reset failed. Switching SBR to pure upsampling mode.\n");
1091  sbr_turnoff(sbr);
1092  }
1093 }
1094 
1095 /**
1096  * Decode Spectral Band Replication extension data; reference: table 4.55.
1097  *
1098  * @param crc flag indicating the presence of CRC checksum
1099  * @param cnt length of TYPE_FIL syntactic element in bytes
1100  *
1101  * @return Returns number of bytes consumed from the TYPE_FIL element.
1102  */
1104  GetBitContext *gb_host, int crc,
1105  int cnt, int id_aac)
1106 {
1107  SpectralBandReplication *sbr = get_sbr(che);
1108  unsigned int num_sbr_bits = 0, num_align_bits;
1109  unsigned bytes_read;
1110  GetBitContext gbc = *gb_host, *gb = &gbc;
1111  skip_bits_long(gb_host, cnt*8 - 4);
1112 
1113  sbr->reset = 0;
1114 
1115  if (!sbr->sample_rate)
1116  sbr->sample_rate = 2 * ac->oc[1].m4ac.sample_rate; //TODO use the nominal sample rate for arbitrary sample rate support
1117  if (!ac->oc[1].m4ac.ext_sample_rate)
1118  ac->oc[1].m4ac.ext_sample_rate = 2 * ac->oc[1].m4ac.sample_rate;
1119 
1120  if (crc) {
1121  skip_bits(gb, 10); // bs_sbr_crc_bits; TODO - implement CRC check
1122  num_sbr_bits += 10;
1123  }
1124 
1125  //Save some state from the previous frame.
1126  sbr->kx[0] = sbr->kx[1];
1127  sbr->m[0] = sbr->m[1];
1128  sbr->kx_and_m_pushed = 1;
1129 
1130  num_sbr_bits++;
1131  if (get_bits1(gb)) // bs_header_flag
1132  num_sbr_bits += read_sbr_header(sbr, gb);
1133 
1134  if (sbr->reset)
1135  sbr_reset(ac, sbr);
1136 
1137  if (sbr->start)
1138  num_sbr_bits += read_sbr_data(ac, sbr, gb, id_aac);
1139 
1140  num_align_bits = ((cnt << 3) - 4 - num_sbr_bits) & 7;
1141  bytes_read = ((num_sbr_bits + num_align_bits + 4) >> 3);
1142 
1143  if (bytes_read > cnt) {
1144  av_log(ac->avctx, AV_LOG_ERROR,
1145  "Expected to read %d SBR bytes actually read %d.\n", cnt, bytes_read);
1146  sbr_turnoff(sbr);
1147  }
1148  return cnt;
1149 }
1150 
1151 /**
1152  * Analysis QMF Bank (14496-3 sp04 p206)
1153  *
1154  * @param x pointer to the beginning of the first sample window
1155  * @param W array of complex-valued samples split into subbands
1156  */
1157 #ifndef sbr_qmf_analysis
1158 #if USE_FIXED
1159 static void sbr_qmf_analysis(AVFixedDSPContext *dsp, AVTXContext *mdct,
1160  av_tx_fn mdct_fn,
1161 #else
1163  av_tx_fn mdct_fn,
1164 #endif /* USE_FIXED */
1165  SBRDSPContext *sbrdsp, const INTFLOAT *in, INTFLOAT *x,
1166  INTFLOAT z[320], INTFLOAT W[2][32][32][2], int buf_idx)
1167 {
1168  int i;
1169 #if USE_FIXED
1170  int j;
1171 #endif
1172  memcpy(x , x+1024, (320-32)*sizeof(x[0]));
1173  memcpy(x+288, in, 1024*sizeof(x[0]));
1174  for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames
1175  // are not supported
1176  dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320);
1177  sbrdsp->sum64x5(z);
1178  sbrdsp->qmf_pre_shuffle(z);
1179 #if USE_FIXED
1180  for (j = 64; j < 128; j++) {
1181  if (z[j] > 1<<24) {
1183  "sbr_qmf_analysis: value %09d too large, setting to %09d\n",
1184  z[j], 1<<24);
1185  z[j] = 1<<24;
1186  } else if (z[j] < -(1<<24)) {
1188  "sbr_qmf_analysis: value %09d too small, setting to %09d\n",
1189  z[j], -(1<<24));
1190  z[j] = -(1<<24);
1191  }
1192  }
1193 #endif
1194  mdct_fn(mdct, z, z + 64, sizeof(INTFLOAT));
1195  sbrdsp->qmf_post_shuffle(W[buf_idx][i], z);
1196  x += 32;
1197  }
1198 }
1199 #endif
1200 
1201 /**
1202  * Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank
1203  * (14496-3 sp04 p206)
1204  */
1205 #ifndef sbr_qmf_synthesis
1206 static void sbr_qmf_synthesis(AVTXContext *mdct, av_tx_fn mdct_fn,
1207 #if USE_FIXED
1208  SBRDSPContext *sbrdsp, AVFixedDSPContext *dsp,
1209 #else
1210  SBRDSPContext *sbrdsp, AVFloatDSPContext *dsp,
1211 #endif /* USE_FIXED */
1212  INTFLOAT *out, INTFLOAT X[2][38][64],
1213  INTFLOAT mdct_buf[2][64],
1214  INTFLOAT *v0, int *v_off, const unsigned int div)
1215 {
1216  int i, n;
1217  const INTFLOAT *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us;
1218  const int step = 128 >> div;
1219  INTFLOAT *v;
1220  for (i = 0; i < 32; i++) {
1221  if (*v_off < step) {
1222  int saved_samples = (1280 - 128) >> div;
1223  memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(INTFLOAT));
1224  *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - step;
1225  } else {
1226  *v_off -= step;
1227  }
1228  v = v0 + *v_off;
1229  if (div) {
1230  for (n = 0; n < 32; n++) {
1231  X[0][i][ n] = -X[0][i][n];
1232  X[0][i][32+n] = X[1][i][31-n];
1233  }
1234  mdct_fn(mdct, mdct_buf[0], X[0][i], sizeof(INTFLOAT));
1235  sbrdsp->qmf_deint_neg(v, mdct_buf[0]);
1236  } else {
1237  sbrdsp->neg_odd_64(X[1][i]);
1238  mdct_fn(mdct, mdct_buf[0], X[0][i], sizeof(INTFLOAT));
1239  mdct_fn(mdct, mdct_buf[1], X[1][i], sizeof(INTFLOAT));
1240  sbrdsp->qmf_deint_bfly(v, mdct_buf[1], mdct_buf[0]);
1241  }
1242  dsp->vector_fmul (out, v , sbr_qmf_window , 64 >> div);
1243  dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div);
1244  dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div);
1245  dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div);
1246  dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div);
1247  dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div);
1248  dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div);
1249  dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div);
1250  dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div);
1251  dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div);
1252  out += 64 >> div;
1253  }
1254 }
1255 #endif
1256 
1257 /// Generate the subband filtered lowband
1259  INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2],
1260  int buf_idx)
1261 {
1262  int i, k;
1263  const int t_HFGen = 8;
1264  const int i_f = 32;
1265  memset(X_low, 0, 32*sizeof(*X_low));
1266  for (k = 0; k < sbr->kx[1]; k++) {
1267  for (i = t_HFGen; i < i_f + t_HFGen; i++) {
1268  X_low[k][i][0] = W[buf_idx][i - t_HFGen][k][0];
1269  X_low[k][i][1] = W[buf_idx][i - t_HFGen][k][1];
1270  }
1271  }
1272  buf_idx = 1-buf_idx;
1273  for (k = 0; k < sbr->kx[0]; k++) {
1274  for (i = 0; i < t_HFGen; i++) {
1275  X_low[k][i][0] = W[buf_idx][i + i_f - t_HFGen][k][0];
1276  X_low[k][i][1] = W[buf_idx][i + i_f - t_HFGen][k][1];
1277  }
1278  }
1279  return 0;
1280 }
1281 
1282 /// High Frequency Generator (14496-3 sp04 p215)
1284  INTFLOAT X_high[64][40][2], const INTFLOAT X_low[32][40][2],
1285  const INTFLOAT (*alpha0)[2], const INTFLOAT (*alpha1)[2],
1286  const INTFLOAT bw_array[5], const uint8_t *t_env,
1287  int bs_num_env)
1288 {
1289  int j, x;
1290  int g = 0;
1291  int k = sbr->kx[1];
1292  for (j = 0; j < sbr->num_patches; j++) {
1293  for (x = 0; x < sbr->patch_num_subbands[j]; x++, k++) {
1294  const int p = sbr->patch_start_subband[j] + x;
1295  while (g <= sbr->n_q && k >= sbr->f_tablenoise[g])
1296  g++;
1297  g--;
1298 
1299  if (g < 0) {
1300  av_log(ac->avctx, AV_LOG_ERROR,
1301  "ERROR : no subband found for frequency %d\n", k);
1302  return -1;
1303  }
1304 
1305  sbr->dsp.hf_gen(X_high[k] + ENVELOPE_ADJUSTMENT_OFFSET,
1306  X_low[p] + ENVELOPE_ADJUSTMENT_OFFSET,
1307  alpha0[p], alpha1[p], bw_array[g],
1308  2 * t_env[0], 2 * t_env[bs_num_env]);
1309  }
1310  }
1311  if (k < sbr->m[1] + sbr->kx[1])
1312  memset(X_high + k, 0, (sbr->m[1] + sbr->kx[1] - k) * sizeof(*X_high));
1313 
1314  return 0;
1315 }
1316 
1317 /// Generate the subband filtered lowband
1318 static int sbr_x_gen(SpectralBandReplication *sbr, INTFLOAT X[2][38][64],
1319  const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2],
1320  const INTFLOAT X_low[32][40][2], int ch)
1321 {
1322  int k, i;
1323  const int i_f = 32;
1324  const int i_Temp = FFMAX(2*sbr->data[ch].t_env_num_env_old - i_f, 0);
1325  memset(X, 0, 2*sizeof(*X));
1326  for (k = 0; k < sbr->kx[0]; k++) {
1327  for (i = 0; i < i_Temp; i++) {
1328  X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0];
1329  X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1];
1330  }
1331  }
1332  for (; k < sbr->kx[0] + sbr->m[0]; k++) {
1333  for (i = 0; i < i_Temp; i++) {
1334  X[0][i][k] = Y0[i + i_f][k][0];
1335  X[1][i][k] = Y0[i + i_f][k][1];
1336  }
1337  }
1338 
1339  for (k = 0; k < sbr->kx[1]; k++) {
1340  for (i = i_Temp; i < 38; i++) {
1341  X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0];
1342  X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1];
1343  }
1344  }
1345  for (; k < sbr->kx[1] + sbr->m[1]; k++) {
1346  for (i = i_Temp; i < i_f; i++) {
1347  X[0][i][k] = Y1[i][k][0];
1348  X[1][i][k] = Y1[i][k][1];
1349  }
1350  }
1351  return 0;
1352 }
1353 
1354 /** High Frequency Adjustment (14496-3 sp04 p217) and Mapping
1355  * (14496-3 sp04 p217)
1356  */
1358  SBRData *ch_data, int e_a[2])
1359 {
1360  int e, i, m;
1361 
1362  memset(ch_data->s_indexmapped[1], 0, 7*sizeof(ch_data->s_indexmapped[1]));
1363  for (e = 0; e < ch_data->bs_num_env; e++) {
1364  const unsigned int ilim = sbr->n[ch_data->bs_freq_res[e + 1]];
1365  uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;
1366  int k;
1367 
1368  if (sbr->kx[1] != table[0]) {
1369  av_log(ac->avctx, AV_LOG_ERROR, "kx != f_table{high,low}[0]. "
1370  "Derived frequency tables were not regenerated.\n");
1371  sbr_turnoff(sbr);
1372  return AVERROR_BUG;
1373  }
1374  for (i = 0; i < ilim; i++)
1375  for (m = table[i]; m < table[i + 1]; m++)
1376  sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i];
1377 
1378  // ch_data->bs_num_noise > 1 => 2 noise floors
1379  k = (ch_data->bs_num_noise > 1) && (ch_data->t_env[e] >= ch_data->t_q[1]);
1380  for (i = 0; i < sbr->n_q; i++)
1381  for (m = sbr->f_tablenoise[i]; m < sbr->f_tablenoise[i + 1]; m++)
1382  sbr->q_mapped[e][m - sbr->kx[1]] = ch_data->noise_facs[k+1][i];
1383 
1384  for (i = 0; i < sbr->n[1]; i++) {
1385  if (ch_data->bs_add_harmonic_flag) {
1386  const unsigned int m_midpoint =
1387  (sbr->f_tablehigh[i] + sbr->f_tablehigh[i + 1]) >> 1;
1388 
1389  ch_data->s_indexmapped[e + 1][m_midpoint - sbr->kx[1]] = ch_data->bs_add_harmonic[i] *
1390  (e >= e_a[1] || (ch_data->s_indexmapped[0][m_midpoint - sbr->kx[1]] == 1));
1391  }
1392  }
1393 
1394  for (i = 0; i < ilim; i++) {
1395  int additional_sinusoid_present = 0;
1396  for (m = table[i]; m < table[i + 1]; m++) {
1397  if (ch_data->s_indexmapped[e + 1][m - sbr->kx[1]]) {
1398  additional_sinusoid_present = 1;
1399  break;
1400  }
1401  }
1402  memset(&sbr->s_mapped[e][table[i] - sbr->kx[1]], additional_sinusoid_present,
1403  (table[i + 1] - table[i]) * sizeof(sbr->s_mapped[e][0]));
1404  }
1405  }
1406 
1407  memcpy(ch_data->s_indexmapped[0], ch_data->s_indexmapped[ch_data->bs_num_env], sizeof(ch_data->s_indexmapped[0]));
1408  return 0;
1409 }
1410 
1411 /// Estimation of current envelope (14496-3 sp04 p218)
1412 static void sbr_env_estimate(AAC_FLOAT (*e_curr)[48], INTFLOAT X_high[64][40][2],
1413  SpectralBandReplication *sbr, SBRData *ch_data)
1414 {
1415  int e, m;
1416  int kx1 = sbr->kx[1];
1417 
1418  if (sbr->bs_interpol_freq) {
1419  for (e = 0; e < ch_data->bs_num_env; e++) {
1420 #if USE_FIXED
1421  const SoftFloat recip_env_size = av_int2sf(0x20000000 / (ch_data->t_env[e + 1] - ch_data->t_env[e]), 30);
1422 #else
1423  const float recip_env_size = 0.5f / (ch_data->t_env[e + 1] - ch_data->t_env[e]);
1424 #endif /* USE_FIXED */
1425  int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET;
1426  int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET;
1427 
1428  for (m = 0; m < sbr->m[1]; m++) {
1429  AAC_FLOAT sum = sbr->dsp.sum_square(X_high[m+kx1] + ilb, iub - ilb);
1430 #if USE_FIXED
1431  e_curr[e][m] = av_mul_sf(sum, recip_env_size);
1432 #else
1433  e_curr[e][m] = sum * recip_env_size;
1434 #endif /* USE_FIXED */
1435  }
1436  }
1437  } else {
1438  int k, p;
1439 
1440  for (e = 0; e < ch_data->bs_num_env; e++) {
1441  const int env_size = 2 * (ch_data->t_env[e + 1] - ch_data->t_env[e]);
1442  int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET;
1443  int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET;
1444  const uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;
1445 
1446  for (p = 0; p < sbr->n[ch_data->bs_freq_res[e + 1]]; p++) {
1447 #if USE_FIXED
1448  SoftFloat sum = FLOAT_0;
1449  const SoftFloat den = av_int2sf(0x20000000 / (env_size * (table[p + 1] - table[p])), 29);
1450  for (k = table[p]; k < table[p + 1]; k++) {
1451  sum = av_add_sf(sum, sbr->dsp.sum_square(X_high[k] + ilb, iub - ilb));
1452  }
1453  sum = av_mul_sf(sum, den);
1454 #else
1455  float sum = 0.0f;
1456  const int den = env_size * (table[p + 1] - table[p]);
1457 
1458  for (k = table[p]; k < table[p + 1]; k++) {
1459  sum += sbr->dsp.sum_square(X_high[k] + ilb, iub - ilb);
1460  }
1461  sum /= den;
1462 #endif /* USE_FIXED */
1463  for (k = table[p]; k < table[p + 1]; k++) {
1464  e_curr[e][k - kx1] = sum;
1465  }
1466  }
1467  }
1468  }
1469 }
1470 
1472  int id_aac, void *L_, void *R_)
1473 {
1474  INTFLOAT *L = L_, *R = R_;
1475  SpectralBandReplication *sbr = get_sbr(che);
1476  int downsampled = ac->oc[1].m4ac.ext_sample_rate < sbr->sample_rate;
1477  int ch;
1478  int nch = (id_aac == TYPE_CPE) ? 2 : 1;
1479  int err;
1480 
1481  if (id_aac != sbr->id_aac) {
1482  av_log(ac->avctx, id_aac == TYPE_LFE ? AV_LOG_VERBOSE : AV_LOG_WARNING,
1483  "element type mismatch %d != %d\n", id_aac, sbr->id_aac);
1484  sbr_turnoff(sbr);
1485  }
1486 
1487  if (sbr->start && !sbr->ready_for_dequant) {
1488  av_log(ac->avctx, AV_LOG_ERROR,
1489  "No quantized data read for sbr_dequant.\n");
1490  sbr_turnoff(sbr);
1491  }
1492 
1493  if (!sbr->kx_and_m_pushed) {
1494  sbr->kx[0] = sbr->kx[1];
1495  sbr->m[0] = sbr->m[1];
1496  } else {
1497  sbr->kx_and_m_pushed = 0;
1498  }
1499 
1500  if (sbr->start) {
1501  sbr_dequant(sbr, id_aac);
1502  sbr->ready_for_dequant = 0;
1503  }
1504  for (ch = 0; ch < nch; ch++) {
1505  /* decode channel */
1506  sbr_qmf_analysis(ac->fdsp, sbr->mdct_ana, sbr->mdct_ana_fn, &sbr->dsp,
1507  ch ? R : L, sbr->data[ch].analysis_filterbank_samples,
1509  sbr->data[ch].W, sbr->data[ch].Ypos);
1510  sbr->c.sbr_lf_gen(sbr, sbr->X_low,
1511  (const INTFLOAT (*)[32][32][2]) sbr->data[ch].W,
1512  sbr->data[ch].Ypos);
1513  sbr->data[ch].Ypos ^= 1;
1514  if (sbr->start) {
1515  sbr->c.sbr_hf_inverse_filter(&sbr->dsp, sbr->alpha0, sbr->alpha1,
1516  (const INTFLOAT (*)[40][2]) sbr->X_low, sbr->k[0]);
1517  sbr_chirp(sbr, &sbr->data[ch]);
1518  av_assert0(sbr->data[ch].bs_num_env > 0);
1519  sbr_hf_gen(ac, sbr, sbr->X_high,
1520  (const INTFLOAT (*)[40][2]) sbr->X_low,
1521  (const INTFLOAT (*)[2]) sbr->alpha0,
1522  (const INTFLOAT (*)[2]) sbr->alpha1,
1523  sbr->data[ch].bw_array, sbr->data[ch].t_env,
1524  sbr->data[ch].bs_num_env);
1525 
1526  // hf_adj
1527  err = sbr_mapping(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);
1528  if (!err) {
1529  sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]);
1530  sbr_gain_calc(sbr, &sbr->data[ch], sbr->data[ch].e_a);
1531  sbr->c.sbr_hf_assemble(sbr->data[ch].Y[sbr->data[ch].Ypos],
1532  (const INTFLOAT (*)[40][2]) sbr->X_high,
1533  sbr, &sbr->data[ch],
1534  sbr->data[ch].e_a);
1535  }
1536  }
1537 
1538  /* synthesis */
1539  sbr->c.sbr_x_gen(sbr, sbr->X[ch],
1540  (const INTFLOAT (*)[64][2]) sbr->data[ch].Y[1-sbr->data[ch].Ypos],
1541  (const INTFLOAT (*)[64][2]) sbr->data[ch].Y[ sbr->data[ch].Ypos],
1542  (const INTFLOAT (*)[40][2]) sbr->X_low, ch);
1543  }
1544 
1545  if (ac->oc[1].m4ac.ps == 1) {
1546  if (sbr->ps.common.start) {
1547  AAC_RENAME(ff_ps_apply)(&sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]);
1548  } else {
1549  memcpy(sbr->X[1], sbr->X[0], sizeof(sbr->X[0]));
1550  }
1551  nch = 2;
1552  }
1553 
1554  sbr_qmf_synthesis(sbr->mdct, sbr->mdct_fn, &sbr->dsp, ac->fdsp,
1555  L, sbr->X[0], sbr->qmf_filter_scratch,
1558  downsampled);
1559  if (nch == 2)
1560  sbr_qmf_synthesis(sbr->mdct, sbr->mdct_fn, &sbr->dsp, ac->fdsp,
1561  R, sbr->X[1], sbr->qmf_filter_scratch,
1564  downsampled);
1565 }
1566 
1568 {
1569  c->sbr_lf_gen = sbr_lf_gen;
1570  c->sbr_hf_assemble = sbr_hf_assemble;
1571  c->sbr_x_gen = sbr_x_gen;
1572  c->sbr_hf_inverse_filter = sbr_hf_inverse_filter;
1573 }
SBRDSPContext::hf_gen
void(* hf_gen)(INTFLOAT(*X_high)[2], const INTFLOAT(*X_low)[2], const INTFLOAT alpha0[2], const INTFLOAT alpha1[2], INTFLOAT bw, int start, int end)
Definition: sbrdsp.h:36
SpectralBandReplication::bs_coupling
unsigned bs_coupling
Definition: sbr.h:157
FIXFIX
@ FIXFIX
Definition: aacsbr.h:60
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
sbr_hf_gen
static int sbr_hf_gen(AACDecContext *ac, SpectralBandReplication *sbr, INTFLOAT X_high[64][40][2], const INTFLOAT X_low[32][40][2], const INTFLOAT(*alpha0)[2], const INTFLOAT(*alpha1)[2], const INTFLOAT bw_array[5], const uint8_t *t_env, int bs_num_env)
High Frequency Generator (14496-3 sp04 p215)
Definition: aacsbr_template.c:1283
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_aac_sbr_init
av_cold void AAC_RENAME() ff_aac_sbr_init(void)
Initialize SBR.
Definition: aacsbr_template.c:52
SpectralBandReplication::data
SBRData data[2]
Definition: sbr.h:167
SpectralBandReplication::bs_limiter_gains
unsigned bs_limiter_gains
Definition: sbr.h:153
Q23
#define Q23(x)
Definition: aac_defines.h:109
SBRDSPContext
Definition: sbrdsp.h:27
out
FILE * out
Definition: movenc.c:55
elements
static const ElemCat * elements[ELEMENT_COUNT]
Definition: signature.h:566
AACDecContext::warned_he_aac_mono
int warned_he_aac_mono
Definition: aacdec.h:338
SpectralBandReplication::e_origmapped
AAC_FLOAT e_origmapped[7][48]
Dequantized envelope scalefactors, remapped.
Definition: sbr.h:199
VARFIX
@ VARFIX
Definition: aacsbr.h:62
log2f
#define log2f(x)
Definition: libm.h:409
T_HUFFMAN_ENV_1_5DB
@ T_HUFFMAN_ENV_1_5DB
Definition: aacsbr.h:44
SBRData::env_facs
AAC_FLOAT env_facs[6][48]
Definition: sbr.h:101
sbr_chirp
static void sbr_chirp(SpectralBandReplication *sbr, SBRData *ch_data)
Chirp Factors (14496-3 sp04 p214)
Definition: aacsbr.c:208
AVTXContext
Definition: tx_priv.h:235
SpectralBandReplication::X
INTFLOAT X[2][2][38][64]
QMF values of the reconstructed signal.
Definition: sbr.h:193
AVFloatDSPContext::vector_fmul_reverse
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats, and store the result in a vector of floats...
Definition: float_dsp.h:152
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
ff_ps_apply
int AAC_RENAME() ff_ps_apply(PSContext *ps, INTFLOAT L[2][38][64], INTFLOAT R[2][38][64], int top)
Definition: aacps.c:719
sbr_qmf_window_ds
static const INTFLOAT sbr_qmf_window_ds[320]
Definition: aacsbrdata.h:45
sbr_hf_inverse_filter
static void sbr_hf_inverse_filter(SBRDSPContext *dsp, float(*alpha0)[2], float(*alpha1)[2], const float X_low[32][40][2], int k0)
High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering (14496-3 sp04 p214) Warning: Thi...
Definition: aacsbr.c:153
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
ff_ps_read_data
int ff_ps_read_data(void *logctx, GetBitContext *gb, PSCommonContext *ps, int bits_left)
Definition: aacps_common.c:122
SpectralBandReplication::m
AAC_SIGNE m[2]
M' and M respectively, M is the number of QMF subbands that use SBR.
Definition: sbr.h:163
b
#define b
Definition: input.c:41
read_sbr_noise
static int read_sbr_noise(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data, int ch)
Definition: aacsbr_template.c:893
table
static const uint16_t table[]
Definition: prosumer.c:205
SBRData::t_env_num_env_old
uint8_t t_env_num_env_old
Envelope time border of the last envelope of the previous frame.
Definition: sbr.h:108
SpectrumParameters::bs_alter_scale
uint8_t bs_alter_scale
Definition: sbr.h:53
R
#define R
Definition: huffyuv.h:44
MAX_PREDICTORS
#define MAX_PREDICTORS
Definition: aac.h:85
PSCommonContext::start
int start
Definition: aacps.h:48
copy_sbr_grid
static void copy_sbr_grid(SBRData *dst, const SBRData *src)
Definition: aacsbr_template.c:777
AACSBRContext::sbr_hf_assemble
void(* sbr_hf_assemble)(INTFLOAT Y1[38][64][2], const INTFLOAT X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
Definition: sbr.h:125
SpectrumParameters::bs_start_freq
uint8_t bs_start_freq
Definition: sbr.h:44
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
ff_ps_init
av_cold void AAC_RENAME() ff_ps_init(void)
Definition: aacps.c:740
AVFixedDSPContext
Definition: fixed_dsp.h:55
SBRData::t_env
uint8_t t_env[8]
Envelope time borders.
Definition: sbr.h:106
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
SpectralBandReplication::X_low
INTFLOAT X_low[32][40][2]
QMF low frequency input to the HF generator.
Definition: sbr.h:189
qsort_comparison_function_int16
static int qsort_comparison_function_int16(const void *a, const void *b)
Definition: aacsbr_template.c:121
ChannelElement::ch
SingleChannelElement ch[2]
Definition: aacdec.h:174
ExtChannelElement::ch
ChannelElement ch
Definition: aacsbr_template.c:42
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:903
W
@ W
Definition: vf_addroi.c:27
sbr_qmf_analysis
static void sbr_qmf_analysis(AVFloatDSPContext *dsp, AVTXContext *mdct, av_tx_fn mdct_fn, SBRDSPContext *sbrdsp, const INTFLOAT *in, INTFLOAT *x, INTFLOAT z[320], INTFLOAT W[2][32][32][2], int buf_idx)
Analysis QMF Bank (14496-3 sp04 p206)
Definition: aacsbr_template.c:1162
SpectralBandReplication::ready_for_dequant
int ready_for_dequant
Definition: sbr.h:143
T_HUFFMAN_ENV_BAL_3_0DB
@ T_HUFFMAN_ENV_BAL_3_0DB
Definition: aacsbr.h:50
sbr_gain_calc
static void sbr_gain_calc(SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
Calculation of levels of additional HF signal components (14496-3 sp04 p219) and Calculation of gain ...
Definition: aacsbr.c:232
ff_aac_sbr_vlc
const VLCElem * ff_aac_sbr_vlc[10]
Definition: aacdec_tab.c:261
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
SBRData::e_a
int e_a[2]
l_APrev and l_A
Definition: sbr.h:88
SBRData::analysis_filterbank_samples
INTFLOAT analysis_filterbank_samples[1312]
Definition: sbr.h:85
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
F_HUFFMAN_ENV_1_5DB
@ F_HUFFMAN_ENV_1_5DB
Definition: aacsbr.h:45
SpectralBandReplication::bs_interpol_freq
unsigned bs_interpol_freq
Definition: sbr.h:154
v0
#define v0
Definition: regdef.h:26
sbr_make_f_master
static int sbr_make_f_master(AACDecContext *ac, SpectralBandReplication *sbr, SpectrumParameters *spectrum)
Master Frequency Band Table (14496-3 sp04 p194)
Definition: aacsbr_template.c:267
ExtChannelElement::sbr
SpectralBandReplication sbr
Definition: aacsbr_template.c:44
SpectralBandReplication::n_master
AAC_SIGNE n_master
The number of frequency bands in f_master.
Definition: sbr.h:166
TYPE_CPE
@ TYPE_CPE
Definition: aac.h:41
GetBitContext
Definition: get_bits.h:108
SBRData::bs_add_harmonic_flag
unsigned bs_add_harmonic_flag
Definition: sbr.h:69
SpectralBandReplication::mdct_fn
av_tx_fn mdct_fn
Definition: sbr.h:215
SpectralBandReplication::reset
int reset
Definition: sbr.h:145
F_HUFFMAN_ENV_BAL_3_0DB
@ F_HUFFMAN_ENV_BAL_3_0DB
Definition: aacsbr.h:51
PSContext::common
PSCommonContext common
Definition: aacps.h:72
sbr_lf_gen
static int sbr_lf_gen(SpectralBandReplication *sbr, INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2], int buf_idx)
Generate the subband filtered lowband.
Definition: aacsbr_template.c:1258
SBRData::noise_facs
AAC_FLOAT noise_facs[3][5]
Definition: sbr.h:104
sbr_hf_assemble
static void sbr_hf_assemble(float Y1[38][64][2], const float X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
Assembling HF Signals (14496-3 sp04 p220)
Definition: aacsbr.c:289
read_sbr_single_channel_element
static int read_sbr_single_channel_element(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb)
Definition: aacsbr_template.c:962
F_HUFFMAN_ENV_3_0DB
@ F_HUFFMAN_ENV_3_0DB
Definition: aacsbr.h:49
ExtChannelElement::predictor_state
PredictorState predictor_state[2][MAX_PREDICTORS]
Definition: aacsbr_template.c:43
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
SpectrumParameters::bs_stop_freq
uint8_t bs_stop_freq
Definition: sbr.h:45
av_cold
#define av_cold
Definition: attributes.h:90
T_HUFFMAN_NOISE_3_0DB
@ T_HUFFMAN_NOISE_3_0DB
Definition: aacsbr.h:52
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
Definition: tx.h:68
SpectralBandReplication::qmf_filter_scratch
INTFLOAT qmf_filter_scratch[5][64]
Definition: sbr.h:211
SBRData::bs_df_noise
uint8_t bs_df_noise[2]
Definition: sbr.h:74
read_sbr_grid
static int read_sbr_grid(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data)
Definition: aacsbr_template.c:630
AV_TX_INT32_MDCT
@ AV_TX_INT32_MDCT
Definition: tx.h:70
g
const char * g
Definition: vf_curves.c:128
SBRData::bs_num_noise
AAC_SIGNE bs_num_noise
Definition: sbr.h:72
bits
uint8_t bits
Definition: vp3data.h:128
read_sbr_header
static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext *gb)
Definition: aacsbr_template.c:187
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
read_sbr_extension
static void read_sbr_extension(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int bs_extension_id, int *num_bits_left)
Definition: aacsbr_template.c:935
T_HUFFMAN_ENV_3_0DB
@ T_HUFFMAN_ENV_3_0DB
Definition: aacsbr.h:48
sbr_offset
static const int8_t sbr_offset[6][16]
window coefficients for analysis/synthesis QMF banks
Definition: aacsbrdata.h:35
PredictorState
Predictor State.
Definition: aac_defines.h:130
SpectrumParameters::bs_xover_band
uint8_t bs_xover_band
Definition: sbr.h:46
SpectralBandReplication::f_tablenoise
uint16_t f_tablenoise[6]
Frequency borders for noise floors.
Definition: sbr.h:182
ff_aac_sbr_apply
void AAC_RENAME() ff_aac_sbr_apply(AACDecContext *ac, ChannelElement *che, int id_aac, void *L_, void *R_)
Apply one SBR element to one AAC element.
Definition: aacsbr_template.c:1471
if
if(ret)
Definition: filter_design.txt:179
AACSBRContext::sbr_x_gen
int(* sbr_x_gen)(SpectralBandReplication *sbr, INTFLOAT X[2][38][64], const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2], const INTFLOAT X_low[32][40][2], int ch)
Definition: sbr.h:129
SpectralBandReplication::n_lim
AAC_SIGNE n_lim
Number of limiter bands.
Definition: sbr.h:174
SBRData::Ypos
int Ypos
QMF output of the HF adjustor.
Definition: sbr.h:94
SBRData::env_facs_q
uint8_t env_facs_q[6][48]
Envelope scalefactors.
Definition: sbr.h:100
NULL
#define NULL
Definition: coverity.c:32
SpectralBandReplication::f_tablelow
uint16_t f_tablelow[25]
Frequency borders for low resolution SBR.
Definition: sbr.h:178
SpectralBandReplication::mdct
AVTXContext * mdct
Definition: sbr.h:214
EXTENSION_ID_PS
@ EXTENSION_ID_PS
Definition: aacsbr.h:67
FLOAT_0
static const SoftFloat FLOAT_0
0.0
Definition: softfloat.h:39
SBRData::f_indexnoise
unsigned f_indexnoise
Definition: sbr.h:111
SBRData::bs_df_env
uint8_t bs_df_env[5]
Definition: sbr.h:73
check_n_master
static int check_n_master(AVCodecContext *avctx, int n_master, int bs_xover_band)
Definition: aacsbr_template.c:250
SpectrumParameters::bs_freq_scale
uint8_t bs_freq_scale
Definition: sbr.h:52
SpectralBandReplication::f_tablelim
uint16_t f_tablelim[30]
Frequency borders for the limiter.
Definition: sbr.h:184
SBRData::bs_add_harmonic
uint8_t bs_add_harmonic[48]
Definition: sbr.h:76
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
AACSBRContext
aacsbr functions pointers
Definition: sbr.h:121
fixed_log
static int fixed_log(int x)
Definition: aacsbr_fixed.c:84
SBR_SYNTHESIS_BUF_SIZE
#define SBR_SYNTHESIS_BUF_SIZE
Definition: sbr.h:58
USE_FIXED
#define USE_FIXED
Definition: aacdec.c:34
make_bands
static void make_bands(int16_t *bands, int start, int stop, int num_bands)
Definition: aacsbr.c:67
SpectralBandReplication::n
AAC_SIGNE n[2]
N_Low and N_High respectively, the number of frequency bands for low and high resolution.
Definition: sbr.h:170
SBRData::bs_num_env
AAC_SIGNE bs_num_env
Definition: sbr.h:70
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:652
SBRData::bs_amp_res
unsigned bs_amp_res
Definition: sbr.h:77
SBRData::s_indexmapped
uint8_t s_indexmapped[8][48]
Definition: sbr.h:98
read_sbr_dtdf
static void read_sbr_dtdf(SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data)
Read how the envelope and noise floor data is delta coded.
Definition: aacsbr_template.c:795
SpectralBandReplication::bs_smoothing_mode
unsigned bs_smoothing_mode
Definition: sbr.h:155
sbr_x_gen
static int sbr_x_gen(SpectralBandReplication *sbr, INTFLOAT X[2][38][64], const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2], const INTFLOAT X_low[32][40][2], int ch)
Generate the subband filtered lowband.
Definition: aacsbr_template.c:1318
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
SpectralBandReplication::mdct_ana_fn
av_tx_fn mdct_ana_fn
Definition: sbr.h:213
SpectrumParameters
Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the pr...
Definition: sbr.h:43
sbr_qmf_synthesis
static void sbr_qmf_synthesis(AVTXContext *mdct, av_tx_fn mdct_fn, SBRDSPContext *sbrdsp, AVFloatDSPContext *dsp, INTFLOAT *out, INTFLOAT X[2][38][64], INTFLOAT mdct_buf[2][64], INTFLOAT *v0, int *v_off, const unsigned int div)
Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank (14496-3 sp04 p206)
Definition: aacsbr_template.c:1206
SpectralBandReplication::f_master
uint16_t f_master[49]
The master QMF frequency grouping.
Definition: sbr.h:176
qsort.h
f
f
Definition: af_crystalizer.c:121
sbr_mapping
static int sbr_mapping(AACDecContext *ac, SpectralBandReplication *sbr, SBRData *ch_data, int e_a[2])
High Frequency Adjustment (14496-3 sp04 p217) and Mapping (14496-3 sp04 p217)
Definition: aacsbr_template.c:1357
AVFloatDSPContext::vector_fmul
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats and store the result in a vector of floats.
Definition: float_dsp.h:36
SpectralBandReplication::sample_rate
int sample_rate
Definition: sbr.h:141
T_HUFFMAN_ENV_BAL_1_5DB
@ T_HUFFMAN_ENV_BAL_1_5DB
Definition: aacsbr.h:46
VLCElem
Definition: vlc.h:32
sbr_turnoff
static void sbr_turnoff(SpectralBandReplication *sbr)
Places SBR in pure upsampling mode.
Definition: aacsbr_template.c:58
SpectralBandReplication
Spectral Band Replication.
Definition: sbr.h:140
SpectralBandReplication::alpha0
INTFLOAT alpha0[64][2]
Zeroth coefficient used to filter the subband signals.
Definition: sbr.h:195
SpectralBandReplication::c
AACSBRContext c
Definition: sbr.h:217
AVFloatDSPContext
Definition: float_dsp.h:22
SpectralBandReplication::bs_amp_res_header
int bs_amp_res_header
Definition: sbr.h:147
SBRData::bs_invf_mode
uint8_t bs_invf_mode[2][5]
Definition: sbr.h:75
read_sbr_envelope
static int read_sbr_envelope(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data, int ch)
Definition: aacsbr_template.c:813
SpectralBandReplication::alpha1
INTFLOAT alpha1[64][2]
First coefficient used to filter the subband signals.
Definition: sbr.h:197
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
SBRData::bs_freq_res
uint8_t bs_freq_res[7]
Definition: sbr.h:71
SBRData::Y
INTFLOAT Y[2][38][64][2]
Definition: sbr.h:95
SpectralBandReplication::n_q
AAC_SIGNE n_q
Number of noise floor bands.
Definition: sbr.h:172
SpectralBandReplication::patch_start_subband
uint8_t patch_start_subband[6]
Definition: sbr.h:187
CONST_076923
static const int CONST_076923
Definition: aacsbr_fixed.c:76
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:295
AACSBRContext::sbr_hf_inverse_filter
void(* sbr_hf_inverse_filter)(SBRDSPContext *dsp, INTFLOAT(*alpha0)[2], INTFLOAT(*alpha1)[2], const INTFLOAT X_low[32][40][2], int k0)
Definition: sbr.h:132
ff_sbrdsp_init
void AAC_RENAME() ff_sbrdsp_init(SBRDSPContext *s)
Definition: sbrdsp_template.c:80
aacsbr_func_ptr_init
static void aacsbr_func_ptr_init(AACSBRContext *c)
Definition: aacsbr_template.c:1567
SpectralBandReplication::e_curr
AAC_FLOAT e_curr[7][48]
Estimated envelope.
Definition: sbr.h:205
SpectralBandReplication::id_aac
int id_aac
Definition: sbr.h:144
SoftFloat
Definition: softfloat.h:34
CONST_RECIP_LN2
static const int CONST_RECIP_LN2
Definition: aacsbr_fixed.c:75
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ceil_log2
static const int8_t ceil_log2[]
ceil(log2(index+1))
Definition: aacsbr_template.c:626
AV_QSORT
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
Definition: qsort.h:33
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:371
F_HUFFMAN_ENV_BAL_1_5DB
@ F_HUFFMAN_ENV_BAL_1_5DB
Definition: aacsbr.h:47
SBRData
Spectral Band Replication per channel data.
Definition: sbr.h:63
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aacdec.h:169
SBRData::bw_array
INTFLOAT bw_array[5]
Chirp factors.
Definition: sbr.h:90
SpectralBandReplication::k
AAC_SIGNE k[5]
k0, k1, k2
Definition: sbr.h:158
AVFloatDSPContext::vector_fmul_add
void(* vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len)
Calculate the entry wise product of two vectors of floats, add a third vector of floats and store the...
Definition: float_dsp.h:135
delta
float delta
Definition: vorbis_enc_data.h:430
SpectralBandReplication::X_high
INTFLOAT X_high[64][40][2]
QMF output of the HF generator.
Definition: sbr.h:191
in_table_int16
static int in_table_int16(const int16_t *table, int last_el, int16_t needle)
Definition: aacsbr_template.c:126
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_int2sf
static av_const SoftFloat av_int2sf(int v, int frac_bits)
Converts a mantisse and exponent to a SoftFloat.
Definition: softfloat.h:185
TYPE_LFE
@ TYPE_LFE
Definition: aac.h:43
SBRData::bs_frame_class
unsigned bs_frame_class
Definition: sbr.h:68
AAC_RENAME
#define AAC_RENAME(x)
Definition: aac_defines.h:99
sbr_make_f_tablelim
static void sbr_make_f_tablelim(SpectralBandReplication *sbr)
Limiter Frequency Band Table (14496-3 sp04 p198)
Definition: aacsbr_template.c:136
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
TYPE_SCE
@ TYPE_SCE
Definition: aac.h:40
AACDecContext::oc
OutputConfiguration oc[2]
Definition: aacdec.h:333
SpectralBandReplication::kx_and_m_pushed
unsigned kx_and_m_pushed
Definition: sbr.h:164
sbr_make_f_derived
static int sbr_make_f_derived(AACDecContext *ac, SpectralBandReplication *sbr)
Derived Frequency Band Tables (14496-3 sp04 p197)
Definition: aacsbr_template.c:545
avcodec.h
SBRData::W
INTFLOAT W[2][32][32][2]
QMF values of the original signal.
Definition: sbr.h:92
read_sbr_invf
static void read_sbr_invf(SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data)
Read inverse filtering data.
Definition: aacsbr_template.c:803
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:111
X
@ X
Definition: vf_addroi.c:27
ret
ret
Definition: filter_design.txt:187
sbr_dequant
static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)
Dequantization and stereo decoding (14496-3 sp04 p203)
Definition: aacsbr.c:86
VARVAR
@ VARVAR
Definition: aacsbr.h:63
array_min_int16
static int array_min_int16(const int16_t *array, int nel)
Definition: aacsbr_template.c:242
U
#define U(x)
Definition: vpx_arith.h:37
aacdec.h
AACDecContext
main AAC decoding context
Definition: aacdec.h:258
sbr_hf_calc_npatches
static int sbr_hf_calc_npatches(AACDecContext *ac, SpectralBandReplication *sbr)
High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46)
Definition: aacsbr_template.c:487
AVCodecContext
main external API structure.
Definition: avcodec.h:445
FIXVAR
@ FIXVAR
Definition: aacsbr.h:61
ff_aac_sbr_ctx_alloc_init
av_cold int AAC_RENAME() ff_aac_sbr_ctx_alloc_init(AACDecContext *ac, ChannelElement **che, int id_aac)
Allocate an ExtChannelElement (if necessary) and initialize the SBR context contained in it.
Definition: aacsbr_template.c:69
AV_PROFILE_AAC_HE_V2
#define AV_PROFILE_AAC_HE_V2
Definition: defs.h:73
AACDecContext::avctx
struct AVCodecContext * avctx
Definition: aacdec.h:260
MPEG4AudioConfig::ps
int ps
-1 implicit, 1 presence
Definition: mpeg4audio.h:40
sbr_env_estimate
static void sbr_env_estimate(AAC_FLOAT(*e_curr)[48], INTFLOAT X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data)
Estimation of current envelope (14496-3 sp04 p218)
Definition: aacsbr_template.c:1412
aacdec_tab.h
SBRData::t_q
uint8_t t_q[3]
Noise time borders.
Definition: sbr.h:110
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1640
SpectralBandReplication::spectrum_params
SpectrumParameters spectrum_params
Definition: sbr.h:146
av_add_sf
static av_const SoftFloat av_add_sf(SoftFloat a, SoftFloat b)
Definition: softfloat.h:162
temp
else temp
Definition: vf_mcdeint.c:263
sbr_qmf_window_us
static const INTFLOAT sbr_qmf_window_us[640]
Definition: aacsbrdata.h:210
L
#define L(x)
Definition: vpx_arith.h:36
SpectralBandReplication::f_tablehigh
uint16_t f_tablehigh[49]
Frequency borders for high resolution SBR.
Definition: sbr.h:180
SBRData::noise_facs_q
uint8_t noise_facs_q[3][5]
Noise scalefactors.
Definition: sbr.h:103
SBRData::synthesis_filterbank_samples
INTFLOAT synthesis_filterbank_samples[SBR_SYNTHESIS_BUF_SIZE]
Definition: sbr.h:84
sbr_reset
static void sbr_reset(AACDecContext *ac, SpectralBandReplication *sbr)
Definition: aacsbr_template.c:1082
SpectralBandReplication::bs_limiter_bands
unsigned bs_limiter_bands
Definition: sbr.h:152
SpectralBandReplication::patch_num_subbands
uint8_t patch_num_subbands[6]
Definition: sbr.h:186
OutputConfiguration::m4ac
MPEG4AudioConfig m4ac
Definition: aacdec.h:180
TYPE_CCE
@ TYPE_CCE
Definition: aac.h:42
SpectralBandReplication::start
int start
Definition: sbr.h:142
ff_aac_sbr_decode_extension
int AAC_RENAME() ff_aac_sbr_decode_extension(AACDecContext *ac, ChannelElement *che, GetBitContext *gb_host, int crc, int cnt, int id_aac)
Decode Spectral Band Replication extension data; reference: table 4.55.
Definition: aacsbr_template.c:1103
mem.h
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
SpectralBandReplication::mdct_ana
AVTXContext * mdct_ana
Definition: sbr.h:212
SBRDSPContext::sum_square
AAC_FLOAT(* sum_square)(INTFLOAT(*x)[2], int n)
Definition: sbrdsp.h:29
ff_ps_ctx_init
static void AAC_RENAME() ff_ps_ctx_init(PSContext *ps)
Definition: aacps.h:97
get_sbr
static SpectralBandReplication * get_sbr(ChannelElement *ch)
Definition: aacsbr_template.c:47
ENVELOPE_ADJUSTMENT_OFFSET
#define ENVELOPE_ADJUSTMENT_OFFSET
Definition: aacsbr.h:37
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
AAC_FLOAT
float AAC_FLOAT
Definition: aac_defines.h:105
read_sbr_channel_pair_element
static int read_sbr_channel_pair_element(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb)
Definition: aacsbr_template.c:986
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
SpectrumParameters::bs_noise_bands
uint8_t bs_noise_bands
Definition: sbr.h:54
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
read_sbr_data
static unsigned int read_sbr_data(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int id_aac)
Definition: aacsbr_template.c:1038
T_HUFFMAN_NOISE_BAL_3_0DB
@ T_HUFFMAN_NOISE_BAL_3_0DB
Definition: aacsbr.h:53
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ExtChannelElement
Definition: aacsbr_template.c:41
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
SpectralBandReplication::q_mapped
AAC_FLOAT q_mapped[7][48]
Dequantized noise scalefactors, remapped.
Definition: sbr.h:201
AACSBRContext::sbr_lf_gen
int(* sbr_lf_gen)(SpectralBandReplication *sbr, INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2], int buf_idx)
Definition: sbr.h:122
get_bits1_vector
static av_always_inline void get_bits1_vector(GetBitContext *gb, uint8_t *vec, int elements)
Definition: aacsbr_template.c:616
ff_aac_sbr_ctx_close
av_cold void AAC_RENAME() ff_aac_sbr_ctx_close(ChannelElement *che)
Close the SBR context implicitly contained in a ChannelElement.
Definition: aacsbr_template.c:114
SBRData::synthesis_filterbank_samples_offset
int synthesis_filterbank_samples_offset
Definition: sbr.h:86
int
int
Definition: ffmpeg_filter.c:424
SpectralBandReplication::kx
AAC_SIGNE kx[2]
kx', and kx respectively, kx is the first QMF subband where SBR is used.
Definition: sbr.h:161
av_mul_sf
static av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b)
Definition: softfloat.h:102
INTFLOAT
float INTFLOAT
Definition: aac_defines.h:101
SpectralBandReplication::s_mapped
uint8_t s_mapped[7][48]
Sinusoidal presence, remapped.
Definition: sbr.h:203
SpectralBandReplication::ps
PSContext ps
Definition: sbr.h:168
min
float min
Definition: vorbis_enc_data.h:429
SpectralBandReplication::num_patches
AAC_SIGNE num_patches
Definition: sbr.h:185
SpectralBandReplication::dsp
SBRDSPContext dsp
Definition: sbr.h:216