FFmpeg
dcaenc.c
Go to the documentation of this file.
1 /*
2  * DCA encoder
3  * Copyright (C) 2008-2012 Alexander E. Patrakov
4  * 2010 Benjamin Larsson
5  * 2011 Xiang Wang
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #define FFT_FLOAT 0
25 #define FFT_FIXED_32 1
26 
27 #include "libavutil/avassert.h"
29 #include "libavutil/common.h"
30 #include "libavutil/ffmath.h"
31 #include "libavutil/mem_internal.h"
32 #include "libavutil/opt.h"
33 #include "avcodec.h"
34 #include "dca.h"
35 #include "dcaadpcm.h"
36 #include "dcamath.h"
37 #include "dca_core.h"
38 #include "dcadata.h"
39 #include "dcaenc.h"
40 #include "encode.h"
41 #include "fft.h"
42 #include "internal.h"
43 #include "mathops.h"
44 #include "put_bits.h"
45 
46 #define MAX_CHANNELS 6
47 #define DCA_MAX_FRAME_SIZE 16384
48 #define DCA_HEADER_SIZE 13
49 #define DCA_LFE_SAMPLES 8
50 
51 #define DCAENC_SUBBANDS 32
52 #define SUBFRAMES 1
53 #define SUBSUBFRAMES 2
54 #define SUBBAND_SAMPLES (SUBFRAMES * SUBSUBFRAMES * 8)
55 #define AUBANDS 25
56 
57 #define COS_T(x) (c->cos_table[(x) & 2047])
58 
59 typedef struct CompressionOptions {
62 
63 typedef struct DCAEncContext {
64  AVClass *class;
72  int channels;
82  const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe
83 
86  int32_t history[MAX_CHANNELS][512]; /* This is a circular buffer */
90  int32_t diff_peak_cb[MAX_CHANNELS][DCAENC_SUBBANDS]; ///< expected peak of residual signal
103  int consumed_adpcm_bits; ///< Number of bits to transmit ADPCM related info
104 
108  int32_t auf[9][AUBANDS][256];
112 } DCAEncContext;
113 
114 /* Transfer function of outer and middle ear, Hz -> dB */
115 static double hom(double f)
116 {
117  double f1 = f / 1000;
118 
119  return -3.64 * pow(f1, -0.8)
120  + 6.8 * exp(-0.6 * (f1 - 3.4) * (f1 - 3.4))
121  - 6.0 * exp(-0.15 * (f1 - 8.7) * (f1 - 8.7))
122  - 0.0006 * (f1 * f1) * (f1 * f1);
123 }
124 
125 static double gammafilter(int i, double f)
126 {
127  double h = (f - fc[i]) / erb[i];
128 
129  h = 1 + h * h;
130  h = 1 / (h * h);
131  return 20 * log10(h);
132 }
133 
135 {
136  int ch, band;
139  sizeof(int32_t));
140  if (!bufer)
141  return AVERROR(ENOMEM);
142 
143  /* we need a place for DCA_ADPCM_COEFF samples from previous frame
144  * to calc prediction coefficients for each subband */
145  for (ch = 0; ch < MAX_CHANNELS; ch++) {
146  for (band = 0; band < DCAENC_SUBBANDS; band++) {
147  c->subband[ch][band] = bufer +
150  }
151  }
152  return 0;
153 }
154 
156 {
157  if (c->subband[0][0]) {
158  int32_t *bufer = c->subband[0][0] - DCA_ADPCM_COEFFS;
159  av_free(bufer);
160  c->subband[0][0] = NULL;
161  }
162 }
163 
164 static int encode_init(AVCodecContext *avctx)
165 {
166  DCAEncContext *c = avctx->priv_data;
167  uint64_t layout = avctx->channel_layout;
168  int i, j, k, min_frame_bits;
169  int ret;
170 
171  if ((ret = subband_bufer_alloc(c)) < 0)
172  return ret;
173 
174  c->fullband_channels = c->channels = avctx->channels;
175  c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6);
176  c->band_interpolation = c->band_interpolation_tab[1];
177  c->band_spectrum = c->band_spectrum_tab[1];
178  c->worst_quantization_noise = -2047;
179  c->worst_noise_ever = -2047;
180  c->consumed_adpcm_bits = 0;
181 
182  if (ff_dcaadpcm_init(&c->adpcm_ctx))
183  return AVERROR(ENOMEM);
184 
185  if (!layout) {
186  av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
187  "encoder will guess the layout, but it "
188  "might be incorrect.\n");
190  }
191  switch (layout) {
192  case AV_CH_LAYOUT_MONO: c->channel_config = 0; break;
193  case AV_CH_LAYOUT_STEREO: c->channel_config = 2; break;
194  case AV_CH_LAYOUT_2_2: c->channel_config = 8; break;
195  case AV_CH_LAYOUT_5POINT0: c->channel_config = 9; break;
196  case AV_CH_LAYOUT_5POINT1: c->channel_config = 9; break;
197  default:
198  av_log(avctx, AV_LOG_ERROR, "Unsupported channel layout!\n");
199  return AVERROR_PATCHWELCOME;
200  }
201 
202  if (c->lfe_channel) {
203  c->fullband_channels--;
204  c->channel_order_tab = channel_reorder_lfe[c->channel_config];
205  } else {
206  c->channel_order_tab = channel_reorder_nolfe[c->channel_config];
207  }
208 
209  for (i = 0; i < MAX_CHANNELS; i++) {
210  for (j = 0; j < DCA_CODE_BOOKS; j++) {
211  c->quant_index_sel[i][j] = ff_dca_quant_index_group_size[j];
212  }
213  /* 6 - no Huffman */
214  c->bit_allocation_sel[i] = 6;
215 
216  for (j = 0; j < DCAENC_SUBBANDS; j++) {
217  /* -1 - no ADPCM */
218  c->prediction_mode[i][j] = -1;
219  memset(c->adpcm_history[i][j], 0, sizeof(int32_t)*DCA_ADPCM_COEFFS);
220  }
221  }
222 
223  for (i = 0; i < 9; i++) {
224  if (sample_rates[i] == avctx->sample_rate)
225  break;
226  }
227  if (i == 9)
228  return AVERROR(EINVAL);
229  c->samplerate_index = i;
230 
231  if (avctx->bit_rate < 32000 || avctx->bit_rate > 3840000) {
232  av_log(avctx, AV_LOG_ERROR, "Bit rate %"PRId64" not supported.", avctx->bit_rate);
233  return AVERROR(EINVAL);
234  }
235  for (i = 0; ff_dca_bit_rates[i] < avctx->bit_rate; i++)
236  ;
237  c->bitrate_index = i;
238  c->frame_bits = FFALIGN((avctx->bit_rate * 512 + avctx->sample_rate - 1) / avctx->sample_rate, 32);
239  min_frame_bits = 132 + (493 + 28 * 32) * c->fullband_channels + c->lfe_channel * 72;
240  if (c->frame_bits < min_frame_bits || c->frame_bits > (DCA_MAX_FRAME_SIZE << 3))
241  return AVERROR(EINVAL);
242 
243  c->frame_size = (c->frame_bits + 7) / 8;
244 
245  avctx->frame_size = 32 * SUBBAND_SAMPLES;
246 
247  if ((ret = ff_mdct_init(&c->mdct, 9, 0, 1.0)) < 0)
248  return ret;
249 
250  /* Init all tables */
251  c->cos_table[0] = 0x7fffffff;
252  c->cos_table[512] = 0;
253  c->cos_table[1024] = -c->cos_table[0];
254  for (i = 1; i < 512; i++) {
255  c->cos_table[i] = (int32_t)(0x7fffffff * cos(M_PI * i / 1024));
256  c->cos_table[1024-i] = -c->cos_table[i];
257  c->cos_table[1024+i] = -c->cos_table[i];
258  c->cos_table[2048-i] = +c->cos_table[i];
259  }
260 
261  for (i = 0; i < 2048; i++)
262  c->cb_to_level[i] = (int32_t)(0x7fffffff * ff_exp10(-0.005 * i));
263 
264  for (k = 0; k < 32; k++) {
265  for (j = 0; j < 8; j++) {
266  c->lfe_fir_64i[64 * j + k] = (int32_t)(0xffffff800000ULL * ff_dca_lfe_fir_64[8 * k + j]);
267  c->lfe_fir_64i[64 * (7-j) + (63 - k)] = (int32_t)(0xffffff800000ULL * ff_dca_lfe_fir_64[8 * k + j]);
268  }
269  }
270 
271  for (i = 0; i < 512; i++) {
272  c->band_interpolation_tab[0][i] = (int32_t)(0x1000000000ULL * ff_dca_fir_32bands_perfect[i]);
273  c->band_interpolation_tab[1][i] = (int32_t)(0x1000000000ULL * ff_dca_fir_32bands_nonperfect[i]);
274  }
275 
276  for (i = 0; i < 9; i++) {
277  for (j = 0; j < AUBANDS; j++) {
278  for (k = 0; k < 256; k++) {
279  double freq = sample_rates[i] * (k + 0.5) / 512;
280 
281  c->auf[i][j][k] = (int32_t)(10 * (hom(freq) + gammafilter(j, freq)));
282  }
283  }
284  }
285 
286  for (i = 0; i < 256; i++) {
287  double add = 1 + ff_exp10(-0.01 * i);
288  c->cb_to_add[i] = (int32_t)(100 * log10(add));
289  }
290  for (j = 0; j < 8; j++) {
291  double accum = 0;
292  for (i = 0; i < 512; i++) {
293  double reconst = ff_dca_fir_32bands_perfect[i] * ((i & 64) ? (-1) : 1);
294  accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (j + 0.5) / 512);
295  }
296  c->band_spectrum_tab[0][j] = (int32_t)(200 * log10(accum));
297  }
298  for (j = 0; j < 8; j++) {
299  double accum = 0;
300  for (i = 0; i < 512; i++) {
301  double reconst = ff_dca_fir_32bands_nonperfect[i] * ((i & 64) ? (-1) : 1);
302  accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (j + 0.5) / 512);
303  }
304  c->band_spectrum_tab[1][j] = (int32_t)(200 * log10(accum));
305  }
306 
307  return 0;
308 }
309 
311 {
312  DCAEncContext *c = avctx->priv_data;
313  ff_mdct_end(&c->mdct);
315  ff_dcaadpcm_free(&c->adpcm_ctx);
316 
317  return 0;
318 }
319 
321 {
322  int ch, subs, i, k, j;
323 
324  for (ch = 0; ch < c->fullband_channels; ch++) {
325  /* History is copied because it is also needed for PSY */
326  int32_t hist[512];
327  int hist_start = 0;
328  const int chi = c->channel_order_tab[ch];
329 
330  memcpy(hist, &c->history[ch][0], 512 * sizeof(int32_t));
331 
332  for (subs = 0; subs < SUBBAND_SAMPLES; subs++) {
333  int32_t accum[64];
334  int32_t resp;
335  int band;
336 
337  /* Calculate the convolutions at once */
338  memset(accum, 0, 64 * sizeof(int32_t));
339 
340  for (k = 0, i = hist_start, j = 0;
341  i < 512; k = (k + 1) & 63, i++, j++)
342  accum[k] += mul32(hist[i], c->band_interpolation[j]);
343  for (i = 0; i < hist_start; k = (k + 1) & 63, i++, j++)
344  accum[k] += mul32(hist[i], c->band_interpolation[j]);
345 
346  for (k = 16; k < 32; k++)
347  accum[k] = accum[k] - accum[31 - k];
348  for (k = 32; k < 48; k++)
349  accum[k] = accum[k] + accum[95 - k];
350 
351  for (band = 0; band < 32; band++) {
352  resp = 0;
353  for (i = 16; i < 48; i++) {
354  int s = (2 * band + 1) * (2 * (i + 16) + 1);
355  resp += mul32(accum[i], COS_T(s << 3)) >> 3;
356  }
357 
358  c->subband[ch][band][subs] = ((band + 1) & 2) ? -resp : resp;
359  }
360 
361  /* Copy in 32 new samples from input */
362  for (i = 0; i < 32; i++)
363  hist[i + hist_start] = input[(subs * 32 + i) * c->channels + chi];
364 
365  hist_start = (hist_start + 32) & 511;
366  }
367  }
368 }
369 
371 {
372  /* FIXME: make 128x LFE downsampling possible */
373  const int lfech = lfe_index[c->channel_config];
374  int i, j, lfes;
375  int32_t hist[512];
376  int32_t accum;
377  int hist_start = 0;
378 
379  memcpy(hist, &c->history[c->channels - 1][0], 512 * sizeof(int32_t));
380 
381  for (lfes = 0; lfes < DCA_LFE_SAMPLES; lfes++) {
382  /* Calculate the convolution */
383  accum = 0;
384 
385  for (i = hist_start, j = 0; i < 512; i++, j++)
386  accum += mul32(hist[i], c->lfe_fir_64i[j]);
387  for (i = 0; i < hist_start; i++, j++)
388  accum += mul32(hist[i], c->lfe_fir_64i[j]);
389 
390  c->downsampled_lfe[lfes] = accum;
391 
392  /* Copy in 64 new samples from input */
393  for (i = 0; i < 64; i++)
394  hist[i + hist_start] = input[(lfes * 64 + i) * c->channels + lfech];
395 
396  hist_start = (hist_start + 64) & 511;
397  }
398 }
399 
401 {
402  int i, res = 0;
403  in = FFABS(in);
404 
405  for (i = 1024; i > 0; i >>= 1) {
406  if (c->cb_to_level[i + res] >= in)
407  res += i;
408  }
409  return -res;
410 }
411 
413 {
414  if (a < b)
415  FFSWAP(int32_t, a, b);
416 
417  if (a - b >= 256)
418  return a;
419  return a + c->cb_to_add[a - b];
420 }
421 
423  const int32_t in[2 * 256], int32_t power[256])
424 {
425  int i;
426  LOCAL_ALIGNED_32(int32_t, data, [512]);
427  LOCAL_ALIGNED_32(int32_t, coeff, [256]);
428 
429  for (i = 0; i < 512; i++)
430  data[i] = norm__(mul32(in[i], 0x3fffffff - (COS_T(4 * i + 2) >> 1)), 4);
431 
432  c->mdct.mdct_calc(&c->mdct, coeff, data);
433  for (i = 0; i < 256; i++) {
434  const int32_t cb = get_cb(c, coeff[i]);
435  power[i] = add_cb(c, cb, cb);
436  }
437 }
438 
440  const int32_t in[512], int32_t out_cb[256])
441 {
442  int32_t power[256];
443  int32_t out_cb_unnorm[256];
444  int32_t denom;
445  const int32_t ca_cb = -1114;
446  const int32_t cs_cb = 928;
447  const int samplerate_index = c->samplerate_index;
448  int i, j;
449 
450  calc_power(c, in, power);
451 
452  for (j = 0; j < 256; j++)
453  out_cb_unnorm[j] = -2047; /* and can only grow */
454 
455  for (i = 0; i < AUBANDS; i++) {
456  denom = ca_cb; /* and can only grow */
457  for (j = 0; j < 256; j++)
458  denom = add_cb(c, denom, power[j] + c->auf[samplerate_index][i][j]);
459  for (j = 0; j < 256; j++)
460  out_cb_unnorm[j] = add_cb(c, out_cb_unnorm[j],
461  -denom + c->auf[samplerate_index][i][j]);
462  }
463 
464  for (j = 0; j < 256; j++)
465  out_cb[j] = add_cb(c, out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb);
466 }
467 
468 typedef void (*walk_band_t)(DCAEncContext *c, int band1, int band2, int f,
469  int32_t spectrum1, int32_t spectrum2, int channel,
470  int32_t * arg);
471 
472 static void walk_band_low(DCAEncContext *c, int band, int channel,
473  walk_band_t walk, int32_t *arg)
474 {
475  int f;
476 
477  if (band == 0) {
478  for (f = 0; f < 4; f++)
479  walk(c, 0, 0, f, 0, -2047, channel, arg);
480  } else {
481  for (f = 0; f < 8; f++)
482  walk(c, band, band - 1, 8 * band - 4 + f,
483  c->band_spectrum[7 - f], c->band_spectrum[f], channel, arg);
484  }
485 }
486 
487 static void walk_band_high(DCAEncContext *c, int band, int channel,
488  walk_band_t walk, int32_t *arg)
489 {
490  int f;
491 
492  if (band == 31) {
493  for (f = 0; f < 4; f++)
494  walk(c, 31, 31, 256 - 4 + f, 0, -2047, channel, arg);
495  } else {
496  for (f = 0; f < 8; f++)
497  walk(c, band, band + 1, 8 * band + 4 + f,
498  c->band_spectrum[f], c->band_spectrum[7 - f], channel, arg);
499  }
500 }
501 
502 static void update_band_masking(DCAEncContext *c, int band1, int band2,
503  int f, int32_t spectrum1, int32_t spectrum2,
504  int channel, int32_t * arg)
505 {
506  int32_t value = c->eff_masking_curve_cb[f] - spectrum1;
507 
508  if (value < c->band_masking_cb[band1])
509  c->band_masking_cb[band1] = value;
510 }
511 
512 static void calc_masking(DCAEncContext *c, const int32_t *input)
513 {
514  int i, k, band, ch, ssf;
515  int32_t data[512];
516 
517  for (i = 0; i < 256; i++)
518  for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
519  c->masking_curve_cb[ssf][i] = -2047;
520 
521  for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
522  for (ch = 0; ch < c->fullband_channels; ch++) {
523  const int chi = c->channel_order_tab[ch];
524 
525  for (i = 0, k = 128 + 256 * ssf; k < 512; i++, k++)
526  data[i] = c->history[ch][k];
527  for (k -= 512; i < 512; i++, k++)
528  data[i] = input[k * c->channels + chi];
529  adjust_jnd(c, data, c->masking_curve_cb[ssf]);
530  }
531  for (i = 0; i < 256; i++) {
532  int32_t m = 2048;
533 
534  for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
535  if (c->masking_curve_cb[ssf][i] < m)
536  m = c->masking_curve_cb[ssf][i];
537  c->eff_masking_curve_cb[i] = m;
538  }
539 
540  for (band = 0; band < 32; band++) {
541  c->band_masking_cb[band] = 2048;
544  }
545 }
546 
547 static inline int32_t find_peak(DCAEncContext *c, const int32_t *in, int len)
548 {
549  int sample;
550  int32_t m = 0;
551  for (sample = 0; sample < len; sample++) {
552  int32_t s = abs(in[sample]);
553  if (m < s)
554  m = s;
555  }
556  return get_cb(c, m);
557 }
558 
560 {
561  int band, ch;
562 
563  for (ch = 0; ch < c->fullband_channels; ch++) {
564  for (band = 0; band < 32; band++)
565  c->peak_cb[ch][band] = find_peak(c, c->subband[ch][band],
567  }
568 
569  if (c->lfe_channel)
570  c->lfe_peak_cb = find_peak(c, c->downsampled_lfe, DCA_LFE_SAMPLES);
571 }
572 
574 {
575  int ch, band;
576  int pred_vq_id;
577  int32_t *samples;
578  int32_t estimated_diff[SUBBAND_SAMPLES];
579 
580  c->consumed_adpcm_bits = 0;
581  for (ch = 0; ch < c->fullband_channels; ch++) {
582  for (band = 0; band < 32; band++) {
583  samples = c->subband[ch][band] - DCA_ADPCM_COEFFS;
584  pred_vq_id = ff_dcaadpcm_subband_analysis(&c->adpcm_ctx, samples,
585  SUBBAND_SAMPLES, estimated_diff);
586  if (pred_vq_id >= 0) {
587  c->prediction_mode[ch][band] = pred_vq_id;
588  c->consumed_adpcm_bits += 12; //12 bits to transmit prediction vq index
589  c->diff_peak_cb[ch][band] = find_peak(c, estimated_diff, 16);
590  } else {
591  c->prediction_mode[ch][band] = -1;
592  }
593  }
594  }
595 }
596 
597 static const int snr_fudge = 128;
598 #define USED_1ABITS 1
599 #define USED_26ABITS 4
600 
601 static inline int32_t get_step_size(DCAEncContext *c, int ch, int band)
602 {
603  int32_t step_size;
604 
605  if (c->bitrate_index == 3)
606  step_size = ff_dca_lossless_quant[c->abits[ch][band]];
607  else
608  step_size = ff_dca_lossy_quant[c->abits[ch][band]];
609 
610  return step_size;
611 }
612 
613 static int calc_one_scale(DCAEncContext *c, int32_t peak_cb, int abits,
614  softfloat *quant)
615 {
616  int32_t peak;
617  int our_nscale, try_remove;
618  softfloat our_quant;
619 
620  av_assert0(peak_cb <= 0);
621  av_assert0(peak_cb >= -2047);
622 
623  our_nscale = 127;
624  peak = c->cb_to_level[-peak_cb];
625 
626  for (try_remove = 64; try_remove > 0; try_remove >>= 1) {
627  if (scalefactor_inv[our_nscale - try_remove].e + stepsize_inv[abits].e <= 17)
628  continue;
629  our_quant.m = mul32(scalefactor_inv[our_nscale - try_remove].m, stepsize_inv[abits].m);
630  our_quant.e = scalefactor_inv[our_nscale - try_remove].e + stepsize_inv[abits].e - 17;
631  if ((ff_dca_quant_levels[abits] - 1) / 2 < quantize_value(peak, our_quant))
632  continue;
633  our_nscale -= try_remove;
634  }
635 
636  if (our_nscale >= 125)
637  our_nscale = 124;
638 
639  quant->m = mul32(scalefactor_inv[our_nscale].m, stepsize_inv[abits].m);
640  quant->e = scalefactor_inv[our_nscale].e + stepsize_inv[abits].e - 17;
641  av_assert0((ff_dca_quant_levels[abits] - 1) / 2 >= quantize_value(peak, *quant));
642 
643  return our_nscale;
644 }
645 
646 static inline void quantize_adpcm_subband(DCAEncContext *c, int ch, int band)
647 {
648  int32_t step_size;
649  int32_t diff_peak_cb = c->diff_peak_cb[ch][band];
650  c->scale_factor[ch][band] = calc_one_scale(c, diff_peak_cb,
651  c->abits[ch][band],
652  &c->quant[ch][band]);
653 
654  step_size = get_step_size(c, ch, band);
655  ff_dcaadpcm_do_real(c->prediction_mode[ch][band],
656  c->quant[ch][band],
657  ff_dca_scale_factor_quant7[c->scale_factor[ch][band]],
658  step_size, c->adpcm_history[ch][band], c->subband[ch][band],
659  c->adpcm_history[ch][band] + 4, c->quantized[ch][band],
660  SUBBAND_SAMPLES, c->cb_to_level[-diff_peak_cb]);
661 }
662 
664 {
665  int band, ch;
666 
667  for (ch = 0; ch < c->fullband_channels; ch++)
668  for (band = 0; band < 32; band++)
669  if (c->prediction_mode[ch][band] >= 0)
670  quantize_adpcm_subband(c, ch, band);
671 }
672 
674 {
675  int sample, band, ch;
676 
677  for (ch = 0; ch < c->fullband_channels; ch++) {
678  for (band = 0; band < 32; band++) {
679  if (c->prediction_mode[ch][band] == -1) {
680  for (sample = 0; sample < SUBBAND_SAMPLES; sample++) {
681  int32_t val = quantize_value(c->subband[ch][band][sample],
682  c->quant[ch][band]);
683  c->quantized[ch][band][sample] = val;
684  }
685  }
686  }
687  }
688 }
689 
690 static void accumulate_huff_bit_consumption(int abits, int32_t *quantized,
691  uint32_t *result)
692 {
693  uint8_t sel, id = abits - 1;
694  for (sel = 0; sel < ff_dca_quant_index_group_size[id]; sel++)
696  sel, id);
697 }
698 
699 static uint32_t set_best_code(uint32_t vlc_bits[DCA_CODE_BOOKS][7],
700  uint32_t clc_bits[DCA_CODE_BOOKS],
701  int32_t res[DCA_CODE_BOOKS])
702 {
703  uint8_t i, sel;
704  uint32_t best_sel_bits[DCA_CODE_BOOKS];
705  int32_t best_sel_id[DCA_CODE_BOOKS];
706  uint32_t t, bits = 0;
707 
708  for (i = 0; i < DCA_CODE_BOOKS; i++) {
709 
710  av_assert0(!((!!vlc_bits[i][0]) ^ (!!clc_bits[i])));
711  if (vlc_bits[i][0] == 0) {
712  /* do not transmit adjustment index for empty codebooks */
714  /* and skip it */
715  continue;
716  }
717 
718  best_sel_bits[i] = vlc_bits[i][0];
719  best_sel_id[i] = 0;
720  for (sel = 0; sel < ff_dca_quant_index_group_size[i]; sel++) {
721  if (best_sel_bits[i] > vlc_bits[i][sel] && vlc_bits[i][sel]) {
722  best_sel_bits[i] = vlc_bits[i][sel];
723  best_sel_id[i] = sel;
724  }
725  }
726 
727  /* 2 bits to transmit scale factor adjustment index */
728  t = best_sel_bits[i] + 2;
729  if (t < clc_bits[i]) {
730  res[i] = best_sel_id[i];
731  bits += t;
732  } else {
734  bits += clc_bits[i];
735  }
736  }
737  return bits;
738 }
739 
740 static uint32_t set_best_abits_code(int abits[DCAENC_SUBBANDS], int bands,
741  int32_t *res)
742 {
743  uint8_t i;
744  uint32_t t;
745  int32_t best_sel = 6;
746  int32_t best_bits = bands * 5;
747 
748  /* Check do we have subband which cannot be encoded by Huffman tables */
749  for (i = 0; i < bands; i++) {
750  if (abits[i] > 12 || abits[i] == 0) {
751  *res = best_sel;
752  return best_bits;
753  }
754  }
755 
756  for (i = 0; i < DCA_BITALLOC_12_COUNT; i++) {
757  t = ff_dca_vlc_calc_alloc_bits(abits, bands, i);
758  if (t < best_bits) {
759  best_bits = t;
760  best_sel = i;
761  }
762  }
763 
764  *res = best_sel;
765  return best_bits;
766 }
767 
768 static int init_quantization_noise(DCAEncContext *c, int noise, int forbid_zero)
769 {
770  int ch, band, ret = USED_26ABITS | USED_1ABITS;
771  uint32_t huff_bit_count_accum[MAX_CHANNELS][DCA_CODE_BOOKS][7];
772  uint32_t clc_bit_count_accum[MAX_CHANNELS][DCA_CODE_BOOKS];
773  uint32_t bits_counter = 0;
774 
775  c->consumed_bits = 132 + 333 * c->fullband_channels;
776  c->consumed_bits += c->consumed_adpcm_bits;
777  if (c->lfe_channel)
778  c->consumed_bits += 72;
779 
780  /* attempt to guess the bit distribution based on the prevoius frame */
781  for (ch = 0; ch < c->fullband_channels; ch++) {
782  for (band = 0; band < 32; band++) {
783  int snr_cb = c->peak_cb[ch][band] - c->band_masking_cb[band] - noise;
784 
785  if (snr_cb >= 1312) {
786  c->abits[ch][band] = 26;
787  ret &= ~USED_1ABITS;
788  } else if (snr_cb >= 222) {
789  c->abits[ch][band] = 8 + mul32(snr_cb - 222, 69000000);
790  ret &= ~(USED_26ABITS | USED_1ABITS);
791  } else if (snr_cb >= 0) {
792  c->abits[ch][band] = 2 + mul32(snr_cb, 106000000);
793  ret &= ~(USED_26ABITS | USED_1ABITS);
794  } else if (forbid_zero || snr_cb >= -140) {
795  c->abits[ch][band] = 1;
796  ret &= ~USED_26ABITS;
797  } else {
798  c->abits[ch][band] = 0;
799  ret &= ~(USED_26ABITS | USED_1ABITS);
800  }
801  }
802  c->consumed_bits += set_best_abits_code(c->abits[ch], 32,
803  &c->bit_allocation_sel[ch]);
804  }
805 
806  /* Recalc scale_factor each time to get bits consumption in case of Huffman coding.
807  It is suboptimal solution */
808  /* TODO: May be cache scaled values */
809  for (ch = 0; ch < c->fullband_channels; ch++) {
810  for (band = 0; band < 32; band++) {
811  if (c->prediction_mode[ch][band] == -1) {
812  c->scale_factor[ch][band] = calc_one_scale(c, c->peak_cb[ch][band],
813  c->abits[ch][band],
814  &c->quant[ch][band]);
815  }
816  }
817  }
818  quantize_adpcm(c);
819  quantize_pcm(c);
820 
821  memset(huff_bit_count_accum, 0, MAX_CHANNELS * DCA_CODE_BOOKS * 7 * sizeof(uint32_t));
822  memset(clc_bit_count_accum, 0, MAX_CHANNELS * DCA_CODE_BOOKS * sizeof(uint32_t));
823  for (ch = 0; ch < c->fullband_channels; ch++) {
824  for (band = 0; band < 32; band++) {
825  if (c->abits[ch][band] && c->abits[ch][band] <= DCA_CODE_BOOKS) {
826  accumulate_huff_bit_consumption(c->abits[ch][band],
827  c->quantized[ch][band],
828  huff_bit_count_accum[ch][c->abits[ch][band] - 1]);
829  clc_bit_count_accum[ch][c->abits[ch][band] - 1] += bit_consumption[c->abits[ch][band]];
830  } else {
831  bits_counter += bit_consumption[c->abits[ch][band]];
832  }
833  }
834  }
835 
836  for (ch = 0; ch < c->fullband_channels; ch++) {
837  bits_counter += set_best_code(huff_bit_count_accum[ch],
838  clc_bit_count_accum[ch],
839  c->quant_index_sel[ch]);
840  }
841 
842  c->consumed_bits += bits_counter;
843 
844  return ret;
845 }
846 
848 {
849  /* Find the bounds where the binary search should work */
850  int low, high, down;
851  int used_abits = 0;
852  int forbid_zero = 1;
853 restart:
854  init_quantization_noise(c, c->worst_quantization_noise, forbid_zero);
855  low = high = c->worst_quantization_noise;
856  if (c->consumed_bits > c->frame_bits) {
857  while (c->consumed_bits > c->frame_bits) {
858  if (used_abits == USED_1ABITS && forbid_zero) {
859  forbid_zero = 0;
860  goto restart;
861  }
862  low = high;
863  high += snr_fudge;
864  used_abits = init_quantization_noise(c, high, forbid_zero);
865  }
866  } else {
867  while (c->consumed_bits <= c->frame_bits) {
868  high = low;
869  if (used_abits == USED_26ABITS)
870  goto out; /* The requested bitrate is too high, pad with zeros */
871  low -= snr_fudge;
872  used_abits = init_quantization_noise(c, low, forbid_zero);
873  }
874  }
875 
876  /* Now do a binary search between low and high to see what fits */
877  for (down = snr_fudge >> 1; down; down >>= 1) {
878  init_quantization_noise(c, high - down, forbid_zero);
879  if (c->consumed_bits <= c->frame_bits)
880  high -= down;
881  }
882  init_quantization_noise(c, high, forbid_zero);
883 out:
884  c->worst_quantization_noise = high;
885  if (high > c->worst_noise_ever)
886  c->worst_noise_ever = high;
887 }
888 
890 {
891  int k, ch;
892 
893  for (k = 0; k < 512; k++)
894  for (ch = 0; ch < c->channels; ch++) {
895  const int chi = c->channel_order_tab[ch];
896 
897  c->history[ch][k] = input[k * c->channels + chi];
898  }
899 }
900 
902 {
903  int ch, band;
904  int32_t step_size;
905  /* We fill in ADPCM work buffer for subbands which hasn't been ADPCM coded
906  * in current frame - we need this data if subband of next frame is
907  * ADPCM
908  */
909  for (ch = 0; ch < c->channels; ch++) {
910  for (band = 0; band < 32; band++) {
911  int32_t *samples = c->subband[ch][band] - DCA_ADPCM_COEFFS;
912  if (c->prediction_mode[ch][band] == -1) {
913  step_size = get_step_size(c, ch, band);
914 
915  ff_dca_core_dequantize(c->adpcm_history[ch][band],
916  c->quantized[ch][band]+12, step_size,
917  ff_dca_scale_factor_quant7[c->scale_factor[ch][band]], 0, 4);
918  } else {
919  AV_COPY128U(c->adpcm_history[ch][band], c->adpcm_history[ch][band]+4);
920  }
921  /* Copy dequantized values for LPC analysis.
922  * It reduces artifacts in case of extreme quantization,
923  * example: in current frame abits is 1 and has no prediction flag,
924  * but end of this frame is sine like signal. In this case, if LPC analysis uses
925  * original values, likely LPC analysis returns good prediction gain, and sets prediction flag.
926  * But there are no proper value in decoder history, so likely result will be no good.
927  * Bitstream has "Predictor history flag switch", but this flag disables history for all subbands
928  */
929  samples[0] = c->adpcm_history[ch][band][0] * (1 << 7);
930  samples[1] = c->adpcm_history[ch][band][1] * (1 << 7);
931  samples[2] = c->adpcm_history[ch][band][2] * (1 << 7);
932  samples[3] = c->adpcm_history[ch][band][3] * (1 << 7);
933  }
934  }
935 }
936 
938 {
939  if (c->lfe_channel)
940  c->lfe_scale_factor = calc_one_scale(c, c->lfe_peak_cb, 11, &c->lfe_quant);
941 }
942 
944 {
945  /* SYNC */
946  put_bits(&c->pb, 16, 0x7ffe);
947  put_bits(&c->pb, 16, 0x8001);
948 
949  /* Frame type: normal */
950  put_bits(&c->pb, 1, 1);
951 
952  /* Deficit sample count: none */
953  put_bits(&c->pb, 5, 31);
954 
955  /* CRC is not present */
956  put_bits(&c->pb, 1, 0);
957 
958  /* Number of PCM sample blocks */
959  put_bits(&c->pb, 7, SUBBAND_SAMPLES - 1);
960 
961  /* Primary frame byte size */
962  put_bits(&c->pb, 14, c->frame_size - 1);
963 
964  /* Audio channel arrangement */
965  put_bits(&c->pb, 6, c->channel_config);
966 
967  /* Core audio sampling frequency */
968  put_bits(&c->pb, 4, bitstream_sfreq[c->samplerate_index]);
969 
970  /* Transmission bit rate */
971  put_bits(&c->pb, 5, c->bitrate_index);
972 
973  /* Embedded down mix: disabled */
974  put_bits(&c->pb, 1, 0);
975 
976  /* Embedded dynamic range flag: not present */
977  put_bits(&c->pb, 1, 0);
978 
979  /* Embedded time stamp flag: not present */
980  put_bits(&c->pb, 1, 0);
981 
982  /* Auxiliary data flag: not present */
983  put_bits(&c->pb, 1, 0);
984 
985  /* HDCD source: no */
986  put_bits(&c->pb, 1, 0);
987 
988  /* Extension audio ID: N/A */
989  put_bits(&c->pb, 3, 0);
990 
991  /* Extended audio data: not present */
992  put_bits(&c->pb, 1, 0);
993 
994  /* Audio sync word insertion flag: after each sub-frame */
995  put_bits(&c->pb, 1, 0);
996 
997  /* Low frequency effects flag: not present or 64x subsampling */
998  put_bits(&c->pb, 2, c->lfe_channel ? 2 : 0);
999 
1000  /* Predictor history switch flag: on */
1001  put_bits(&c->pb, 1, 1);
1002 
1003  /* No CRC */
1004  /* Multirate interpolator switch: non-perfect reconstruction */
1005  put_bits(&c->pb, 1, 0);
1006 
1007  /* Encoder software revision: 7 */
1008  put_bits(&c->pb, 4, 7);
1009 
1010  /* Copy history: 0 */
1011  put_bits(&c->pb, 2, 0);
1012 
1013  /* Source PCM resolution: 16 bits, not DTS ES */
1014  put_bits(&c->pb, 3, 0);
1015 
1016  /* Front sum/difference coding: no */
1017  put_bits(&c->pb, 1, 0);
1018 
1019  /* Surrounds sum/difference coding: no */
1020  put_bits(&c->pb, 1, 0);
1021 
1022  /* Dialog normalization: 0 dB */
1023  put_bits(&c->pb, 4, 0);
1024 }
1025 
1027 {
1028  int ch, i;
1029  /* Number of subframes */
1030  put_bits(&c->pb, 4, SUBFRAMES - 1);
1031 
1032  /* Number of primary audio channels */
1033  put_bits(&c->pb, 3, c->fullband_channels - 1);
1034 
1035  /* Subband activity count */
1036  for (ch = 0; ch < c->fullband_channels; ch++)
1037  put_bits(&c->pb, 5, DCAENC_SUBBANDS - 2);
1038 
1039  /* High frequency VQ start subband */
1040  for (ch = 0; ch < c->fullband_channels; ch++)
1041  put_bits(&c->pb, 5, DCAENC_SUBBANDS - 1);
1042 
1043  /* Joint intensity coding index: 0, 0 */
1044  for (ch = 0; ch < c->fullband_channels; ch++)
1045  put_bits(&c->pb, 3, 0);
1046 
1047  /* Transient mode codebook: A4, A4 (arbitrary) */
1048  for (ch = 0; ch < c->fullband_channels; ch++)
1049  put_bits(&c->pb, 2, 0);
1050 
1051  /* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each channel) */
1052  for (ch = 0; ch < c->fullband_channels; ch++)
1053  put_bits(&c->pb, 3, 6);
1054 
1055  /* Bit allocation quantizer select: linear 5-bit */
1056  for (ch = 0; ch < c->fullband_channels; ch++)
1057  put_bits(&c->pb, 3, c->bit_allocation_sel[ch]);
1058 
1059  /* Quantization index codebook select */
1060  for (i = 0; i < DCA_CODE_BOOKS; i++)
1061  for (ch = 0; ch < c->fullband_channels; ch++)
1062  put_bits(&c->pb, ff_dca_quant_index_sel_nbits[i], c->quant_index_sel[ch][i]);
1063 
1064  /* Scale factor adjustment index: transmitted in case of Huffman coding */
1065  for (i = 0; i < DCA_CODE_BOOKS; i++)
1066  for (ch = 0; ch < c->fullband_channels; ch++)
1067  if (c->quant_index_sel[ch][i] < ff_dca_quant_index_group_size[i])
1068  put_bits(&c->pb, 2, 0);
1069 
1070  /* Audio header CRC check word: not transmitted */
1071 }
1072 
1073 static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch)
1074 {
1075  int i, j, sum, bits, sel;
1076  if (c->abits[ch][band] <= DCA_CODE_BOOKS) {
1077  av_assert0(c->abits[ch][band] > 0);
1078  sel = c->quant_index_sel[ch][c->abits[ch][band] - 1];
1079  // Huffman codes
1080  if (sel < ff_dca_quant_index_group_size[c->abits[ch][band] - 1]) {
1081  ff_dca_vlc_enc_quant(&c->pb, &c->quantized[ch][band][ss * 8], 8,
1082  sel, c->abits[ch][band] - 1);
1083  return;
1084  }
1085 
1086  // Block codes
1087  if (c->abits[ch][band] <= 7) {
1088  for (i = 0; i < 8; i += 4) {
1089  sum = 0;
1090  for (j = 3; j >= 0; j--) {
1091  sum *= ff_dca_quant_levels[c->abits[ch][band]];
1092  sum += c->quantized[ch][band][ss * 8 + i + j];
1093  sum += (ff_dca_quant_levels[c->abits[ch][band]] - 1) / 2;
1094  }
1095  put_bits(&c->pb, bit_consumption[c->abits[ch][band]] / 4, sum);
1096  }
1097  return;
1098  }
1099  }
1100 
1101  for (i = 0; i < 8; i++) {
1102  bits = bit_consumption[c->abits[ch][band]] / 16;
1103  put_sbits(&c->pb, bits, c->quantized[ch][band][ss * 8 + i]);
1104  }
1105 }
1106 
1107 static void put_subframe(DCAEncContext *c, int subframe)
1108 {
1109  int i, band, ss, ch;
1110 
1111  /* Subsubframes count */
1112  put_bits(&c->pb, 2, SUBSUBFRAMES -1);
1113 
1114  /* Partial subsubframe sample count: dummy */
1115  put_bits(&c->pb, 3, 0);
1116 
1117  /* Prediction mode: no ADPCM, in each channel and subband */
1118  for (ch = 0; ch < c->fullband_channels; ch++)
1119  for (band = 0; band < DCAENC_SUBBANDS; band++)
1120  put_bits(&c->pb, 1, !(c->prediction_mode[ch][band] == -1));
1121 
1122  /* Prediction VQ address */
1123  for (ch = 0; ch < c->fullband_channels; ch++)
1124  for (band = 0; band < DCAENC_SUBBANDS; band++)
1125  if (c->prediction_mode[ch][band] >= 0)
1126  put_bits(&c->pb, 12, c->prediction_mode[ch][band]);
1127 
1128  /* Bit allocation index */
1129  for (ch = 0; ch < c->fullband_channels; ch++) {
1130  if (c->bit_allocation_sel[ch] == 6) {
1131  for (band = 0; band < DCAENC_SUBBANDS; band++) {
1132  put_bits(&c->pb, 5, c->abits[ch][band]);
1133  }
1134  } else {
1135  ff_dca_vlc_enc_alloc(&c->pb, c->abits[ch], DCAENC_SUBBANDS,
1136  c->bit_allocation_sel[ch]);
1137  }
1138  }
1139 
1140  if (SUBSUBFRAMES > 1) {
1141  /* Transition mode: none for each channel and subband */
1142  for (ch = 0; ch < c->fullband_channels; ch++)
1143  for (band = 0; band < DCAENC_SUBBANDS; band++)
1144  if (c->abits[ch][band])
1145  put_bits(&c->pb, 1, 0); /* codebook A4 */
1146  }
1147 
1148  /* Scale factors */
1149  for (ch = 0; ch < c->fullband_channels; ch++)
1150  for (band = 0; band < DCAENC_SUBBANDS; band++)
1151  if (c->abits[ch][band])
1152  put_bits(&c->pb, 7, c->scale_factor[ch][band]);
1153 
1154  /* Joint subband scale factor codebook select: not transmitted */
1155  /* Scale factors for joint subband coding: not transmitted */
1156  /* Stereo down-mix coefficients: not transmitted */
1157  /* Dynamic range coefficient: not transmitted */
1158  /* Stde information CRC check word: not transmitted */
1159  /* VQ encoded high frequency subbands: not transmitted */
1160 
1161  /* LFE data: 8 samples and scalefactor */
1162  if (c->lfe_channel) {
1163  for (i = 0; i < DCA_LFE_SAMPLES; i++)
1164  put_bits(&c->pb, 8, quantize_value(c->downsampled_lfe[i], c->lfe_quant) & 0xff);
1165  put_bits(&c->pb, 8, c->lfe_scale_factor);
1166  }
1167 
1168  /* Audio data (subsubframes) */
1169  for (ss = 0; ss < SUBSUBFRAMES ; ss++)
1170  for (ch = 0; ch < c->fullband_channels; ch++)
1171  for (band = 0; band < DCAENC_SUBBANDS; band++)
1172  if (c->abits[ch][band])
1173  put_subframe_samples(c, ss, band, ch);
1174 
1175  /* DSYNC */
1176  put_bits(&c->pb, 16, 0xffff);
1177 }
1178 
1179 static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
1180  const AVFrame *frame, int *got_packet_ptr)
1181 {
1182  DCAEncContext *c = avctx->priv_data;
1183  const int32_t *samples;
1184  int ret, i;
1185 
1186  if ((ret = ff_get_encode_buffer(avctx, avpkt, c->frame_size, 0)) < 0)
1187  return ret;
1188 
1189  samples = (const int32_t *)frame->data[0];
1190 
1192  if (c->lfe_channel)
1194 
1196  if (c->options.adpcm_mode)
1197  adpcm_analysis(c);
1198  find_peaks(c);
1199  assign_bits(c);
1200  calc_lfe_scales(c);
1202 
1203  init_put_bits(&c->pb, avpkt->data, avpkt->size);
1207  for (i = 0; i < SUBFRAMES; i++)
1208  put_subframe(c, i);
1209 
1210  flush_put_bits(&c->pb);
1211  memset(put_bits_ptr(&c->pb), 0, put_bytes_left(&c->pb, 0));
1212 
1213  avpkt->pts = frame->pts;
1214  avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
1215  *got_packet_ptr = 1;
1216  return 0;
1217 }
1218 
1219 #define DCAENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
1220 
1221 static const AVOption options[] = {
1222  { "dca_adpcm", "Use ADPCM encoding", offsetof(DCAEncContext, options.adpcm_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DCAENC_FLAGS },
1223  { NULL },
1224 };
1225 
1226 static const AVClass dcaenc_class = {
1227  .class_name = "DCA (DTS Coherent Acoustics)",
1228  .item_name = av_default_item_name,
1229  .option = options,
1230  .version = LIBAVUTIL_VERSION_INT,
1231 };
1232 
1233 static const AVCodecDefault defaults[] = {
1234  { "b", "1411200" },
1235  { NULL },
1236 };
1237 
1239  .name = "dca",
1240  .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
1241  .type = AVMEDIA_TYPE_AUDIO,
1242  .id = AV_CODEC_ID_DTS,
1243  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_EXPERIMENTAL,
1244  .priv_data_size = sizeof(DCAEncContext),
1245  .init = encode_init,
1246  .close = encode_close,
1247  .encode2 = encode_frame,
1249  .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32,
1251  .supported_samplerates = sample_rates,
1252  .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
1257  0 },
1258  .defaults = defaults,
1259  .priv_class = &dcaenc_class,
1260 };
dcamath.h
DCAEncContext::pb
PutBitContext pb
Definition: dcaenc.c:65
lfe_downsample
static void lfe_downsample(DCAEncContext *c, const int32_t *input)
Definition: dcaenc.c:370
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1118
AVCodec
AVCodec.
Definition: codec.h:197
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:187
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:41
ff_exp10
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
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
opt.h
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1149
ff_dcaadpcm_do_real
int ff_dcaadpcm_do_real(int pred_vq_index, softfloat quant, int32_t scale_factor, int32_t step_size, const int32_t *prev_hist, const int32_t *in, int32_t *next_hist, int32_t *out, int len, int32_t peak)
Definition: dcaadpcm.c:183
mem_internal.h
DCAADPCMEncContext
Definition: dcaadpcm.h:29
DCAEncContext::subband
int32_t * subband[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:87
out
FILE * out
Definition: movenc.c:54
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1098
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:108
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:215
dca.h
options
static const AVOption options[]
Definition: dcaenc.c:1221
DCAEncContext::frame_size
int frame_size
Definition: dcaenc.c:69
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:953
walk_band_low
static void walk_band_low(DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
Definition: dcaenc.c:472
DCAEncContext::worst_noise_ever
int32_t worst_noise_ever
Definition: dcaenc.c:101
ff_dca_bit_rates
const uint32_t ff_dca_bit_rates[32]
Definition: dcadata.c:32
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:90
SUBSUBFRAMES
#define SUBSUBFRAMES
Definition: dcaenc.c:53
ff_dcaadpcm_free
av_cold void ff_dcaadpcm_free(DCAADPCMEncContext *s)
Definition: dcaadpcm.c:225
scalefactor_inv
static const softfloat scalefactor_inv[128]
Definition: dcaenc.h:63
put_sbits
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:280
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:61
erb
static const uint16_t erb[]
Definition: dcaenc.h:48
lfe_index
static const uint8_t lfe_index[7]
Definition: dca_lbr.c:106
put_subframe
static void put_subframe(DCAEncContext *c, int subframe)
Definition: dcaenc.c:1107
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:219
DCAEncContext::options
CompressionOptions options
Definition: dcaenc.c:68
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:365
get_step_size
static int32_t get_step_size(DCAEncContext *c, int ch, int band)
Definition: dcaenc.c:601
ff_dca_lossy_quant
const uint32_t ff_dca_lossy_quant[32]
Definition: dcadata.c:4223
AVOption
AVOption.
Definition: opt.h:248
encode.h
b
#define b
Definition: input.c:41
MAX_CHANNELS
#define MAX_CHANNELS
Definition: dcaenc.c:46
data
const char data[16]
Definition: mxf.c:142
ff_mdct_init
#define ff_mdct_init
Definition: fft.h:161
calc_lfe_scales
static void calc_lfe_scales(DCAEncContext *c)
Definition: dcaenc.c:937
DCAEncContext::adpcm_history
int32_t adpcm_history[MAX_CHANNELS][DCAENC_SUBBANDS][DCA_ADPCM_COEFFS *2]
Definition: dcaenc.c:85
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:551
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:383
update_band_masking
static void update_band_masking(DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
Definition: dcaenc.c:502
calc_one_scale
static int calc_one_scale(DCAEncContext *c, int32_t peak_cb, int abits, softfloat *quant)
Definition: dcaenc.c:613
DCAEncContext::lfe_quant
softfloat lfe_quant
Definition: dcaenc.c:80
quantize_value
static int32_t quantize_value(int32_t value, softfloat quant)
Definition: dcaenc.h:149
DCAEncContext::band_interpolation
const int32_t * band_interpolation
Definition: dcaenc.c:77
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: dcaenc.c:1179
put_frame_header
static void put_frame_header(DCAEncContext *c)
Definition: dcaenc.c:943
DCAEncContext::adpcm_ctx
DCAADPCMEncContext adpcm_ctx
Definition: dcaenc.c:66
ff_dca_vlc_calc_alloc_bits
uint32_t ff_dca_vlc_calc_alloc_bits(int *values, uint8_t n, uint8_t sel)
Definition: dcahuff.c:1354
DCAEncContext::history
int32_t history[MAX_CHANNELS][512]
Definition: dcaenc.c:86
calc_masking
static void calc_masking(DCAEncContext *c, const int32_t *input)
Definition: dcaenc.c:512
ff_dca_encoder
const AVCodec ff_dca_encoder
Definition: dcaenc.c:1238
DCAEncContext::fullband_channels
int fullband_channels
Definition: dcaenc.c:71
adpcm_analysis
static void adpcm_analysis(DCAEncContext *c)
Definition: dcaenc.c:573
ff_dca_fir_32bands_nonperfect
const float ff_dca_fir_32bands_nonperfect[512]
Definition: dcadata.c:6808
ff_dca_quant_index_group_size
const uint8_t ff_dca_quant_index_group_size[DCA_CODE_BOOKS]
Definition: dcadata.c:53
CompressionOptions::adpcm_mode
int adpcm_mode
Definition: dcaenc.c:60
accumulate_huff_bit_consumption
static void accumulate_huff_bit_consumption(int abits, int32_t *quantized, uint32_t *result)
Definition: dcaenc.c:690
init_quantization_noise
static int init_quantization_noise(DCAEncContext *c, int noise, int forbid_zero)
Definition: dcaenc.c:768
val
static double val(void *priv, double ch)
Definition: aeval.c:76
ff_dca_quant_levels
const uint32_t ff_dca_quant_levels[32]
Definition: dcadata.c:4215
ss
#define ss(width, name, subs,...)
Definition: cbs_vp9.c:261
dcadata.h
dca_core.h
DCAEncContext::auf
int32_t auf[9][AUBANDS][256]
Definition: dcaenc.c:108
DCAEncContext::consumed_bits
int consumed_bits
Definition: dcaenc.c:102
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:91
quant
static int quant(float coef, const float Q, const float rounding)
Quantize one coefficient.
Definition: aacenc_utils.h:59
put_bytes_left
static int put_bytes_left(const PutBitContext *s, int round_up)
Definition: put_bits.h:134
bit_consumption
static const int bit_consumption[27]
Definition: dcaenc.h:101
walk_band_high
static void walk_band_high(DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
Definition: dcaenc.c:487
quantize_adpcm_subband
static void quantize_adpcm_subband(DCAEncContext *c, int ch, int band)
Definition: dcaenc.c:646
DCAEncContext::quantized
int32_t quantized[MAX_CHANNELS][DCAENC_SUBBANDS][SUBBAND_SAMPLES]
Definition: dcaenc.c:88
avassert.h
DCAEncContext::lfe_fir_64i
int32_t lfe_fir_64i[512]
Definition: dcaenc.c:111
ff_samples_to_time_base
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
Definition: internal.h:262
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:181
AV_CODEC_CAP_EXPERIMENTAL
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: codec.h:100
av_cold
#define av_cold
Definition: attributes.h:90
DCA_LFE_SAMPLES
#define DCA_LFE_SAMPLES
Definition: dcaenc.c:49
quantize_adpcm
static void quantize_adpcm(DCAEncContext *c)
Definition: dcaenc.c:663
DCAEncContext::lfe_channel
int lfe_channel
Definition: dcaenc.c:73
DCAEncContext::abits
int abits[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:94
DCAEncContext::peak_cb
int32_t peak_cb[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:89
DCAEncContext::band_spectrum
const int32_t * band_spectrum
Definition: dcaenc.c:78
DCAEncContext::lfe_scale_factor
int lfe_scale_factor
Definition: dcaenc.c:79
s
#define s(width, name)
Definition: cbs_vp9.c:257
DCA_ADPCM_COEFFS
#define DCA_ADPCM_COEFFS
Definition: dcadata.h:28
hom
static double hom(double f)
Definition: dcaenc.c:115
DCAEncContext::eff_masking_curve_cb
int32_t eff_masking_curve_cb[256]
Definition: dcaenc.c:98
DCAEncContext::downsampled_lfe
int32_t downsampled_lfe[DCA_LFE_SAMPLES]
Definition: dcaenc.c:91
SUBBAND_SAMPLES
#define SUBBAND_SAMPLES
Definition: dcaenc.c:54
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
DCAEncContext::samplerate_index
int samplerate_index
Definition: dcaenc.c:74
bits
uint8_t bits
Definition: vp3data.h:141
set_best_abits_code
static uint32_t set_best_abits_code(int abits[DCAENC_SUBBANDS], int bands, int32_t *res)
Definition: dcaenc.c:740
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
CompressionOptions
Definition: dcaenc.c:59
bands
static const float bands[]
Definition: af_superequalizer.c:56
f
#define f(width, name)
Definition: cbs_vp9.c:255
PutBitContext
Definition: put_bits.h:49
arg
const char * arg
Definition: jacosubdec.c:67
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
if
if(ret)
Definition: filter_design.txt:179
AVCodecDefault
Definition: internal.h:207
softfloat
Definition: dcaenc.h:29
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
adjust_jnd
static void adjust_jnd(DCAEncContext *c, const int32_t in[512], int32_t out_cb[256])
Definition: dcaenc.c:439
NULL
#define NULL
Definition: coverity.c:32
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:136
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
ff_dca_lossless_quant
const uint32_t ff_dca_lossless_quant[32]
Definition: dcadata.c:4231
mul32
static int32_t mul32(int32_t a, int32_t b)
Definition: dcamath.h:52
ff_dca_lfe_fir_64
const float ff_dca_lfe_fir_64[256]
Definition: dcadata.c:7339
AV_COPY128U
#define AV_COPY128U(d, s)
Definition: intreadwrite.h:580
USED_26ABITS
#define USED_26ABITS
Definition: dcaenc.c:599
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:551
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
USED_1ABITS
#define USED_1ABITS
Definition: dcaenc.c:598
ff_dca_vlc_calc_quant_bits
uint32_t ff_dca_vlc_calc_quant_bits(int *values, uint8_t n, uint8_t sel, uint8_t table)
Definition: dcahuff.c:1332
stepsize_inv
static const softfloat stepsize_inv[27]
Definition: dcaenc.h:53
mathops.h
AV_CH_LAYOUT_5POINT1
#define AV_CH_LAYOUT_5POINT1
Definition: channel_layout.h:101
softfloat::e
int32_t e
Definition: dcaenc.h:31
DCAEncContext::band_masking_cb
int32_t band_masking_cb[32]
Definition: dcaenc.c:99
abs
#define abs(x)
Definition: cuda_runtime.h:35
ff_dcaadpcm_subband_analysis
int ff_dcaadpcm_subband_analysis(const DCAADPCMEncContext *s, const int32_t *in, int len, int *diff)
Definition: dcaadpcm.c:125
DCAEncContext::mdct
FFTContext mdct
Definition: dcaenc.c:67
exp
int8_t exp
Definition: eval.c:72
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
DCAEncContext::channels
int channels
Definition: dcaenc.c:72
encode_close
static av_cold int encode_close(AVCodecContext *avctx)
Definition: dcaenc.c:310
SUBFRAMES
#define SUBFRAMES
Definition: dcaenc.c:52
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
DCAEncContext::worst_quantization_noise
int32_t worst_quantization_noise
Definition: dcaenc.c:100
DCAEncContext::band_interpolation_tab
int32_t band_interpolation_tab[2][512]
Definition: dcaenc.c:106
DCAEncContext::lfe_peak_cb
int32_t lfe_peak_cb
Definition: dcaenc.c:81
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
ff_dca_scale_factor_quant7
const uint32_t ff_dca_scale_factor_quant7[128]
Definition: dcadata.c:4172
AVPacket::size
int size
Definition: packet.h:366
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:325
subband_bufer_free
static void subband_bufer_free(DCAEncContext *c)
Definition: dcaenc.c:155
DCAEncContext::quant
softfloat quant[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:96
walk_band_t
void(* walk_band_t)(DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
Definition: dcaenc.c:468
add_cb
static int32_t add_cb(DCAEncContext *c, int32_t a, int32_t b)
Definition: dcaenc.c:412
AV_CODEC_ID_DTS
@ AV_CODEC_ID_DTS
Definition: codec_id.h:425
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
sample
#define sample
Definition: flacdsp_template.c:44
DCA_CODE_BOOKS
#define DCA_CODE_BOOKS
Definition: dcahuff.h:32
ff_mdct_end
#define ff_mdct_end
Definition: fft.h:162
DCA_BITALLOC_12_COUNT
#define DCA_BITALLOC_12_COUNT
Definition: dcahuff.h:33
encode_init
static int encode_init(AVCodecContext *avctx)
Definition: dcaenc.c:164
fill_in_adpcm_bufer
static void fill_in_adpcm_bufer(DCAEncContext *c)
Definition: dcaenc.c:901
DCAEncContext::bitrate_index
int bitrate_index
Definition: dcaenc.c:75
dcaadpcm.h
DCA_MAX_FRAME_SIZE
#define DCA_MAX_FRAME_SIZE
Definition: dcaenc.c:47
quantize_pcm
static void quantize_pcm(DCAEncContext *c)
Definition: dcaenc.c:673
DCAEncContext::masking_curve_cb
int32_t masking_curve_cb[SUBSUBFRAMES][256]
Definition: dcaenc.c:92
dcaenc.h
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
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
put_primary_audio_header
static void put_primary_audio_header(DCAEncContext *c)
Definition: dcaenc.c:1026
M_PI
#define M_PI
Definition: mathematics.h:52
sample_rates
sample_rates
Definition: ffmpeg_filter.c:156
DCAEncContext::quant_index_sel
int32_t quant_index_sel[MAX_CHANNELS][DCA_CODE_BOOKS]
Definition: dcaenc.c:97
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:1099
layout
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 layout
Definition: filter_design.txt:18
DCAEncContext::frame_bits
int frame_bits
Definition: dcaenc.c:70
AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_5POINT0
Definition: channel_layout.h:100
find_peaks
static void find_peaks(DCAEncContext *c)
Definition: dcaenc.c:559
ff_dca_quant_index_sel_nbits
const uint8_t ff_dca_quant_index_sel_nbits[DCA_CODE_BOOKS]
Definition: dcadata.c:49
FFTContext
Definition: fft.h:83
i
int i
Definition: input.c:407
ff_dca_vlc_enc_quant
void ff_dca_vlc_enc_quant(PutBitContext *pb, int *values, uint8_t n, uint8_t sel, uint8_t table)
Definition: dcahuff.c:1344
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:358
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:49
common.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AUBANDS
#define AUBANDS
Definition: dcaenc.c:55
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:204
len
int len
Definition: vorbis_enc_data.h:426
norm__
static int32_t norm__(int64_t a, int bits)
Definition: dcamath.h:27
DCAEncContext::channel_config
int channel_config
Definition: dcaenc.c:76
channel_reorder_nolfe
static const int8_t channel_reorder_nolfe[7][5]
Definition: dca_lbr.c:86
avcodec.h
snr_fudge
static const int snr_fudge
Definition: dcaenc.c:597
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
subband_transform
static void subband_transform(DCAEncContext *c, const int32_t *input)
Definition: dcaenc.c:320
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
DCAEncContext::consumed_adpcm_bits
int consumed_adpcm_bits
Number of bits to transmit ADPCM related info.
Definition: dcaenc.c:103
channel_reorder_lfe
static const int8_t channel_reorder_lfe[7][5]
Definition: dca_lbr.c:96
ff_dca_core_dequantize
static void ff_dca_core_dequantize(int32_t *output, const int32_t *input, int32_t step_size, int32_t scale, int residual, int len)
Definition: dca_core.h:227
fft.h
ff_dcaadpcm_init
av_cold int ff_dcaadpcm_init(DCAADPCMEncContext *s)
Definition: dcaadpcm.c:212
AVCodecContext
main external API structure.
Definition: avcodec.h:501
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:251
put_bits_ptr
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:369
channel_layout.h
noise
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise_bsf.c:36
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:81
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
DCAEncContext
Definition: dcaenc.c:63
ffmath.h
subband_bufer_alloc
static int subband_bufer_alloc(DCAEncContext *c)
Definition: dcaenc.c:134
assign_bits
static void assign_bits(DCAEncContext *c)
Definition: dcaenc.c:847
DCAENC_SUBBANDS
#define DCAENC_SUBBANDS
Definition: dcaenc.c:51
get_cb
static int32_t get_cb(DCAEncContext *c, int32_t in)
Definition: dcaenc.c:400
DCAEncContext::cos_table
int32_t cos_table[2048]
Definition: dcaenc.c:105
bitstream_sfreq
static const uint8_t bitstream_sfreq[]
Definition: dcaenc.h:38
add
static float add(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:36
find_peak
static int32_t find_peak(DCAEncContext *c, const int32_t *in, int len)
Definition: dcaenc.c:547
av_get_default_channel_layout
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
Definition: channel_layout.c:231
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:142
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
AVPacket
This structure stores compressed data.
Definition: packet.h:342
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:528
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
ff_dca_fir_32bands_perfect
const float ff_dca_fir_32bands_perfect[512]
Definition: dcadata.c:6293
defaults
static const AVCodecDefault defaults[]
Definition: dcaenc.c:1233
shift_history
static void shift_history(DCAEncContext *c, const int32_t *input)
Definition: dcaenc.c:889
set_best_code
static uint32_t set_best_code(uint32_t vlc_bits[DCA_CODE_BOOKS][7], uint32_t clc_bits[DCA_CODE_BOOKS], int32_t res[DCA_CODE_BOOKS])
Definition: dcaenc.c:699
softfloat::m
int32_t m
Definition: dcaenc.h:30
int32_t
int32_t
Definition: audioconvert.c:56
DCAEncContext::prediction_mode
int32_t prediction_mode[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:84
ff_dca_vlc_enc_alloc
void ff_dca_vlc_enc_alloc(PutBitContext *pb, int *values, uint8_t n, uint8_t sel)
Definition: dcahuff.c:1365
DCAEncContext::cb_to_add
int32_t cb_to_add[256]
Definition: dcaenc.c:109
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:73
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
COS_T
#define COS_T(x)
Definition: dcaenc.c:57
h
h
Definition: vp9dsp_template.c:2038
DCAEncContext::cb_to_level
int32_t cb_to_level[2048]
Definition: dcaenc.c:110
put_subframe_samples
static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch)
Definition: dcaenc.c:1073
DCAEncContext::bit_allocation_sel
int32_t bit_allocation_sel[MAX_CHANNELS]
Definition: dcaenc.c:93
DCAEncContext::band_spectrum_tab
int32_t band_spectrum_tab[2][8]
Definition: dcaenc.c:107
put_bits.h
calc_power
static void calc_power(DCAEncContext *c, const int32_t in[2 *256], int32_t power[256])
Definition: dcaenc.c:422
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:62
AV_CH_LAYOUT_2_2
#define AV_CH_LAYOUT_2_2
Definition: channel_layout.h:98
channel
channel
Definition: ebur128.h:39
DCAEncContext::diff_peak_cb
int32_t diff_peak_cb[MAX_CHANNELS][DCAENC_SUBBANDS]
expected peak of residual signal
Definition: dcaenc.c:90
DCAENC_FLAGS
#define DCAENC_FLAGS
Definition: dcaenc.c:1219
dcaenc_class
static const AVClass dcaenc_class
Definition: dcaenc.c:1226
DCAEncContext::scale_factor
int scale_factor[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:95
gammafilter
static double gammafilter(int i, double f)
Definition: dcaenc.c:125
DCAEncContext::channel_order_tab
const int8_t * channel_order_tab
channel reordering table, lfe and non lfe
Definition: dcaenc.c:82