dcaenc.c
Go to the documentation of this file.
1 /*
2  * DCA encoder
3  * Copyright (C) 2008 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 
25 #include "libavutil/common.h"
26 #include "libavutil/avassert.h"
27 #include "avcodec.h"
28 #include "internal.h"
29 #include "put_bits.h"
30 #include "dcaenc.h"
31 #include "dcadata.h"
32 #include "dca.h"
33 
34 #undef NDEBUG
35 
36 #define MAX_CHANNELS 6
37 #define DCA_SUBBANDS_32 32
38 #define DCA_MAX_FRAME_SIZE 16383
39 #define DCA_HEADER_SIZE 13
40 
41 #define DCA_SUBBANDS 32 ///< Subband activity count
42 #define QUANTIZER_BITS 16
43 #define SUBFRAMES 1
44 #define SUBSUBFRAMES 4
45 #define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8)
46 #define LFE_BITS 8
47 #define LFE_INTERPOLATION 64
48 #define LFE_PRESENT 2
49 #define LFE_MISSING 0
50 
51 static const int8_t dca_lfe_index[] = {
52  1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3
53 };
54 
55 static const int8_t dca_channel_reorder_lfe[][9] = {
56  { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
57  { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
58  { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
59  { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
60  { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
61  { 1, 2, 0, -1, -1, -1, -1, -1, -1 },
62  { 0, 1, -1, 2, -1, -1, -1, -1, -1 },
63  { 1, 2, 0, -1, 3, -1, -1, -1, -1 },
64  { 0, 1, -1, 2, 3, -1, -1, -1, -1 },
65  { 1, 2, 0, -1, 3, 4, -1, -1, -1 },
66  { 2, 3, -1, 0, 1, 4, 5, -1, -1 },
67  { 1, 2, 0, -1, 3, 4, 5, -1, -1 },
68  { 0, -1, 4, 5, 2, 3, 1, -1, -1 },
69  { 3, 4, 1, -1, 0, 2, 5, 6, -1 },
70  { 2, 3, -1, 5, 7, 0, 1, 4, 6 },
71  { 3, 4, 1, -1, 0, 2, 5, 7, 6 },
72 };
73 
74 static const int8_t dca_channel_reorder_nolfe[][9] = {
75  { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
76  { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
77  { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
78  { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
79  { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
80  { 1, 2, 0, -1, -1, -1, -1, -1, -1 },
81  { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
82  { 1, 2, 0, 3, -1, -1, -1, -1, -1 },
83  { 0, 1, 2, 3, -1, -1, -1, -1, -1 },
84  { 1, 2, 0, 3, 4, -1, -1, -1, -1 },
85  { 2, 3, 0, 1, 4, 5, -1, -1, -1 },
86  { 1, 2, 0, 3, 4, 5, -1, -1, -1 },
87  { 0, 4, 5, 2, 3, 1, -1, -1, -1 },
88  { 3, 4, 1, 0, 2, 5, 6, -1, -1 },
89  { 2, 3, 5, 7, 0, 1, 4, 6, -1 },
90  { 3, 4, 1, 0, 2, 5, 7, 6, -1 },
91 };
92 
93 typedef struct {
95  int32_t history[MAX_CHANNELS][512]; /* This is a circular buffer */
97  int frame_size;
98  int prim_channels;
101  int scale_factor[MAX_CHANNELS][DCA_SUBBANDS_32];
102  int lfe_scale_factor;
103  int lfe_data[SUBFRAMES*SUBSUBFRAMES*4];
104 
105  int a_mode; ///< audio channels arrangement
109  const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe
110 
112  int32_t subband[PCM_SAMPLES][MAX_CHANNELS][DCA_SUBBANDS_32]; /* [sample][channel][subband] */
113 } DCAContext;
114 
115 static int32_t cos_table[128];
116 
117 static inline int32_t mul32(int32_t a, int32_t b)
118 {
119  int64_t r = (int64_t) a * b;
120  /* round the result before truncating - improves accuracy */
121  return (r + 0x80000000) >> 32;
122 }
123 
124 /* Integer version of the cosine modulated Pseudo QMF */
125 
126 static void qmf_init(void)
127 {
128  int i;
129  int32_t c[17], s[17];
130  s[0] = 0; /* sin(index * PI / 64) * 0x7fffffff */
131  c[0] = 0x7fffffff; /* cos(index * PI / 64) * 0x7fffffff */
132 
133  for (i = 1; i <= 16; i++) {
134  s[i] = 2 * (mul32(c[i - 1], 105372028) + mul32(s[i - 1], 2144896908));
135  c[i] = 2 * (mul32(c[i - 1], 2144896908) - mul32(s[i - 1], 105372028));
136  }
137 
138  for (i = 0; i < 16; i++) {
139  cos_table[i ] = c[i] >> 3; /* avoid output overflow */
140  cos_table[i + 16] = s[16 - i] >> 3;
141  cos_table[i + 32] = -s[i] >> 3;
142  cos_table[i + 48] = -c[16 - i] >> 3;
143  cos_table[i + 64] = -c[i] >> 3;
144  cos_table[i + 80] = -s[16 - i] >> 3;
145  cos_table[i + 96] = s[i] >> 3;
146  cos_table[i + 112] = c[16 - i] >> 3;
147  }
148 }
149 
150 static int32_t band_delta_factor(int band, int sample_num)
151 {
152  int index = band * (2 * sample_num + 1);
153  if (band == 0)
154  return 0x07ffffff;
155  else
156  return cos_table[index & 127];
157 }
158 
159 static void add_new_samples(DCAContext *c, const int32_t *in,
160  int count, int channel)
161 {
162  int i;
163 
164  /* Place new samples into the history buffer */
165  for (i = 0; i < count; i++) {
166  c->history[channel][c->start[channel] + i] = in[i];
167  av_assert0(c->start[channel] + i < 512);
168  }
169  c->start[channel] += count;
170  if (c->start[channel] == 512)
171  c->start[channel] = 0;
172  av_assert0(c->start[channel] < 512);
173 }
174 
175 static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32],
176  int channel)
177 {
178  int band, i, j, k;
179  int32_t resp;
180  int32_t accum[DCA_SUBBANDS_32] = {0};
181 
182  add_new_samples(c, in, DCA_SUBBANDS_32, channel);
183 
184  /* Calculate the dot product of the signal with the (possibly inverted)
185  reference decoder's response to this vector:
186  (0.0, 0.0, ..., 0.0, -1.0, 1.0, 0.0, ..., 0.0)
187  so that -1.0 cancels 1.0 from the previous step */
188 
189  for (k = 48, j = 0, i = c->start[channel]; i < 512; k++, j++, i++)
190  accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]);
191  for (i = 0; i < c->start[channel]; k++, j++, i++)
192  accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]);
193 
194  resp = 0;
195  /* TODO: implement FFT instead of this naive calculation */
196  for (band = 0; band < DCA_SUBBANDS_32; band++) {
197  for (j = 0; j < 32; j++)
198  resp += mul32(accum[j], band_delta_factor(band, j));
199 
200  out[band] = (band & 2) ? (-resp) : resp;
201  }
202 }
203 
204 static int32_t lfe_fir_64i[512];
206 {
207  int i, j;
208  int channel = c->prim_channels;
209  int32_t accum = 0;
210 
211  add_new_samples(c, in, LFE_INTERPOLATION, channel);
212  for (i = c->start[channel], j = 0; i < 512; i++, j++)
213  accum += mul32(c->history[channel][i], lfe_fir_64i[j]);
214  for (i = 0; i < c->start[channel]; i++, j++)
215  accum += mul32(c->history[channel][i], lfe_fir_64i[j]);
216  return accum;
217 }
218 
219 static void init_lfe_fir(void)
220 {
221  static int initialized = 0;
222  int i;
223  if (initialized)
224  return;
225 
226  for (i = 0; i < 512; i++)
227  lfe_fir_64i[i] = lfe_fir_64[i] * (1 << 25); //float -> int32_t
228  initialized = 1;
229 }
230 
232 {
233  /* SYNC */
234  put_bits(&c->pb, 16, 0x7ffe);
235  put_bits(&c->pb, 16, 0x8001);
236 
237  /* Frame type: normal */
238  put_bits(&c->pb, 1, 1);
239 
240  /* Deficit sample count: none */
241  put_bits(&c->pb, 5, 31);
242 
243  /* CRC is not present */
244  put_bits(&c->pb, 1, 0);
245 
246  /* Number of PCM sample blocks */
247  put_bits(&c->pb, 7, PCM_SAMPLES-1);
248 
249  /* Primary frame byte size */
250  put_bits(&c->pb, 14, c->frame_size-1);
251 
252  /* Audio channel arrangement: L + R (stereo) */
253  put_bits(&c->pb, 6, c->num_channel);
254 
255  /* Core audio sampling frequency */
256  put_bits(&c->pb, 4, c->sample_rate_code);
257 
258  /* Transmission bit rate: 1411.2 kbps */
259  put_bits(&c->pb, 5, 0x16); /* FIXME: magic number */
260 
261  /* Embedded down mix: disabled */
262  put_bits(&c->pb, 1, 0);
263 
264  /* Embedded dynamic range flag: not present */
265  put_bits(&c->pb, 1, 0);
266 
267  /* Embedded time stamp flag: not present */
268  put_bits(&c->pb, 1, 0);
269 
270  /* Auxiliary data flag: not present */
271  put_bits(&c->pb, 1, 0);
272 
273  /* HDCD source: no */
274  put_bits(&c->pb, 1, 0);
275 
276  /* Extension audio ID: N/A */
277  put_bits(&c->pb, 3, 0);
278 
279  /* Extended audio data: not present */
280  put_bits(&c->pb, 1, 0);
281 
282  /* Audio sync word insertion flag: after each sub-frame */
283  put_bits(&c->pb, 1, 0);
284 
285  /* Low frequency effects flag: not present or interpolation factor=64 */
286  put_bits(&c->pb, 2, c->lfe_state);
287 
288  /* Predictor history switch flag: on */
289  put_bits(&c->pb, 1, 1);
290 
291  /* No CRC */
292  /* Multirate interpolator switch: non-perfect reconstruction */
293  put_bits(&c->pb, 1, 0);
294 
295  /* Encoder software revision: 7 */
296  put_bits(&c->pb, 4, 7);
297 
298  /* Copy history: 0 */
299  put_bits(&c->pb, 2, 0);
300 
301  /* Source PCM resolution: 16 bits, not DTS ES */
302  put_bits(&c->pb, 3, 0);
303 
304  /* Front sum/difference coding: no */
305  put_bits(&c->pb, 1, 0);
306 
307  /* Surrounds sum/difference coding: no */
308  put_bits(&c->pb, 1, 0);
309 
310  /* Dialog normalization: 0 dB */
311  put_bits(&c->pb, 4, 0);
312 }
313 
315 {
316  static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
317  static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
318 
319  int ch, i;
320  /* Number of subframes */
321  put_bits(&c->pb, 4, SUBFRAMES - 1);
322 
323  /* Number of primary audio channels */
324  put_bits(&c->pb, 3, c->prim_channels - 1);
325 
326  /* Subband activity count */
327  for (ch = 0; ch < c->prim_channels; ch++)
328  put_bits(&c->pb, 5, DCA_SUBBANDS - 2);
329 
330  /* High frequency VQ start subband */
331  for (ch = 0; ch < c->prim_channels; ch++)
332  put_bits(&c->pb, 5, DCA_SUBBANDS - 1);
333 
334  /* Joint intensity coding index: 0, 0 */
335  for (ch = 0; ch < c->prim_channels; ch++)
336  put_bits(&c->pb, 3, 0);
337 
338  /* Transient mode codebook: A4, A4 (arbitrary) */
339  for (ch = 0; ch < c->prim_channels; ch++)
340  put_bits(&c->pb, 2, 0);
341 
342  /* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each channel) */
343  for (ch = 0; ch < c->prim_channels; ch++)
344  put_bits(&c->pb, 3, 6);
345 
346  /* Bit allocation quantizer select: linear 5-bit */
347  for (ch = 0; ch < c->prim_channels; ch++)
348  put_bits(&c->pb, 3, 6);
349 
350  /* Quantization index codebook select: dummy data
351  to avoid transmission of scale factor adjustment */
352 
353  for (i = 1; i < 11; i++)
354  for (ch = 0; ch < c->prim_channels; ch++)
355  put_bits(&c->pb, bitlen[i], thr[i]);
356 
357  /* Scale factor adjustment index: not transmitted */
358 }
359 
360 /**
361  * 8-23 bits quantization
362  * @param sample
363  * @param bits
364  */
365 static inline uint32_t quantize(int32_t sample, int bits)
366 {
367  av_assert0(sample < 1 << (bits - 1));
368  av_assert0(sample >= -(1 << (bits - 1)));
369  return sample & ((1 << bits) - 1);
370 }
371 
372 static inline int find_scale_factor7(int64_t max_value, int bits)
373 {
374  int i = 0, j = 128, q;
375  max_value = ((max_value << 15) / lossy_quant[bits + 3]) >> (bits - 1);
376  while (i < j) {
377  q = (i + j) >> 1;
378  if (max_value < scale_factor_quant7[q])
379  j = q;
380  else
381  i = q + 1;
382  }
383  av_assert1(i < 128);
384  return i;
385 }
386 
387 static inline void put_sample7(DCAContext *c, int64_t sample, int bits,
388  int scale_factor)
389 {
390  sample = (sample << 15) / ((int64_t) lossy_quant[bits + 3] * scale_factor_quant7[scale_factor]);
391  put_bits(&c->pb, bits, quantize((int) sample, bits));
392 }
393 
394 static void put_subframe(DCAContext *c,
395  int32_t subband_data[8 * SUBSUBFRAMES][MAX_CHANNELS][32],
396  int subframe)
397 {
398  int i, sub, ss, ch, max_value;
399  int32_t *lfe_data = c->lfe_data + 4 * SUBSUBFRAMES * subframe;
400 
401  /* Subsubframes count */
402  put_bits(&c->pb, 2, SUBSUBFRAMES -1);
403 
404  /* Partial subsubframe sample count: dummy */
405  put_bits(&c->pb, 3, 0);
406 
407  /* Prediction mode: no ADPCM, in each channel and subband */
408  for (ch = 0; ch < c->prim_channels; ch++)
409  for (sub = 0; sub < DCA_SUBBANDS; sub++)
410  put_bits(&c->pb, 1, 0);
411 
412  /* Prediction VQ addres: not transmitted */
413  /* Bit allocation index */
414  for (ch = 0; ch < c->prim_channels; ch++)
415  for (sub = 0; sub < DCA_SUBBANDS; sub++)
416  put_bits(&c->pb, 5, QUANTIZER_BITS+3);
417 
418  if (SUBSUBFRAMES > 1) {
419  /* Transition mode: none for each channel and subband */
420  for (ch = 0; ch < c->prim_channels; ch++)
421  for (sub = 0; sub < DCA_SUBBANDS; sub++)
422  put_bits(&c->pb, 1, 0); /* codebook A4 */
423  }
424 
425  /* Determine scale_factor */
426  for (ch = 0; ch < c->prim_channels; ch++)
427  for (sub = 0; sub < DCA_SUBBANDS; sub++) {
428  max_value = 0;
429  for (i = 0; i < 8 * SUBSUBFRAMES; i++)
430  max_value = FFMAX(max_value, FFABS(subband_data[i][ch][sub]));
431  c->scale_factor[ch][sub] = find_scale_factor7(max_value, QUANTIZER_BITS);
432  }
433 
434  if (c->lfe_channel) {
435  max_value = 0;
436  for (i = 0; i < 4 * SUBSUBFRAMES; i++)
437  max_value = FFMAX(max_value, FFABS(lfe_data[i]));
439  }
440 
441  /* Scale factors: the same for each channel and subband,
442  encoded according to Table D.1.2 */
443  for (ch = 0; ch < c->prim_channels; ch++)
444  for (sub = 0; sub < DCA_SUBBANDS; sub++)
445  put_bits(&c->pb, 7, c->scale_factor[ch][sub]);
446 
447  /* Joint subband scale factor codebook select: not transmitted */
448  /* Scale factors for joint subband coding: not transmitted */
449  /* Stereo down-mix coefficients: not transmitted */
450  /* Dynamic range coefficient: not transmitted */
451  /* Stde information CRC check word: not transmitted */
452  /* VQ encoded high frequency subbands: not transmitted */
453 
454  /* LFE data */
455  if (c->lfe_channel) {
456  for (i = 0; i < 4 * SUBSUBFRAMES; i++)
457  put_sample7(c, lfe_data[i], LFE_BITS, c->lfe_scale_factor);
458  put_bits(&c->pb, 8, c->lfe_scale_factor);
459  }
460 
461  /* Audio data (subsubframes) */
462 
463  for (ss = 0; ss < SUBSUBFRAMES ; ss++)
464  for (ch = 0; ch < c->prim_channels; ch++)
465  for (sub = 0; sub < DCA_SUBBANDS; sub++)
466  for (i = 0; i < 8; i++)
467  put_sample7(c, subband_data[ss * 8 + i][ch][sub], QUANTIZER_BITS, c->scale_factor[ch][sub]);
468 
469  /* DSYNC */
470  put_bits(&c->pb, 16, 0xffff);
471 }
472 
473 static void put_frame(DCAContext *c,
474  int32_t subband_data[PCM_SAMPLES][MAX_CHANNELS][32],
475  uint8_t *frame)
476 {
477  int i;
479 
481  for (i = 0; i < SUBFRAMES; i++)
482  put_subframe(c, &subband_data[SUBSUBFRAMES * 8 * i], i);
483 
484  flush_put_bits(&c->pb);
485  c->frame_size = (put_bits_count(&c->pb) >> 3) + DCA_HEADER_SIZE;
486 
487  init_put_bits(&c->pb, frame, DCA_HEADER_SIZE);
488  put_frame_header(c);
489  flush_put_bits(&c->pb);
490 }
491 
492 static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
493  const AVFrame *frame, int *got_packet_ptr)
494 {
495  int i, k, channel;
496  DCAContext *c = avctx->priv_data;
497  const int16_t *samples;
498  int ret, real_channel = 0;
499 
500  if ((ret = ff_alloc_packet2(avctx, avpkt, DCA_MAX_FRAME_SIZE + DCA_HEADER_SIZE)) < 0)
501  return ret;
502 
503  samples = (const int16_t *)frame->data[0];
504  for (i = 0; i < PCM_SAMPLES; i ++) { /* i is the decimated sample number */
505  for (channel = 0; channel < c->prim_channels + 1; channel++) {
506  real_channel = c->channel_order_tab[channel];
507  if (real_channel >= 0) {
508  /* Get 32 PCM samples */
509  for (k = 0; k < 32; k++) { /* k is the sample number in a 32-sample block */
510  c->pcm[k] = samples[avctx->channels * (32 * i + k) + channel] << 16;
511  }
512  /* Put subband samples into the proper place */
513  qmf_decompose(c, c->pcm, &c->subband[i][real_channel][0], real_channel);
514  }
515  }
516  }
517 
518  if (c->lfe_channel) {
519  for (i = 0; i < PCM_SAMPLES / 2; i++) {
520  for (k = 0; k < LFE_INTERPOLATION; k++) /* k is the sample number in a 32-sample block */
521  c->pcm[k] = samples[avctx->channels * (LFE_INTERPOLATION*i+k) + c->lfe_offset] << 16;
522  c->lfe_data[i] = lfe_downsample(c, c->pcm);
523  }
524  }
525 
526  put_frame(c, c->subband, avpkt->data);
527 
528  avpkt->size = c->frame_size;
529  *got_packet_ptr = 1;
530  return 0;
531 }
532 
533 static int encode_init(AVCodecContext *avctx)
534 {
535  DCAContext *c = avctx->priv_data;
536  int i;
537  uint64_t layout = avctx->channel_layout;
538 
539  c->prim_channels = avctx->channels;
540  c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6);
541 
542  if (!layout) {
543  av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
544  "encoder will guess the layout, but it "
545  "might be incorrect.\n");
546  layout = av_get_default_channel_layout(avctx->channels);
547  }
548  switch (layout) {
549  case AV_CH_LAYOUT_STEREO: c->a_mode = 2; c->num_channel = 2; break;
550  case AV_CH_LAYOUT_5POINT0: c->a_mode = 9; c->num_channel = 9; break;
551  case AV_CH_LAYOUT_5POINT1: c->a_mode = 9; c->num_channel = 9; break;
552  case AV_CH_LAYOUT_5POINT0_BACK: c->a_mode = 9; c->num_channel = 9; break;
553  case AV_CH_LAYOUT_5POINT1_BACK: c->a_mode = 9; c->num_channel = 9; break;
554  default:
555  av_log(avctx, AV_LOG_ERROR,
556  "Only stereo, 5.0, 5.1 channel layouts supported at the moment!\n");
557  return AVERROR_PATCHWELCOME;
558  }
559 
560  if (c->lfe_channel) {
561  init_lfe_fir();
562  c->prim_channels--;
564  c->lfe_state = LFE_PRESENT;
566  } else {
568  c->lfe_state = LFE_MISSING;
569  }
570 
571  for (i = 0; i < 16; i++) {
573  break;
574  }
575  if (i == 16) {
576  av_log(avctx, AV_LOG_ERROR, "Sample rate %iHz not supported, only ", avctx->sample_rate);
577  for (i = 0; i < 16; i++)
578  av_log(avctx, AV_LOG_ERROR, "%d, ", avpriv_dca_sample_rates[i]);
579  av_log(avctx, AV_LOG_ERROR, "supported.\n");
580  return -1;
581  }
582  c->sample_rate_code = i;
583 
584  avctx->frame_size = 32 * PCM_SAMPLES;
585 
586  if (!cos_table[127])
587  qmf_init();
588  return 0;
589 }
590 
592  .name = "dca",
593  .type = AVMEDIA_TYPE_AUDIO,
594  .id = AV_CODEC_ID_DTS,
595  .priv_data_size = sizeof(DCAContext),
596  .init = encode_init,
597  .encode2 = encode_frame,
598  .capabilities = CODEC_CAP_EXPERIMENTAL,
599  .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
601  .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
602 };
Definition: start.py:1
#define MAX_CHANNELS
Definition: dcaenc.c:36
const char * s
Definition: avisynth_c.h:668
static void put_primary_audio_header(DCAContext *c)
Definition: dcaenc.c:314
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static void add_new_samples(DCAContext *c, const int32_t *in, int count, int channel)
Definition: dcaenc.c:159
int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2]
scale factors (2 if transient)
Definition: dcadec.c:401
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
int num_channel
Definition: dcaenc.c:106
int sample_rate_code
Definition: dcaenc.c:100
static void init_lfe_fir(void)
Definition: dcaenc.c:219
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
static int find_scale_factor7(int64_t max_value, int bits)
Definition: dcaenc.c:372
#define AV_CH_LAYOUT_STEREO
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: dcaenc.c:492
signed 16 bits
Definition: samplefmt.h:52
#define sample
#define AV_CH_LAYOUT_5POINT0
static void qmf_init(void)
Definition: dcaenc.c:126
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define SUBSUBFRAMES
Definition: dcaenc.c:44
uint8_t bits
Definition: crc.c:216
uint8_t
#define QUANTIZER_BITS
Definition: dcaenc.c:42
static int32_t lfe_fir_64i[512]
Definition: dcaenc.c:204
static const uint32_t scale_factor_quant7[128]
Definition: dcadata.h:4168
#define b
Definition: input.c:42
#define LFE_MISSING
Definition: dcaenc.c:49
int32_t history[MAX_CHANNELS][512]
Definition: dcaenc.c:95
uint8_t * data
int lfe_channel
Definition: dcaenc.c:99
int a_mode
audio channels arrangement
Definition: dcaenc.c:105
#define DCA_SUBBANDS
Subband activity count.
Definition: dcaenc.c:41
static void put_subframe(DCAContext *c, int32_t subband_data[8 *SUBSUBFRAMES][MAX_CHANNELS][32], int subframe)
Definition: dcaenc.c:394
frame
Definition: stft.m:14
#define AV_CH_LAYOUT_5POINT1
static const uint8_t frame_size[4]
Definition: g723_1_data.h:58
static const int8_t dca_channel_reorder_lfe[][9]
Definition: dcaenc.c:55
int lfe_offset
Definition: dcaenc.c:108
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * r
Definition: vf_curves.c:94
static const int8_t dca_lfe_index[]
Definition: dcaenc.c:51
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
static int32_t band_delta_factor(int band, int sample_num)
Definition: dcaenc.c:150
static void put_bits(J2kEncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:160
#define FFMAX(a, b)
Definition: common.h:56
external API header
uint64_t channel_layout
Audio channel layout.
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:73
const int8_t * channel_order_tab
channel reordering table, lfe and non lfe
Definition: dcaenc.c:109
float lfe_data[2 *DCA_LFE_MAX *(DCA_BLOCKS_MAX+4)]
Low frequency effect data.
Definition: dcadec.c:409
audio channel layout utility functions
static const uint32_t lossy_quant[32]
Definition: dcadata.h:4188
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
ret
Definition: avfilter.c:821
PutBitContext pb
Definition: dcaenc.c:94
static int lfe_downsample(DCAContext *c, int32_t in[LFE_INTERPOLATION])
Definition: dcaenc.c:205
int32_t
int32_t subband[PCM_SAMPLES][MAX_CHANNELS][DCA_SUBBANDS_32]
Definition: dcaenc.c:112
static const int8_t dca_channel_reorder_nolfe[][9]
Definition: dcaenc.c:74
#define FFABS(a)
Definition: common.h:53
static uint32_t quantize(int32_t sample, int bits)
8-23 bits quantization
Definition: dcaenc.c:365
static const int32_t UnQMF[512]
Definition: dcaenc.h:31
#define DCA_MAX_FRAME_SIZE
Definition: dcaenc.c:38
const uint32_t avpriv_dca_sample_rates[16]
Definition: dca.c:31
#define AV_CH_LAYOUT_5POINT1_BACK
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int start[MAX_CHANNELS]
Definition: dcaenc.c:96
int lfe_scale_factor
Definition: dcadec.c:410
for k
int frame_size
Number of samples per channel in an audio frame.
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip please avoid problems through this extra level of scrutiny For cosmetics only commits you should e g by running git config global user name My Name git config global user email my email which is either set in your personal configuration file through git config core editor or set by one of the following environment VISUAL or EDITOR Log messages should be concise but descriptive Explain why you made a what you did will be obvious from the changes themselves most of the time Saying just bug fix or is bad Remember that people of varying skill levels look at and educate themselves while reading through your code Don t include filenames in log Git provides that information Possibly make the commit message have a descriptive first an empty line and then a full description The first line will be used to name the patch by git format patch Renaming moving copying files or contents of making those normal commits mv cp path file otherpath otherfile git add[-A] git commit Do not rename or copy files of which you are not the maintainer without discussing it on the mailing list first Reverting broken commits git revert< commit > git revert will generate a revert commit This will not make the faulty commit disappear from the history git reset< commit > git reset will uncommit the changes till< commit > rewriting the current branch history git commit amend allows to amend the last commit details quickly git rebase i origin master will replay local commits over the main repository allowing to merge or remove some of them in the process Note that the commit amend and rebase rewrite history
Definition: git-howto.txt:153
static int32_t mul32(int32_t a, int32_t b)
Definition: dcaenc.c:117
static void put_sample7(DCAContext *c, int64_t sample, int bits, int scale_factor)
Definition: dcaenc.c:387
int sample_rate
samples per second
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
#define DCA_HEADER_SIZE
Definition: dcaenc.c:39
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
#define AV_CH_LAYOUT_5POINT0_BACK
static int32_t cos_table[128]
Definition: dcaenc.c:115
static int encode_init(AVCodecContext *avctx)
Definition: dcaenc.c:533
#define LFE_INTERPOLATION
Definition: dcaenc.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
#define LFE_PRESENT
Definition: dcaenc.c:48
#define SUBFRAMES
Definition: dcaenc.c:43
#define DCA_SUBBANDS_32
Definition: dcaenc.c:37
AVCodec ff_dca_encoder
Definition: dcaenc.c:591
static void put_frame_header(DCAContext *c)
Definition: dcaenc.c:231
common internal api header.
int32_t pcm[FFMAX(LFE_INTERPOLATION, DCA_SUBBANDS_32)]
Definition: dcaenc.c:111
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:81
common internal and external API header
#define PCM_SAMPLES
Definition: dcaenc.c:45
static double c[64]
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:54
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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
#define LFE_BITS
Definition: dcaenc.c:46
int channels
number of audio channels
static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32], int channel)
Definition: dcaenc.c:175
int frame_size
primary frame byte size
Definition: dcadec.c:356
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:700
Filter the word “frame” indicates either a video frame or a group of audio samples
void INT64 INT64 count
Definition: avisynth_c.h:594
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
int prim_channels
number of primary audio channels
Definition: dcadec.c:384
int lfe_state
Definition: dcaenc.c:107
This structure stores compressed data.
for(j=16;j >0;--j)
static void put_frame(DCAContext *c, int32_t subband_data[PCM_SAMPLES][MAX_CHANNELS][32], uint8_t *frame)
Definition: dcaenc.c:473
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
bitstream writer API