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