FFmpeg
aacenc_tns.c
Go to the documentation of this file.
1 /*
2  * AAC encoder TNS
3  * Copyright (C) 2015 Rostislav Pehlivanov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * AAC encoder temporal noise shaping
25  * @author Rostislav Pehlivanov ( atomnuker gmail com )
26  */
27 
28 #include "libavutil/libm.h"
29 #include "aacenc.h"
30 #include <float.h>
31 #include "aacenc_tns.h"
32 #include "aactab.h"
33 #include "aacenc_utils.h"
34 #include "lpc_functions.h"
35 
36 /* Could be set to 3 to save an additional bit at the cost of little quality */
37 #define TNS_Q_BITS 4
38 
39 /* Coefficient resolution in short windows */
40 #define TNS_Q_BITS_IS8 4
41 
42 /* We really need the bits we save here elsewhere */
43 #define TNS_ENABLE_COEF_COMPRESSION
44 
45 /* Apple-derived TNS: weighted-spectrum predictor, accepted only if the measured
46  * post-quantization prediction gain clears a block-type-dependent bar (Apple RE). */
47 #define TNS_PREDGAIN_GATE 1.4f /* first gate: predicted LPC gain */
48 #define TNS_PG_C1_LONG 1.4f /* min measured gain, long blocks */
49 #define TNS_PG_C1_SHORT 3.2f /* min measured gain, short blocks */
50 #define TNS_PG_CLAMP 6.0f /* upper bound: poles near unit circle → noise blowup */
51 #define TNS_WEIGHT_FLOOR 0.01f /* per-bin masking floor for the weighted spectrum */
52 
53 static inline int compress_coeffs(int *coef, int order, int c_bits)
54 {
55  int i;
56  const int low_idx = c_bits ? 4 : 2;
57  const int shift_val = c_bits ? 8 : 4;
58  const int high_idx = c_bits ? 11 : 5;
59 #ifndef TNS_ENABLE_COEF_COMPRESSION
60  return 0;
61 #endif /* TNS_ENABLE_COEF_COMPRESSION */
62  for (i = 0; i < order; i++)
63  if (coef[i] >= low_idx && coef[i] <= high_idx)
64  return 0;
65  for (i = 0; i < order; i++)
66  coef[i] -= (coef[i] > high_idx) ? shift_val : 0;
67  return 1;
68 }
69 
70 /** Encode TNS data. */
72 {
73  TemporalNoiseShaping *tns = &sce->tns;
74  int i, w, filt, coef_compress = 0, coef_len;
75  const int is8 = sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE;
76  const int c_bits = is8 ? TNS_Q_BITS_IS8 == 4 : TNS_Q_BITS == 4;
77 
78  if (!sce->tns.present)
79  return;
80 
81  for (i = 0; i < sce->ics.num_windows; i++) {
82  put_bits(&s->pb, 2 - is8, sce->tns.n_filt[i]);
83  if (!tns->n_filt[i])
84  continue;
85  put_bits(&s->pb, 1, c_bits);
86  for (filt = 0; filt < tns->n_filt[i]; filt++) {
87  put_bits(&s->pb, 6 - 2 * is8, tns->length[i][filt]);
88  put_bits(&s->pb, 5 - 2 * is8, tns->order[i][filt]);
89  if (!tns->order[i][filt])
90  continue;
91  put_bits(&s->pb, 1, tns->direction[i][filt]);
92  coef_compress = compress_coeffs(tns->coef_idx[i][filt],
93  tns->order[i][filt], c_bits);
94  put_bits(&s->pb, 1, coef_compress);
95  coef_len = c_bits + 3 - coef_compress;
96  for (w = 0; w < tns->order[i][filt]; w++)
97  put_bits(&s->pb, coef_len, tns->coef_idx[i][filt][w]);
98  }
99  }
100 }
101 
102 /* Cap the TNS band range at the first PNS band to avoid TNS+PNS conflicts. */
103 static int tns_max_nonpns(const SingleChannelElement *sce, int mmm)
104 {
105  for (int w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
106  for (int g = 0; g < mmm; g++)
107  if (sce->band_type[w*16+g] == NOISE_BT) { mmm = g; break; }
108  return mmm;
109 }
110 
111 /* Apply TNS filter */
113 {
114  TemporalNoiseShaping *tns = &sce->tns;
115  IndividualChannelStream *ics = &sce->ics;
116  int w, filt, m, i, top, order, bottom, start, end, size, inc;
117  const int mmm = tns_max_nonpns(sce, FFMIN(ics->tns_max_bands, ics->max_sfb));
118  float lpc[TNS_MAX_ORDER];
119 
120  /* TNS predicts from the post-M/S and post-I/S coefficients. */
121  float hist[1024];
122  memcpy(hist, sce->coeffs, sizeof(hist));
123 
124  for (w = 0; w < ics->num_windows; w++) {
125  bottom = ics->num_swb;
126  for (filt = 0; filt < tns->n_filt[w]; filt++) {
127  int b0, e0;
128  top = bottom;
129  bottom = FFMAX(0, top - tns->length[w][filt]);
130  order = tns->order[w][filt];
131  if (order == 0)
132  continue;
133 
134  // tns_decode_coef
135  compute_lpc_coefs(tns->coef[w][filt], 0, order, lpc, 0, 0, 0, NULL);
136 
137  b0 = FFMIN(bottom, mmm);
138  e0 = FFMIN( top, mmm);
139  start = ics->swb_offset[b0];
140  end = ics->swb_offset[e0];
141  if ((size = end - start) <= 0)
142  continue;
143  if (tns->direction[w][filt]) {
144  inc = -1;
145  start = end - 1;
146  } else {
147  inc = 1;
148  }
149  start += w * 128;
150 
151  /* AR filter */
152  for (m = 0; m < size; m++, start += inc) {
153  for (i = 1; i <= FFMIN(m, order); i++) {
154  sce->coeffs[start] += lpc[i-1]*hist[start - i*inc];
155  }
156  }
157 
158  }
159  }
160 }
161 
162 /*
163  * c_bits - 1 if 4 bit coefficients, 0 if 3 bit coefficients
164  */
165 static inline void quantize_coefs(double *coef, int *idx, float *lpc, int order,
166  int c_bits)
167 {
168  int i;
169  const float *quant_arr = ff_tns_tmp2_map[c_bits];
170  for (i = 0; i < order; i++) {
171  idx[i] = quant_array_idx(coef[i], quant_arr, c_bits ? 16 : 8);
172  lpc[i] = quant_arr[idx[i]];
173  }
174 }
175 
176 /*
177  * 3 bits per coefficient with 8 short windows
178  */
179 /* Short blocks, pooled per group: one filter per scalefactor group so the
180  * shared sf sees uniform residuals (per-window filters caused silent
181  * sub-windows); all-or-none accept. */
183 {
184  TemporalNoiseShaping *tns = &sce->tns;
185  const int mmm = tns_max_nonpns(sce, FFMIN(sce->ics.tns_max_bands, sce->ics.max_sfb ? sce->ics.max_sfb : sce->ics.num_swb));
186  const int sfb_start = av_clip(tns_min_sfb[1][s->samplerate_index], 0, mmm);
187  const int sfb_end = av_clip(sce->ics.num_swb, 0, mmm);
188  const int c_bits = TNS_Q_BITS_IS8 == 4;
189  int count = 0;
190  FFPsyBand *const psy_bands = &s->psy.ch[s->cur_channel].psy_bands[0];
191 
192  memset(tns, 0, sizeof(*tns));
193  if (sfb_end - sfb_start <= 0)
194  return;
195  const int c_lo = sce->ics.swb_offset[sfb_start];
196  const int c_hi = sce->ics.swb_offset[sfb_end];
197  const int clen = c_hi - c_lo;
198  const int ord_g = 7;
199  if (clen <= 2*ord_g)
200  return;
201 
202  for (int wh = 0; wh < sce->ics.num_windows; wh += sce->ics.group_len[wh]) {
203  int gl = sce->ics.group_len[wh];
204  double coefs[MAX_LPC_ORDER];
205  float pooled[1024], lpc_q[TNS_MAX_ORDER];
206  float gain, gmin;
207  int ok = 1;
208 
209  /* per-window weighted spectra, concatenated over the group */
210  for (int w2 = 0; w2 < gl; w2++) {
211  int w = wh + w2;
212  float maxrms = 0.0f, floorrms;
213  for (int g = sfb_start; g < sfb_end; g++) {
214  int s0 = sce->ics.swb_offset[g], s1 = sce->ics.swb_offset[g+1];
215  float rms = sqrtf(FFMAX(psy_bands[w*16 + g].threshold, 0.0f) / FFMAX(s1 - s0, 1));
216  maxrms = FFMAX(maxrms, rms);
217  }
218  floorrms = FFMAX(maxrms * TNS_WEIGHT_FLOOR, 1e-9f);
219  for (int g = sfb_start; g < sfb_end; g++) {
220  int s0 = sce->ics.swb_offset[g], s1 = sce->ics.swb_offset[g+1];
221  float rms = sqrtf(FFMAX(psy_bands[w*16 + g].threshold, 0.0f) / FFMAX(s1 - s0, 1));
222  float wgt = 1.0f / FFMAX(rms, floorrms);
223  for (int k = s0; k < s1; k++)
224  pooled[w2*clen + (k - c_lo)] = sce->coeffs[w*128 + k] * wgt;
225  }
226  }
227 
228  gain = ff_lpc_calc_ref_coefs_f(&s->lpc, pooled, clen*gl, ord_g, coefs, 0);
229  if (!isfinite(gain) || gain < TNS_PREDGAIN_GATE || gain > TNS_PG_CLAMP)
230  continue;
231  for (int i = 0; i < ord_g; i++)
232  coefs[i] = -coefs[i];
233 
234  quantize_coefs(coefs, tns->coef_idx[wh][0], tns->coef[wh][0], ord_g, c_bits);
235  compute_lpc_coefs(tns->coef[wh][0], 0, ord_g, lpc_q, 0, 0, 0, NULL);
236 
237  /* every window must clear the measured post-quantization bar */
238  gmin = FLT_MAX;
239  for (int w2 = 0; w2 < gl; w2++) {
240  const float *msrc = pooled + w2*clen;
241  float orig_e = 0.0f, filt_e = 0.0f;
242  for (int m = 0; m < clen; m++) {
243  float acc = msrc[m];
244  for (int i = 1; i <= FFMIN(m, ord_g); i++)
245  acc += lpc_q[i-1] * msrc[m - i];
246  orig_e += msrc[m]*msrc[m];
247  filt_e += acc*acc;
248  }
249  gmin = FFMIN(gmin, orig_e / FFMAX(filt_e, 1e-9f));
250  }
251  {
252  /* accept Schmitt, run-scoped: hard entry / easy hold inside
253  * short runs (anti-gravel); isolated frames use the base bar */
254  int in_run = s->nmr ? s->nmr->prev_was_short : 0;
255  int prev_on = s->nmr ? s->nmr->tns8_prev[s->cur_channel & 15] : 0;
256  float bar = TNS_PG_C1_SHORT * (!in_run ? 1.0f : prev_on ? 0.5f : 1.8f);
257  if (gmin < bar)
258  ok = 0;
259  }
260 
261  if (ok) {
262  for (int w2 = 0; w2 < gl; w2++) {
263  int w = wh + w2;
264  tns->n_filt[w] = 1;
265  tns->length[w][0] = sfb_end - sfb_start;
266  tns->order[w][0] = ord_g;
267  tns->direction[w][0] = 0;
268  if (w2) {
269  memcpy(tns->coef_idx[w][0], tns->coef_idx[wh][0], sizeof(tns->coef_idx[w][0]));
270  memcpy(tns->coef[w][0], tns->coef[wh][0], sizeof(tns->coef[w][0]));
271  }
272  count++;
273  }
274  }
275  }
276  sce->tns.present = !!count;
277  if (s->nmr)
278  s->nmr->tns8_prev[s->cur_channel & 15] = !!count;
279 }
280 
282 {
283  TemporalNoiseShaping *tns = &sce->tns;
284  int w, count = 0;
285  const int mmm = tns_max_nonpns(sce, FFMIN(sce->ics.tns_max_bands, sce->ics.max_sfb));
286  const int is8 = sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE;
287  const int c_bits = is8 ? TNS_Q_BITS_IS8 == 4 : TNS_Q_BITS == 4;
288  const int sfb_start = av_clip(tns_min_sfb[is8][s->samplerate_index], 0, mmm);
289  const int sfb_end = av_clip(sce->ics.num_swb, 0, mmm);
290  const int order = is8 ? 7 : 12;
291  const int slant = sce->ics.window_sequence[0] == LONG_STOP_SEQUENCE ? 1 :
292  sce->ics.window_sequence[0] == LONG_START_SEQUENCE ? 0 : 2;
293  const int sfb_len = sfb_end - sfb_start;
294  const int coef_len = sce->ics.swb_offset[sfb_end] - sce->ics.swb_offset[sfb_start];
295  const int n_filt = is8 ? 1 : order != TNS_MAX_ORDER ? 2 : 3;
296  const int ord_g = order / n_filt;
297 
298  /* Apple's accept bar (minimum measured prediction gain): higher on short blocks,
299  * where a weak filter's shaped-noise tail spreads across the 50% overlap. */
300  const float c1 = is8 ? TNS_PG_C1_SHORT : TNS_PG_C1_LONG;
301  FFPsyBand *const psy_bands = &s->psy.ch[s->cur_channel].psy_bands[0];
302 
303  if (coef_len <= 0 || sfb_len <= 0) {
304  sce->tns.present = 0;
305  return;
306  }
307  if (is8) {
309  return;
310  }
311 
312  /* time-domain window length backing one coding window: a long MDCT block is
313  * fed 2048 windowed samples (current 1024 + overlap), each short block 256. */
314  const int tlen = is8 ? 256 : 2048;
315 
316  float mgain[8] = {0};
317 
318  for (w = 0; w < sce->ics.num_windows; w++) {
319  int filt, any = 0;
320 
321  /* The filter gets ran in the direction of the signal's *temporal* energy,
322  * so the quantization noise stays in the loud masked part rather than spilling
323  * into the quiet part. */
324  const float *tw = sce->ret_buf + w*tlen;
325  float e_early = 0.0f, e_late = 0.0f;
326  int ti;
327  for (ti = 0; ti < tlen/2; ti++)
328  e_early += tw[ti]*tw[ti];
329  for (; ti < tlen; ti++)
330  e_late += tw[ti]*tw[ti];
331  const int tdir = e_early > e_late;
332 
333  /* Walk the frequency regions exactly as the decoder does: filter 0 is the
334  * topmost band region, each subsequent filter covers the next region down,
335  * clamped to mmm. Each filter gets its own LPC over its own region. */
336  int top_sfb = sce->ics.num_swb;
337  for (filt = 0; filt < n_filt; filt++) {
338  double coefs[MAX_LPC_ORDER];
339  float wspec[1024], tmp[1024], lpc_q[TNS_MAX_ORDER];
340  int len_sfb = (filt == n_filt - 1) ? sfb_len - filt*(sfb_len/n_filt)
341  : sfb_len/n_filt;
342  int bot_sfb = FFMAX(0, top_sfb - len_sfb);
343  int g_lo = FFMIN(bot_sfb, mmm), g_hi = FFMIN(top_sfb, mmm);
344  int c_lo = sce->ics.swb_offset[g_lo];
345  int c_hi = sce->ics.swb_offset[g_hi];
346  int clen = c_hi - c_lo;
347  const int dir = slant != 2 ? slant : tdir;
348  float gain, orig_e = 0.0f, filt_e = 0.0f;
349  int m, i, g, inc, st;
350 
351  tns->length[w][filt] = len_sfb;
352  tns->order[w][filt] = 0; /* default: region carries no filter */
353  top_sfb = bot_sfb;
354 
355  if (clen <= 2*ord_g) /* too short for a stable order-ord_g LPC */
356  continue;
357 
358  /* Fit LPC on the perceptually-weighted spectrum X/sqrt(thr), floored
359  * to avoid a near-zero threshold blowing up a single bin (Apple). */
360  {
361  float maxrms = 0.0f, floorrms;
362  int k;
363  for (g = g_lo; g < g_hi; g++) {
364  int s0 = sce->ics.swb_offset[g], s1 = sce->ics.swb_offset[g+1];
365  float rms = sqrtf(FFMAX(psy_bands[w*16 + g].threshold, 0.0f) /
366  FFMAX(s1 - s0, 1));
367  maxrms = FFMAX(maxrms, rms);
368  }
369  floorrms = FFMAX(maxrms * TNS_WEIGHT_FLOOR, 1e-9f);
370  for (g = g_lo; g < g_hi; g++) {
371  int s0 = sce->ics.swb_offset[g], s1 = sce->ics.swb_offset[g+1];
372  float rms = sqrtf(FFMAX(psy_bands[w*16 + g].threshold, 0.0f) /
373  FFMAX(s1 - s0, 1));
374  float wgt = 1.0f / FFMAX(rms, floorrms);
375  for (k = s0; k < s1; k++)
376  wspec[k - c_lo] = sce->coeffs[w*128 + k] * wgt;
377  }
378  /* Short blocks: unwindowed fit; Hann window zeros the edges of the
379  * tiny region, wrecking the LPC. Long blocks keep the window. */
380  gain = ff_lpc_calc_ref_coefs_f(&s->lpc, wspec, clen, ord_g, coefs, !is8);
381  }
382  /* Reject below the first gate and above the clamp (poles near unit circle). */
383  if (!isfinite(gain) || gain < TNS_PREDGAIN_GATE || gain > TNS_PG_CLAMP)
384  continue;
385  /* Negate: ff_lpc_calc_ref_coefs_f sign convention is opposite to what
386  * ff_aac_apply_tns's MA filter needs; fed unnegated, it anti-whitens. */
387  for (i = 0; i < ord_g; i++)
388  coefs[i] = -coefs[i];
389 
390  /* Quantize, then build the decoder's direct-form LPC. */
391  quantize_coefs(coefs, tns->coef_idx[w][filt], tns->coef[w][filt],
392  ord_g, c_bits);
393  compute_lpc_coefs(tns->coef[w][filt], 0, ord_g, lpc_q, 0, 0, 0, NULL);
394 
395  /* Apply the quantized filter to the weighted spectrum and measure gain. */
396  const float *msrc = wspec;
397  inc = dir ? -1 : 1;
398  st = dir ? clen - 1 : 0;
399  for (m = 0; m < clen; m++) {
400  int idx = st + m*inc;
401  float acc = msrc[idx];
402  for (i = 1; i <= FFMIN(m, ord_g); i++)
403  acc += lpc_q[i-1] * msrc[idx - i*inc];
404  tmp[idx] = acc;
405  }
406  for (m = 0; m < clen; m++) {
407  orig_e += msrc[m]*msrc[m];
408  filt_e += tmp[m]*tmp[m];
409  }
410  filt_e = FFMAX(filt_e, 1e-9f);
411 
412  /* Keep only if measured post-quantization gain clears C1 (Apple's outcome gate). */
413  if (orig_e < c1*filt_e)
414  continue;
415 
416  tns->order[w][filt] = ord_g;
417  tns->direction[w][filt] = dir;
418  mgain[w] = orig_e / filt_e;
419  any = 1;
420  }
421  tns->n_filt[w] = any ? n_filt : 0;
422  if (any)
423  count++;
424  }
425 
426  /* per-window path: group-uniformity gate (mismatched whitening within a
427  * shared-sf group silences sub-windows) */
428  if (is8 && count) {
429  const float gspread = 2.0f;
430  count = 0;
431  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
432  int gl = sce->ics.group_len[w], drop = 0;
433  float gmin = FLT_MAX, gmax = 0.0f;
434  for (int w2 = w; w2 < w + gl; w2++) {
435  if (!tns->n_filt[w2] || mgain[w2] <= 0.0f) { drop = 1; break; }
436  gmin = FFMIN(gmin, mgain[w2]);
437  gmax = FFMAX(gmax, mgain[w2]);
438  }
439  if (!drop && gmax > gspread * gmin)
440  drop = 1;
441  for (int w2 = w; w2 < w + gl; w2++) {
442  if (drop) {
443  tns->n_filt[w2] = 0;
444  for (int f2 = 0; f2 < n_filt; f2++)
445  tns->order[w2][f2] = 0;
446  } else if (tns->n_filt[w2]) {
447  count++;
448  }
449  }
450  }
451  }
452  sce->tns.present = !!count;
453 }
av_clip
#define av_clip
Definition: common.h:100
TNS_Q_BITS_IS8
#define TNS_Q_BITS_IS8
Definition: aacenc_tns.c:40
libm.h
TemporalNoiseShaping::coef_idx
int coef_idx[8][4][TNS_MAX_ORDER]
Definition: aacenc.h:102
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:154
TNS_PG_C1_LONG
#define TNS_PG_C1_LONG
Definition: aacenc_tns.c:48
compress_coeffs
static int compress_coeffs(int *coef, int order, int c_bits)
Definition: aacenc_tns.c:53
TemporalNoiseShaping::present
int present
Definition: aacdec.h:192
float.h
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
c1
static const uint64_t c1
Definition: murmur3.c:52
IndividualChannelStream::num_swb
int num_swb
number of scalefactor window bands
Definition: aacdec.h:178
TNS_Q_BITS
#define TNS_Q_BITS
Definition: aacenc_tns.c:37
SingleChannelElement::coeffs
float coeffs[1024]
coefficients for IMDCT, maybe processed
Definition: aacenc.h:121
SingleChannelElement::ret_buf
float ret_buf[2048]
PCM output buffer.
Definition: aacenc.h:122
TNS_PG_CLAMP
#define TNS_PG_CLAMP
Definition: aacenc_tns.c:50
SingleChannelElement::ics
IndividualChannelStream ics
Definition: aacdec.h:218
NOISE_BT
@ NOISE_BT
Spectral data are scaled white noise not coded in the bitstream.
Definition: aac.h:75
g
const char * g
Definition: vf_curves.c:128
EIGHT_SHORT_SEQUENCE
@ EIGHT_SHORT_SEQUENCE
Definition: aac.h:66
TemporalNoiseShaping::direction
int direction[8][4]
Definition: aacdec.h:195
isfinite
#define isfinite(x)
Definition: libm.h:361
TNS_PG_C1_SHORT
#define TNS_PG_C1_SHORT
Definition: aacenc_tns.c:49
TNS_WEIGHT_FLOOR
#define TNS_WEIGHT_FLOOR
Definition: aacenc_tns.c:51
IndividualChannelStream
Individual Channel Stream.
Definition: aacdec.h:169
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
NULL
#define NULL
Definition: coverity.c:32
ff_aac_apply_tns
void ff_aac_apply_tns(AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc_tns.c:112
FFPsyBand
single band psychoacoustic information
Definition: psymodel.h:50
aactab.h
ff_aac_encode_tns_info
void ff_aac_encode_tns_info(AACEncContext *s, SingleChannelElement *sce)
Encode TNS data.
Definition: aacenc_tns.c:71
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
TNS_MAX_ORDER
#define TNS_MAX_ORDER
Definition: aac.h:36
inc
static int inc(int num, int period)
Definition: perlin.c:34
IndividualChannelStream::window_sequence
enum WindowSequence window_sequence[2]
Definition: aacdec.h:171
f
f
Definition: af_crystalizer.c:122
ff_lpc_calc_ref_coefs_f
double ff_lpc_calc_ref_coefs_f(LPCContext *s, const float *samples, int len, int order, double *ref, int apply_window)
Definition: lpc.c:209
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
MAX_LPC_ORDER
#define MAX_LPC_ORDER
Definition: lpc.h:37
size
int size
Definition: twinvq_data.h:10344
quant_array_idx
static int quant_array_idx(const float val, const float *arr, const int num)
Definition: aacenc_utils.h:147
SingleChannelElement::band_type
enum BandType band_type[128]
band types
Definition: aacdec.h:221
ff_tns_tmp2_map
const float *const ff_tns_tmp2_map[4]
Definition: aactab.c:142
tns_min_sfb
static const uint8_t *const tns_min_sfb[2]
Definition: aacenctab.h:125
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aacdec.h:217
search_for_tns_short_pooled
static void search_for_tns_short_pooled(AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc_tns.c:182
compute_lpc_coefs
static int compute_lpc_coefs(const LPC_TYPE *autoc, int i, int max_order, LPC_TYPE *lpc, int lpc_stride, int fail, int normalize, LPC_TYPE *err_ptr)
Levinson-Durbin recursion.
Definition: lpc_functions.h:54
IndividualChannelStream::num_windows
int num_windows
Definition: aacdec.h:179
ff_aac_search_for_tns
void ff_aac_search_for_tns(AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc_tns.c:281
LONG_STOP_SEQUENCE
@ LONG_STOP_SEQUENCE
Definition: aac.h:67
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:177
s
uint8_t s
Definition: llvidencdsp.c:39
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
TemporalNoiseShaping::order
int order[8][4]
Definition: aacdec.h:196
filt
static const int8_t filt[NUMTAPS *2]
Definition: af_earwax.c:40
IndividualChannelStream::tns_max_bands
int tns_max_bands
Definition: aacdec.h:180
TemporalNoiseShaping::length
int length[8][4]
Definition: aacdec.h:194
LONG_START_SEQUENCE
@ LONG_START_SEQUENCE
Definition: aac.h:65
TemporalNoiseShaping::coef
float coef[8][4][TNS_MAX_ORDER]
Definition: aacenc.h:103
SingleChannelElement::tns
TemporalNoiseShaping tns
Definition: aacdec.h:220
AACEncContext
AAC encoder context.
Definition: aacenc.h:258
lpc_functions.h
tns_max_nonpns
static int tns_max_nonpns(const SingleChannelElement *sce, int mmm)
Definition: aacenc_tns.c:103
TemporalNoiseShaping
Temporal Noise Shaping.
Definition: aacdec.h:191
quantize_coefs
static void quantize_coefs(double *coef, int *idx, float *lpc, int order, int c_bits)
Definition: aacenc_tns.c:165
aacenc_tns.h
w
uint8_t w
Definition: llvidencdsp.c:39
IndividualChannelStream::max_sfb
uint8_t max_sfb
number of scalefactor bands per group
Definition: aacdec.h:170
b0
static double b0(void *priv, double x, double y)
Definition: vf_xfade.c:2033
aacenc_utils.h
IndividualChannelStream::group_len
uint8_t group_len[8]
Definition: aacdec.h:175
TemporalNoiseShaping::n_filt
int n_filt[8]
Definition: aacdec.h:193
aacenc.h