FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
aaccoder.c
Go to the documentation of this file.
1 /*
2  * AAC coefficients encoder
3  * Copyright (C) 2008-2009 Konstantin Shishkov
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 coefficients encoder
25  */
26 
27 /***********************************
28  * TODOs:
29  * speedup quantizer selection
30  * add sane pulse detection
31  ***********************************/
32 
33 #include "libavutil/libm.h" // brought forward to work around cygwin header breakage
34 
35 #include <float.h>
36 #include "libavutil/mathematics.h"
37 #include "avcodec.h"
38 #include "put_bits.h"
39 #include "aac.h"
40 #include "aacenc.h"
41 #include "aactab.h"
42 #include "aacenctab.h"
43 #include "aacenc_utils.h"
44 #include "aacenc_quantization.h"
45 #include "aac_tablegen_decl.h"
46 
47 #include "aacenc_is.h"
48 #include "aacenc_tns.h"
49 #include "aacenc_pred.h"
50 
51 /** Frequency in Hz for lower limit of noise substitution **/
52 #define NOISE_LOW_LIMIT 4500
53 
54 /* Energy spread threshold value below which no PNS is used, this corresponds to
55  * typically around 17Khz, after which PNS usage decays ending at 19Khz */
56 #define NOISE_SPREAD_THRESHOLD 0.5f
57 
58 /* This constant gets divided by lambda to return ~1.65 which when multiplied
59  * by the band->threshold and compared to band->energy is the boundary between
60  * excessive PNS and little PNS usage. */
61 #define NOISE_LAMBDA_NUMERATOR 252.1f
62 
63 /**
64  * structure used in optimal codebook search
65  */
66 typedef struct BandCodingPath {
67  int prev_idx; ///< pointer to the previous path point
68  float cost; ///< path cost
69  int run;
71 
72 /**
73  * Encode band info for single window group bands.
74  */
76  int win, int group_len, const float lambda)
77 {
78  BandCodingPath path[120][CB_TOT_ALL];
79  int w, swb, cb, start, size;
80  int i, j;
81  const int max_sfb = sce->ics.max_sfb;
82  const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
83  const int run_esc = (1 << run_bits) - 1;
84  int idx, ppos, count;
85  int stackrun[120], stackcb[120], stack_len;
86  float next_minrd = INFINITY;
87  int next_mincb = 0;
88 
89  abs_pow34_v(s->scoefs, sce->coeffs, 1024);
90  start = win*128;
91  for (cb = 0; cb < CB_TOT_ALL; cb++) {
92  path[0][cb].cost = 0.0f;
93  path[0][cb].prev_idx = -1;
94  path[0][cb].run = 0;
95  }
96  for (swb = 0; swb < max_sfb; swb++) {
97  size = sce->ics.swb_sizes[swb];
98  if (sce->zeroes[win*16 + swb]) {
99  for (cb = 0; cb < CB_TOT_ALL; cb++) {
100  path[swb+1][cb].prev_idx = cb;
101  path[swb+1][cb].cost = path[swb][cb].cost;
102  path[swb+1][cb].run = path[swb][cb].run + 1;
103  }
104  } else {
105  float minrd = next_minrd;
106  int mincb = next_mincb;
107  next_minrd = INFINITY;
108  next_mincb = 0;
109  for (cb = 0; cb < CB_TOT_ALL; cb++) {
110  float cost_stay_here, cost_get_here;
111  float rd = 0.0f;
112  if (cb >= 12 && sce->band_type[win*16+swb] < aac_cb_out_map[cb] ||
113  cb < aac_cb_in_map[sce->band_type[win*16+swb]] && sce->band_type[win*16+swb] > aac_cb_out_map[cb]) {
114  path[swb+1][cb].prev_idx = -1;
115  path[swb+1][cb].cost = INFINITY;
116  path[swb+1][cb].run = path[swb][cb].run + 1;
117  continue;
118  }
119  for (w = 0; w < group_len; w++) {
120  FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(win+w)*16+swb];
121  rd += quantize_band_cost(s, &sce->coeffs[start + w*128],
122  &s->scoefs[start + w*128], size,
123  sce->sf_idx[(win+w)*16+swb], aac_cb_out_map[cb],
124  lambda / band->threshold, INFINITY, NULL, 0);
125  }
126  cost_stay_here = path[swb][cb].cost + rd;
127  cost_get_here = minrd + rd + run_bits + 4;
128  if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
129  != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
130  cost_stay_here += run_bits;
131  if (cost_get_here < cost_stay_here) {
132  path[swb+1][cb].prev_idx = mincb;
133  path[swb+1][cb].cost = cost_get_here;
134  path[swb+1][cb].run = 1;
135  } else {
136  path[swb+1][cb].prev_idx = cb;
137  path[swb+1][cb].cost = cost_stay_here;
138  path[swb+1][cb].run = path[swb][cb].run + 1;
139  }
140  if (path[swb+1][cb].cost < next_minrd) {
141  next_minrd = path[swb+1][cb].cost;
142  next_mincb = cb;
143  }
144  }
145  }
146  start += sce->ics.swb_sizes[swb];
147  }
148 
149  //convert resulting path from backward-linked list
150  stack_len = 0;
151  idx = 0;
152  for (cb = 1; cb < CB_TOT_ALL; cb++)
153  if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
154  idx = cb;
155  ppos = max_sfb;
156  while (ppos > 0) {
157  av_assert1(idx >= 0);
158  cb = idx;
159  stackrun[stack_len] = path[ppos][cb].run;
160  stackcb [stack_len] = cb;
161  idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;
162  ppos -= path[ppos][cb].run;
163  stack_len++;
164  }
165  //perform actual band info encoding
166  start = 0;
167  for (i = stack_len - 1; i >= 0; i--) {
168  cb = aac_cb_out_map[stackcb[i]];
169  put_bits(&s->pb, 4, cb);
170  count = stackrun[i];
171  memset(sce->zeroes + win*16 + start, !cb, count);
172  //XXX: memset when band_type is also uint8_t
173  for (j = 0; j < count; j++) {
174  sce->band_type[win*16 + start] = cb;
175  start++;
176  }
177  while (count >= run_esc) {
178  put_bits(&s->pb, run_bits, run_esc);
179  count -= run_esc;
180  }
181  put_bits(&s->pb, run_bits, count);
182  }
183 }
184 
186  int win, int group_len, const float lambda)
187 {
188  BandCodingPath path[120][CB_TOT_ALL];
189  int w, swb, cb, start, size;
190  int i, j;
191  const int max_sfb = sce->ics.max_sfb;
192  const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
193  const int run_esc = (1 << run_bits) - 1;
194  int idx, ppos, count;
195  int stackrun[120], stackcb[120], stack_len;
196  float next_minbits = INFINITY;
197  int next_mincb = 0;
198 
199  abs_pow34_v(s->scoefs, sce->coeffs, 1024);
200  start = win*128;
201  for (cb = 0; cb < CB_TOT_ALL; cb++) {
202  path[0][cb].cost = run_bits+4;
203  path[0][cb].prev_idx = -1;
204  path[0][cb].run = 0;
205  }
206  for (swb = 0; swb < max_sfb; swb++) {
207  size = sce->ics.swb_sizes[swb];
208  if (sce->zeroes[win*16 + swb]) {
209  float cost_stay_here = path[swb][0].cost;
210  float cost_get_here = next_minbits + run_bits + 4;
211  if ( run_value_bits[sce->ics.num_windows == 8][path[swb][0].run]
212  != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1])
213  cost_stay_here += run_bits;
214  if (cost_get_here < cost_stay_here) {
215  path[swb+1][0].prev_idx = next_mincb;
216  path[swb+1][0].cost = cost_get_here;
217  path[swb+1][0].run = 1;
218  } else {
219  path[swb+1][0].prev_idx = 0;
220  path[swb+1][0].cost = cost_stay_here;
221  path[swb+1][0].run = path[swb][0].run + 1;
222  }
223  next_minbits = path[swb+1][0].cost;
224  next_mincb = 0;
225  for (cb = 1; cb < CB_TOT_ALL; cb++) {
226  path[swb+1][cb].cost = 61450;
227  path[swb+1][cb].prev_idx = -1;
228  path[swb+1][cb].run = 0;
229  }
230  } else {
231  float minbits = next_minbits;
232  int mincb = next_mincb;
233  int startcb = sce->band_type[win*16+swb];
234  startcb = aac_cb_in_map[startcb];
235  next_minbits = INFINITY;
236  next_mincb = 0;
237  for (cb = 0; cb < startcb; cb++) {
238  path[swb+1][cb].cost = 61450;
239  path[swb+1][cb].prev_idx = -1;
240  path[swb+1][cb].run = 0;
241  }
242  for (cb = startcb; cb < CB_TOT_ALL; cb++) {
243  float cost_stay_here, cost_get_here;
244  float bits = 0.0f;
245  if (cb >= 12 && sce->band_type[win*16+swb] != aac_cb_out_map[cb]) {
246  path[swb+1][cb].cost = 61450;
247  path[swb+1][cb].prev_idx = -1;
248  path[swb+1][cb].run = 0;
249  continue;
250  }
251  for (w = 0; w < group_len; w++) {
252  bits += quantize_band_cost(s, &sce->coeffs[start + w*128],
253  &s->scoefs[start + w*128], size,
254  sce->sf_idx[win*16+swb],
255  aac_cb_out_map[cb],
256  0, INFINITY, NULL, 0);
257  }
258  cost_stay_here = path[swb][cb].cost + bits;
259  cost_get_here = minbits + bits + run_bits + 4;
260  if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
261  != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
262  cost_stay_here += run_bits;
263  if (cost_get_here < cost_stay_here) {
264  path[swb+1][cb].prev_idx = mincb;
265  path[swb+1][cb].cost = cost_get_here;
266  path[swb+1][cb].run = 1;
267  } else {
268  path[swb+1][cb].prev_idx = cb;
269  path[swb+1][cb].cost = cost_stay_here;
270  path[swb+1][cb].run = path[swb][cb].run + 1;
271  }
272  if (path[swb+1][cb].cost < next_minbits) {
273  next_minbits = path[swb+1][cb].cost;
274  next_mincb = cb;
275  }
276  }
277  }
278  start += sce->ics.swb_sizes[swb];
279  }
280 
281  //convert resulting path from backward-linked list
282  stack_len = 0;
283  idx = 0;
284  for (cb = 1; cb < CB_TOT_ALL; cb++)
285  if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
286  idx = cb;
287  ppos = max_sfb;
288  while (ppos > 0) {
289  av_assert1(idx >= 0);
290  cb = idx;
291  stackrun[stack_len] = path[ppos][cb].run;
292  stackcb [stack_len] = cb;
293  idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;
294  ppos -= path[ppos][cb].run;
295  stack_len++;
296  }
297  //perform actual band info encoding
298  start = 0;
299  for (i = stack_len - 1; i >= 0; i--) {
300  cb = aac_cb_out_map[stackcb[i]];
301  put_bits(&s->pb, 4, cb);
302  count = stackrun[i];
303  memset(sce->zeroes + win*16 + start, !cb, count);
304  //XXX: memset when band_type is also uint8_t
305  for (j = 0; j < count; j++) {
306  sce->band_type[win*16 + start] = cb;
307  start++;
308  }
309  while (count >= run_esc) {
310  put_bits(&s->pb, run_bits, run_esc);
311  count -= run_esc;
312  }
313  put_bits(&s->pb, run_bits, count);
314  }
315 }
316 
317 typedef struct TrellisPath {
318  float cost;
319  int prev;
320 } TrellisPath;
321 
322 #define TRELLIS_STAGES 121
323 #define TRELLIS_STATES (SCALE_MAX_DIFF+1)
324 
326 {
327  int w, g, start = 0;
328  int minscaler_n = sce->sf_idx[0], minscaler_i = sce->sf_idx[0];
329  int bands = 0;
330 
331  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
332  start = 0;
333  for (g = 0; g < sce->ics.num_swb; g++) {
334  if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) {
335  sce->sf_idx[w*16+g] = av_clip(ceilf(log2f(sce->is_ener[w*16+g])*2), -155, 100);
336  minscaler_i = FFMIN(minscaler_i, sce->sf_idx[w*16+g]);
337  bands++;
338  } else if (sce->band_type[w*16+g] == NOISE_BT) {
339  sce->sf_idx[w*16+g] = av_clip(4+log2f(sce->pns_ener[w*16+g])*2, -100, 155);
340  minscaler_n = FFMIN(minscaler_n, sce->sf_idx[w*16+g]);
341  bands++;
342  }
343  start += sce->ics.swb_sizes[g];
344  }
345  }
346 
347  if (!bands)
348  return;
349 
350  /* Clip the scalefactor indices */
351  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
352  for (g = 0; g < sce->ics.num_swb; g++) {
353  if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) {
354  sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler_i, minscaler_i + SCALE_MAX_DIFF);
355  } else if (sce->band_type[w*16+g] == NOISE_BT) {
356  sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler_n, minscaler_n + SCALE_MAX_DIFF);
357  }
358  }
359  }
360 }
361 
364  const float lambda)
365 {
366  int q, w, w2, g, start = 0;
367  int i, j;
368  int idx;
370  int bandaddr[TRELLIS_STAGES];
371  int minq;
372  float mincost;
373  float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f;
374  int q0, q1, qcnt = 0;
375 
376  for (i = 0; i < 1024; i++) {
377  float t = fabsf(sce->coeffs[i]);
378  if (t > 0.0f) {
379  q0f = FFMIN(q0f, t);
380  q1f = FFMAX(q1f, t);
381  qnrgf += t*t;
382  qcnt++;
383  }
384  }
385 
386  if (!qcnt) {
387  memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
388  memset(sce->zeroes, 1, sizeof(sce->zeroes));
389  return;
390  }
391 
392  //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
393  q0 = coef2minsf(q0f);
394  //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
395  q1 = coef2maxsf(q1f);
396  if (q1 - q0 > 60) {
397  int q0low = q0;
398  int q1high = q1;
399  //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped
400  int qnrg = av_clip_uint8(log2f(sqrtf(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512);
401  q1 = qnrg + 30;
402  q0 = qnrg - 30;
403  if (q0 < q0low) {
404  q1 += q0low - q0;
405  q0 = q0low;
406  } else if (q1 > q1high) {
407  q0 -= q1 - q1high;
408  q1 = q1high;
409  }
410  }
411 
412  for (i = 0; i < TRELLIS_STATES; i++) {
413  paths[0][i].cost = 0.0f;
414  paths[0][i].prev = -1;
415  }
416  for (j = 1; j < TRELLIS_STAGES; j++) {
417  for (i = 0; i < TRELLIS_STATES; i++) {
418  paths[j][i].cost = INFINITY;
419  paths[j][i].prev = -2;
420  }
421  }
422  idx = 1;
423  abs_pow34_v(s->scoefs, sce->coeffs, 1024);
424  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
425  start = w*128;
426  for (g = 0; g < sce->ics.num_swb; g++) {
427  const float *coefs = &sce->coeffs[start];
428  float qmin, qmax;
429  int nz = 0;
430 
431  bandaddr[idx] = w * 16 + g;
432  qmin = INT_MAX;
433  qmax = 0.0f;
434  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
435  FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
436  if (band->energy <= band->threshold || band->threshold == 0.0f) {
437  sce->zeroes[(w+w2)*16+g] = 1;
438  continue;
439  }
440  sce->zeroes[(w+w2)*16+g] = 0;
441  nz = 1;
442  for (i = 0; i < sce->ics.swb_sizes[g]; i++) {
443  float t = fabsf(coefs[w2*128+i]);
444  if (t > 0.0f)
445  qmin = FFMIN(qmin, t);
446  qmax = FFMAX(qmax, t);
447  }
448  }
449  if (nz) {
450  int minscale, maxscale;
451  float minrd = INFINITY;
452  float maxval;
453  //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
454  minscale = coef2minsf(qmin);
455  //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
456  maxscale = coef2maxsf(qmax);
457  minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
458  maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
459  maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);
460  for (q = minscale; q < maxscale; q++) {
461  float dist = 0;
462  int cb = find_min_book(maxval, sce->sf_idx[w*16+g]);
463  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
464  FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
465  dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g],
466  q + q0, cb, lambda / band->threshold, INFINITY, NULL, 0);
467  }
468  minrd = FFMIN(minrd, dist);
469 
470  for (i = 0; i < q1 - q0; i++) {
471  float cost;
472  cost = paths[idx - 1][i].cost + dist
474  if (cost < paths[idx][q].cost) {
475  paths[idx][q].cost = cost;
476  paths[idx][q].prev = i;
477  }
478  }
479  }
480  } else {
481  for (q = 0; q < q1 - q0; q++) {
482  paths[idx][q].cost = paths[idx - 1][q].cost + 1;
483  paths[idx][q].prev = q;
484  }
485  }
486  sce->zeroes[w*16+g] = !nz;
487  start += sce->ics.swb_sizes[g];
488  idx++;
489  }
490  }
491  idx--;
492  mincost = paths[idx][0].cost;
493  minq = 0;
494  for (i = 1; i < TRELLIS_STATES; i++) {
495  if (paths[idx][i].cost < mincost) {
496  mincost = paths[idx][i].cost;
497  minq = i;
498  }
499  }
500  while (idx) {
501  sce->sf_idx[bandaddr[idx]] = minq + q0;
502  minq = paths[idx][minq].prev;
503  idx--;
504  }
505  //set the same quantizers inside window groups
506  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
507  for (g = 0; g < sce->ics.num_swb; g++)
508  for (w2 = 1; w2 < sce->ics.group_len[w]; w2++)
509  sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];
510 }
511 
512 /**
513  * two-loop quantizers search taken from ISO 13818-7 Appendix C
514  */
516  AACEncContext *s,
518  const float lambda)
519 {
520  int start = 0, i, w, w2, g;
521  int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels * (lambda / 120.f);
522  float dists[128] = { 0 }, uplims[128] = { 0 };
523  float maxvals[128];
524  int fflag, minscaler;
525  int its = 0;
526  int allz = 0;
527  float minthr = INFINITY;
528 
529  // for values above this the decoder might end up in an endless loop
530  // due to always having more bits than what can be encoded.
531  destbits = FFMIN(destbits, 5800);
532  //XXX: some heuristic to determine initial quantizers will reduce search time
533  //determine zero bands and upper limits
534  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
535  for (g = 0; g < sce->ics.num_swb; g++) {
536  int nz = 0;
537  float uplim = 0.0f, energy = 0.0f;
538  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
539  FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
540  uplim += band->threshold;
541  energy += band->energy;
542  if (band->energy <= band->threshold || band->threshold == 0.0f) {
543  sce->zeroes[(w+w2)*16+g] = 1;
544  continue;
545  }
546  nz = 1;
547  }
548  uplims[w*16+g] = uplim *512;
549  sce->zeroes[w*16+g] = !nz;
550  if (nz)
551  minthr = FFMIN(minthr, uplim);
552  allz |= nz;
553  }
554  }
555  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
556  for (g = 0; g < sce->ics.num_swb; g++) {
557  if (sce->zeroes[w*16+g]) {
558  sce->sf_idx[w*16+g] = SCALE_ONE_POS;
559  continue;
560  }
561  sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59);
562  }
563  }
564 
565  if (!allz)
566  return;
567  abs_pow34_v(s->scoefs, sce->coeffs, 1024);
568 
569  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
570  start = w*128;
571  for (g = 0; g < sce->ics.num_swb; g++) {
572  const float *scaled = s->scoefs + start;
573  maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);
574  start += sce->ics.swb_sizes[g];
575  }
576  }
577 
578  //perform two-loop search
579  //outer loop - improve quality
580  do {
581  int tbits, qstep;
582  minscaler = sce->sf_idx[0];
583  //inner loop - quantize spectrum to fit into given number of bits
584  qstep = its ? 1 : 32;
585  do {
586  int prev = -1;
587  tbits = 0;
588  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
589  start = w*128;
590  for (g = 0; g < sce->ics.num_swb; g++) {
591  const float *coefs = &sce->coeffs[start];
592  const float *scaled = &s->scoefs[start];
593  int bits = 0;
594  int cb;
595  float dist = 0.0f;
596 
597  if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) {
598  start += sce->ics.swb_sizes[g];
599  continue;
600  }
601  minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
602  cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
603  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
604  int b;
605  dist += quantize_band_cost(s, coefs + w2*128,
606  scaled + w2*128,
607  sce->ics.swb_sizes[g],
608  sce->sf_idx[w*16+g],
609  cb,
610  1.0f,
611  INFINITY,
612  &b,
613  0);
614  bits += b;
615  }
616  dists[w*16+g] = dist - bits;
617  if (prev != -1) {
618  bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO];
619  }
620  tbits += bits;
621  start += sce->ics.swb_sizes[g];
622  prev = sce->sf_idx[w*16+g];
623  }
624  }
625  if (tbits > destbits) {
626  for (i = 0; i < 128; i++)
627  if (sce->sf_idx[i] < 218 - qstep)
628  sce->sf_idx[i] += qstep;
629  } else {
630  for (i = 0; i < 128; i++)
631  if (sce->sf_idx[i] > 60 - qstep)
632  sce->sf_idx[i] -= qstep;
633  }
634  qstep >>= 1;
635  if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217)
636  qstep = 1;
637  } while (qstep);
638 
639  fflag = 0;
640  minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF);
641 
642  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
643  for (g = 0; g < sce->ics.num_swb; g++) {
644  int prevsc = sce->sf_idx[w*16+g];
645  if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) {
646  if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1))
647  sce->sf_idx[w*16+g]--;
648  else //Try to make sure there is some energy in every band
649  sce->sf_idx[w*16+g]-=2;
650  }
651  sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF);
652  sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219);
653  if (sce->sf_idx[w*16+g] != prevsc)
654  fflag = 1;
655  sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
656  }
657  }
658  its++;
659  } while (fflag && its < 10);
660 }
661 
664  const float lambda)
665 {
666  int start = 0, i, w, w2, g;
667  float uplim[128], maxq[128];
668  int minq, maxsf;
669  float distfact = ((sce->ics.num_windows > 1) ? 85.80 : 147.84) / lambda;
670  int last = 0, lastband = 0, curband = 0;
671  float avg_energy = 0.0;
672  if (sce->ics.num_windows == 1) {
673  start = 0;
674  for (i = 0; i < 1024; i++) {
675  if (i - start >= sce->ics.swb_sizes[curband]) {
676  start += sce->ics.swb_sizes[curband];
677  curband++;
678  }
679  if (sce->coeffs[i]) {
680  avg_energy += sce->coeffs[i] * sce->coeffs[i];
681  last = i;
682  lastband = curband;
683  }
684  }
685  } else {
686  for (w = 0; w < 8; w++) {
687  const float *coeffs = &sce->coeffs[w*128];
688  curband = start = 0;
689  for (i = 0; i < 128; i++) {
690  if (i - start >= sce->ics.swb_sizes[curband]) {
691  start += sce->ics.swb_sizes[curband];
692  curband++;
693  }
694  if (coeffs[i]) {
695  avg_energy += coeffs[i] * coeffs[i];
696  last = FFMAX(last, i);
697  lastband = FFMAX(lastband, curband);
698  }
699  }
700  }
701  }
702  last++;
703  avg_energy /= last;
704  if (avg_energy == 0.0f) {
705  for (i = 0; i < FF_ARRAY_ELEMS(sce->sf_idx); i++)
706  sce->sf_idx[i] = SCALE_ONE_POS;
707  return;
708  }
709  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
710  start = w*128;
711  for (g = 0; g < sce->ics.num_swb; g++) {
712  float *coefs = &sce->coeffs[start];
713  const int size = sce->ics.swb_sizes[g];
714  int start2 = start, end2 = start + size, peakpos = start;
715  float maxval = -1, thr = 0.0f, t;
716  maxq[w*16+g] = 0.0f;
717  if (g > lastband) {
718  maxq[w*16+g] = 0.0f;
719  start += size;
720  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++)
721  memset(coefs + w2*128, 0, sizeof(coefs[0])*size);
722  continue;
723  }
724  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
725  for (i = 0; i < size; i++) {
726  float t = coefs[w2*128+i]*coefs[w2*128+i];
727  maxq[w*16+g] = FFMAX(maxq[w*16+g], fabsf(coefs[w2*128 + i]));
728  thr += t;
729  if (sce->ics.num_windows == 1 && maxval < t) {
730  maxval = t;
731  peakpos = start+i;
732  }
733  }
734  }
735  if (sce->ics.num_windows == 1) {
736  start2 = FFMAX(peakpos - 2, start2);
737  end2 = FFMIN(peakpos + 3, end2);
738  } else {
739  start2 -= start;
740  end2 -= start;
741  }
742  start += size;
743  thr = pow(thr / (avg_energy * (end2 - start2)), 0.3 + 0.1*(lastband - g) / lastband);
744  t = 1.0 - (1.0 * start2 / last);
745  uplim[w*16+g] = distfact / (1.4 * thr + t*t*t + 0.075);
746  }
747  }
748  memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
749  abs_pow34_v(s->scoefs, sce->coeffs, 1024);
750  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
751  start = w*128;
752  for (g = 0; g < sce->ics.num_swb; g++) {
753  const float *coefs = &sce->coeffs[start];
754  const float *scaled = &s->scoefs[start];
755  const int size = sce->ics.swb_sizes[g];
756  int scf, prev_scf, step;
757  int min_scf = -1, max_scf = 256;
758  float curdiff;
759  if (maxq[w*16+g] < 21.544) {
760  sce->zeroes[w*16+g] = 1;
761  start += size;
762  continue;
763  }
764  sce->zeroes[w*16+g] = 0;
765  scf = prev_scf = av_clip(SCALE_ONE_POS - SCALE_DIV_512 - log2f(1/maxq[w*16+g])*16/3, 60, 218);
766  for (;;) {
767  float dist = 0.0f;
768  int quant_max;
769 
770  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
771  int b;
772  dist += quantize_band_cost(s, coefs + w2*128,
773  scaled + w2*128,
774  sce->ics.swb_sizes[g],
775  scf,
776  ESC_BT,
777  lambda,
778  INFINITY,
779  &b,
780  0);
781  dist -= b;
782  }
783  dist *= 1.0f / 512.0f / lambda;
784  quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[POW_SF2_ZERO - scf + SCALE_ONE_POS - SCALE_DIV_512], ROUND_STANDARD);
785  if (quant_max >= 8191) { // too much, return to the previous quantizer
786  sce->sf_idx[w*16+g] = prev_scf;
787  break;
788  }
789  prev_scf = scf;
790  curdiff = fabsf(dist - uplim[w*16+g]);
791  if (curdiff <= 1.0f)
792  step = 0;
793  else
794  step = log2f(curdiff);
795  if (dist > uplim[w*16+g])
796  step = -step;
797  scf += step;
798  scf = av_clip_uint8(scf);
799  step = scf - prev_scf;
800  if (FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) {
801  sce->sf_idx[w*16+g] = av_clip(scf, min_scf, max_scf);
802  break;
803  }
804  if (step > 0)
805  min_scf = prev_scf;
806  else
807  max_scf = prev_scf;
808  }
809  start += size;
810  }
811  }
812  minq = sce->sf_idx[0] ? sce->sf_idx[0] : INT_MAX;
813  for (i = 1; i < 128; i++) {
814  if (!sce->sf_idx[i])
815  sce->sf_idx[i] = sce->sf_idx[i-1];
816  else
817  minq = FFMIN(minq, sce->sf_idx[i]);
818  }
819  if (minq == INT_MAX)
820  minq = 0;
821  minq = FFMIN(minq, SCALE_MAX_POS);
822  maxsf = FFMIN(minq + SCALE_MAX_DIFF, SCALE_MAX_POS);
823  for (i = 126; i >= 0; i--) {
824  if (!sce->sf_idx[i])
825  sce->sf_idx[i] = sce->sf_idx[i+1];
826  sce->sf_idx[i] = av_clip(sce->sf_idx[i], minq, maxsf);
827  }
828 }
829 
832  const float lambda)
833 {
834  int i, w, w2, g;
835  int minq = 255;
836 
837  memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
838  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
839  for (g = 0; g < sce->ics.num_swb; g++) {
840  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
841  FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
842  if (band->energy <= band->threshold) {
843  sce->sf_idx[(w+w2)*16+g] = 218;
844  sce->zeroes[(w+w2)*16+g] = 1;
845  } else {
846  sce->sf_idx[(w+w2)*16+g] = av_clip(SCALE_ONE_POS - SCALE_DIV_512 + log2f(band->threshold), 80, 218);
847  sce->zeroes[(w+w2)*16+g] = 0;
848  }
849  minq = FFMIN(minq, sce->sf_idx[(w+w2)*16+g]);
850  }
851  }
852  }
853  for (i = 0; i < 128; i++) {
854  sce->sf_idx[i] = 140;
855  //av_clip(sce->sf_idx[i], minq, minq + SCALE_MAX_DIFF - 1);
856  }
857  //set the same quantizers inside window groups
858  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
859  for (g = 0; g < sce->ics.num_swb; g++)
860  for (w2 = 1; w2 < sce->ics.group_len[w]; w2++)
861  sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];
862 }
863 
865 {
866  int start = 0, w, w2, g;
867  const float lambda = s->lambda;
868  const float freq_mult = avctx->sample_rate/(1024.0f/sce->ics.num_windows)/2.0f;
869  const float spread_threshold = NOISE_SPREAD_THRESHOLD*(lambda/120.f);
870  const float thr_mult = NOISE_LAMBDA_NUMERATOR/lambda;
871 
872  for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
873  start = 0;
874  for (g = 0; g < sce->ics.num_swb; g++) {
875  if (start*freq_mult > NOISE_LOW_LIMIT*(lambda/170.0f)) {
876  float energy = 0.0f, threshold = 0.0f, spread = 0.0f;
877  for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
878  FFPsyBand *band = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];
879  energy += band->energy;
880  threshold += band->threshold;
881  spread += band->spread;
882  }
883  if (spread > spread_threshold*sce->ics.group_len[w] &&
884  ((sce->zeroes[w*16+g] && energy >= threshold) ||
885  energy < threshold*thr_mult*sce->ics.group_len[w])) {
886  sce->band_type[w*16+g] = NOISE_BT;
887  sce->pns_ener[w*16+g] = energy / sce->ics.group_len[w];
888  sce->zeroes[w*16+g] = 0;
889  }
890  }
891  start += sce->ics.swb_sizes[g];
892  }
893  }
894 }
895 
897 {
898  int start = 0, i, w, w2, g;
899  float M[128], S[128];
900  float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;
901  const float lambda = s->lambda;
902  SingleChannelElement *sce0 = &cpe->ch[0];
903  SingleChannelElement *sce1 = &cpe->ch[1];
904  if (!cpe->common_window)
905  return;
906  for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {
907  start = 0;
908  for (g = 0; g < sce0->ics.num_swb; g++) {
909  if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {
910  float dist1 = 0.0f, dist2 = 0.0f;
911  for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {
912  FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];
913  FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];
914  float minthr = FFMIN(band0->threshold, band1->threshold);
915  float maxthr = FFMAX(band0->threshold, band1->threshold);
916  for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {
917  M[i] = (sce0->coeffs[start+(w+w2)*128+i]
918  + sce1->coeffs[start+(w+w2)*128+i]) * 0.5;
919  S[i] = M[i]
920  - sce1->coeffs[start+(w+w2)*128+i];
921  }
922  abs_pow34_v(L34, sce0->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]);
923  abs_pow34_v(R34, sce1->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]);
924  abs_pow34_v(M34, M, sce0->ics.swb_sizes[g]);
925  abs_pow34_v(S34, S, sce0->ics.swb_sizes[g]);
926  dist1 += quantize_band_cost(s, &sce0->coeffs[start + (w+w2)*128],
927  L34,
928  sce0->ics.swb_sizes[g],
929  sce0->sf_idx[(w+w2)*16+g],
930  sce0->band_type[(w+w2)*16+g],
931  lambda / band0->threshold, INFINITY, NULL, 0);
932  dist1 += quantize_band_cost(s, &sce1->coeffs[start + (w+w2)*128],
933  R34,
934  sce1->ics.swb_sizes[g],
935  sce1->sf_idx[(w+w2)*16+g],
936  sce1->band_type[(w+w2)*16+g],
937  lambda / band1->threshold, INFINITY, NULL, 0);
938  dist2 += quantize_band_cost(s, M,
939  M34,
940  sce0->ics.swb_sizes[g],
941  sce0->sf_idx[(w+w2)*16+g],
942  sce0->band_type[(w+w2)*16+g],
943  lambda / maxthr, INFINITY, NULL, 0);
944  dist2 += quantize_band_cost(s, S,
945  S34,
946  sce1->ics.swb_sizes[g],
947  sce1->sf_idx[(w+w2)*16+g],
948  sce1->band_type[(w+w2)*16+g],
949  lambda / minthr, INFINITY, NULL, 0);
950  }
951  cpe->ms_mask[w*16+g] = dist2 < dist1;
952  }
953  start += sce0->ics.swb_sizes[g];
954  }
955  }
956 }
957 
959  [AAC_CODER_FAAC] = {
974  },
975  [AAC_CODER_ANMR] = {
990  },
991  [AAC_CODER_TWOLOOP] = {
1003  search_for_ms,
1006  },
1007  [AAC_CODER_FAST] = {
1019  search_for_ms,
1022  },
1023 };
static const uint8_t *const run_value_bits[2]
Definition: aacenctab.h:101
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
float pns_ener[128]
Noise energy values (used by encoder)
Definition: aac.h:256
AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB]
Definition: aaccoder.c:958
static const uint8_t aac_cb_out_map[CB_TOT_ALL]
Map to convert values from BandCodingPath index to a codebook index.
Definition: aacenctab.h:106
static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Encode band info for single window group bands.
Definition: aaccoder.c:75
static void abs_pow34_v(float *out, const float *in, const int size)
Definition: aacenc_utils.h:39
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:167
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
Definition: aac.h:152
const char * g
Definition: vf_curves.c:108
FFPsyBand psy_bands[PSY_MAX_BANDS]
channel bands information
Definition: psymodel.h:48
void ff_aac_encode_tns_info(AACEncContext *s, SingleChannelElement *sce)
Encode TNS data.
Definition: aacenc_tns.c:38
#define SCALE_MAX_POS
scalefactor index maximum value
Definition: aac.h:150
#define TRELLIS_STATES
Definition: aaccoder.c:323
#define SCALE_MAX_DIFF
maximum scalefactor difference allowed by standard
Definition: aac.h:151
const char * b
Definition: vf_curves.c:109
int common_window
Set if channels share a common 'IndividualChannelStream' in bitstream.
Definition: aac.h:273
float cost
Definition: aaccoder.c:318
int prev_idx
pointer to the previous path point
Definition: aaccoder.c:67
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
Definition: aac.h:276
float lambda
Definition: aacenc.h:101
static const uint8_t q1[256]
Definition: twofish.c:96
static uint8_t coef2maxsf(float coef)
Return the maximum scalefactor where the quantized coef is not zero.
Definition: aacenc_utils.h:109
static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aaccoder.c:830
static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
Definition: aaccoder.c:864
Spectral data are scaled white noise not coded in the bitstream.
Definition: aac.h:87
AAC encoder quantizer.
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:97
#define M(a, b)
Definition: vp3dsp.c:44
AAC encoder context.
Definition: aacenc.h:80
uint8_t bits
Definition: crc.c:295
SingleChannelElement ch[2]
Definition: aac.h:279
const uint8_t ff_aac_scalefactor_bits[121]
Definition: aactab.c:80
AAC encoder main prediction.
static const uint8_t run_bits[7][16]
Definition: h264_cavlc.c:229
void ff_aac_encode_main_pred(AACEncContext *s, SingleChannelElement *sce)
Encoder predictors data.
Definition: aacenc_pred.c:328
Scalefactor data are intensity stereo positions (in phase).
Definition: aac.h:89
single band psychoacoustic information
Definition: psymodel.h:37
ptrdiff_t size
Definition: opengl_enc.c:101
static const uint8_t aac_cb_in_map[CB_TOT_ALL+1]
Inverse map to convert from codebooks to BandCodingPath indices.
Definition: aacenctab.h:108
float coeffs[1024]
coefficients for IMDCT, maybe processed
Definition: aac.h:258
void ff_aac_search_for_tns(AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc_tns.c:125
#define S(s, c, i)
float is_ener[128]
Intensity stereo pos (used by encoder)
Definition: aac.h:255
void ff_aac_apply_tns(AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc_tns.c:85
uint8_t max_sfb
number of scalefactor bands per group
Definition: aac.h:172
float energy
Definition: psymodel.h:39
GLsizei count
Definition: opengl_enc.c:109
int num_swb
number of scalefactor window bands
Definition: aac.h:180
#define FFMAX(a, b)
Definition: common.h:79
float cost
path cost
Definition: aaccoder.c:68
Libavcodec external API header.
static const uint8_t q0[256]
Definition: twofish.c:77
void ff_aac_search_for_pred(AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc_pred.c:233
#define NOISE_LOW_LIMIT
Frequency in Hz for lower limit of noise substitution.
Definition: aaccoder.c:52
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0);
#define NOISE_LAMBDA_NUMERATOR
Definition: aaccoder.c:61
#define SCALE_DIV_512
scalefactor difference that corresponds to scale difference in 512 times
Definition: aac.h:148
static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aaccoder.c:362
void ff_aac_adjust_common_prediction(AACEncContext *s, ChannelElement *cpe)
Definition: aacenc_pred.c:151
int bit_rate
the average bitrate
Definition: avcodec.h:1567
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
static uint8_t coef2minsf(float coef)
Return the minimum scalefactor where the quantized coef does not clip.
Definition: aacenc_utils.h:103
int cur_channel
Definition: aacenc.h:99
#define FFMIN(a, b)
Definition: common.h:81
void ff_aac_apply_main_pred(AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc_pred.c:119
static void set_special_band_scalefactors(AACEncContext *s, SingleChannelElement *sce)
Definition: aaccoder.c:325
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:68
AAC encoder Intensity Stereo.
AAC definitions and structures.
PutBitContext pb
Definition: aacenc.h:83
#define ROUND_STANDARD
Definition: aacenc_utils.h:35
#define FF_ARRAY_ELEMS(a)
#define TRELLIS_STAGES
Definition: aaccoder.c:322
#define INFINITY
Definition: math.h:27
void ff_aac_search_for_is(AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe)
Definition: aacenc_is.c:92
static int find_min_book(float maxval, int sf)
Definition: aacenc_utils.h:86
int sample_rate
samples per second
Definition: avcodec.h:2262
static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Definition: aaccoder.c:185
main external API structure.
Definition: avcodec.h:1502
IndividualChannelStream ics
Definition: aac.h:246
structure used in optimal codebook search
Definition: aaccoder.c:66
uint8_t group_len[8]
Definition: aac.h:176
Replacements for frequently missing libm functions.
Spectral data are coded with an escape sequence.
Definition: aac.h:85
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window
Definition: aac.h:179
FFPsyContext psy
Definition: aacenc.h:96
#define NOISE_SPREAD_THRESHOLD
Definition: aaccoder.c:56
AAC encoder data.
const uint8_t * quant
#define CB_TOT_ALL
Total number of codebooks, including special ones.
Definition: aacenctab.h:37
uint8_t zeroes[128]
band is not coded (used by encoder)
Definition: aac.h:254
int sf_idx[128]
scalefactor indices (used by encoder)
Definition: aac.h:253
Scalefactor data are intensity stereo positions (out of phase).
Definition: aac.h:88
#define SCALE_ONE_POS
scalefactor index that corresponds to scale=1.0
Definition: aac.h:149
static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aaccoder.c:662
static void search_for_quantizers_twoloop(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
two-loop quantizers search taken from ISO 13818-7 Appendix C
Definition: aaccoder.c:515
AAC encoder utilities.
Single Channel Element - used for both SCE and LFE elements.
Definition: aac.h:245
#define log2f(x)
Definition: libm.h:127
float ff_aac_pow2sf_tab[428]
Definition: aac_tablegen.h:32
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aac.h:270
static const int16_t coeffs[]
int channels
number of audio channels
Definition: avcodec.h:2263
FFPsyChannel * ch
single channel information
Definition: psymodel.h:80
enum BandType band_type[128]
band types
Definition: aac.h:249
static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size, int scale_idx, int cb, const float lambda, int rtz)
AAC encoder temporal noise shaping.
static float find_max_val(int group_len, int swb_size, const float *scaled)
Definition: aacenc_utils.h:74
void INT64 start
Definition: avisynth_c.h:553
float threshold
Definition: psymodel.h:40
AAC data declarations.
float scoefs[1024]
scaled coefficients
Definition: aacenc.h:104
static void search_for_ms(AACEncContext *s, ChannelElement *cpe)
Definition: aaccoder.c:896
float spread
Definition: psymodel.h:41
static float quantize_band_cost(struct AACEncContext *s, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, int rtz)
bitstream writer API