FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 #include "libavutil/avassert.h"
26 #include "libavutil/common.h"
27 #include "libavutil/ffmath.h"
28 #include "avcodec.h"
29 #include "dca.h"
30 #include "dcadata.h"
31 #include "dcaenc.h"
32 #include "internal.h"
33 #include "mathops.h"
34 #include "put_bits.h"
35 
36 #define MAX_CHANNELS 6
37 #define DCA_MAX_FRAME_SIZE 16384
38 #define DCA_HEADER_SIZE 13
39 #define DCA_LFE_SAMPLES 8
40 
41 #define DCAENC_SUBBANDS 32
42 #define SUBFRAMES 1
43 #define SUBSUBFRAMES 2
44 #define SUBBAND_SAMPLES (SUBFRAMES * SUBSUBFRAMES * 8)
45 #define AUBANDS 25
46 
47 typedef struct DCAEncContext {
52  int channels;
62  const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe
63 
64  int32_t history[MAX_CHANNELS][512]; /* This is a circular buffer */
81 
82 static int32_t cos_table[2048];
83 static int32_t band_interpolation[2][512];
84 static int32_t band_spectrum[2][8];
85 static int32_t auf[9][AUBANDS][256];
86 static int32_t cb_to_add[256];
87 static int32_t cb_to_level[2048];
88 static int32_t lfe_fir_64i[512];
89 
90 /* Transfer function of outer and middle ear, Hz -> dB */
91 static double hom(double f)
92 {
93  double f1 = f / 1000;
94 
95  return -3.64 * pow(f1, -0.8)
96  + 6.8 * exp(-0.6 * (f1 - 3.4) * (f1 - 3.4))
97  - 6.0 * exp(-0.15 * (f1 - 8.7) * (f1 - 8.7))
98  - 0.0006 * (f1 * f1) * (f1 * f1);
99 }
100 
101 static double gammafilter(int i, double f)
102 {
103  double h = (f - fc[i]) / erb[i];
104 
105  h = 1 + h * h;
106  h = 1 / (h * h);
107  return 20 * log10(h);
108 }
109 
110 static int encode_init(AVCodecContext *avctx)
111 {
112  DCAEncContext *c = avctx->priv_data;
113  uint64_t layout = avctx->channel_layout;
114  int i, j, min_frame_bits;
115 
116  c->fullband_channels = c->channels = avctx->channels;
117  c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6);
120  c->worst_quantization_noise = -2047;
121  c->worst_noise_ever = -2047;
122 
123  if (!layout) {
124  av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
125  "encoder will guess the layout, but it "
126  "might be incorrect.\n");
127  layout = av_get_default_channel_layout(avctx->channels);
128  }
129  switch (layout) {
130  case AV_CH_LAYOUT_MONO: c->channel_config = 0; break;
131  case AV_CH_LAYOUT_STEREO: c->channel_config = 2; break;
132  case AV_CH_LAYOUT_2_2: c->channel_config = 8; break;
133  case AV_CH_LAYOUT_5POINT0: c->channel_config = 9; break;
134  case AV_CH_LAYOUT_5POINT1: c->channel_config = 9; break;
135  default:
136  av_log(avctx, AV_LOG_ERROR, "Unsupported channel layout!\n");
137  return AVERROR_PATCHWELCOME;
138  }
139 
140  if (c->lfe_channel) {
141  c->fullband_channels--;
143  } else {
145  }
146 
147  for (i = 0; i < MAX_CHANNELS; i++) {
148  for (j = 0; j < DCA_CODE_BOOKS; j++) {
150  }
151  /* 6 - no Huffman */
152  c->bit_allocation_sel[i] = 6;
153  }
154 
155  for (i = 0; i < 9; i++) {
156  if (sample_rates[i] == avctx->sample_rate)
157  break;
158  }
159  if (i == 9)
160  return AVERROR(EINVAL);
161  c->samplerate_index = i;
162 
163  if (avctx->bit_rate < 32000 || avctx->bit_rate > 3840000) {
164  av_log(avctx, AV_LOG_ERROR, "Bit rate %"PRId64" not supported.", (int64_t)avctx->bit_rate);
165  return AVERROR(EINVAL);
166  }
167  for (i = 0; ff_dca_bit_rates[i] < avctx->bit_rate; i++)
168  ;
169  c->bitrate_index = i;
170  c->frame_bits = FFALIGN((avctx->bit_rate * 512 + avctx->sample_rate - 1) / avctx->sample_rate, 32);
171  min_frame_bits = 132 + (493 + 28 * 32) * c->fullband_channels + c->lfe_channel * 72;
172  if (c->frame_bits < min_frame_bits || c->frame_bits > (DCA_MAX_FRAME_SIZE << 3))
173  return AVERROR(EINVAL);
174 
175  c->frame_size = (c->frame_bits + 7) / 8;
176 
177  avctx->frame_size = 32 * SUBBAND_SAMPLES;
178 
179  if (!cos_table[0]) {
180  int j, k;
181 
182  cos_table[0] = 0x7fffffff;
183  cos_table[512] = 0;
184  cos_table[1024] = -cos_table[0];
185  for (i = 1; i < 512; i++) {
186  cos_table[i] = (int32_t)(0x7fffffff * cos(M_PI * i / 1024));
187  cos_table[1024-i] = -cos_table[i];
188  cos_table[1024+i] = -cos_table[i];
189  cos_table[2048-i] = cos_table[i];
190  }
191  for (i = 0; i < 2048; i++) {
192  cb_to_level[i] = (int32_t)(0x7fffffff * ff_exp10(-0.005 * i));
193  }
194 
195  for (k = 0; k < 32; k++) {
196  for (j = 0; j < 8; j++) {
197  lfe_fir_64i[64 * j + k] = (int32_t)(0xffffff800000ULL * ff_dca_lfe_fir_64[8 * k + j]);
198  lfe_fir_64i[64 * (7-j) + (63 - k)] = (int32_t)(0xffffff800000ULL * ff_dca_lfe_fir_64[8 * k + j]);
199  }
200  }
201 
202  for (i = 0; i < 512; i++) {
203  band_interpolation[0][i] = (int32_t)(0x1000000000ULL * ff_dca_fir_32bands_perfect[i]);
204  band_interpolation[1][i] = (int32_t)(0x1000000000ULL * ff_dca_fir_32bands_nonperfect[i]);
205  }
206 
207  for (i = 0; i < 9; i++) {
208  for (j = 0; j < AUBANDS; j++) {
209  for (k = 0; k < 256; k++) {
210  double freq = sample_rates[i] * (k + 0.5) / 512;
211 
212  auf[i][j][k] = (int32_t)(10 * (hom(freq) + gammafilter(j, freq)));
213  }
214  }
215  }
216 
217  for (i = 0; i < 256; i++) {
218  double add = 1 + ff_exp10(-0.01 * i);
219  cb_to_add[i] = (int32_t)(100 * log10(add));
220  }
221  for (j = 0; j < 8; j++) {
222  double accum = 0;
223  for (i = 0; i < 512; i++) {
224  double reconst = ff_dca_fir_32bands_perfect[i] * ((i & 64) ? (-1) : 1);
225  accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (j + 0.5) / 512);
226  }
227  band_spectrum[0][j] = (int32_t)(200 * log10(accum));
228  }
229  for (j = 0; j < 8; j++) {
230  double accum = 0;
231  for (i = 0; i < 512; i++) {
232  double reconst = ff_dca_fir_32bands_nonperfect[i] * ((i & 64) ? (-1) : 1);
233  accum += reconst * cos(2 * M_PI * (i + 0.5 - 256) * (j + 0.5) / 512);
234  }
235  band_spectrum[1][j] = (int32_t)(200 * log10(accum));
236  }
237  }
238  return 0;
239 }
240 
241 static inline int32_t cos_t(int x)
242 {
243  return cos_table[x & 2047];
244 }
245 
246 static inline int32_t sin_t(int x)
247 {
248  return cos_t(x - 512);
249 }
250 
251 static inline int32_t half32(int32_t a)
252 {
253  return (a + 1) >> 1;
254 }
255 
256 static inline int32_t mul32(int32_t a, int32_t b)
257 {
258  int64_t r = (int64_t)a * b + 0x80000000ULL;
259  return r >> 32;
260 }
261 
262 static void subband_transform(DCAEncContext *c, const int32_t *input)
263 {
264  int ch, subs, i, k, j;
265 
266  for (ch = 0; ch < c->fullband_channels; ch++) {
267  /* History is copied because it is also needed for PSY */
268  int32_t hist[512];
269  int hist_start = 0;
270  const int chi = c->channel_order_tab[ch];
271 
272  memcpy(hist, &c->history[ch][0], 512 * sizeof(int32_t));
273 
274  for (subs = 0; subs < SUBBAND_SAMPLES; subs++) {
275  int32_t accum[64];
276  int32_t resp;
277  int band;
278 
279  /* Calculate the convolutions at once */
280  memset(accum, 0, 64 * sizeof(int32_t));
281 
282  for (k = 0, i = hist_start, j = 0;
283  i < 512; k = (k + 1) & 63, i++, j++)
284  accum[k] += mul32(hist[i], c->band_interpolation[j]);
285  for (i = 0; i < hist_start; k = (k + 1) & 63, i++, j++)
286  accum[k] += mul32(hist[i], c->band_interpolation[j]);
287 
288  for (k = 16; k < 32; k++)
289  accum[k] = accum[k] - accum[31 - k];
290  for (k = 32; k < 48; k++)
291  accum[k] = accum[k] + accum[95 - k];
292 
293  for (band = 0; band < 32; band++) {
294  resp = 0;
295  for (i = 16; i < 48; i++) {
296  int s = (2 * band + 1) * (2 * (i + 16) + 1);
297  resp += mul32(accum[i], cos_t(s << 3)) >> 3;
298  }
299 
300  c->subband[ch][band][subs] = ((band + 1) & 2) ? -resp : resp;
301  }
302 
303  /* Copy in 32 new samples from input */
304  for (i = 0; i < 32; i++)
305  hist[i + hist_start] = input[(subs * 32 + i) * c->channels + chi];
306 
307  hist_start = (hist_start + 32) & 511;
308  }
309  }
310 }
311 
312 static void lfe_downsample(DCAEncContext *c, const int32_t *input)
313 {
314  /* FIXME: make 128x LFE downsampling possible */
315  const int lfech = lfe_index[c->channel_config];
316  int i, j, lfes;
317  int32_t hist[512];
318  int32_t accum;
319  int hist_start = 0;
320 
321  memcpy(hist, &c->history[c->channels - 1][0], 512 * sizeof(int32_t));
322 
323  for (lfes = 0; lfes < DCA_LFE_SAMPLES; lfes++) {
324  /* Calculate the convolution */
325  accum = 0;
326 
327  for (i = hist_start, j = 0; i < 512; i++, j++)
328  accum += mul32(hist[i], lfe_fir_64i[j]);
329  for (i = 0; i < hist_start; i++, j++)
330  accum += mul32(hist[i], lfe_fir_64i[j]);
331 
332  c->downsampled_lfe[lfes] = accum;
333 
334  /* Copy in 64 new samples from input */
335  for (i = 0; i < 64; i++)
336  hist[i + hist_start] = input[(lfes * 64 + i) * c->channels + lfech];
337 
338  hist_start = (hist_start + 64) & 511;
339  }
340 }
341 
342 typedef struct {
345 } cplx32;
346 
347 static void fft(const int32_t in[2 * 256], cplx32 out[256])
348 {
349  cplx32 buf[256], rin[256], rout[256];
350  int i, j, k, l;
351 
352  /* do two transforms in parallel */
353  for (i = 0; i < 256; i++) {
354  /* Apply the Hann window */
355  rin[i].re = mul32(in[2 * i], 0x3fffffff - (cos_t(8 * i + 2) >> 1));
356  rin[i].im = mul32(in[2 * i + 1], 0x3fffffff - (cos_t(8 * i + 6) >> 1));
357  }
358  /* pre-rotation */
359  for (i = 0; i < 256; i++) {
360  buf[i].re = mul32(cos_t(4 * i + 2), rin[i].re)
361  - mul32(sin_t(4 * i + 2), rin[i].im);
362  buf[i].im = mul32(cos_t(4 * i + 2), rin[i].im)
363  + mul32(sin_t(4 * i + 2), rin[i].re);
364  }
365 
366  for (j = 256, l = 1; j != 1; j >>= 1, l <<= 1) {
367  for (k = 0; k < 256; k += j) {
368  for (i = k; i < k + j / 2; i++) {
369  cplx32 sum, diff;
370  int t = 8 * l * i;
371 
372  sum.re = buf[i].re + buf[i + j / 2].re;
373  sum.im = buf[i].im + buf[i + j / 2].im;
374 
375  diff.re = buf[i].re - buf[i + j / 2].re;
376  diff.im = buf[i].im - buf[i + j / 2].im;
377 
378  buf[i].re = half32(sum.re);
379  buf[i].im = half32(sum.im);
380 
381  buf[i + j / 2].re = mul32(diff.re, cos_t(t))
382  - mul32(diff.im, sin_t(t));
383  buf[i + j / 2].im = mul32(diff.im, cos_t(t))
384  + mul32(diff.re, sin_t(t));
385  }
386  }
387  }
388  /* post-rotation */
389  for (i = 0; i < 256; i++) {
390  int b = ff_reverse[i];
391  rout[i].re = mul32(buf[b].re, cos_t(4 * i))
392  - mul32(buf[b].im, sin_t(4 * i));
393  rout[i].im = mul32(buf[b].im, cos_t(4 * i))
394  + mul32(buf[b].re, sin_t(4 * i));
395  }
396  for (i = 0; i < 256; i++) {
397  /* separate the results of the two transforms */
398  cplx32 o1, o2;
399 
400  o1.re = rout[i].re - rout[255 - i].re;
401  o1.im = rout[i].im + rout[255 - i].im;
402 
403  o2.re = rout[i].im - rout[255 - i].im;
404  o2.im = -rout[i].re - rout[255 - i].re;
405 
406  /* combine them into one long transform */
407  out[i].re = mul32( o1.re + o2.re, cos_t(2 * i + 1))
408  + mul32( o1.im - o2.im, sin_t(2 * i + 1));
409  out[i].im = mul32( o1.im + o2.im, cos_t(2 * i + 1))
410  + mul32(-o1.re + o2.re, sin_t(2 * i + 1));
411  }
412 }
413 
415 {
416  int i, res;
417 
418  res = 0;
419  if (in < 0)
420  in = -in;
421  for (i = 1024; i > 0; i >>= 1) {
422  if (cb_to_level[i + res] >= in)
423  res += i;
424  }
425  return -res;
426 }
427 
429 {
430  if (a < b)
431  FFSWAP(int32_t, a, b);
432 
433  if (a - b >= 256)
434  return a;
435  return a + cb_to_add[a - b];
436 }
437 
438 static void adjust_jnd(int samplerate_index,
439  const int32_t in[512], int32_t out_cb[256])
440 {
441  int32_t power[256];
442  cplx32 out[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  int i, j;
448 
449  fft(in, out);
450 
451  for (j = 0; j < 256; j++) {
452  power[j] = add_cb(get_cb(out[j].re), get_cb(out[j].im));
453  out_cb_unnorm[j] = -2047; /* and can only grow */
454  }
455 
456  for (i = 0; i < AUBANDS; i++) {
457  denom = ca_cb; /* and can only grow */
458  for (j = 0; j < 256; j++)
459  denom = add_cb(denom, power[j] + auf[samplerate_index][i][j]);
460  for (j = 0; j < 256; j++)
461  out_cb_unnorm[j] = add_cb(out_cb_unnorm[j],
462  -denom + auf[samplerate_index][i][j]);
463  }
464 
465  for (j = 0; j < 256; j++)
466  out_cb[j] = add_cb(out_cb[j], -out_cb_unnorm[j] - ca_cb - cs_cb);
467 }
468 
469 typedef void (*walk_band_t)(DCAEncContext *c, int band1, int band2, int f,
470  int32_t spectrum1, int32_t spectrum2, int channel,
471  int32_t * arg);
472 
473 static void walk_band_low(DCAEncContext *c, int band, int channel,
474  walk_band_t walk, int32_t *arg)
475 {
476  int f;
477 
478  if (band == 0) {
479  for (f = 0; f < 4; f++)
480  walk(c, 0, 0, f, 0, -2047, channel, arg);
481  } else {
482  for (f = 0; f < 8; f++)
483  walk(c, band, band - 1, 8 * band - 4 + f,
484  c->band_spectrum[7 - f], c->band_spectrum[f], channel, arg);
485  }
486 }
487 
488 static void walk_band_high(DCAEncContext *c, int band, int channel,
489  walk_band_t walk, int32_t *arg)
490 {
491  int f;
492 
493  if (band == 31) {
494  for (f = 0; f < 4; f++)
495  walk(c, 31, 31, 256 - 4 + f, 0, -2047, channel, arg);
496  } else {
497  for (f = 0; f < 8; f++)
498  walk(c, band, band + 1, 8 * band + 4 + f,
499  c->band_spectrum[f], c->band_spectrum[7 - f], channel, arg);
500  }
501 }
502 
503 static void update_band_masking(DCAEncContext *c, int band1, int band2,
504  int f, int32_t spectrum1, int32_t spectrum2,
505  int channel, int32_t * arg)
506 {
507  int32_t value = c->eff_masking_curve_cb[f] - spectrum1;
508 
509  if (value < c->band_masking_cb[band1])
510  c->band_masking_cb[band1] = value;
511 }
512 
513 static void calc_masking(DCAEncContext *c, const int32_t *input)
514 {
515  int i, k, band, ch, ssf;
516  int32_t data[512];
517 
518  for (i = 0; i < 256; i++)
519  for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
520  c->masking_curve_cb[ssf][i] = -2047;
521 
522  for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
523  for (ch = 0; ch < c->fullband_channels; ch++) {
524  const int chi = c->channel_order_tab[ch];
525 
526  for (i = 0, k = 128 + 256 * ssf; k < 512; i++, k++)
527  data[i] = c->history[ch][k];
528  for (k -= 512; i < 512; i++, k++)
529  data[i] = input[k * c->channels + chi];
530  adjust_jnd(c->samplerate_index, data, c->masking_curve_cb[ssf]);
531  }
532  for (i = 0; i < 256; i++) {
533  int32_t m = 2048;
534 
535  for (ssf = 0; ssf < SUBSUBFRAMES; ssf++)
536  if (c->masking_curve_cb[ssf][i] < m)
537  m = c->masking_curve_cb[ssf][i];
538  c->eff_masking_curve_cb[i] = m;
539  }
540 
541  for (band = 0; band < 32; band++) {
542  c->band_masking_cb[band] = 2048;
543  walk_band_low(c, band, 0, update_band_masking, NULL);
545  }
546 }
547 
549 {
550  int band, ch;
551 
552  for (ch = 0; ch < c->fullband_channels; ch++)
553  for (band = 0; band < 32; band++) {
554  int sample;
555  int32_t m = 0;
556 
557  for (sample = 0; sample < SUBBAND_SAMPLES; sample++) {
558  int32_t s = abs(c->subband[ch][band][sample]);
559  if (m < s)
560  m = s;
561  }
562  c->peak_cb[ch][band] = get_cb(m);
563  }
564 
565  if (c->lfe_channel) {
566  int sample;
567  int32_t m = 0;
568 
569  for (sample = 0; sample < DCA_LFE_SAMPLES; sample++)
570  if (m < abs(c->downsampled_lfe[sample]))
571  m = abs(c->downsampled_lfe[sample]);
572  c->lfe_peak_cb = get_cb(m);
573  }
574 }
575 
576 static const int snr_fudge = 128;
577 #define USED_1ABITS 1
578 #define USED_NABITS 2
579 #define USED_26ABITS 4
580 
582 {
583  int32_t offset = 1 << (quant.e - 1);
584 
585  value = mul32(value, quant.m) + offset;
586  value = value >> quant.e;
587  return value;
588 }
589 
590 static int calc_one_scale(int32_t peak_cb, int abits, softfloat *quant)
591 {
592  int32_t peak;
593  int our_nscale, try_remove;
594  softfloat our_quant;
595 
596  av_assert0(peak_cb <= 0);
597  av_assert0(peak_cb >= -2047);
598 
599  our_nscale = 127;
600  peak = cb_to_level[-peak_cb];
601 
602  for (try_remove = 64; try_remove > 0; try_remove >>= 1) {
603  if (scalefactor_inv[our_nscale - try_remove].e + stepsize_inv[abits].e <= 17)
604  continue;
605  our_quant.m = mul32(scalefactor_inv[our_nscale - try_remove].m, stepsize_inv[abits].m);
606  our_quant.e = scalefactor_inv[our_nscale - try_remove].e + stepsize_inv[abits].e - 17;
607  if ((ff_dca_quant_levels[abits] - 1) / 2 < quantize_value(peak, our_quant))
608  continue;
609  our_nscale -= try_remove;
610  }
611 
612  if (our_nscale >= 125)
613  our_nscale = 124;
614 
615  quant->m = mul32(scalefactor_inv[our_nscale].m, stepsize_inv[abits].m);
616  quant->e = scalefactor_inv[our_nscale].e + stepsize_inv[abits].e - 17;
617  av_assert0((ff_dca_quant_levels[abits] - 1) / 2 >= quantize_value(peak, *quant));
618 
619  return our_nscale;
620 }
621 
623 {
624  int sample, band, ch;
625 
626  for (ch = 0; ch < c->fullband_channels; ch++)
627  for (band = 0; band < 32; band++)
628  for (sample = 0; sample < SUBBAND_SAMPLES; sample++)
629  c->quantized[ch][band][sample] = quantize_value(c->subband[ch][band][sample], c->quant[ch][band]);
630 }
631 
632 static void accumulate_huff_bit_consumption(int abits, int32_t *quantized, uint32_t *result)
633 {
634  uint8_t sel, id = abits - 1;
635  for (sel = 0; sel < ff_dca_quant_index_group_size[id]; sel++)
636  result[sel] += ff_dca_vlc_calc_quant_bits(quantized, SUBBAND_SAMPLES, sel, id);
637 }
638 
639 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])
640 {
641  uint8_t i, sel;
642  uint32_t best_sel_bits[DCA_CODE_BOOKS];
643  int32_t best_sel_id[DCA_CODE_BOOKS];
644  uint32_t t, bits = 0;
645 
646  for (i = 0; i < DCA_CODE_BOOKS; i++) {
647 
648  av_assert0(!((!!vlc_bits[i][0]) ^ (!!clc_bits[i])));
649  if (vlc_bits[i][0] == 0) {
650  /* do not transmit adjustment index for empty codebooks */
651  res[i] = ff_dca_quant_index_group_size[i];
652  /* and skip it */
653  continue;
654  }
655 
656  best_sel_bits[i] = vlc_bits[i][0];
657  best_sel_id[i] = 0;
658  for (sel = 0; sel < ff_dca_quant_index_group_size[i]; sel++) {
659  if (best_sel_bits[i] > vlc_bits[i][sel] && vlc_bits[i][sel]) {
660  best_sel_bits[i] = vlc_bits[i][sel];
661  best_sel_id[i] = sel;
662  }
663  }
664 
665  /* 2 bits to transmit scale factor adjustment index */
666  t = best_sel_bits[i] + 2;
667  if (t < clc_bits[i]) {
668  res[i] = best_sel_id[i];
669  bits += t;
670  } else {
671  res[i] = ff_dca_quant_index_group_size[i];
672  bits += clc_bits[i];
673  }
674  }
675  return bits;
676 }
677 
678 static uint32_t set_best_abits_code(int abits[DCAENC_SUBBANDS], int bands, int32_t *res)
679 {
680  uint8_t i;
681  uint32_t t;
682  int32_t best_sel = 6;
683  int32_t best_bits = bands * 5;
684 
685  /* Check do we have subband which cannot be encoded by Huffman tables */
686  for (i = 0; i < bands; i++) {
687  if (abits[i] > 12) {
688  *res = best_sel;
689  return best_bits;
690  }
691  }
692 
693  for (i = 0; i < DCA_BITALLOC_12_COUNT; i++) {
694  t = ff_dca_vlc_calc_alloc_bits(abits, bands, i);
695  if (t < best_bits) {
696  best_bits = t;
697  best_sel = i;
698  }
699  }
700 
701  *res = best_sel;
702  return best_bits;
703 }
704 
706 {
707  int ch, band, ret = 0;
708  uint32_t huff_bit_count_accum[MAX_CHANNELS][DCA_CODE_BOOKS][7];
709  uint32_t clc_bit_count_accum[MAX_CHANNELS][DCA_CODE_BOOKS];
710  uint32_t bits_counter = 0;
711 
712  c->consumed_bits = 132 + 333 * c->fullband_channels;
713  if (c->lfe_channel)
714  c->consumed_bits += 72;
715 
716  /* attempt to guess the bit distribution based on the prevoius frame */
717  for (ch = 0; ch < c->fullband_channels; ch++) {
718  for (band = 0; band < 32; band++) {
719  int snr_cb = c->peak_cb[ch][band] - c->band_masking_cb[band] - noise;
720 
721  if (snr_cb >= 1312) {
722  c->abits[ch][band] = 26;
723  ret |= USED_26ABITS;
724  } else if (snr_cb >= 222) {
725  c->abits[ch][band] = 8 + mul32(snr_cb - 222, 69000000);
726  ret |= USED_NABITS;
727  } else if (snr_cb >= 0) {
728  c->abits[ch][band] = 2 + mul32(snr_cb, 106000000);
729  ret |= USED_NABITS;
730  } else {
731  c->abits[ch][band] = 1;
732  ret |= USED_1ABITS;
733  }
734  }
735  c->consumed_bits += set_best_abits_code(c->abits[ch], 32, &c->bit_allocation_sel[ch]);
736  }
737 
738  /* Recalc scale_factor each time to get bits consumption in case of Huffman coding.
739  It is suboptimal solution */
740  /* TODO: May be cache scaled values */
741  for (ch = 0; ch < c->fullband_channels; ch++) {
742  for (band = 0; band < 32; band++) {
743  c->scale_factor[ch][band] = calc_one_scale(c->peak_cb[ch][band],
744  c->abits[ch][band],
745  &c->quant[ch][band]);
746  }
747  }
748  quantize_all(c);
749 
750  memset(huff_bit_count_accum, 0, MAX_CHANNELS * DCA_CODE_BOOKS * 7 * sizeof(uint32_t));
751  memset(clc_bit_count_accum, 0, MAX_CHANNELS * DCA_CODE_BOOKS * sizeof(uint32_t));
752  for (ch = 0; ch < c->fullband_channels; ch++) {
753  for (band = 0; band < 32; band++) {
754  if (c->abits[ch][band] && c->abits[ch][band] <= DCA_CODE_BOOKS) {
755  accumulate_huff_bit_consumption(c->abits[ch][band], c->quantized[ch][band], huff_bit_count_accum[ch][c->abits[ch][band] - 1]);
756  clc_bit_count_accum[ch][c->abits[ch][band] - 1] += bit_consumption[c->abits[ch][band]];
757  } else {
758  bits_counter += bit_consumption[c->abits[ch][band]];
759  }
760  }
761  }
762 
763  for (ch = 0; ch < c->fullband_channels; ch++) {
764  bits_counter += set_best_code(huff_bit_count_accum[ch], clc_bit_count_accum[ch], c->quant_index_sel[ch]);
765  }
766 
767  c->consumed_bits += bits_counter;
768 
769  return ret;
770 }
771 
773 {
774  /* Find the bounds where the binary search should work */
775  int low, high, down;
776  int used_abits = 0;
777 
779  low = high = c->worst_quantization_noise;
780  if (c->consumed_bits > c->frame_bits) {
781  while (c->consumed_bits > c->frame_bits) {
782  av_assert0(used_abits != USED_1ABITS);
783  low = high;
784  high += snr_fudge;
785  used_abits = init_quantization_noise(c, high);
786  }
787  } else {
788  while (c->consumed_bits <= c->frame_bits) {
789  high = low;
790  if (used_abits == USED_26ABITS)
791  goto out; /* The requested bitrate is too high, pad with zeros */
792  low -= snr_fudge;
793  used_abits = init_quantization_noise(c, low);
794  }
795  }
796 
797  /* Now do a binary search between low and high to see what fits */
798  for (down = snr_fudge >> 1; down; down >>= 1) {
799  init_quantization_noise(c, high - down);
800  if (c->consumed_bits <= c->frame_bits)
801  high -= down;
802  }
803  init_quantization_noise(c, high);
804 out:
805  c->worst_quantization_noise = high;
806  if (high > c->worst_noise_ever)
807  c->worst_noise_ever = high;
808 }
809 
810 static void shift_history(DCAEncContext *c, const int32_t *input)
811 {
812  int k, ch;
813 
814  for (k = 0; k < 512; k++)
815  for (ch = 0; ch < c->channels; ch++) {
816  const int chi = c->channel_order_tab[ch];
817 
818  c->history[ch][k] = input[k * c->channels + chi];
819  }
820 }
821 
823 {
824  if (c->lfe_channel)
826 }
827 
829 {
830  /* SYNC */
831  put_bits(&c->pb, 16, 0x7ffe);
832  put_bits(&c->pb, 16, 0x8001);
833 
834  /* Frame type: normal */
835  put_bits(&c->pb, 1, 1);
836 
837  /* Deficit sample count: none */
838  put_bits(&c->pb, 5, 31);
839 
840  /* CRC is not present */
841  put_bits(&c->pb, 1, 0);
842 
843  /* Number of PCM sample blocks */
844  put_bits(&c->pb, 7, SUBBAND_SAMPLES - 1);
845 
846  /* Primary frame byte size */
847  put_bits(&c->pb, 14, c->frame_size - 1);
848 
849  /* Audio channel arrangement */
850  put_bits(&c->pb, 6, c->channel_config);
851 
852  /* Core audio sampling frequency */
854 
855  /* Transmission bit rate */
856  put_bits(&c->pb, 5, c->bitrate_index);
857 
858  /* Embedded down mix: disabled */
859  put_bits(&c->pb, 1, 0);
860 
861  /* Embedded dynamic range flag: not present */
862  put_bits(&c->pb, 1, 0);
863 
864  /* Embedded time stamp flag: not present */
865  put_bits(&c->pb, 1, 0);
866 
867  /* Auxiliary data flag: not present */
868  put_bits(&c->pb, 1, 0);
869 
870  /* HDCD source: no */
871  put_bits(&c->pb, 1, 0);
872 
873  /* Extension audio ID: N/A */
874  put_bits(&c->pb, 3, 0);
875 
876  /* Extended audio data: not present */
877  put_bits(&c->pb, 1, 0);
878 
879  /* Audio sync word insertion flag: after each sub-frame */
880  put_bits(&c->pb, 1, 0);
881 
882  /* Low frequency effects flag: not present or 64x subsampling */
883  put_bits(&c->pb, 2, c->lfe_channel ? 2 : 0);
884 
885  /* Predictor history switch flag: on */
886  put_bits(&c->pb, 1, 1);
887 
888  /* No CRC */
889  /* Multirate interpolator switch: non-perfect reconstruction */
890  put_bits(&c->pb, 1, 0);
891 
892  /* Encoder software revision: 7 */
893  put_bits(&c->pb, 4, 7);
894 
895  /* Copy history: 0 */
896  put_bits(&c->pb, 2, 0);
897 
898  /* Source PCM resolution: 16 bits, not DTS ES */
899  put_bits(&c->pb, 3, 0);
900 
901  /* Front sum/difference coding: no */
902  put_bits(&c->pb, 1, 0);
903 
904  /* Surrounds sum/difference coding: no */
905  put_bits(&c->pb, 1, 0);
906 
907  /* Dialog normalization: 0 dB */
908  put_bits(&c->pb, 4, 0);
909 }
910 
912 {
913  int ch, i;
914  /* Number of subframes */
915  put_bits(&c->pb, 4, SUBFRAMES - 1);
916 
917  /* Number of primary audio channels */
918  put_bits(&c->pb, 3, c->fullband_channels - 1);
919 
920  /* Subband activity count */
921  for (ch = 0; ch < c->fullband_channels; ch++)
922  put_bits(&c->pb, 5, DCAENC_SUBBANDS - 2);
923 
924  /* High frequency VQ start subband */
925  for (ch = 0; ch < c->fullband_channels; ch++)
926  put_bits(&c->pb, 5, DCAENC_SUBBANDS - 1);
927 
928  /* Joint intensity coding index: 0, 0 */
929  for (ch = 0; ch < c->fullband_channels; ch++)
930  put_bits(&c->pb, 3, 0);
931 
932  /* Transient mode codebook: A4, A4 (arbitrary) */
933  for (ch = 0; ch < c->fullband_channels; ch++)
934  put_bits(&c->pb, 2, 0);
935 
936  /* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each channel) */
937  for (ch = 0; ch < c->fullband_channels; ch++)
938  put_bits(&c->pb, 3, 6);
939 
940  /* Bit allocation quantizer select: linear 5-bit */
941  for (ch = 0; ch < c->fullband_channels; ch++)
942  put_bits(&c->pb, 3, c->bit_allocation_sel[ch]);
943 
944  /* Quantization index codebook select */
945  for (i = 0; i < DCA_CODE_BOOKS; i++)
946  for (ch = 0; ch < c->fullband_channels; ch++)
948 
949  /* Scale factor adjustment index: transmitted in case of Huffman coding */
950  for (i = 0; i < DCA_CODE_BOOKS; i++)
951  for (ch = 0; ch < c->fullband_channels; ch++)
953  put_bits(&c->pb, 2, 0);
954 
955  /* Audio header CRC check word: not transmitted */
956 }
957 
958 static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch)
959 {
960  int i, j, sum, bits, sel;
961  if (c->abits[ch][band] <= DCA_CODE_BOOKS) {
962  av_assert0(c->abits[ch][band] > 0);
963  sel = c->quant_index_sel[ch][c->abits[ch][band] - 1];
964  // Huffman codes
965  if (sel < ff_dca_quant_index_group_size[c->abits[ch][band] - 1]) {
966  ff_dca_vlc_enc_quant(&c->pb, &c->quantized[ch][band][ss * 8], 8, sel, c->abits[ch][band] - 1);
967  return;
968  }
969 
970  // Block codes
971  if (c->abits[ch][band] <= 7) {
972  for (i = 0; i < 8; i += 4) {
973  sum = 0;
974  for (j = 3; j >= 0; j--) {
975  sum *= ff_dca_quant_levels[c->abits[ch][band]];
976  sum += c->quantized[ch][band][ss * 8 + i + j];
977  sum += (ff_dca_quant_levels[c->abits[ch][band]] - 1) / 2;
978  }
979  put_bits(&c->pb, bit_consumption[c->abits[ch][band]] / 4, sum);
980  }
981  return;
982  }
983  }
984 
985  for (i = 0; i < 8; i++) {
986  bits = bit_consumption[c->abits[ch][band]] / 16;
987  put_sbits(&c->pb, bits, c->quantized[ch][band][ss * 8 + i]);
988  }
989 }
990 
991 static void put_subframe(DCAEncContext *c, int subframe)
992 {
993  int i, band, ss, ch;
994 
995  /* Subsubframes count */
996  put_bits(&c->pb, 2, SUBSUBFRAMES -1);
997 
998  /* Partial subsubframe sample count: dummy */
999  put_bits(&c->pb, 3, 0);
1000 
1001  /* Prediction mode: no ADPCM, in each channel and subband */
1002  for (ch = 0; ch < c->fullband_channels; ch++)
1003  for (band = 0; band < DCAENC_SUBBANDS; band++)
1004  put_bits(&c->pb, 1, 0);
1005 
1006  /* Prediction VQ address: not transmitted */
1007  /* Bit allocation index */
1008  for (ch = 0; ch < c->fullband_channels; ch++) {
1009  if (c->bit_allocation_sel[ch] == 6) {
1010  for (band = 0; band < DCAENC_SUBBANDS; band++) {
1011  put_bits(&c->pb, 5, c->abits[ch][band]);
1012  }
1013  } else {
1014  ff_dca_vlc_enc_alloc(&c->pb, c->abits[ch], DCAENC_SUBBANDS, c->bit_allocation_sel[ch]);
1015  }
1016  }
1017 
1018  if (SUBSUBFRAMES > 1) {
1019  /* Transition mode: none for each channel and subband */
1020  for (ch = 0; ch < c->fullband_channels; ch++)
1021  for (band = 0; band < DCAENC_SUBBANDS; band++)
1022  put_bits(&c->pb, 1, 0); /* codebook A4 */
1023  }
1024 
1025  /* Scale factors */
1026  for (ch = 0; ch < c->fullband_channels; ch++)
1027  for (band = 0; band < DCAENC_SUBBANDS; band++)
1028  put_bits(&c->pb, 7, c->scale_factor[ch][band]);
1029 
1030  /* Joint subband scale factor codebook select: not transmitted */
1031  /* Scale factors for joint subband coding: not transmitted */
1032  /* Stereo down-mix coefficients: not transmitted */
1033  /* Dynamic range coefficient: not transmitted */
1034  /* Stde information CRC check word: not transmitted */
1035  /* VQ encoded high frequency subbands: not transmitted */
1036 
1037  /* LFE data: 8 samples and scalefactor */
1038  if (c->lfe_channel) {
1039  for (i = 0; i < DCA_LFE_SAMPLES; i++)
1040  put_bits(&c->pb, 8, quantize_value(c->downsampled_lfe[i], c->lfe_quant) & 0xff);
1041  put_bits(&c->pb, 8, c->lfe_scale_factor);
1042  }
1043 
1044  /* Audio data (subsubframes) */
1045  for (ss = 0; ss < SUBSUBFRAMES ; ss++)
1046  for (ch = 0; ch < c->fullband_channels; ch++)
1047  for (band = 0; band < DCAENC_SUBBANDS; band++)
1048  put_subframe_samples(c, ss, band, ch);
1049 
1050  /* DSYNC */
1051  put_bits(&c->pb, 16, 0xffff);
1052 }
1053 
1054 static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
1055  const AVFrame *frame, int *got_packet_ptr)
1056 {
1057  DCAEncContext *c = avctx->priv_data;
1058  const int32_t *samples;
1059  int ret, i;
1060 
1061  if ((ret = ff_alloc_packet2(avctx, avpkt, c->frame_size, 0)) < 0)
1062  return ret;
1063 
1064  samples = (const int32_t *)frame->data[0];
1065 
1066  subband_transform(c, samples);
1067  if (c->lfe_channel)
1068  lfe_downsample(c, samples);
1069 
1070  calc_masking(c, samples);
1071  find_peaks(c);
1072  assign_bits(c);
1073  calc_lfe_scales(c);
1074  shift_history(c, samples);
1075 
1076  init_put_bits(&c->pb, avpkt->data, avpkt->size);
1077  put_frame_header(c);
1079  for (i = 0; i < SUBFRAMES; i++)
1080  put_subframe(c, i);
1081 
1082 
1083  for (i = put_bits_count(&c->pb); i < 8*c->frame_size; i++)
1084  put_bits(&c->pb, 1, 0);
1085 
1086  flush_put_bits(&c->pb);
1087 
1088  avpkt->pts = frame->pts;
1089  avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
1090  avpkt->size = put_bits_count(&c->pb) >> 3;
1091  *got_packet_ptr = 1;
1092  return 0;
1093 }
1094 
1095 static const AVCodecDefault defaults[] = {
1096  { "b", "1411200" },
1097  { NULL },
1098 };
1099 
1101  .name = "dca",
1102  .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
1103  .type = AVMEDIA_TYPE_AUDIO,
1104  .id = AV_CODEC_ID_DTS,
1105  .priv_data_size = sizeof(DCAEncContext),
1106  .init = encode_init,
1107  .encode2 = encode_frame,
1108  .capabilities = AV_CODEC_CAP_EXPERIMENTAL,
1109  .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32,
1111  .supported_samplerates = sample_rates,
1112  .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
1117  0 },
1118  .defaults = defaults,
1119 };
#define MAX_CHANNELS
Definition: dcaenc.c:36
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
int32_t subband[MAX_CHANNELS][DCAENC_SUBBANDS][SUBBAND_SAMPLES]
Definition: dcaenc.c:65
int32_t m
Definition: dcaenc.h:28
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
static int32_t cb_to_add[256]
Definition: dcaenc.c:86
uint32_t ff_dca_vlc_calc_alloc_bits(int *values, uint8_t n, uint8_t sel)
Definition: dcahuff.c:1360
static int noise(AVBSFContext *ctx, AVPacket *out)
Definition: noise_bsf.c:37
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int32_t eff_masking_curve_cb[256]
Definition: dcaenc.c:75
float re
Definition: fft.c:82
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:200
static int32_t auf[9][AUBANDS][256]
Definition: dcaenc.c:85
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:206
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static void put_frame_header(DCAEncContext *c)
Definition: dcaenc.c:828
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1797
#define AUBANDS
Definition: dcaenc.c:45
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
const int8_t * channel_order_tab
channel reordering table, lfe and non lfe
Definition: dcaenc.c:62
const uint8_t ff_reverse[256]
Definition: reverse.c:23
static int32_t band_spectrum[2][8]
Definition: dcaenc.c:84
int size
Definition: avcodec.h:1658
const char * b
Definition: vf_curves.c:113
static const uint8_t bitstream_sfreq[]
Definition: dcaenc.h:36
static const uint16_t erb[]
Definition: dcaenc.h:46
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:1049
static void shift_history(DCAEncContext *c, const int32_t *input)
Definition: dcaenc.c:810
softfloat lfe_quant
Definition: dcaenc.c:60
#define AV_CH_LAYOUT_STEREO
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: dcaenc.c:1054
#define sample
static void walk_band_high(DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
Definition: dcaenc.c:488
AVCodec.
Definition: avcodec.h:3681
#define AV_CH_LAYOUT_5POINT0
int abits[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:71
#define USED_NABITS
Definition: dcaenc.c:578
int frame_size
Definition: dcaenc.c:49
const float ff_dca_fir_32bands_nonperfect[512]
Definition: dcadata.c:6812
static void walk_band_low(DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
Definition: dcaenc.c:473
softfloat quant[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:73
static void accumulate_huff_bit_consumption(int abits, int32_t *quantized, uint32_t *result)
Definition: dcaenc.c:632
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define SUBSUBFRAMES
Definition: dcaenc.c:43
static void calc_masking(DCAEncContext *c, const int32_t *input)
Definition: dcaenc.c:513
static const softfloat stepsize_inv[27]
Definition: dcaenc.h:51
const uint32_t ff_dca_bit_rates[32]
Definition: dcadata.c:32
uint8_t bits
Definition: crc.c:296
uint8_t
static int32_t lfe_fir_64i[512]
Definition: dcaenc.c:88
int32_t im
Definition: dcaenc.c:344
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1675
static int32_t cos_table[2048]
Definition: dcaenc.c:82
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:271
static int calc_one_scale(int32_t peak_cb, int abits, softfloat *quant)
Definition: dcaenc.c:590
int32_t masking_curve_cb[SUBSUBFRAMES][256]
Definition: dcaenc.c:69
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1657
static void quantize_all(DCAEncContext *c)
Definition: dcaenc.c:622
static int32_t sin_t(int x)
Definition: dcaenc.c:246
int frame_bits
Definition: dcaenc.c:50
int lfe_channel
Definition: dcaenc.c:53
int32_t re
Definition: dcaenc.c:343
signed 32 bits
Definition: samplefmt.h:62
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
int scale_factor[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:72
#define DCA_LFE_SAMPLES
Definition: dcaenc.c:39
#define AV_CH_LAYOUT_5POINT1
static int32_t add_cb(int32_t a, int32_t b)
Definition: dcaenc.c:428
#define USED_1ABITS
Definition: dcaenc.c:577
static const softfloat scalefactor_inv[128]
Definition: dcaenc.h:61
static void lfe_downsample(DCAEncContext *c, const int32_t *input)
Definition: dcaenc.c:312
static double hom(double f)
Definition: dcaenc.c:91
int32_t band_masking_cb[32]
Definition: dcaenc.c:76
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static void put_subframe(DCAEncContext *c, int subframe)
Definition: dcaenc.c:991
Definition: dcaenc.c:342
int samplerate_index
Definition: dcaenc.c:54
static const int snr_fudge
Definition: dcaenc.c:576
#define AVERROR(e)
Definition: error.h:43
const uint8_t ff_dca_quant_index_group_size[DCA_CODE_BOOKS]
Definition: dcadata.c:57
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
int channels
Definition: dcaenc.c:52
static uint32_t set_best_abits_code(int abits[DCAENC_SUBBANDS], int bands, int32_t *res)
Definition: dcaenc.c:678
const char * r
Definition: vf_curves.c:111
const float ff_dca_lfe_fir_64[256]
Definition: dcadata.c:7343
const char * arg
Definition: jacosubdec.c:66
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:503
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: avcodec.h:3688
const uint32_t ff_dca_quant_levels[32]
Definition: dcadata.c:4219
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int8_t exp
Definition: eval.c:65
static int32_t quantize_value(int32_t value, softfloat quant)
Definition: dcaenc.c:581
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2545
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
int32_t e
Definition: dcaenc.h:29
#define AV_CH_LAYOUT_2_2
static const uint16_t fc[]
Definition: dcaenc.h:41
static void assign_bits(DCAEncContext *c)
Definition: dcaenc.c:772
audio channel layout utility functions
static void calc_lfe_scales(DCAEncContext *c)
Definition: dcaenc.c:822
int fullband_channels
Definition: dcaenc.c:51
static int init_quantization_noise(DCAEncContext *c, int noise)
Definition: dcaenc.c:705
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
uint32_t ff_dca_vlc_calc_quant_bits(int *values, uint8_t n, uint8_t sel, uint8_t table)
Definition: dcahuff.c:1338
int32_t
int32_t worst_noise_ever
Definition: dcaenc.c:78
#define DCA_MAX_FRAME_SIZE
Definition: dcaenc.c:37
#define DCAENC_SUBBANDS
Definition: dcaenc.c:41
int32_t lfe_peak_cb
Definition: dcaenc.c:61
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define SUBBAND_SAMPLES
Definition: dcaenc.c:44
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2514
int bitrate_index
Definition: dcaenc.c:55
static const int8_t channel_reorder_lfe[7][5]
Definition: dca_lbr.c:100
static void put_primary_audio_header(DCAEncContext *c)
Definition: dcaenc.c:911
int frame_size
Definition: mxfenc.c:1820
static void find_peaks(DCAEncContext *c)
Definition: dcaenc.c:548
void ff_dca_vlc_enc_quant(PutBitContext *pb, int *values, uint8_t n, uint8_t sel, uint8_t table)
Definition: dcahuff.c:1350
static int32_t mul32(int32_t a, int32_t b)
Definition: dcaenc.c:256
Libavcodec external API header.
const int32_t * band_spectrum
Definition: dcaenc.c:58
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int32_t history[MAX_CHANNELS][512]
Definition: dcaenc.c:64
static int32_t cb_to_level[2048]
Definition: dcaenc.c:87
#define DCA_CODE_BOOKS
Definition: dcahuff.h:32
int sample_rate
samples per second
Definition: avcodec.h:2494
#define ss
main external API structure.
Definition: avcodec.h:1732
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
void * buf
Definition: avisynth_c.h:690
static void put_subframe_samples(DCAEncContext *c, int ss, int band, int ch)
Definition: dcaenc.c:958
static void adjust_jnd(int samplerate_index, const int32_t in[512], int32_t out_cb[256])
Definition: dcaenc.c:438
float im
Definition: fft.c:82
const uint8_t ff_dca_quant_index_sel_nbits[DCA_CODE_BOOKS]
Definition: dcadata.c:53
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1736
int32_t worst_quantization_noise
Definition: dcaenc.c:77
static int encode_init(AVCodecContext *avctx)
Definition: dcaenc.c:110
static int32_t band_interpolation[2][512]
Definition: dcaenc.c:83
static int32_t cos_t(int x)
Definition: dcaenc.c:241
#define DCA_BITALLOC_12_COUNT
Definition: dcahuff.h:33
const uint8_t * quant
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
#define SUBFRAMES
Definition: dcaenc.c:42
static void subband_transform(DCAEncContext *c, const int32_t *input)
Definition: dcaenc.c:262
internal math functions header
int channel_config
Definition: dcaenc.c:56
AVCodec ff_dca_encoder
Definition: dcaenc.c:1100
PutBitContext pb
Definition: dcaenc.c:48
static void fft(const int32_t in[2 *256], cplx32 out[256])
Definition: dcaenc.c:347
common internal api header.
sample_rates
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:101
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:282
#define USED_26ABITS
Definition: dcaenc.c:579
static double c[64]
channel
Use these values when setting the channel map with ebur128_set_channel().
Definition: ebur128.h:39
static int32_t get_cb(int32_t in)
Definition: dcaenc.c:414
int lfe_scale_factor
Definition: dcaenc.c:59
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
int32_t quant_index_sel[MAX_CHANNELS][DCA_CODE_BOOKS]
Definition: dcaenc.c:74
void * priv_data
Definition: avcodec.h:1774
static av_always_inline int diff(const uint32_t a, const uint32_t b)
int32_t quantized[MAX_CHANNELS][DCAENC_SUBBANDS][SUBBAND_SAMPLES]
Definition: dcaenc.c:66
int consumed_bits
Definition: dcaenc.c:79
int channels
number of audio channels
Definition: avcodec.h:2495
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:469
static int32_t half32(int32_t a)
Definition: dcaenc.c:251
static const int8_t channel_reorder_nolfe[7][5]
Definition: dca_lbr.c:90
uint64_t layout
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
FILE * out
Definition: movenc.c:54
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:639
const int32_t * band_interpolation
Definition: dcaenc.c:57
int32_t downsampled_lfe[DCA_LFE_SAMPLES]
Definition: dcaenc.c:68
int32_t peak_cb[MAX_CHANNELS][DCAENC_SUBBANDS]
Definition: dcaenc.c:67
int32_t bit_allocation_sel[MAX_CHANNELS]
Definition: dcaenc.c:70
#define M_PI
Definition: mathematics.h:52
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:251
#define FFSWAP(type, a, b)
Definition: common.h:99
static const AVCodecDefault defaults[]
Definition: dcaenc.c:1095
static const uint8_t lfe_index[7]
Definition: dca_lbr.c:110
static const int bit_consumption[27]
Definition: dcaenc.h:99
const float ff_dca_fir_32bands_perfect[512]
Definition: dcadata.c:6297
#define AV_CH_LAYOUT_MONO
enum AVCodecID id
This structure stores compressed data.
Definition: avcodec.h:1634
void ff_dca_vlc_enc_alloc(PutBitContext *pb, int *values, uint8_t n, uint8_t sel)
Definition: dcahuff.c:1371
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:244
static double gammafilter(int i, double f)
Definition: dcaenc.c:101
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1650
for(j=16;j >0;--j)
bitstream writer API