dcadec.c
Go to the documentation of this file.
1 /*
2  * DCA compatible decoder
3  * Copyright (C) 2004 Gildas Bazin
4  * Copyright (C) 2004 Benjamin Zores
5  * Copyright (C) 2006 Benjamin Larsson
6  * Copyright (C) 2007 Konstantin Shishkov
7  *
8  * This file is part of Libav.
9  *
10  * Libav is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * Libav is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with Libav; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 #include <math.h>
26 #include <stddef.h>
27 #include <stdio.h>
28 
30 #include "libavutil/common.h"
31 #include "libavutil/float_dsp.h"
32 #include "libavutil/intmath.h"
33 #include "libavutil/intreadwrite.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/samplefmt.h"
36 #include "avcodec.h"
37 #include "dsputil.h"
38 #include "fft.h"
39 #include "get_bits.h"
40 #include "put_bits.h"
41 #include "dcadata.h"
42 #include "dcahuff.h"
43 #include "dca.h"
44 #include "dca_parser.h"
45 #include "synth_filter.h"
46 #include "dcadsp.h"
47 #include "fmtconvert.h"
48 #include "internal.h"
49 
50 #if ARCH_ARM
51 # include "arm/dca.h"
52 #endif
53 
54 //#define TRACE
55 
56 #define DCA_PRIM_CHANNELS_MAX (7)
57 #define DCA_SUBBANDS (32)
58 #define DCA_ABITS_MAX (32) /* Should be 28 */
59 #define DCA_SUBSUBFRAMES_MAX (4)
60 #define DCA_SUBFRAMES_MAX (16)
61 #define DCA_BLOCKS_MAX (16)
62 #define DCA_LFE_MAX (3)
63 
64 enum DCAMode {
65  DCA_MONO = 0,
76 };
77 
78 /* these are unconfirmed but should be mostly correct */
83  DCA_EXSS_LFE = 0x0008,
92  DCA_EXSS_LFE2 = 0x1000,
96 };
97 
99  DCA_EXT_CORE = 0x001,
100  DCA_EXT_XXCH = 0x002,
101  DCA_EXT_X96 = 0x004,
102  DCA_EXT_XCH = 0x008,
109 };
110 
111 /* -1 are reserved or unknown */
112 static const int dca_ext_audio_descr_mask[] = {
113  DCA_EXT_XCH,
114  -1,
115  DCA_EXT_X96,
117  -1,
118  -1,
119  DCA_EXT_XXCH,
120  -1,
121 };
122 
123 /* extensions that reside in core substream */
124 #define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96)
125 
126 /* Tables for mapping dts channel configurations to libavcodec multichannel api.
127  * Some compromises have been made for special configurations. Most configurations
128  * are never used so complete accuracy is not needed.
129  *
130  * L = left, R = right, C = center, S = surround, F = front, R = rear, T = total, OV = overhead.
131  * S -> side, when both rear and back are configured move one of them to the side channel
132  * OV -> center back
133  * All 2 channel configurations -> AV_CH_LAYOUT_STEREO
134  */
135 static const uint64_t dca_core_channel_layout[] = {
141  AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER,
142  AV_CH_LAYOUT_STEREO | AV_CH_BACK_CENTER,
143  AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER | AV_CH_BACK_CENTER,
144  AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT,
145 
146  AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER | AV_CH_SIDE_LEFT |
148 
149  AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT |
151 
152  AV_CH_LAYOUT_STEREO | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT |
154 
158 
160  AV_CH_FRONT_RIGHT_OF_CENTER | AV_CH_LAYOUT_STEREO |
162 
164  AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT |
166 
168  AV_CH_FRONT_RIGHT_OF_CENTER | AV_CH_LAYOUT_STEREO |
170 };
171 
172 static const int8_t dca_lfe_index[] = {
173  1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
174 };
175 
176 static const int8_t dca_channel_reorder_lfe[][9] = {
177  { 0, -1, -1, -1, -1, -1, -1, -1, -1},
178  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
179  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
180  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
181  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
182  { 2, 0, 1, -1, -1, -1, -1, -1, -1},
183  { 0, 1, 3, -1, -1, -1, -1, -1, -1},
184  { 2, 0, 1, 4, -1, -1, -1, -1, -1},
185  { 0, 1, 3, 4, -1, -1, -1, -1, -1},
186  { 2, 0, 1, 4, 5, -1, -1, -1, -1},
187  { 3, 4, 0, 1, 5, 6, -1, -1, -1},
188  { 2, 0, 1, 4, 5, 6, -1, -1, -1},
189  { 0, 6, 4, 5, 2, 3, -1, -1, -1},
190  { 4, 2, 5, 0, 1, 6, 7, -1, -1},
191  { 5, 6, 0, 1, 7, 3, 8, 4, -1},
192  { 4, 2, 5, 0, 1, 6, 8, 7, -1},
193 };
194 
195 static const int8_t dca_channel_reorder_lfe_xch[][9] = {
196  { 0, 2, -1, -1, -1, -1, -1, -1, -1},
197  { 0, 1, 3, -1, -1, -1, -1, -1, -1},
198  { 0, 1, 3, -1, -1, -1, -1, -1, -1},
199  { 0, 1, 3, -1, -1, -1, -1, -1, -1},
200  { 0, 1, 3, -1, -1, -1, -1, -1, -1},
201  { 2, 0, 1, 4, -1, -1, -1, -1, -1},
202  { 0, 1, 3, 4, -1, -1, -1, -1, -1},
203  { 2, 0, 1, 4, 5, -1, -1, -1, -1},
204  { 0, 1, 4, 5, 3, -1, -1, -1, -1},
205  { 2, 0, 1, 5, 6, 4, -1, -1, -1},
206  { 3, 4, 0, 1, 6, 7, 5, -1, -1},
207  { 2, 0, 1, 4, 5, 6, 7, -1, -1},
208  { 0, 6, 4, 5, 2, 3, 7, -1, -1},
209  { 4, 2, 5, 0, 1, 7, 8, 6, -1},
210  { 5, 6, 0, 1, 8, 3, 9, 4, 7},
211  { 4, 2, 5, 0, 1, 6, 9, 8, 7},
212 };
213 
214 static const int8_t dca_channel_reorder_nolfe[][9] = {
215  { 0, -1, -1, -1, -1, -1, -1, -1, -1},
216  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
217  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
218  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
219  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
220  { 2, 0, 1, -1, -1, -1, -1, -1, -1},
221  { 0, 1, 2, -1, -1, -1, -1, -1, -1},
222  { 2, 0, 1, 3, -1, -1, -1, -1, -1},
223  { 0, 1, 2, 3, -1, -1, -1, -1, -1},
224  { 2, 0, 1, 3, 4, -1, -1, -1, -1},
225  { 2, 3, 0, 1, 4, 5, -1, -1, -1},
226  { 2, 0, 1, 3, 4, 5, -1, -1, -1},
227  { 0, 5, 3, 4, 1, 2, -1, -1, -1},
228  { 3, 2, 4, 0, 1, 5, 6, -1, -1},
229  { 4, 5, 0, 1, 6, 2, 7, 3, -1},
230  { 3, 2, 4, 0, 1, 5, 7, 6, -1},
231 };
232 
233 static const int8_t dca_channel_reorder_nolfe_xch[][9] = {
234  { 0, 1, -1, -1, -1, -1, -1, -1, -1},
235  { 0, 1, 2, -1, -1, -1, -1, -1, -1},
236  { 0, 1, 2, -1, -1, -1, -1, -1, -1},
237  { 0, 1, 2, -1, -1, -1, -1, -1, -1},
238  { 0, 1, 2, -1, -1, -1, -1, -1, -1},
239  { 2, 0, 1, 3, -1, -1, -1, -1, -1},
240  { 0, 1, 2, 3, -1, -1, -1, -1, -1},
241  { 2, 0, 1, 3, 4, -1, -1, -1, -1},
242  { 0, 1, 3, 4, 2, -1, -1, -1, -1},
243  { 2, 0, 1, 4, 5, 3, -1, -1, -1},
244  { 2, 3, 0, 1, 5, 6, 4, -1, -1},
245  { 2, 0, 1, 3, 4, 5, 6, -1, -1},
246  { 0, 5, 3, 4, 1, 2, 6, -1, -1},
247  { 3, 2, 4, 0, 1, 6, 7, 5, -1},
248  { 4, 5, 0, 1, 7, 2, 8, 3, 6},
249  { 3, 2, 4, 0, 1, 5, 8, 7, 6},
250 };
251 
252 #define DCA_DOLBY 101 /* FIXME */
253 
254 #define DCA_CHANNEL_BITS 6
255 #define DCA_CHANNEL_MASK 0x3F
256 
257 #define DCA_LFE 0x80
258 
259 #define HEADER_SIZE 14
260 
261 #define DCA_MAX_FRAME_SIZE 16384
262 #define DCA_MAX_EXSS_HEADER_SIZE 4096
263 
264 #define DCA_BUFFER_PADDING_SIZE 1024
265 
267 typedef struct {
268  int offset;
269  int maxbits[8];
270  int wrap;
271  VLC vlc[8];
272 } BitAlloc;
273 
278 
280  int idx)
281 {
282  return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) +
283  ba->offset;
284 }
285 
286 typedef struct {
289  /* Frame header */
295  int amode;
297  int bit_rate;
299 
300  int downmix;
301  int dynrange;
302  int timestamp;
303  int aux_data;
304  int hdcd;
305  int ext_descr;
307  int aspf;
308  int lfe;
312  int version;
315  int front_sum;
318 
319  /* Primary audio coding header */
320  int subframes;
323  int subband_activity[DCA_PRIM_CHANNELS_MAX];
324  int vq_start_subband[DCA_PRIM_CHANNELS_MAX];
325  int joint_intensity[DCA_PRIM_CHANNELS_MAX];
326  int transient_huffman[DCA_PRIM_CHANNELS_MAX];
327  int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX];
328  int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX];
329  int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX];
330  float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX];
331 
332  /* Primary audio coding side information */
333  int subsubframes[DCA_SUBFRAMES_MAX];
334  int partial_samples[DCA_SUBFRAMES_MAX];
335  int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
336  int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
338  int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
339  int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2];
340  int joint_huff[DCA_PRIM_CHANNELS_MAX];
341  int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];
342  int downmix_coef[DCA_PRIM_CHANNELS_MAX][2];
344 
346 
347  float lfe_data[2 * DCA_LFE_MAX * (DCA_BLOCKS_MAX + 4)];
349 
350  /* Subband samples history (for ADPCM) */
351  DECLARE_ALIGNED(16, float, subband_samples_hist)[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
352  DECLARE_ALIGNED(32, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512];
353  DECLARE_ALIGNED(32, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32];
354  int hist_index[DCA_PRIM_CHANNELS_MAX];
355  DECLARE_ALIGNED(32, float, raXin)[32];
356 
357  int output;
358 
360  float *samples_chanptr[DCA_PRIM_CHANNELS_MAX + 1];
361  float *extra_channels[DCA_PRIM_CHANNELS_MAX + 1];
364 
367 
368  const int8_t *channel_order_tab;
370  /* Current position in DCA frame */
373 
375 
376  /* XCh extension information */
379 
380  /* ExSS header parser */
384  int mix_config_num_ch[4];
385 
386  int profile;
387 
394 } DCAContext;
395 
396 static const uint16_t dca_vlc_offs[] = {
397  0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
398  5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
399  5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
400  7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
401  12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
402  18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
403 };
404 
405 static av_cold void dca_init_vlcs(void)
406 {
407  static int vlcs_initialized = 0;
408  int i, j, c = 14;
409  static VLC_TYPE dca_table[23622][2];
410 
411  if (vlcs_initialized)
412  return;
413 
414  dca_bitalloc_index.offset = 1;
415  dca_bitalloc_index.wrap = 2;
416  for (i = 0; i < 5; i++) {
417  dca_bitalloc_index.vlc[i].table = &dca_table[dca_vlc_offs[i]];
418  dca_bitalloc_index.vlc[i].table_allocated = dca_vlc_offs[i + 1] - dca_vlc_offs[i];
419  init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12,
420  bitalloc_12_bits[i], 1, 1,
422  }
423  dca_scalefactor.offset = -64;
424  dca_scalefactor.wrap = 2;
425  for (i = 0; i < 5; i++) {
426  dca_scalefactor.vlc[i].table = &dca_table[dca_vlc_offs[i + 5]];
427  dca_scalefactor.vlc[i].table_allocated = dca_vlc_offs[i + 6] - dca_vlc_offs[i + 5];
428  init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129,
429  scales_bits[i], 1, 1,
431  }
432  dca_tmode.offset = 0;
433  dca_tmode.wrap = 1;
434  for (i = 0; i < 4; i++) {
435  dca_tmode.vlc[i].table = &dca_table[dca_vlc_offs[i + 10]];
436  dca_tmode.vlc[i].table_allocated = dca_vlc_offs[i + 11] - dca_vlc_offs[i + 10];
437  init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4,
438  tmode_bits[i], 1, 1,
440  }
441 
442  for (i = 0; i < 10; i++)
443  for (j = 0; j < 7; j++) {
444  if (!bitalloc_codes[i][j])
445  break;
446  dca_smpl_bitalloc[i + 1].offset = bitalloc_offsets[i];
447  dca_smpl_bitalloc[i + 1].wrap = 1 + (j > 4);
448  dca_smpl_bitalloc[i + 1].vlc[j].table = &dca_table[dca_vlc_offs[c]];
449  dca_smpl_bitalloc[i + 1].vlc[j].table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c];
450 
451  init_vlc(&dca_smpl_bitalloc[i + 1].vlc[j], bitalloc_maxbits[i][j],
452  bitalloc_sizes[i],
453  bitalloc_bits[i][j], 1, 1,
455  c++;
456  }
457  vlcs_initialized = 1;
458 }
459 
460 static inline void get_array(GetBitContext *gb, int *dst, int len, int bits)
461 {
462  while (len--)
463  *dst++ = get_bits(gb, bits);
464 }
465 
466 static int dca_parse_audio_coding_header(DCAContext *s, int base_channel)
467 {
468  int i, j;
469  static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
470  static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
471  static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
472 
473  s->total_channels = get_bits(&s->gb, 3) + 1 + base_channel;
475 
478 
479 
480  for (i = base_channel; i < s->prim_channels; i++) {
481  s->subband_activity[i] = get_bits(&s->gb, 5) + 2;
482  if (s->subband_activity[i] > DCA_SUBBANDS)
484  }
485  for (i = base_channel; i < s->prim_channels; i++) {
486  s->vq_start_subband[i] = get_bits(&s->gb, 5) + 1;
487  if (s->vq_start_subband[i] > DCA_SUBBANDS)
489  }
490  get_array(&s->gb, s->joint_intensity + base_channel, s->prim_channels - base_channel, 3);
491  get_array(&s->gb, s->transient_huffman + base_channel, s->prim_channels - base_channel, 2);
492  get_array(&s->gb, s->scalefactor_huffman + base_channel, s->prim_channels - base_channel, 3);
493  get_array(&s->gb, s->bitalloc_huffman + base_channel, s->prim_channels - base_channel, 3);
494 
495  /* Get codebooks quantization indexes */
496  if (!base_channel)
497  memset(s->quant_index_huffman, 0, sizeof(s->quant_index_huffman));
498  for (j = 1; j < 11; j++)
499  for (i = base_channel; i < s->prim_channels; i++)
500  s->quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]);
501 
502  /* Get scale factor adjustment */
503  for (j = 0; j < 11; j++)
504  for (i = base_channel; i < s->prim_channels; i++)
505  s->scalefactor_adj[i][j] = 1;
506 
507  for (j = 1; j < 11; j++)
508  for (i = base_channel; i < s->prim_channels; i++)
509  if (s->quant_index_huffman[i][j] < thr[j])
510  s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)];
511 
512  if (s->crc_present) {
513  /* Audio header CRC check */
514  get_bits(&s->gb, 16);
515  }
516 
517  s->current_subframe = 0;
518  s->current_subsubframe = 0;
519 
520 #ifdef TRACE
521  av_log(s->avctx, AV_LOG_DEBUG, "subframes: %i\n", s->subframes);
522  av_log(s->avctx, AV_LOG_DEBUG, "prim channels: %i\n", s->prim_channels);
523  for (i = base_channel; i < s->prim_channels; i++) {
524  av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\n",
525  s->subband_activity[i]);
526  av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\n",
527  s->vq_start_subband[i]);
528  av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\n",
529  s->joint_intensity[i]);
530  av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\n",
531  s->transient_huffman[i]);
532  av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\n",
533  s->scalefactor_huffman[i]);
534  av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\n",
535  s->bitalloc_huffman[i]);
536  av_log(s->avctx, AV_LOG_DEBUG, "quant index huff:");
537  for (j = 0; j < 11; j++)
538  av_log(s->avctx, AV_LOG_DEBUG, " %i", s->quant_index_huffman[i][j]);
539  av_log(s->avctx, AV_LOG_DEBUG, "\n");
540  av_log(s->avctx, AV_LOG_DEBUG, "scalefac adj:");
541  for (j = 0; j < 11; j++)
542  av_log(s->avctx, AV_LOG_DEBUG, " %1.3f", s->scalefactor_adj[i][j]);
543  av_log(s->avctx, AV_LOG_DEBUG, "\n");
544  }
545 #endif
546 
547  return 0;
548 }
549 
551 {
552  init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
553 
554  /* Sync code */
555  skip_bits_long(&s->gb, 32);
556 
557  /* Frame header */
558  s->frame_type = get_bits(&s->gb, 1);
559  s->samples_deficit = get_bits(&s->gb, 5) + 1;
560  s->crc_present = get_bits(&s->gb, 1);
561  s->sample_blocks = get_bits(&s->gb, 7) + 1;
562  s->frame_size = get_bits(&s->gb, 14) + 1;
563  if (s->frame_size < 95)
564  return AVERROR_INVALIDDATA;
565  s->amode = get_bits(&s->gb, 6);
567  if (!s->sample_rate)
568  return AVERROR_INVALIDDATA;
569  s->bit_rate_index = get_bits(&s->gb, 5);
571  if (!s->bit_rate)
572  return AVERROR_INVALIDDATA;
573 
574  s->downmix = get_bits(&s->gb, 1);
575  s->dynrange = get_bits(&s->gb, 1);
576  s->timestamp = get_bits(&s->gb, 1);
577  s->aux_data = get_bits(&s->gb, 1);
578  s->hdcd = get_bits(&s->gb, 1);
579  s->ext_descr = get_bits(&s->gb, 3);
580  s->ext_coding = get_bits(&s->gb, 1);
581  s->aspf = get_bits(&s->gb, 1);
582  s->lfe = get_bits(&s->gb, 2);
583  s->predictor_history = get_bits(&s->gb, 1);
584 
585  if (s->lfe > 2) {
586  av_log(s->avctx, AV_LOG_ERROR, "Invalid LFE value: %d\n", s->lfe);
587  return AVERROR_INVALIDDATA;
588  }
589 
590  /* TODO: check CRC */
591  if (s->crc_present)
592  s->header_crc = get_bits(&s->gb, 16);
593 
594  s->multirate_inter = get_bits(&s->gb, 1);
595  s->version = get_bits(&s->gb, 4);
596  s->copy_history = get_bits(&s->gb, 2);
597  s->source_pcm_res = get_bits(&s->gb, 3);
598  s->front_sum = get_bits(&s->gb, 1);
599  s->surround_sum = get_bits(&s->gb, 1);
600  s->dialog_norm = get_bits(&s->gb, 4);
601 
602  /* FIXME: channels mixing levels */
603  s->output = s->amode;
604  if (s->lfe)
605  s->output |= DCA_LFE;
606 
607 #ifdef TRACE
608  av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type);
609  av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\n", s->samples_deficit);
610  av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\n", s->crc_present);
611  av_log(s->avctx, AV_LOG_DEBUG, "sample blocks: %i (%i samples)\n",
612  s->sample_blocks, s->sample_blocks * 32);
613  av_log(s->avctx, AV_LOG_DEBUG, "frame size: %i bytes\n", s->frame_size);
614  av_log(s->avctx, AV_LOG_DEBUG, "amode: %i (%i channels)\n",
615  s->amode, dca_channels[s->amode]);
616  av_log(s->avctx, AV_LOG_DEBUG, "sample rate: %i Hz\n",
617  s->sample_rate);
618  av_log(s->avctx, AV_LOG_DEBUG, "bit rate: %i bits/s\n",
619  s->bit_rate);
620  av_log(s->avctx, AV_LOG_DEBUG, "downmix: %i\n", s->downmix);
621  av_log(s->avctx, AV_LOG_DEBUG, "dynrange: %i\n", s->dynrange);
622  av_log(s->avctx, AV_LOG_DEBUG, "timestamp: %i\n", s->timestamp);
623  av_log(s->avctx, AV_LOG_DEBUG, "aux_data: %i\n", s->aux_data);
624  av_log(s->avctx, AV_LOG_DEBUG, "hdcd: %i\n", s->hdcd);
625  av_log(s->avctx, AV_LOG_DEBUG, "ext descr: %i\n", s->ext_descr);
626  av_log(s->avctx, AV_LOG_DEBUG, "ext coding: %i\n", s->ext_coding);
627  av_log(s->avctx, AV_LOG_DEBUG, "aspf: %i\n", s->aspf);
628  av_log(s->avctx, AV_LOG_DEBUG, "lfe: %i\n", s->lfe);
629  av_log(s->avctx, AV_LOG_DEBUG, "predictor history: %i\n",
630  s->predictor_history);
631  av_log(s->avctx, AV_LOG_DEBUG, "header crc: %i\n", s->header_crc);
632  av_log(s->avctx, AV_LOG_DEBUG, "multirate inter: %i\n",
633  s->multirate_inter);
634  av_log(s->avctx, AV_LOG_DEBUG, "version number: %i\n", s->version);
635  av_log(s->avctx, AV_LOG_DEBUG, "copy history: %i\n", s->copy_history);
637  "source pcm resolution: %i (%i bits/sample)\n",
639  av_log(s->avctx, AV_LOG_DEBUG, "front sum: %i\n", s->front_sum);
640  av_log(s->avctx, AV_LOG_DEBUG, "surround sum: %i\n", s->surround_sum);
641  av_log(s->avctx, AV_LOG_DEBUG, "dialog norm: %i\n", s->dialog_norm);
642  av_log(s->avctx, AV_LOG_DEBUG, "\n");
643 #endif
644 
645  /* Primary audio coding header */
646  s->subframes = get_bits(&s->gb, 4) + 1;
647 
648  return dca_parse_audio_coding_header(s, 0);
649 }
650 
651 
652 static inline int get_scale(GetBitContext *gb, int level, int value, int log2range)
653 {
654  if (level < 5) {
655  /* huffman encoded */
656  value += get_bitalloc(gb, &dca_scalefactor, level);
657  value = av_clip(value, 0, (1 << log2range) - 1);
658  } else if (level < 8) {
659  if (level + 1 > log2range) {
660  skip_bits(gb, level + 1 - log2range);
661  value = get_bits(gb, log2range);
662  } else {
663  value = get_bits(gb, level + 1);
664  }
665  }
666  return value;
667 }
668 
669 static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
670 {
671  /* Primary audio coding side information */
672  int j, k;
673 
674  if (get_bits_left(&s->gb) < 0)
675  return AVERROR_INVALIDDATA;
676 
677  if (!base_channel) {
678  s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1;
679  s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3);
680  }
681 
682  for (j = base_channel; j < s->prim_channels; j++) {
683  for (k = 0; k < s->subband_activity[j]; k++)
684  s->prediction_mode[j][k] = get_bits(&s->gb, 1);
685  }
686 
687  /* Get prediction codebook */
688  for (j = base_channel; j < s->prim_channels; j++) {
689  for (k = 0; k < s->subband_activity[j]; k++) {
690  if (s->prediction_mode[j][k] > 0) {
691  /* (Prediction coefficient VQ address) */
692  s->prediction_vq[j][k] = get_bits(&s->gb, 12);
693  }
694  }
695  }
696 
697  /* Bit allocation index */
698  for (j = base_channel; j < s->prim_channels; j++) {
699  for (k = 0; k < s->vq_start_subband[j]; k++) {
700  if (s->bitalloc_huffman[j] == 6)
701  s->bitalloc[j][k] = get_bits(&s->gb, 5);
702  else if (s->bitalloc_huffman[j] == 5)
703  s->bitalloc[j][k] = get_bits(&s->gb, 4);
704  else if (s->bitalloc_huffman[j] == 7) {
706  "Invalid bit allocation index\n");
707  return AVERROR_INVALIDDATA;
708  } else {
709  s->bitalloc[j][k] =
710  get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]);
711  }
712 
713  if (s->bitalloc[j][k] > 26) {
714  av_dlog(s->avctx, "bitalloc index [%i][%i] too big (%i)\n",
715  j, k, s->bitalloc[j][k]);
716  return AVERROR_INVALIDDATA;
717  }
718  }
719  }
720 
721  /* Transition mode */
722  for (j = base_channel; j < s->prim_channels; j++) {
723  for (k = 0; k < s->subband_activity[j]; k++) {
724  s->transition_mode[j][k] = 0;
725  if (s->subsubframes[s->current_subframe] > 1 &&
726  k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {
727  s->transition_mode[j][k] =
728  get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);
729  }
730  }
731  }
732 
733  if (get_bits_left(&s->gb) < 0)
734  return AVERROR_INVALIDDATA;
735 
736  for (j = base_channel; j < s->prim_channels; j++) {
737  const uint32_t *scale_table;
738  int scale_sum, log_size;
739 
740  memset(s->scale_factor[j], 0,
741  s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);
742 
743  if (s->scalefactor_huffman[j] == 6) {
744  scale_table = scale_factor_quant7;
745  log_size = 7;
746  } else {
747  scale_table = scale_factor_quant6;
748  log_size = 6;
749  }
750 
751  /* When huffman coded, only the difference is encoded */
752  scale_sum = 0;
753 
754  for (k = 0; k < s->subband_activity[j]; k++) {
755  if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {
756  scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum, log_size);
757  s->scale_factor[j][k][0] = scale_table[scale_sum];
758  }
759 
760  if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {
761  /* Get second scale factor */
762  scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum, log_size);
763  s->scale_factor[j][k][1] = scale_table[scale_sum];
764  }
765  }
766  }
767 
768  /* Joint subband scale factor codebook select */
769  for (j = base_channel; j < s->prim_channels; j++) {
770  /* Transmitted only if joint subband coding enabled */
771  if (s->joint_intensity[j] > 0)
772  s->joint_huff[j] = get_bits(&s->gb, 3);
773  }
774 
775  if (get_bits_left(&s->gb) < 0)
776  return AVERROR_INVALIDDATA;
777 
778  /* Scale factors for joint subband coding */
779  for (j = base_channel; j < s->prim_channels; j++) {
780  int source_channel;
781 
782  /* Transmitted only if joint subband coding enabled */
783  if (s->joint_intensity[j] > 0) {
784  int scale = 0;
785  source_channel = s->joint_intensity[j] - 1;
786 
787  /* When huffman coded, only the difference is encoded
788  * (is this valid as well for joint scales ???) */
789 
790  for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
791  scale = get_scale(&s->gb, s->joint_huff[j], 64 /* bias */, 7);
792  s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */
793  }
794 
795  if (!(s->debug_flag & 0x02)) {
797  "Joint stereo coding not supported\n");
798  s->debug_flag |= 0x02;
799  }
800  }
801  }
802 
803  /* Stereo downmix coefficients */
804  if (!base_channel && s->prim_channels > 2) {
805  if (s->downmix) {
806  for (j = base_channel; j < s->prim_channels; j++) {
807  s->downmix_coef[j][0] = get_bits(&s->gb, 7);
808  s->downmix_coef[j][1] = get_bits(&s->gb, 7);
809  }
810  } else {
811  int am = s->amode & DCA_CHANNEL_MASK;
812  if (am >= FF_ARRAY_ELEMS(dca_default_coeffs)) {
814  "Invalid channel mode %d\n", am);
815  return AVERROR_INVALIDDATA;
816  }
818  av_log_ask_for_sample(s->avctx, "Downmixing %d channels",
819  s->prim_channels);
820  return AVERROR_PATCHWELCOME;
821  }
822 
823  for (j = base_channel; j < s->prim_channels; j++) {
824  s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];
825  s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];
826  }
827  }
828  }
829 
830  /* Dynamic range coefficient */
831  if (!base_channel && s->dynrange)
832  s->dynrange_coef = get_bits(&s->gb, 8);
833 
834  /* Side information CRC check word */
835  if (s->crc_present) {
836  get_bits(&s->gb, 16);
837  }
838 
839  /*
840  * Primary audio data arrays
841  */
842 
843  /* VQ encoded high frequency subbands */
844  for (j = base_channel; j < s->prim_channels; j++)
845  for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
846  /* 1 vector -> 32 samples */
847  s->high_freq_vq[j][k] = get_bits(&s->gb, 10);
848 
849  /* Low frequency effect data */
850  if (!base_channel && s->lfe) {
851  /* LFE samples */
852  int lfe_samples = 2 * s->lfe * (4 + block_index);
853  int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
854  float lfe_scale;
855 
856  for (j = lfe_samples; j < lfe_end_sample; j++) {
857  /* Signed 8 bits int */
858  s->lfe_data[j] = get_sbits(&s->gb, 8);
859  }
860 
861  /* Scale factor index */
862  skip_bits(&s->gb, 1);
864 
865  /* Quantization step size * scale factor */
866  lfe_scale = 0.035 * s->lfe_scale_factor;
867 
868  for (j = lfe_samples; j < lfe_end_sample; j++)
869  s->lfe_data[j] *= lfe_scale;
870  }
871 
872 #ifdef TRACE
873  av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n",
875  av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n",
877 
878  for (j = base_channel; j < s->prim_channels; j++) {
879  av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:");
880  for (k = 0; k < s->subband_activity[j]; k++)
881  av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]);
882  av_log(s->avctx, AV_LOG_DEBUG, "\n");
883  }
884  for (j = base_channel; j < s->prim_channels; j++) {
885  for (k = 0; k < s->subband_activity[j]; k++)
887  "prediction coefs: %f, %f, %f, %f\n",
888  (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192,
889  (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192,
890  (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192,
891  (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192);
892  }
893  for (j = base_channel; j < s->prim_channels; j++) {
894  av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: ");
895  for (k = 0; k < s->vq_start_subband[j]; k++)
896  av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]);
897  av_log(s->avctx, AV_LOG_DEBUG, "\n");
898  }
899  for (j = base_channel; j < s->prim_channels; j++) {
900  av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:");
901  for (k = 0; k < s->subband_activity[j]; k++)
902  av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]);
903  av_log(s->avctx, AV_LOG_DEBUG, "\n");
904  }
905  for (j = base_channel; j < s->prim_channels; j++) {
906  av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:");
907  for (k = 0; k < s->subband_activity[j]; k++) {
908  if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0)
909  av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]);
910  if (k < s->vq_start_subband[j] && s->transition_mode[j][k])
911  av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]);
912  }
913  av_log(s->avctx, AV_LOG_DEBUG, "\n");
914  }
915  for (j = base_channel; j < s->prim_channels; j++) {
916  if (s->joint_intensity[j] > 0) {
917  int source_channel = s->joint_intensity[j] - 1;
918  av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n");
919  for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++)
920  av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]);
921  av_log(s->avctx, AV_LOG_DEBUG, "\n");
922  }
923  }
924  if (!base_channel && s->prim_channels > 2 && s->downmix) {
925  av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n");
926  for (j = 0; j < s->prim_channels; j++) {
927  av_log(s->avctx, AV_LOG_DEBUG, "Channel 0, %d = %f\n", j,
928  dca_downmix_coeffs[s->downmix_coef[j][0]]);
929  av_log(s->avctx, AV_LOG_DEBUG, "Channel 1, %d = %f\n", j,
930  dca_downmix_coeffs[s->downmix_coef[j][1]]);
931  }
932  av_log(s->avctx, AV_LOG_DEBUG, "\n");
933  }
934  for (j = base_channel; j < s->prim_channels; j++)
935  for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
936  av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]);
937  if (!base_channel && s->lfe) {
938  int lfe_samples = 2 * s->lfe * (4 + block_index);
939  int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
940 
941  av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n");
942  for (j = lfe_samples; j < lfe_end_sample; j++)
943  av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]);
944  av_log(s->avctx, AV_LOG_DEBUG, "\n");
945  }
946 #endif
947 
948  return 0;
949 }
950 
951 static void qmf_32_subbands(DCAContext *s, int chans,
952  float samples_in[32][8], float *samples_out,
953  float scale)
954 {
955  const float *prCoeff;
956  int i;
957 
958  int sb_act = s->subband_activity[chans];
959  int subindex;
960 
961  scale *= sqrt(1 / 8.0);
962 
963  /* Select filter */
964  if (!s->multirate_inter) /* Non-perfect reconstruction */
965  prCoeff = fir_32bands_nonperfect;
966  else /* Perfect reconstruction */
967  prCoeff = fir_32bands_perfect;
968 
969  for (i = sb_act; i < 32; i++)
970  s->raXin[i] = 0.0;
971 
972  /* Reconstructed channel sample index */
973  for (subindex = 0; subindex < 8; subindex++) {
974  /* Load in one sample from each subband and clear inactive subbands */
975  for (i = 0; i < sb_act; i++) {
976  unsigned sign = (i - 1) & 2;
977  uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
978  AV_WN32A(&s->raXin[i], v);
979  }
980 
982  s->subband_fir_hist[chans],
983  &s->hist_index[chans],
984  s->subband_fir_noidea[chans], prCoeff,
985  samples_out, s->raXin, scale);
986  samples_out += 32;
987  }
988 }
989 
990 static void lfe_interpolation_fir(DCAContext *s, int decimation_select,
991  int num_deci_sample, float *samples_in,
992  float *samples_out, float scale)
993 {
994  /* samples_in: An array holding decimated samples.
995  * Samples in current subframe starts from samples_in[0],
996  * while samples_in[-1], samples_in[-2], ..., stores samples
997  * from last subframe as history.
998  *
999  * samples_out: An array holding interpolated samples
1000  */
1001 
1002  int decifactor;
1003  const float *prCoeff;
1004  int deciindex;
1005 
1006  /* Select decimation filter */
1007  if (decimation_select == 1) {
1008  decifactor = 64;
1009  prCoeff = lfe_fir_128;
1010  } else {
1011  decifactor = 32;
1012  prCoeff = lfe_fir_64;
1013  }
1014  /* Interpolation */
1015  for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
1016  s->dcadsp.lfe_fir(samples_out, samples_in, prCoeff, decifactor, scale);
1017  samples_in++;
1018  samples_out += 2 * decifactor;
1019  }
1020 }
1021 
1022 /* downmixing routines */
1023 #define MIX_REAR1(samples, s1, rs, coef) \
1024  samples[0][i] += samples[s1][i] * coef[rs][0]; \
1025  samples[1][i] += samples[s1][i] * coef[rs][1];
1026 
1027 #define MIX_REAR2(samples, s1, s2, rs, coef) \
1028  samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
1029  samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
1030 
1031 #define MIX_FRONT3(samples, coef) \
1032  t = samples[c][i]; \
1033  u = samples[l][i]; \
1034  v = samples[r][i]; \
1035  samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
1036  samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
1037 
1038 #define DOWNMIX_TO_STEREO(op1, op2) \
1039  for (i = 0; i < 256; i++) { \
1040  op1 \
1041  op2 \
1042  }
1043 
1044 static void dca_downmix(float **samples, int srcfmt,
1045  int downmix_coef[DCA_PRIM_CHANNELS_MAX][2],
1046  const int8_t *channel_mapping)
1047 {
1048  int c, l, r, sl, sr, s;
1049  int i;
1050  float t, u, v;
1051  float coef[DCA_PRIM_CHANNELS_MAX][2];
1052 
1053  for (i = 0; i < DCA_PRIM_CHANNELS_MAX; i++) {
1054  coef[i][0] = dca_downmix_coeffs[downmix_coef[i][0]];
1055  coef[i][1] = dca_downmix_coeffs[downmix_coef[i][1]];
1056  }
1057 
1058  switch (srcfmt) {
1059  case DCA_MONO:
1060  case DCA_CHANNEL:
1061  case DCA_STEREO_TOTAL:
1062  case DCA_STEREO_SUMDIFF:
1063  case DCA_4F2R:
1064  av_log(NULL, 0, "Not implemented!\n");
1065  break;
1066  case DCA_STEREO:
1067  break;
1068  case DCA_3F:
1069  c = channel_mapping[0];
1070  l = channel_mapping[1];
1071  r = channel_mapping[2];
1072  DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef), );
1073  break;
1074  case DCA_2F1R:
1075  s = channel_mapping[2];
1076  DOWNMIX_TO_STEREO(MIX_REAR1(samples, s, 2, coef), );
1077  break;
1078  case DCA_3F1R:
1079  c = channel_mapping[0];
1080  l = channel_mapping[1];
1081  r = channel_mapping[2];
1082  s = channel_mapping[3];
1083  DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),
1084  MIX_REAR1(samples, s, 3, coef));
1085  break;
1086  case DCA_2F2R:
1087  sl = channel_mapping[2];
1088  sr = channel_mapping[3];
1089  DOWNMIX_TO_STEREO(MIX_REAR2(samples, sl, sr, 2, coef), );
1090  break;
1091  case DCA_3F2R:
1092  c = channel_mapping[0];
1093  l = channel_mapping[1];
1094  r = channel_mapping[2];
1095  sl = channel_mapping[3];
1096  sr = channel_mapping[4];
1097  DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),
1098  MIX_REAR2(samples, sl, sr, 3, coef));
1099  break;
1100  }
1101 }
1102 
1103 
1104 #ifndef decode_blockcodes
1105 /* Very compact version of the block code decoder that does not use table
1106  * look-up but is slightly slower */
1107 static int decode_blockcode(int code, int levels, int *values)
1108 {
1109  int i;
1110  int offset = (levels - 1) >> 1;
1111 
1112  for (i = 0; i < 4; i++) {
1113  int div = FASTDIV(code, levels);
1114  values[i] = code - offset - div * levels;
1115  code = div;
1116  }
1117 
1118  return code;
1119 }
1120 
1121 static int decode_blockcodes(int code1, int code2, int levels, int *values)
1122 {
1123  return decode_blockcode(code1, levels, values) |
1124  decode_blockcode(code2, levels, values + 4);
1125 }
1126 #endif
1127 
1128 static const uint8_t abits_sizes[7] = { 7, 10, 12, 13, 15, 17, 19 };
1129 static const uint8_t abits_levels[7] = { 3, 5, 7, 9, 13, 17, 25 };
1130 
1131 #ifndef int8x8_fmul_int32
1132 static inline void int8x8_fmul_int32(float *dst, const int8_t *src, int scale)
1133 {
1134  float fscale = scale / 16.0;
1135  int i;
1136  for (i = 0; i < 8; i++)
1137  dst[i] = src[i] * fscale;
1138 }
1139 #endif
1140 
1141 static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)
1142 {
1143  int k, l;
1144  int subsubframe = s->current_subsubframe;
1145 
1146  const float *quant_step_table;
1147 
1148  /* FIXME */
1149  float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index];
1150  LOCAL_ALIGNED_16(int, block, [8]);
1151 
1152  /*
1153  * Audio data
1154  */
1155 
1156  /* Select quantization step size table */
1157  if (s->bit_rate_index == 0x1f)
1158  quant_step_table = lossless_quant_d;
1159  else
1160  quant_step_table = lossy_quant_d;
1161 
1162  for (k = base_channel; k < s->prim_channels; k++) {
1163  if (get_bits_left(&s->gb) < 0)
1164  return AVERROR_INVALIDDATA;
1165 
1166  for (l = 0; l < s->vq_start_subband[k]; l++) {
1167  int m;
1168 
1169  /* Select the mid-tread linear quantizer */
1170  int abits = s->bitalloc[k][l];
1171 
1172  float quant_step_size = quant_step_table[abits];
1173 
1174  /*
1175  * Determine quantization index code book and its type
1176  */
1177 
1178  /* Select quantization index code book */
1179  int sel = s->quant_index_huffman[k][abits];
1180 
1181  /*
1182  * Extract bits from the bit stream
1183  */
1184  if (!abits) {
1185  memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0]));
1186  } else {
1187  /* Deal with transients */
1188  int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l];
1189  float rscale = quant_step_size * s->scale_factor[k][l][sfi] *
1190  s->scalefactor_adj[k][sel];
1191 
1192  if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) {
1193  if (abits <= 7) {
1194  /* Block code */
1195  int block_code1, block_code2, size, levels, err;
1196 
1197  size = abits_sizes[abits - 1];
1198  levels = abits_levels[abits - 1];
1199 
1200  block_code1 = get_bits(&s->gb, size);
1201  block_code2 = get_bits(&s->gb, size);
1202  err = decode_blockcodes(block_code1, block_code2,
1203  levels, block);
1204  if (err) {
1206  "ERROR: block code look-up failed\n");
1207  return AVERROR_INVALIDDATA;
1208  }
1209  } else {
1210  /* no coding */
1211  for (m = 0; m < 8; m++)
1212  block[m] = get_sbits(&s->gb, abits - 3);
1213  }
1214  } else {
1215  /* Huffman coded */
1216  for (m = 0; m < 8; m++)
1217  block[m] = get_bitalloc(&s->gb,
1218  &dca_smpl_bitalloc[abits], sel);
1219  }
1220 
1221  s->fmt_conv.int32_to_float_fmul_scalar(subband_samples[k][l],
1222  block, rscale, 8);
1223  }
1224 
1225  /*
1226  * Inverse ADPCM if in prediction mode
1227  */
1228  if (s->prediction_mode[k][l]) {
1229  int n;
1230  for (m = 0; m < 8; m++) {
1231  for (n = 1; n <= 4; n++)
1232  if (m >= n)
1233  subband_samples[k][l][m] +=
1234  (adpcm_vb[s->prediction_vq[k][l]][n - 1] *
1235  subband_samples[k][l][m - n] / 8192);
1236  else if (s->predictor_history)
1237  subband_samples[k][l][m] +=
1238  (adpcm_vb[s->prediction_vq[k][l]][n - 1] *
1239  s->subband_samples_hist[k][l][m - n + 4] / 8192);
1240  }
1241  }
1242  }
1243 
1244  /*
1245  * Decode VQ encoded high frequencies
1246  */
1247  for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) {
1248  /* 1 vector -> 32 samples but we only need the 8 samples
1249  * for this subsubframe. */
1250  int hfvq = s->high_freq_vq[k][l];
1251 
1252  if (!s->debug_flag & 0x01) {
1254  "Stream with high frequencies VQ coding\n");
1255  s->debug_flag |= 0x01;
1256  }
1257 
1258  int8x8_fmul_int32(subband_samples[k][l],
1259  &high_freq_vq[hfvq][subsubframe * 8],
1260  s->scale_factor[k][l][0]);
1261  }
1262  }
1263 
1264  /* Check for DSYNC after subsubframe */
1265  if (s->aspf || subsubframe == s->subsubframes[s->current_subframe] - 1) {
1266  if (0xFFFF == get_bits(&s->gb, 16)) { /* 0xFFFF */
1267 #ifdef TRACE
1268  av_log(s->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n");
1269 #endif
1270  } else {
1271  av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");
1272  return AVERROR_INVALIDDATA;
1273  }
1274  }
1275 
1276  /* Backup predictor history for adpcm */
1277  for (k = base_channel; k < s->prim_channels; k++)
1278  for (l = 0; l < s->vq_start_subband[k]; l++)
1279  memcpy(s->subband_samples_hist[k][l],
1280  &subband_samples[k][l][4],
1281  4 * sizeof(subband_samples[0][0][0]));
1282 
1283  return 0;
1284 }
1285 
1286 static int dca_filter_channels(DCAContext *s, int block_index)
1287 {
1288  float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index];
1289  int k;
1290 
1291  /* 32 subbands QMF */
1292  for (k = 0; k < s->prim_channels; k++) {
1293 /* static float pcm_to_double[8] = { 32768.0, 32768.0, 524288.0, 524288.0,
1294  0, 8388608.0, 8388608.0 };*/
1295  if (s->channel_order_tab[k] >= 0)
1296  qmf_32_subbands(s, k, subband_samples[k],
1298  M_SQRT1_2 / 32768.0 /* pcm_to_double[s->source_pcm_res] */);
1299  }
1300 
1301  /* Down mixing */
1302  if (s->avctx->request_channels == 2 && s->prim_channels > 2) {
1304  }
1305 
1306  /* Generate LFE samples for this subsubframe FIXME!!! */
1307  if (s->output & DCA_LFE) {
1308  lfe_interpolation_fir(s, s->lfe, 2 * s->lfe,
1309  s->lfe_data + 2 * s->lfe * (block_index + 4),
1311  1.0 / (256.0 * 32768.0));
1312  /* Outputs 20bits pcm samples */
1313  }
1314 
1315  return 0;
1316 }
1317 
1318 
1319 static int dca_subframe_footer(DCAContext *s, int base_channel)
1320 {
1321  int aux_data_count = 0, i;
1322 
1323  /*
1324  * Unpack optional information
1325  */
1326 
1327  /* presumably optional information only appears in the core? */
1328  if (!base_channel) {
1329  if (s->timestamp)
1330  skip_bits_long(&s->gb, 32);
1331 
1332  if (s->aux_data)
1333  aux_data_count = get_bits(&s->gb, 6);
1334 
1335  for (i = 0; i < aux_data_count; i++)
1336  get_bits(&s->gb, 8);
1337 
1338  if (s->crc_present && (s->downmix || s->dynrange))
1339  get_bits(&s->gb, 16);
1340  }
1341 
1342  return 0;
1343 }
1344 
1351 static int dca_decode_block(DCAContext *s, int base_channel, int block_index)
1352 {
1353  int ret;
1354 
1355  /* Sanity check */
1356  if (s->current_subframe >= s->subframes) {
1357  av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i",
1358  s->current_subframe, s->subframes);
1359  return AVERROR_INVALIDDATA;
1360  }
1361 
1362  if (!s->current_subsubframe) {
1363 #ifdef TRACE
1364  av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_header\n");
1365 #endif
1366  /* Read subframe header */
1367  if ((ret = dca_subframe_header(s, base_channel, block_index)))
1368  return ret;
1369  }
1370 
1371  /* Read subsubframe */
1372 #ifdef TRACE
1373  av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subsubframe\n");
1374 #endif
1375  if ((ret = dca_subsubframe(s, base_channel, block_index)))
1376  return ret;
1377 
1378  /* Update state */
1379  s->current_subsubframe++;
1381  s->current_subsubframe = 0;
1382  s->current_subframe++;
1383  }
1384  if (s->current_subframe >= s->subframes) {
1385 #ifdef TRACE
1386  av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_footer\n");
1387 #endif
1388  /* Read subframe footer */
1389  if ((ret = dca_subframe_footer(s, base_channel)))
1390  return ret;
1391  }
1392 
1393  return 0;
1394 }
1395 
1399 static int dca_exss_mask2count(int mask)
1400 {
1401  /* count bits that mean speaker pairs twice */
1402  return av_popcount(mask) +
1403  av_popcount(mask & (DCA_EXSS_CENTER_LEFT_RIGHT |
1412 }
1413 
1417 static void dca_exss_skip_mix_coeffs(GetBitContext *gb, int channels, int out_ch)
1418 {
1419  int i;
1420 
1421  for (i = 0; i < channels; i++) {
1422  int mix_map_mask = get_bits(gb, out_ch);
1423  int num_coeffs = av_popcount(mix_map_mask);
1424  skip_bits_long(gb, num_coeffs * 6);
1425  }
1426 }
1427 
1432 {
1433  int header_pos = get_bits_count(&s->gb);
1434  int header_size;
1435  int channels;
1436  int embedded_stereo = 0;
1437  int embedded_6ch = 0;
1438  int drc_code_present;
1439  int extensions_mask;
1440  int i, j;
1441 
1442  if (get_bits_left(&s->gb) < 16)
1443  return -1;
1444 
1445  /* We will parse just enough to get to the extensions bitmask with which
1446  * we can set the profile value. */
1447 
1448  header_size = get_bits(&s->gb, 9) + 1;
1449  skip_bits(&s->gb, 3); // asset index
1450 
1451  if (s->static_fields) {
1452  if (get_bits1(&s->gb))
1453  skip_bits(&s->gb, 4); // asset type descriptor
1454  if (get_bits1(&s->gb))
1455  skip_bits_long(&s->gb, 24); // language descriptor
1456 
1457  if (get_bits1(&s->gb)) {
1458  /* How can one fit 1024 bytes of text here if the maximum value
1459  * for the asset header size field above was 512 bytes? */
1460  int text_length = get_bits(&s->gb, 10) + 1;
1461  if (get_bits_left(&s->gb) < text_length * 8)
1462  return -1;
1463  skip_bits_long(&s->gb, text_length * 8); // info text
1464  }
1465 
1466  skip_bits(&s->gb, 5); // bit resolution - 1
1467  skip_bits(&s->gb, 4); // max sample rate code
1468  channels = get_bits(&s->gb, 8) + 1;
1469 
1470  if (get_bits1(&s->gb)) { // 1-to-1 channels to speakers
1471  int spkr_remap_sets;
1472  int spkr_mask_size = 16;
1473  int num_spkrs[7];
1474 
1475  if (channels > 2)
1476  embedded_stereo = get_bits1(&s->gb);
1477  if (channels > 6)
1478  embedded_6ch = get_bits1(&s->gb);
1479 
1480  if (get_bits1(&s->gb)) {
1481  spkr_mask_size = (get_bits(&s->gb, 2) + 1) << 2;
1482  skip_bits(&s->gb, spkr_mask_size); // spkr activity mask
1483  }
1484 
1485  spkr_remap_sets = get_bits(&s->gb, 3);
1486 
1487  for (i = 0; i < spkr_remap_sets; i++) {
1488  /* std layout mask for each remap set */
1489  num_spkrs[i] = dca_exss_mask2count(get_bits(&s->gb, spkr_mask_size));
1490  }
1491 
1492  for (i = 0; i < spkr_remap_sets; i++) {
1493  int num_dec_ch_remaps = get_bits(&s->gb, 5) + 1;
1494  if (get_bits_left(&s->gb) < 0)
1495  return -1;
1496 
1497  for (j = 0; j < num_spkrs[i]; j++) {
1498  int remap_dec_ch_mask = get_bits_long(&s->gb, num_dec_ch_remaps);
1499  int num_dec_ch = av_popcount(remap_dec_ch_mask);
1500  skip_bits_long(&s->gb, num_dec_ch * 5); // remap codes
1501  }
1502  }
1503 
1504  } else {
1505  skip_bits(&s->gb, 3); // representation type
1506  }
1507  }
1508 
1509  drc_code_present = get_bits1(&s->gb);
1510  if (drc_code_present)
1511  get_bits(&s->gb, 8); // drc code
1512 
1513  if (get_bits1(&s->gb))
1514  skip_bits(&s->gb, 5); // dialog normalization code
1515 
1516  if (drc_code_present && embedded_stereo)
1517  get_bits(&s->gb, 8); // drc stereo code
1518 
1519  if (s->mix_metadata && get_bits1(&s->gb)) {
1520  skip_bits(&s->gb, 1); // external mix
1521  skip_bits(&s->gb, 6); // post mix gain code
1522 
1523  if (get_bits(&s->gb, 2) != 3) // mixer drc code
1524  skip_bits(&s->gb, 3); // drc limit
1525  else
1526  skip_bits(&s->gb, 8); // custom drc code
1527 
1528  if (get_bits1(&s->gb)) // channel specific scaling
1529  for (i = 0; i < s->num_mix_configs; i++)
1530  skip_bits_long(&s->gb, s->mix_config_num_ch[i] * 6); // scale codes
1531  else
1532  skip_bits_long(&s->gb, s->num_mix_configs * 6); // scale codes
1533 
1534  for (i = 0; i < s->num_mix_configs; i++) {
1535  if (get_bits_left(&s->gb) < 0)
1536  return -1;
1537  dca_exss_skip_mix_coeffs(&s->gb, channels, s->mix_config_num_ch[i]);
1538  if (embedded_6ch)
1540  if (embedded_stereo)
1542  }
1543  }
1544 
1545  switch (get_bits(&s->gb, 2)) {
1546  case 0: extensions_mask = get_bits(&s->gb, 12); break;
1547  case 1: extensions_mask = DCA_EXT_EXSS_XLL; break;
1548  case 2: extensions_mask = DCA_EXT_EXSS_LBR; break;
1549  case 3: extensions_mask = 0; /* aux coding */ break;
1550  }
1551 
1552  /* not parsed further, we were only interested in the extensions mask */
1553 
1554  if (get_bits_left(&s->gb) < 0)
1555  return -1;
1556 
1557  if (get_bits_count(&s->gb) - header_pos > header_size * 8) {
1558  av_log(s->avctx, AV_LOG_WARNING, "Asset header size mismatch.\n");
1559  return -1;
1560  }
1561  skip_bits_long(&s->gb, header_pos + header_size * 8 - get_bits_count(&s->gb));
1562 
1563  if (extensions_mask & DCA_EXT_EXSS_XLL)
1565  else if (extensions_mask & (DCA_EXT_EXSS_XBR | DCA_EXT_EXSS_X96 |
1568 
1569  if (!(extensions_mask & DCA_EXT_CORE))
1570  av_log(s->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n");
1571  if ((extensions_mask & DCA_CORE_EXTS) != s->core_ext_mask)
1573  "DTS extensions detection mismatch (%d, %d)\n",
1574  extensions_mask & DCA_CORE_EXTS, s->core_ext_mask);
1575 
1576  return 0;
1577 }
1578 
1583 {
1584  int ss_index;
1585  int blownup;
1586  int num_audiop = 1;
1587  int num_assets = 1;
1588  int active_ss_mask[8];
1589  int i, j;
1590 
1591  if (get_bits_left(&s->gb) < 52)
1592  return;
1593 
1594  skip_bits(&s->gb, 8); // user data
1595  ss_index = get_bits(&s->gb, 2);
1596 
1597  blownup = get_bits1(&s->gb);
1598  skip_bits(&s->gb, 8 + 4 * blownup); // header_size
1599  skip_bits(&s->gb, 16 + 4 * blownup); // hd_size
1600 
1601  s->static_fields = get_bits1(&s->gb);
1602  if (s->static_fields) {
1603  skip_bits(&s->gb, 2); // reference clock code
1604  skip_bits(&s->gb, 3); // frame duration code
1605 
1606  if (get_bits1(&s->gb))
1607  skip_bits_long(&s->gb, 36); // timestamp
1608 
1609  /* a single stream can contain multiple audio assets that can be
1610  * combined to form multiple audio presentations */
1611 
1612  num_audiop = get_bits(&s->gb, 3) + 1;
1613  if (num_audiop > 1) {
1614  av_log_ask_for_sample(s->avctx, "Multiple DTS-HD audio presentations.");
1615  /* ignore such streams for now */
1616  return;
1617  }
1618 
1619  num_assets = get_bits(&s->gb, 3) + 1;
1620  if (num_assets > 1) {
1621  av_log_ask_for_sample(s->avctx, "Multiple DTS-HD audio assets.");
1622  /* ignore such streams for now */
1623  return;
1624  }
1625 
1626  for (i = 0; i < num_audiop; i++)
1627  active_ss_mask[i] = get_bits(&s->gb, ss_index + 1);
1628 
1629  for (i = 0; i < num_audiop; i++)
1630  for (j = 0; j <= ss_index; j++)
1631  if (active_ss_mask[i] & (1 << j))
1632  skip_bits(&s->gb, 8); // active asset mask
1633 
1634  s->mix_metadata = get_bits1(&s->gb);
1635  if (s->mix_metadata) {
1636  int mix_out_mask_size;
1637 
1638  skip_bits(&s->gb, 2); // adjustment level
1639  mix_out_mask_size = (get_bits(&s->gb, 2) + 1) << 2;
1640  s->num_mix_configs = get_bits(&s->gb, 2) + 1;
1641 
1642  for (i = 0; i < s->num_mix_configs; i++) {
1643  int mix_out_mask = get_bits(&s->gb, mix_out_mask_size);
1644  s->mix_config_num_ch[i] = dca_exss_mask2count(mix_out_mask);
1645  }
1646  }
1647  }
1648 
1649  for (i = 0; i < num_assets; i++)
1650  skip_bits_long(&s->gb, 16 + 4 * blownup); // asset size
1651 
1652  for (i = 0; i < num_assets; i++) {
1654  return;
1655  }
1656 
1657  /* not parsed further, we were only interested in the extensions mask
1658  * from the asset header */
1659 }
1660 
1665 static int dca_decode_frame(AVCodecContext *avctx, void *data,
1666  int *got_frame_ptr, AVPacket *avpkt)
1667 {
1668  const uint8_t *buf = avpkt->data;
1669  int buf_size = avpkt->size;
1670 
1671  int lfe_samples;
1672  int num_core_channels = 0;
1673  int i, ret;
1674  float **samples_flt;
1675  DCAContext *s = avctx->priv_data;
1676  int channels, full_channels;
1677  int core_ss_end;
1678 
1679 
1680  s->xch_present = 0;
1681 
1682  s->dca_buffer_size = ff_dca_convert_bitstream(buf, buf_size, s->dca_buffer,
1685  av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
1686  return AVERROR_INVALIDDATA;
1687  }
1688 
1689  init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
1690  if ((ret = dca_parse_frame_header(s)) < 0) {
1691  //seems like the frame is corrupt, try with the next one
1692  return ret;
1693  }
1694  //set AVCodec values with parsed data
1695  avctx->sample_rate = s->sample_rate;
1696  avctx->bit_rate = s->bit_rate;
1697 
1698  s->profile = FF_PROFILE_DTS;
1699 
1700  for (i = 0; i < (s->sample_blocks / 8); i++) {
1701  if ((ret = dca_decode_block(s, 0, i))) {
1702  av_log(avctx, AV_LOG_ERROR, "error decoding block\n");
1703  return ret;
1704  }
1705  }
1706 
1707  /* record number of core channels incase less than max channels are requested */
1708  num_core_channels = s->prim_channels;
1709 
1710  if (s->ext_coding)
1712  else
1713  s->core_ext_mask = 0;
1714 
1715  core_ss_end = FFMIN(s->frame_size, s->dca_buffer_size) * 8;
1716 
1717  /* only scan for extensions if ext_descr was unknown or indicated a
1718  * supported XCh extension */
1719  if (s->core_ext_mask < 0 || s->core_ext_mask & DCA_EXT_XCH) {
1720 
1721  /* if ext_descr was unknown, clear s->core_ext_mask so that the
1722  * extensions scan can fill it up */
1723  s->core_ext_mask = FFMAX(s->core_ext_mask, 0);
1724 
1725  /* extensions start at 32-bit boundaries into bitstream */
1726  skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1727 
1728  while (core_ss_end - get_bits_count(&s->gb) >= 32) {
1729  uint32_t bits = get_bits_long(&s->gb, 32);
1730 
1731  switch (bits) {
1732  case 0x5a5a5a5a: {
1733  int ext_amode, xch_fsize;
1734 
1736 
1737  /* validate sync word using XCHFSIZE field */
1738  xch_fsize = show_bits(&s->gb, 10);
1739  if ((s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize) &&
1740  (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize + 1))
1741  continue;
1742 
1743  /* skip length-to-end-of-frame field for the moment */
1744  skip_bits(&s->gb, 10);
1745 
1746  s->core_ext_mask |= DCA_EXT_XCH;
1747 
1748  /* extension amode(number of channels in extension) should be 1 */
1749  /* AFAIK XCh is not used for more channels */
1750  if ((ext_amode = get_bits(&s->gb, 4)) != 1) {
1751  av_log(avctx, AV_LOG_ERROR, "XCh extension amode %d not"
1752  " supported!\n", ext_amode);
1753  continue;
1754  }
1755 
1756  /* much like core primary audio coding header */
1758 
1759  for (i = 0; i < (s->sample_blocks / 8); i++)
1760  if ((ret = dca_decode_block(s, s->xch_base_channel, i))) {
1761  av_log(avctx, AV_LOG_ERROR, "error decoding XCh extension\n");
1762  continue;
1763  }
1764 
1765  s->xch_present = 1;
1766  break;
1767  }
1768  case 0x47004a03:
1769  /* XXCh: extended channels */
1770  /* usually found either in core or HD part in DTS-HD HRA streams,
1771  * but not in DTS-ES which contains XCh extensions instead */
1773  break;
1774 
1775  case 0x1d95f262: {
1776  int fsize96 = show_bits(&s->gb, 12) + 1;
1777  if (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + fsize96)
1778  continue;
1779 
1780  av_log(avctx, AV_LOG_DEBUG, "X96 extension found at %d bits\n",
1781  get_bits_count(&s->gb));
1782  skip_bits(&s->gb, 12);
1783  av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\n", fsize96);
1784  av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\n", get_bits(&s->gb, 4));
1785 
1786  s->core_ext_mask |= DCA_EXT_X96;
1787  break;
1788  }
1789  }
1790 
1791  skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1792  }
1793  } else {
1794  /* no supported extensions, skip the rest of the core substream */
1795  skip_bits_long(&s->gb, core_ss_end - get_bits_count(&s->gb));
1796  }
1797 
1798  if (s->core_ext_mask & DCA_EXT_X96)
1800  else if (s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH))
1802 
1803  /* check for ExSS (HD part) */
1804  if (s->dca_buffer_size - s->frame_size > 32 &&
1805  get_bits_long(&s->gb, 32) == DCA_HD_MARKER)
1807 
1808  avctx->profile = s->profile;
1809 
1810  full_channels = channels = s->prim_channels + !!s->lfe;
1811 
1812  if (s->amode < 16) {
1814 
1815  if (s->xch_present && (!avctx->request_channels ||
1816  avctx->request_channels > num_core_channels + !!s->lfe)) {
1818  if (s->lfe) {
1821  } else {
1823  }
1824  } else {
1825  channels = num_core_channels + !!s->lfe;
1826  s->xch_present = 0; /* disable further xch processing */
1827  if (s->lfe) {
1830  } else
1832  }
1833 
1834  if (channels > !!s->lfe &&
1835  s->channel_order_tab[channels - 1 - !!s->lfe] < 0)
1836  return AVERROR_INVALIDDATA;
1837 
1838  if (avctx->request_channels == 2 && s->prim_channels > 2) {
1839  channels = 2;
1840  s->output = DCA_STEREO;
1842  }
1843  } else {
1844  av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n", s->amode);
1845  return AVERROR_INVALIDDATA;
1846  }
1847  avctx->channels = channels;
1848 
1849  /* get output buffer */
1850  s->frame.nb_samples = 256 * (s->sample_blocks / 8);
1851  if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
1852  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1853  return ret;
1854  }
1855  samples_flt = (float **) s->frame.extended_data;
1856 
1857  /* allocate buffer for extra channels if downmixing */
1858  if (avctx->channels < full_channels) {
1859  ret = av_samples_get_buffer_size(NULL, full_channels - channels,
1860  s->frame.nb_samples,
1861  avctx->sample_fmt, 0);
1862  if (ret < 0)
1863  return ret;
1864 
1866  &s->extra_channels_buffer_size, ret);
1867  if (!s->extra_channels_buffer)
1868  return AVERROR(ENOMEM);
1869 
1872  full_channels - channels,
1873  s->frame.nb_samples, avctx->sample_fmt, 0);
1874  if (ret < 0)
1875  return ret;
1876  }
1877 
1878  /* filter to get final output */
1879  for (i = 0; i < (s->sample_blocks / 8); i++) {
1880  int ch;
1881 
1882  for (ch = 0; ch < channels; ch++)
1883  s->samples_chanptr[ch] = samples_flt[ch] + i * 256;
1884  for (; ch < full_channels; ch++)
1885  s->samples_chanptr[ch] = s->extra_channels[ch - channels] + i * 256;
1886 
1887  dca_filter_channels(s, i);
1888 
1889  /* If this was marked as a DTS-ES stream we need to subtract back- */
1890  /* channel from SL & SR to remove matrixed back-channel signal */
1891  if ((s->source_pcm_res & 1) && s->xch_present) {
1892  float *back_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel]];
1893  float *lt_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel - 2]];
1894  float *rt_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel - 1]];
1895  s->fdsp.vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256);
1896  s->fdsp.vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256);
1897  }
1898  }
1899 
1900  /* update lfe history */
1901  lfe_samples = 2 * s->lfe * (s->sample_blocks / 8);
1902  for (i = 0; i < 2 * s->lfe * 4; i++)
1903  s->lfe_data[i] = s->lfe_data[i + lfe_samples];
1904 
1905  *got_frame_ptr = 1;
1906  *(AVFrame *) data = s->frame;
1907 
1908  return buf_size;
1909 }
1910 
1911 
1912 
1920 {
1921  DCAContext *s = avctx->priv_data;
1922 
1923  s->avctx = avctx;
1924  dca_init_vlcs();
1925 
1927  ff_mdct_init(&s->imdct, 6, 1, 1.0);
1929  ff_dcadsp_init(&s->dcadsp);
1930  ff_fmt_convert_init(&s->fmt_conv, avctx);
1931 
1932  avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
1933 
1934  /* allow downmixing to stereo */
1935  if (avctx->channels > 0 && avctx->request_channels < avctx->channels &&
1936  avctx->request_channels == 2) {
1937  avctx->channels = avctx->request_channels;
1938  }
1939 
1941  avctx->coded_frame = &s->frame;
1942 
1943  return 0;
1944 }
1945 
1947 {
1948  DCAContext *s = avctx->priv_data;
1949  ff_mdct_end(&s->imdct);
1951  return 0;
1952 }
1953 
1954 static const AVProfile profiles[] = {
1955  { FF_PROFILE_DTS, "DTS" },
1956  { FF_PROFILE_DTS_ES, "DTS-ES" },
1957  { FF_PROFILE_DTS_96_24, "DTS 96/24" },
1958  { FF_PROFILE_DTS_HD_HRA, "DTS-HD HRA" },
1959  { FF_PROFILE_DTS_HD_MA, "DTS-HD MA" },
1960  { FF_PROFILE_UNKNOWN },
1961 };
1962 
1964  .name = "dca",
1965  .type = AVMEDIA_TYPE_AUDIO,
1966  .id = AV_CODEC_ID_DTS,
1967  .priv_data_size = sizeof(DCAContext),
1968  .init = dca_decode_init,
1970  .close = dca_decode_end,
1971  .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
1972  .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1,
1973  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1975  .profiles = NULL_IF_CONFIG_SMALL(profiles),
1976 };
int wrap
wrap for get_vlc2()
Definition: dcadec.c:270
int ext_descr
extension audio descriptor flag
Definition: dcadec.c:305
static const int8_t bitalloc_offsets[10]
Definition: dcahuff.h:1024
int downmix
embedded downmix enabled
Definition: dcadec.c:300
int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]
quantization index codebook select
Definition: dcadec.c:329
#define DCA_BLOCKS_MAX
Definition: dcadec.c:61
static int16_t * samples
int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]
bit allocation quantizer select
Definition: dcadec.c:328
int crc_present
crc is present in the bitstream
Definition: dcadec.c:292
int size
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
low bitrate component in ExSS
Definition: dcadec.c:107
int timestamp
embedded time stamp flag
Definition: dcadec.c:302
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
Definition: samplefmt.c:108
int amode
audio channels arrangement
Definition: dcadec.c:295
static const AVProfile profiles[]
Definition: dcadec.c:1954
static const uint16_t tmode_codes[TMODE_COUNT][4]
Definition: dcahuff.h:31
int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]
stereo downmix coefficients
Definition: dcadec.c:342
int transient_huffman[DCA_PRIM_CHANNELS_MAX]
transient mode code book
Definition: dcadec.c:326
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:237
int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, int max_size)
Convert bitstream to one representation based on sync marker.
Definition: dca_parser.c:106
static const uint32_t scale_factor_quant6[64]
Definition: dcadata.h:4157
int mix_config_num_ch[4]
number of channels in each mix out configuration
Definition: dcadec.c:384
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:197
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
FmtConvertContext fmt_conv
Definition: dcadec.c:393
static int dca_parse_frame_header(DCAContext *s)
Definition: dcadec.c:550
static int dca_exss_parse_asset_header(DCAContext *s)
Parse extension substream asset header (HD)
Definition: dcadec.c:1431
static void dca_exss_skip_mix_coeffs(GetBitContext *gb, int channels, int out_ch)
Skip mixing coefficients of a single mix out configuration (HD)
Definition: dcadec.c:1417
int vq_start_subband[DCA_PRIM_CHANNELS_MAX]
high frequency vq start subband
Definition: dcadec.c:324
XXCh channels extension in core substream.
Definition: dcadec.c:100
int size
Definition: avcodec.h:916
void ff_dcadsp_init(DCADSPContext *s)
Definition: dcadsp.c:47
float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][32]
Definition: dcadec.c:353
int hist_index[DCA_PRIM_CHANNELS_MAX]
Definition: dcadec.c:354
int samples_deficit
deficit sample count
Definition: dcadec.c:291
Definition: dcadec.c:70
static const float lossless_quant_d[32]
Definition: dcadata.h:4210
int dynrange
embedded dynamic range flag
Definition: dcadec.c:301
int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
joint subband scale factors
Definition: dcadec.c:341
int version
encoder software revision
Definition: dcadec.c:312
static const int8_t dca_channel_reorder_lfe_xch[][9]
Definition: dcadec.c:195
#define VLC_TYPE
Definition: get_bits.h:61
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
core in core substream
Definition: dcadec.c:99
#define AV_CH_LAYOUT_STEREO
void(* lfe_fir)(float *out, const float *in, const float *coefs, int decifactor, float scale)
Definition: dcadsp.h:23
static BitAlloc dca_scalefactor
scalefactor VLCs
Definition: dcadec.c:276
SynthFilterContext synth
Definition: dcadec.c:391
int profile
profile
Definition: avcodec.h:2815
AVCodec.
Definition: avcodec.h:2960
#define AV_WN32A(p, v)
Definition: intreadwrite.h:458
#define DCA_BUFFER_PADDING_SIZE
Definition: dcadec.c:264
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:223
float subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512]
Definition: dcadec.c:352
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
float * extra_channels[DCA_PRIM_CHANNELS_MAX+1]
Definition: dcadec.c:361
#define DCA_HD_MARKER
DCA-HD specific block starts with this marker.
Definition: dca.h:38
void(* vector_fmac_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float and add to destination vector.
Definition: float_dsp.h:52
#define AV_RN32A(p)
Definition: intreadwrite.h:446
static int dca_subframe_footer(DCAContext *s, int base_channel)
Definition: dcadec.c:1319
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: utils.c:72
static BitAlloc dca_tmode
transition mode VLCs
Definition: dcadec.c:275
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Fill channel data pointers and linesize for samples with sample format sample_fmt.
Definition: samplefmt.c:140
#define MIX_FRONT3(samples, coef)
Definition: dcadec.c:1031
static int dca_exss_mask2count(int mask)
Return the number of channels in an ExSS speaker mask (HD)
Definition: dcadec.c:1399
static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
Definition: dcadec.c:669
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]
scale factor code book
Definition: dcadec.c:327
static int dca_decode_block(DCAContext *s, int base_channel, int block_index)
Decode a dca frame block.
Definition: dcadec.c:1351
void(* int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len)
Convert an array of int32_t to float and multiply by a float value.
Definition: fmtconvert.h:38
static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)
Definition: dcadec.c:1141
uint8_t bits
Definition: crc.c:31
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2112
uint8_t
static const uint16_t dca_vlc_offs[]
Definition: dcadec.c:396
int xch_base_channel
index of first (only) channel containing XCH data
Definition: dcadec.c:378
float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4]
Definition: dcadec.c:351
#define DCA_LFE
Definition: dcadec.c:257
#define DCA_SUBBANDS
Definition: dcadec.c:57
int dca_buffer_size
how much data is in the dca_buffer
Definition: dcadec.c:366
static const uint32_t scale_factor_quant7[128]
Definition: dcadata.h:4168
#define MIX_REAR2(samples, s1, s2, rs, coef)
Definition: dcadec.c:1027
static void get_array(GetBitContext *gb, int *dst, int len, int bits)
Definition: dcadec.c:460
static av_cold int dca_decode_end(AVCodecContext *avctx)
Definition: dcadec.c:1946
#define AV_CH_LOW_FREQUENCY
int header_crc
header crc check bytes
Definition: dcadec.c:310
DCAMode
Definition: dcadec.c:64
int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
transition mode (transients)
Definition: dcadec.c:338
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:915
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:192
int sample_rate
audio sampling rate
Definition: dcadec.c:296
bitstream reader API header.
#define AV_CH_BACK_LEFT
AVCodecContext * avctx
Definition: dcadec.c:287
XCh channel extension in core substream.
Definition: dcadec.c:102
static BitAlloc dca_bitalloc_index
indexes for samples VLC select
Definition: dcadec.c:274
int lfe
low frequency effects flag
Definition: dcadec.c:308
static const float fir_32bands_nonperfect[]
Definition: dcadata.h:6792
#define LOCAL_ALIGNED_16(t, v,...)
Definition: dsputil.h:602
static BitAlloc dca_smpl_bitalloc[11]
samples VLCs
Definition: dcadec.c:277
XXCh channels extension in ExSS.
Definition: dcadec.c:105
static const uint8_t bitalloc_sizes[10]
Definition: dcahuff.h:1022
static float t
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:335
float, planar
Definition: samplefmt.h:60
#define r
Definition: input.c:51
#define DCA_CHANNEL_MASK
Definition: dcadec.c:255
int predictor_history
predictor history flag
Definition: dcadec.c:309
int dynrange_coef
dynamic range coefficient
Definition: dcadec.c:343
int joint_huff[DCA_PRIM_CHANNELS_MAX]
joint subband scale factors codebook
Definition: dcadec.c:340
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:547
int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2]
scale factors (2 if transient)
Definition: dcadec.c:339
FFTContext imdct
Definition: dcadec.c:390
float raXin[32]
Definition: dcadec.c:355
float subband_samples[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]
Definition: dcadec.c:359
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
static const uint16_t mask[17]
Definition: lzw.c:38
#define MIX_REAR1(samples, s1, rs, coef)
Definition: dcadec.c:1023
#define DCA_PRIM_CHANNELS_MAX
Definition: dcadec.c:56
static const uint16_t bitalloc_12_codes[BITALLOC_12_COUNT][12]
Definition: dcahuff.h:50
int current_subsubframe
Definition: dcadec.c:372
int hdcd
source material is mastered in HDCD
Definition: dcadec.c:304
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
int mix_metadata
mixing metadata present
Definition: dcadec.c:382
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1434
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
static const uint8_t bitalloc_12_bits[BITALLOC_12_COUNT][12]
Definition: dcahuff.h:72
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
bit allocation index
Definition: dcadec.c:337
static int dca_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Main frame decoding function FIXME add arguments.
Definition: dcadec.c:1665
#define ff_mdct_init
Definition: fft.h:146
int debug_flag
used for suppressing repeated error messages output
Definition: dcadec.c:388
#define DCA_CORE_EXTS
Definition: dcadec.c:124
DCAExtensionMask
Definition: dcadec.c:98
Definition: get_bits.h:63
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2165
static const int8_t dca_lfe_index[]
Definition: dcadec.c:172
const int8_t * channel_order_tab
channel reordering table, lfe and non lfe
Definition: dcadec.c:368
float lfe_data[2 *DCA_LFE_MAX *(DCA_BLOCKS_MAX+4)]
Low frequency effect data.
Definition: dcadec.c:347
static const uint8_t tmode_bits[TMODE_COUNT][4]
Definition: dcahuff.h:37
static void qmf_32_subbands(DCAContext *s, int chans, float samples_in[32][8], float *samples_out, float scale)
Definition: dcadec.c:951
int front_sum
front sum/difference flag
Definition: dcadec.c:315
#define DCA_ABITS_MAX
Definition: dcadec.c:58
static const float dca_downmix_coeffs[65]
Definition: dcadata.h:7511
int source_pcm_res
source pcm resolution
Definition: dcadec.c:314
Definition: fft.h:62
int bit_rate
the average bitrate
Definition: avcodec.h:1404
audio channel layout utility functions
static DCTELEM block[64]
Definition: dct-test.c:169
static const int8_t dca_channel_reorder_lfe[][9]
Definition: dcadec.c:176
static const int8_t dca_channel_reorder_nolfe[][9]
Definition: dcadec.c:214
int surround_sum
surround sum/difference flag
Definition: dcadec.c:316
static av_cold void dca_init_vlcs(void)
Definition: dcadec.c:405
av_cold void ff_synth_filter_init(SynthFilterContext *c)
Definition: synth_filter.c:59
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
uint8_t dca_buffer[DCA_MAX_FRAME_SIZE+DCA_MAX_EXSS_HEADER_SIZE+DCA_BUFFER_PADDING_SIZE]
Definition: dcadec.c:365
static const uint8_t scales_bits[SCALES_COUNT][129]
Definition: dcahuff.h:181
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:251
int joint_intensity[DCA_PRIM_CHANNELS_MAX]
joint intensity coding index
Definition: dcadec.c:325
static const int16_t adpcm_vb[4096][4]
Definition: dcadata.h:55
static const uint16_t *const bitalloc_codes[10][8]
Definition: dcahuff.h:1040
int multirate_inter
multirate interpolator switch
Definition: dcadec.c:311
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:515
static const uint8_t dca_channels[16]
Definition: dcadata.h:41
#define AV_CH_FRONT_LEFT_OF_CENTER
Bit allocation.
Definition: dcadec.c:267
lossless extension in ExSS
Definition: dcadec.c:108
#define AV_CH_FRONT_CENTER
const uint32_t avpriv_dca_sample_rates[16]
Definition: dca.c:25
int bit_rate
transmission bit rate
Definition: dcadec.c:297
static const uint8_t *const bitalloc_bits[10][8]
Definition: dcahuff.h:1058
#define INIT_VLC_USE_NEW_STATIC
Definition: get_bits.h:433
int offset
code values offset
Definition: dcadec.c:268
static const uint8_t abits_levels[7]
Definition: dcadec.c:1129
#define AV_CH_FRONT_RIGHT_OF_CENTER
static const float lfe_fir_64[]
Definition: dcadata.h:7308
int xch_present
XCh extension present and valid.
Definition: dcadec.c:377
int bits
Definition: get_bits.h:64
#define SCALES_VLC_BITS
Definition: dcahuff.h:82
int table_allocated
Definition: get_bits.h:66
int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
VQ encoded high frequency subbands.
Definition: dcadec.c:345
int core_ext_mask
present extensions in the core substream
Definition: dcadec.c:374
int lfe_scale_factor
Definition: dcadec.c:348
NULL
Definition: eval.c:52
#define DCA_MAX_FRAME_SIZE
Definition: dcadec.c:261
external API header
int aux_data
auxiliary data flag
Definition: dcadec.c:303
AV_SAMPLE_FMT_NONE
Definition: avconv_filter.c:63
int sample_rate
samples per second
Definition: avcodec.h:2104
int ext_coding
extended coding flag
Definition: dcadec.c:306
int subband_activity[DCA_PRIM_CHANNELS_MAX]
subband activity count
Definition: dcadec.c:323
main external API structure.
Definition: avcodec.h:1339
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:326
#define FASTDIV(a, b)
Definition: mathops.h:195
float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]
scale factor adjustment
Definition: dcadec.c:330
int copy_history
copy history
Definition: dcadec.c:313
static void dca_exss_parse_header(DCAContext *s)
Parse extension substream header (HD)
Definition: dcadec.c:1582
static void int8x8_fmul_int32(float *dst, const int8_t *src, int scale)
Definition: dcadec.c:1132
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: get_bits.h:418
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:268
VLC vlc[8]
actual codes
Definition: dcadec.c:271
core in ExSS (extension substream)
Definition: dcadec.c:103
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:602
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:260
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:372
static const uint64_t dca_core_channel_layout[]
Definition: dcadec.c:135
static void dca_downmix(float **samples, int srcfmt, int downmix_coef[DCA_PRIM_CHANNELS_MAX][2], const int8_t *channel_mapping)
Definition: dcadec.c:1044
static int decode_blockcodes(int code1, int code2, int levels, int *values)
Definition: dcadec.c:1121
static const float lossy_quant_d[32]
Definition: dcadata.h:4195
extended bitrate extension in ExSS
Definition: dcadec.c:104
DCAExSSSpeakerMask
Definition: dcadec.c:79
static int decode_blockcode(int code, int levels, int *values)
Definition: dcadec.c:1107
int sample_blocks
number of PCM sample blocks
Definition: dcadec.c:293
static const uint8_t abits_sizes[7]
Definition: dcadec.c:1128
static const int8_t dca_channel_reorder_nolfe_xch[][9]
Definition: dcadec.c:233
AVCodec ff_dca_decoder
Definition: dcadec.c:1963
GetBitContext gb
Definition: dcadec.c:369
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:301
int current_subframe
Definition: dcadec.c:371
static const uint16_t scale[4]
#define AV_CH_BACK_CENTER
#define AV_CH_SIDE_RIGHT
uint8_t level
Definition: svq3.c:125
int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
prediction mode (ADPCM used or not)
Definition: dcadec.c:335
static av_cold int dca_decode_init(AVCodecContext *avctx)
DCA initialization.
Definition: dcadec.c:1919
AVFrame frame
Definition: dcadec.c:288
static const float fir_32bands_perfect[]
Definition: dcadata.h:6276
int num_mix_configs
number of mix out configurations
Definition: dcadec.c:383
void(* synth_filter_float)(FFTContext *imdct, float *synth_buf_ptr, int *synth_buf_offset, float synth_buf2[32], const float window[512], float out[32], const float in[32], float scale)
Definition: synth_filter.h:27
static const uint8_t dca_default_coeffs[10][5][2]
Definition: dcadata.h:7525
DCADSPContext dcadsp
Definition: dcadec.c:392
96/24 extension in core substream
Definition: dcadec.c:101
common internal api header.
common internal and external API header
static void lfe_interpolation_fir(DCAContext *s, int decimation_select, int num_deci_sample, float *samples_in, float *samples_out, float scale)
Definition: dcadec.c:990
uint8_t * extra_channels_buffer
Definition: dcadec.c:362
#define DCA_LFE_MAX
Definition: dcadec.c:62
#define ff_mdct_end
Definition: fft.h:147
int total_channels
number of channels including extensions
Definition: dcadec.c:321
static const uint16_t scales_codes[SCALES_COUNT][129]
Definition: dcahuff.h:83
static int dca_filter_channels(DCAContext *s, int block_index)
Definition: dcadec.c:1286
int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
prediction VQ coefs
Definition: dcadec.c:336
int dialog_norm
dialog normalisation parameter
Definition: dcadec.c:317
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
AVProfile.
Definition: avcodec.h:2948
DSP utils.
int bit_rate_index
transmission bit rate index
Definition: dcadec.c:298
void * priv_data
Definition: avcodec.h:1382
static const uint8_t bitalloc_maxbits[10][7]
Definition: dcahuff.h:1027
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
Definition: fmtconvert.c:79
int len
int channels
number of audio channels
Definition: avcodec.h:2105
static const uint32_t dca_bit_rates[32]
Definition: dcadata.h:31
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:65
float * samples_chanptr[DCA_PRIM_CHANNELS_MAX+1]
Definition: dcadec.c:360
AVFloatDSPContext fdsp
Definition: dcadec.c:389
static const int8_t high_freq_vq[1024][32]
Definition: dcadata.h:4221
int subsubframes[DCA_SUBFRAMES_MAX]
number of subsubframes
Definition: dcadec.c:333
#define DCA_MAX_EXSS_HEADER_SIZE
Definition: dcadec.c:262
static const float lfe_fir_128[]
Definition: dcadata.h:7440
static const int dca_ext_audio_descr_mask[]
Definition: dcadec.c:112
96/24 extension in ExSS
Definition: dcadec.c:106
#define DOWNMIX_TO_STEREO(op1, op2)
Definition: dcadec.c:1038
int frame_size
primary frame byte size
Definition: dcadec.c:294
#define DCA_SUBFRAMES_MAX
Definition: dcadec.c:60
int aspf
audio sync word insertion flag
Definition: dcadec.c:307
int prim_channels
number of primary audio channels
Definition: dcadec.c:322
#define AV_CH_SIDE_LEFT
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
Definition: float_dsp.c:55
static const uint8_t bitalloc_12_vlc_bits[BITALLOC_12_COUNT]
Definition: dcahuff.h:47
int output
type of output
Definition: dcadec.c:357
static int get_scale(GetBitContext *gb, int level, int value, int log2range)
Definition: dcadec.c:652
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: avcodec.h:1028
int partial_samples[DCA_SUBFRAMES_MAX]
partial subsubframe samples count
Definition: dcadec.c:334
This structure stores compressed data.
Definition: avcodec.h:898
int subframes
number of subframes
Definition: dcadec.c:320
static int dca_parse_audio_coding_header(DCAContext *s, int base_channel)
Definition: dcadec.c:466
int nb_samples
number of audio samples (per channel) described by this frame
Definition: avcodec.h:1042
unsigned int extra_channels_buffer_size
Definition: dcadec.c:363
for(j=16;j >0;--j)
static const uint8_t tmode_vlc_bits[TMODE_COUNT]
Definition: dcahuff.h:30
static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx)
Definition: dcadec.c:279
int static_fields
static fields present
Definition: dcadec.c:381
#define AV_CH_BACK_RIGHT
int frame_type
type of the current frame
Definition: dcadec.c:290
static const uint8_t dca_bits_per_sample[7]
Definition: dcadata.h:46
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)
int profile
Definition: dcadec.c:386
bitstream writer API