FFmpeg
Loading...
Searching...
No Matches
dca_xll.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 foo86
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "avcodec.h"
23#include "libavutil/mem.h"
24#include "dcadec.h"
25#include "dcadata.h"
26#include "dcamath.h"
27#include "dca_syncwords.h"
28#include "decode.h"
29#include "unary.h"
30
31static int get_linear(GetBitContext *gb, int n)
32{
33 unsigned int v = get_bits_long(gb, n);
34 return (v >> 1) ^ -(v & 1);
35}
36
37static int get_rice_un(GetBitContext *gb, int k)
38{
39 unsigned int v = get_unary(gb, 1, get_bits_left(gb));
40 return (v << k) | get_bits_long(gb, k);
41}
42
43static int get_rice(GetBitContext *gb, int k)
44{
45 unsigned int v = get_rice_un(gb, k);
46 return (v >> 1) ^ -(v & 1);
47}
48
49static void get_array(GetBitContext *gb, int32_t *array, int size, int n)
50{
51 int i;
52
53 for (i = 0; i < size; i++)
54 array[i] = get_bits(gb, n);
55}
56
57static void get_linear_array(GetBitContext *gb, int32_t *array, int size, int n)
58{
59 int i;
60
61 if (n == 0)
62 memset(array, 0, sizeof(*array) * size);
63 else for (i = 0; i < size; i++)
64 array[i] = get_linear(gb, n);
65}
66
67static int get_rice_array(GetBitContext *gb, int32_t *array, int size, int k)
68{
69 int i;
70
71 for (i = 0; i < size && get_bits_left(gb) > k; i++)
72 array[i] = get_rice(gb, k);
73
74 if (i < size)
76 return 0;
77}
78
80{
81 // Size of downmix coefficient matrix
82 int m = c->primary_chset ? ff_dca_dmix_primary_nch[c->dmix_type] : c->hier_ofs;
83 int i, j, *coeff_ptr = c->dmix_coeff;
84
85 for (i = 0; i < m; i++) {
86 int code, sign, coeff, scale, scale_inv = 0;
87 unsigned int index;
88
89 // Downmix scale (only for non-primary channel sets)
90 if (!c->primary_chset) {
91 code = get_bits(&s->gb, 9);
92 sign = (code >> 8) - 1;
95 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL downmix scale index\n");
97 }
99 scale_inv = ff_dca_inv_dmixtable[index];
100 c->dmix_scale[i] = (scale ^ sign) - sign;
101 c->dmix_scale_inv[i] = (scale_inv ^ sign) - sign;
102 }
103
104 // Downmix coefficients
105 for (j = 0; j < c->nchannels; j++) {
106 code = get_bits(&s->gb, 9);
107 sign = (code >> 8) - 1;
108 index = code & 0xff;
110 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL downmix coefficient index\n");
111 return AVERROR_INVALIDDATA;
112 }
114 if (!c->primary_chset)
115 // Multiply by |InvDmixScale| to get |UndoDmixScale|
116 coeff = mul16(scale_inv, coeff);
117 *coeff_ptr++ = (coeff ^ sign) - sign;
118 }
119 }
120
121 return 0;
122}
123
125{
126 int i, j, k, ret, band, header_size, header_pos = get_bits_count(&s->gb);
127 DCAXllChSet *p = &s->chset[0];
128 DCAXllBand *b;
129
130 // Size of channel set sub-header
131 header_size = get_bits(&s->gb, 10) + 1;
132
133 // Check CRC
134 if (ff_dca_check_crc(s->avctx, &s->gb, header_pos, header_pos + header_size * 8)) {
135 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL sub-header checksum\n");
136 return AVERROR_INVALIDDATA;
137 }
138
139 // Number of channels in the channel set
140 c->nchannels = get_bits(&s->gb, 4) + 1;
141 if (c->nchannels > DCA_XLL_CHANNELS_MAX) {
142 avpriv_request_sample(s->avctx, "%d XLL channels", c->nchannels);
144 }
145
146 // Residual type
147 c->residual_encode = get_bits(&s->gb, c->nchannels);
148
149 // PCM bit resolution
150 c->pcm_bit_res = get_bits(&s->gb, 5) + 1;
151
152 // Storage unit width
153 c->storage_bit_res = get_bits(&s->gb, 5) + 1;
154 if (c->storage_bit_res != 16 && c->storage_bit_res != 20 && c->storage_bit_res != 24) {
155 avpriv_request_sample(s->avctx, "%d-bit XLL storage resolution", c->storage_bit_res);
157 }
158
159 if (c->pcm_bit_res > c->storage_bit_res) {
160 av_log(s->avctx, AV_LOG_ERROR, "Invalid PCM bit resolution for XLL channel set (%d > %d)\n", c->pcm_bit_res, c->storage_bit_res);
161 return AVERROR_INVALIDDATA;
162 }
163
164 // Original sampling frequency
165 c->freq = ff_dca_sampling_freqs[get_bits(&s->gb, 4)];
166 if (c->freq > 192000) {
167 avpriv_request_sample(s->avctx, "%d Hz XLL sampling frequency", c->freq);
169 }
170
171 // Sampling frequency modifier
172 if (get_bits(&s->gb, 2)) {
173 avpriv_request_sample(s->avctx, "XLL sampling frequency modifier");
175 }
176
177 // Which replacement set this channel set is member of
178 if (get_bits(&s->gb, 2)) {
179 avpriv_request_sample(s->avctx, "XLL replacement set");
181 }
182
183 if (asset->one_to_one_map_ch_to_spkr) {
184 // Primary channel set flag
185 c->primary_chset = get_bits1(&s->gb);
186 if (c->primary_chset != (c == p)) {
187 av_log(s->avctx, AV_LOG_ERROR, "The first (and only) XLL channel set must be primary\n");
188 return AVERROR_INVALIDDATA;
189 }
190
191 // Downmix coefficients present in stream
192 c->dmix_coeffs_present = get_bits1(&s->gb);
193
194 // Downmix already performed by encoder
195 c->dmix_embedded = c->dmix_coeffs_present && get_bits1(&s->gb);
196
197 // Downmix type
198 if (c->dmix_coeffs_present && c->primary_chset) {
199 c->dmix_type = get_bits(&s->gb, 3);
200 if (c->dmix_type >= DCA_DMIX_TYPE_COUNT) {
201 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL primary channel set downmix type\n");
202 return AVERROR_INVALIDDATA;
203 }
204 }
205
206 // Whether the channel set is part of a hierarchy
207 c->hier_chset = get_bits1(&s->gb);
208 if (!c->hier_chset && s->nchsets != 1) {
209 avpriv_request_sample(s->avctx, "XLL channel set outside of hierarchy");
211 }
212
213 // Downmix coefficients
214 if (c->dmix_coeffs_present && (ret = parse_dmix_coeffs(s, c)) < 0)
215 return ret;
216
217 // Channel mask enabled
218 if (!get_bits1(&s->gb)) {
219 avpriv_request_sample(s->avctx, "Disabled XLL channel mask");
221 }
222
223 // Channel mask for set
224 c->ch_mask = get_bits_long(&s->gb, s->ch_mask_nbits);
225 if (av_popcount(c->ch_mask) != c->nchannels) {
226 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL channel mask\n");
227 return AVERROR_INVALIDDATA;
228 }
229
230 // Build the channel to speaker map
231 for (i = 0, j = 0; i < s->ch_mask_nbits; i++)
232 if (c->ch_mask & (1U << i))
233 c->ch_remap[j++] = i;
234 } else {
235 // Mapping coeffs present flag
236 if (c->nchannels != 2 || s->nchsets != 1 || get_bits1(&s->gb)) {
237 avpriv_request_sample(s->avctx, "Custom XLL channel to speaker mapping");
239 }
240
241 // Setup for LtRt decoding
242 c->primary_chset = 1;
243 c->dmix_coeffs_present = 0;
244 c->dmix_embedded = 0;
245 c->hier_chset = 0;
246 c->ch_mask = DCA_SPEAKER_LAYOUT_STEREO;
247 c->ch_remap[0] = DCA_SPEAKER_L;
248 c->ch_remap[1] = DCA_SPEAKER_R;
249 }
250
251 if (c->freq > 96000) {
252 // Extra frequency bands flag
253 if (get_bits1(&s->gb)) {
254 avpriv_request_sample(s->avctx, "Extra XLL frequency bands");
256 }
257 c->nfreqbands = 2;
258 } else {
259 c->nfreqbands = 1;
260 }
261
262 // Set the sampling frequency to that of the first frequency band.
263 // Frequency will be doubled again after bands assembly.
264 c->freq >>= c->nfreqbands - 1;
265
266 // Verify that all channel sets have the same audio characteristics
267 if (c != p && (c->nfreqbands != p->nfreqbands || c->freq != p->freq
268 || c->pcm_bit_res != p->pcm_bit_res
269 || c->storage_bit_res != p->storage_bit_res)) {
270 avpriv_request_sample(s->avctx, "Different XLL audio characteristics");
272 }
273
274 // Determine number of bits to read bit allocation coding parameter
275 if (c->storage_bit_res > 16)
276 c->nabits = 5;
277 else if (c->storage_bit_res > 8)
278 c->nabits = 4;
279 else
280 c->nabits = 3;
281
282 // Account for embedded downmix and decimator saturation
283 if ((s->nchsets > 1 || c->nfreqbands > 1) && c->nabits < 5)
284 c->nabits++;
285
286 for (band = 0, b = c->bands; band < c->nfreqbands; band++, b++) {
287 // Pairwise channel decorrelation
288 if ((b->decor_enabled = get_bits1(&s->gb)) && c->nchannels > 1) {
289 int ch_nbits = av_ceil_log2(c->nchannels);
290
291 // Original channel order
292 for (i = 0; i < c->nchannels; i++) {
293 b->orig_order[i] = get_bits(&s->gb, ch_nbits);
294 if (b->orig_order[i] >= c->nchannels) {
295 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL original channel order\n");
296 return AVERROR_INVALIDDATA;
297 }
298 }
299
300 // Pairwise channel coefficients
301 for (i = 0; i < c->nchannels / 2; i++)
302 b->decor_coeff[i] = get_bits1(&s->gb) ? get_linear(&s->gb, 7) : 0;
303 } else {
304 for (i = 0; i < c->nchannels; i++)
305 b->orig_order[i] = i;
306 for (i = 0; i < c->nchannels / 2; i++)
307 b->decor_coeff[i] = 0;
308 }
309
310 // Adaptive predictor order
311 b->highest_pred_order = 0;
312 for (i = 0; i < c->nchannels; i++) {
313 b->adapt_pred_order[i] = get_bits(&s->gb, 4);
314 if (b->adapt_pred_order[i] > b->highest_pred_order)
315 b->highest_pred_order = b->adapt_pred_order[i];
316 }
317 if (b->highest_pred_order > s->nsegsamples) {
318 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL adaptive prediction order\n");
319 return AVERROR_INVALIDDATA;
320 }
321
322 // Fixed predictor order
323 for (i = 0; i < c->nchannels; i++)
324 b->fixed_pred_order[i] = b->adapt_pred_order[i] ? 0 : get_bits(&s->gb, 2);
325
326 // Adaptive predictor quantized reflection coefficients
327 for (i = 0; i < c->nchannels; i++) {
328 for (j = 0; j < b->adapt_pred_order[i]; j++) {
329 k = get_linear(&s->gb, 8);
330 if (k == -128) {
331 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL reflection coefficient index\n");
332 return AVERROR_INVALIDDATA;
333 }
334 if (k < 0)
335 b->adapt_refl_coeff[i][j] = -(int)ff_dca_xll_refl_coeff[-k];
336 else
337 b->adapt_refl_coeff[i][j] = (int)ff_dca_xll_refl_coeff[ k];
338 }
339 }
340
341 // Downmix performed by encoder in extension frequency band
342 b->dmix_embedded = c->dmix_embedded && (band == 0 || get_bits1(&s->gb));
343
344 // MSB/LSB split flag in extension frequency band
345 if ((band == 0 && s->scalable_lsbs) || (band != 0 && get_bits1(&s->gb))) {
346 // Size of LSB section in any segment
347 b->lsb_section_size = get_bits_long(&s->gb, s->seg_size_nbits);
348 if (b->lsb_section_size < 0 || b->lsb_section_size > s->frame_size) {
349 av_log(s->avctx, AV_LOG_ERROR, "Invalid LSB section size\n");
350 return AVERROR_INVALIDDATA;
351 }
352
353 // Account for optional CRC bytes after LSB section
354 if (b->lsb_section_size && (s->band_crc_present > 2 ||
355 (band == 0 && s->band_crc_present > 1)))
356 b->lsb_section_size += 2;
357
358 // Number of bits to represent the samples in LSB part
359 for (i = 0; i < c->nchannels; i++) {
360 b->nscalablelsbs[i] = get_bits(&s->gb, 4);
361 if (b->nscalablelsbs[i] && !b->lsb_section_size) {
362 av_log(s->avctx, AV_LOG_ERROR, "LSB section missing with non-zero LSB width\n");
363 return AVERROR_INVALIDDATA;
364 }
365 }
366 } else {
367 b->lsb_section_size = 0;
368 for (i = 0; i < c->nchannels; i++)
369 b->nscalablelsbs[i] = 0;
370 }
371
372 // Scalable resolution flag in extension frequency band
373 if ((band == 0 && s->scalable_lsbs) || (band != 0 && get_bits1(&s->gb))) {
374 // Number of bits discarded by authoring
375 for (i = 0; i < c->nchannels; i++)
376 b->bit_width_adjust[i] = get_bits(&s->gb, 4);
377 } else {
378 for (i = 0; i < c->nchannels; i++)
379 b->bit_width_adjust[i] = 0;
380 }
381 }
382
383 // Reserved
384 // Byte align
385 // CRC16 of channel set sub-header
386 if (ff_dca_seek_bits(&s->gb, header_pos + header_size * 8)) {
387 av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL sub-header\n");
388 return AVERROR_INVALIDDATA;
389 }
390
391 return 0;
392}
393
395{
396 int ndecisamples = c->nfreqbands > 1 ? DCA_XLL_DECI_HISTORY_MAX : 0;
397 int nchsamples = s->nframesamples + ndecisamples;
398 int i, j, nsamples = nchsamples * c->nchannels * c->nfreqbands;
399 int32_t *ptr;
400
401 // Reallocate MSB sample buffer
402 av_fast_malloc(&c->sample_buffer[0], &c->sample_size[0], nsamples * sizeof(int32_t));
403 if (!c->sample_buffer[0])
404 return AVERROR(ENOMEM);
405
406 ptr = c->sample_buffer[0] + ndecisamples;
407 for (i = 0; i < c->nfreqbands; i++) {
408 for (j = 0; j < c->nchannels; j++) {
409 c->bands[i].msb_sample_buffer[j] = ptr;
410 ptr += nchsamples;
411 }
412 }
413
414 return 0;
415}
416
418{
419 int i, j, nsamples = 0;
420 int32_t *ptr;
421
422 // Determine number of frequency bands that have MSB/LSB split
423 for (i = 0; i < c->nfreqbands; i++)
424 if (c->bands[i].lsb_section_size)
425 nsamples += s->nframesamples * c->nchannels;
426 if (!nsamples)
427 return 0;
428
429 // Reallocate LSB sample buffer
430 av_fast_malloc(&c->sample_buffer[1], &c->sample_size[1], nsamples * sizeof(int32_t));
431 if (!c->sample_buffer[1])
432 return AVERROR(ENOMEM);
433
434 ptr = c->sample_buffer[1];
435 for (i = 0; i < c->nfreqbands; i++) {
436 if (c->bands[i].lsb_section_size) {
437 for (j = 0; j < c->nchannels; j++) {
438 c->bands[i].lsb_sample_buffer[j] = ptr;
439 ptr += s->nframesamples;
440 }
441 } else {
442 for (j = 0; j < c->nchannels; j++)
443 c->bands[i].lsb_sample_buffer[j] = NULL;
444 }
445 }
446
447 return 0;
448}
449
450static int chs_parse_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band, int seg, int band_data_end)
451{
452 DCAXllBand *b = &c->bands[band];
453 int i, j, k;
454
455 // Start unpacking MSB portion of the segment
456 if (!(seg && get_bits1(&s->gb))) {
457 // Unpack segment type
458 // 0 - distinct coding parameters for each channel
459 // 1 - common coding parameters for all channels
460 c->seg_common = get_bits1(&s->gb);
461
462 // Determine number of coding parameters encoded in segment
463 k = c->seg_common ? 1 : c->nchannels;
464
465 // Unpack Rice coding parameters
466 for (i = 0; i < k; i++) {
467 // Unpack Rice coding flag
468 // 0 - linear code, 1 - Rice code
469 c->rice_code_flag[i] = get_bits1(&s->gb);
470 // Unpack Hybrid Rice coding flag
471 // 0 - Rice code, 1 - Hybrid Rice code
472 if (!c->seg_common && c->rice_code_flag[i] && get_bits1(&s->gb))
473 // Unpack binary code length for isolated samples
474 c->bitalloc_hybrid_linear[i] = get_bits(&s->gb, c->nabits) + 1;
475 else
476 // 0 indicates no Hybrid Rice coding
477 c->bitalloc_hybrid_linear[i] = 0;
478 }
479
480 // Unpack coding parameters
481 for (i = 0; i < k; i++) {
482 if (seg == 0) {
483 // Unpack coding parameter for part A of segment 0
484 c->bitalloc_part_a[i] = get_bits(&s->gb, c->nabits);
485
486 // Adjust for the linear code
487 if (!c->rice_code_flag[i] && c->bitalloc_part_a[i])
488 c->bitalloc_part_a[i]++;
489
490 if (!c->seg_common)
491 c->nsamples_part_a[i] = b->adapt_pred_order[i];
492 else
493 c->nsamples_part_a[i] = b->highest_pred_order;
494 } else {
495 c->bitalloc_part_a[i] = 0;
496 c->nsamples_part_a[i] = 0;
497 }
498
499 // Unpack coding parameter for part B of segment
500 c->bitalloc_part_b[i] = get_bits(&s->gb, c->nabits);
501
502 // Adjust for the linear code
503 if (!c->rice_code_flag[i] && c->bitalloc_part_b[i])
504 c->bitalloc_part_b[i]++;
505 }
506 }
507
508 // Unpack entropy codes
509 for (i = 0; i < c->nchannels; i++) {
510 int32_t *part_a, *part_b;
511 int nsamples_part_b;
512
513 // Select index of coding parameters
514 k = c->seg_common ? 0 : i;
515
516 // Slice the segment into parts A and B
517 part_a = b->msb_sample_buffer[i] + seg * s->nsegsamples;
518 part_b = part_a + c->nsamples_part_a[k];
519 nsamples_part_b = s->nsegsamples - c->nsamples_part_a[k];
520
521 if (get_bits_left(&s->gb) < 0)
522 return AVERROR_INVALIDDATA;
523
524 if (!c->rice_code_flag[k]) {
525 // Linear codes
526 // Unpack all residuals of part A of segment 0
527 get_linear_array(&s->gb, part_a, c->nsamples_part_a[k],
528 c->bitalloc_part_a[k]);
529
530 // Unpack all residuals of part B of segment 0 and others
531 get_linear_array(&s->gb, part_b, nsamples_part_b,
532 c->bitalloc_part_b[k]);
533 } else {
534 // Rice codes
535 // Unpack all residuals of part A of segment 0
536 int ret = get_rice_array(&s->gb, part_a, c->nsamples_part_a[k],
537 c->bitalloc_part_a[k]);
538 if (ret < 0)
539 return ret;
540
541 if (c->bitalloc_hybrid_linear[k]) {
542 // Hybrid Rice codes
543 // Unpack the number of isolated samples
544 int nisosamples = get_bits(&s->gb, s->nsegsamples_log2);
545
546 // Set all locations to 0
547 memset(part_b, 0, sizeof(*part_b) * nsamples_part_b);
548
549 // Extract the locations of isolated samples and flag by -1
550 for (j = 0; j < nisosamples; j++) {
551 int loc = get_bits(&s->gb, s->nsegsamples_log2);
552 if (loc >= nsamples_part_b) {
553 av_log(s->avctx, AV_LOG_ERROR, "Invalid isolated sample location\n");
554 return AVERROR_INVALIDDATA;
555 }
556 part_b[loc] = -1;
557 }
558
559 // Unpack all residuals of part B of segment 0 and others
560 for (j = 0; j < nsamples_part_b; j++) {
561 if (part_b[j])
562 part_b[j] = get_linear(&s->gb, c->bitalloc_hybrid_linear[k]);
563 else
564 part_b[j] = get_rice(&s->gb, c->bitalloc_part_b[k]);
565 }
566 } else {
567 // Rice codes
568 // Unpack all residuals of part B of segment 0 and others
569 ret = get_rice_array(&s->gb, part_b, nsamples_part_b, c->bitalloc_part_b[k]);
570 if (ret < 0)
571 return ret;
572 }
573 }
574 }
575
576 // Unpack decimator history for frequency band 1
577 if (seg == 0 && band == 1) {
578 int nbits = get_bits(&s->gb, 5) + 1;
579 for (i = 0; i < c->nchannels; i++)
580 for (j = 1; j < DCA_XLL_DECI_HISTORY_MAX; j++)
581 c->deci_history[i][j] = get_sbits_long(&s->gb, nbits);
582 }
583
584 // Start unpacking LSB portion of the segment
585 if (b->lsb_section_size) {
586 // Skip to the start of LSB portion
587 if (ff_dca_seek_bits(&s->gb, band_data_end - b->lsb_section_size * 8)) {
588 av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
589 return AVERROR_INVALIDDATA;
590 }
591
592 // Unpack all LSB parts of residuals of this segment
593 for (i = 0; i < c->nchannels; i++) {
594 if (b->nscalablelsbs[i]) {
595 get_array(&s->gb,
596 b->lsb_sample_buffer[i] + seg * s->nsegsamples,
597 s->nsegsamples, b->nscalablelsbs[i]);
598 }
599 }
600 }
601
602 // Skip to the end of band data
603 if (ff_dca_seek_bits(&s->gb, band_data_end)) {
604 av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
605 return AVERROR_INVALIDDATA;
606 }
607
608 return 0;
609}
610
611static av_cold void chs_clear_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band, int seg)
612{
613 DCAXllBand *b = &c->bands[band];
614 int i, offset, nsamples;
615
616 if (seg < 0) {
617 offset = 0;
618 nsamples = s->nframesamples;
619 } else {
620 offset = seg * s->nsegsamples;
621 nsamples = s->nsegsamples;
622 }
623
624 for (i = 0; i < c->nchannels; i++) {
625 memset(b->msb_sample_buffer[i] + offset, 0, nsamples * sizeof(int32_t));
626 if (b->lsb_section_size)
627 memset(b->lsb_sample_buffer[i] + offset, 0, nsamples * sizeof(int32_t));
628 }
629
630 if (seg <= 0 && band)
631 memset(c->deci_history, 0, sizeof(c->deci_history));
632
633 if (seg < 0) {
634 memset(b->nscalablelsbs, 0, sizeof(b->nscalablelsbs));
635 memset(b->bit_width_adjust, 0, sizeof(b->bit_width_adjust));
636 }
637}
638
640{
641 DCAXllBand *b = &c->bands[band];
642 int nsamples = s->nframesamples;
643 int i, j, k;
644
645 // Inverse adaptive or fixed prediction
646 for (i = 0; i < c->nchannels; i++) {
647 int32_t *buf = b->msb_sample_buffer[i];
648 int order = b->adapt_pred_order[i];
649 if (order > 0) {
651 // Conversion from reflection coefficients to direct form coefficients
652 for (j = 0; j < order; j++) {
653 int rc = b->adapt_refl_coeff[i][j];
654 for (k = 0; k < (j + 1) / 2; k++) {
655 int tmp1 = coeff[ k ];
656 int tmp2 = coeff[j - k - 1];
657 coeff[ k ] = tmp1 + mul16(rc, tmp2);
658 coeff[j - k - 1] = tmp2 + mul16(rc, tmp1);
659 }
660 coeff[j] = rc;
661 }
662 // Inverse adaptive prediction
663 for (j = 0; j < nsamples - order; j++) {
664 int64_t err = 0;
665 for (k = 0; k < order; k++)
666 err += (int64_t)buf[j + k] * coeff[order - k - 1];
667 buf[j + k] -= (SUINT)clip23(norm16(err));
668 }
669 } else {
670 // Inverse fixed coefficient prediction
671 for (j = 0; j < b->fixed_pred_order[i]; j++)
672 for (k = 1; k < nsamples; k++)
673 buf[k] += (unsigned)buf[k - 1];
674 }
675 }
676
677 // Inverse pairwise channel decorrelation
678 if (b->decor_enabled) {
680
681 for (i = 0; i < c->nchannels / 2; i++) {
682 int coeff = b->decor_coeff[i];
683 if (coeff) {
684 s->dcadsp->decor(b->msb_sample_buffer[i * 2 + 1],
685 b->msb_sample_buffer[i * 2 ],
686 coeff, nsamples);
687 }
688 }
689
690 // Reorder channel pointers to the original order
691 for (i = 0; i < c->nchannels; i++)
692 tmp[i] = b->msb_sample_buffer[i];
693
694 for (i = 0; i < c->nchannels; i++)
695 b->msb_sample_buffer[b->orig_order[i]] = tmp[i];
696 }
697
698 // Map output channel pointers for frequency band 0
699 if (c->nfreqbands == 1)
700 for (i = 0; i < c->nchannels; i++)
701 s->output_samples[c->ch_remap[i]] = b->msb_sample_buffer[i];
702}
703
704static int chs_get_lsb_width(DCAXllDecoder *s, DCAXllChSet *c, int band, int ch)
705{
706 int adj = c->bands[band].bit_width_adjust[ch];
707 int shift = c->bands[band].nscalablelsbs[ch];
708
709 if (s->fixed_lsb_width)
710 shift = s->fixed_lsb_width;
711 else if (shift && adj)
712 shift += adj - 1;
713 else
714 shift += adj;
715
716 return shift;
717}
718
720{
721 DCAXllBand *b = &c->bands[band];
722 int n, ch, nsamples = s->nframesamples;
723
724 for (ch = 0; ch < c->nchannels; ch++) {
725 int shift = chs_get_lsb_width(s, c, band, ch);
726 if (shift) {
727 int32_t *msb = b->msb_sample_buffer[ch];
728 if (b->nscalablelsbs[ch]) {
729 int32_t *lsb = b->lsb_sample_buffer[ch];
730 int adj = b->bit_width_adjust[ch];
731 for (n = 0; n < nsamples; n++)
732 msb[n] = msb[n] * (SUINT)(1 << shift) + (lsb[n] << adj);
733 } else {
734 for (n = 0; n < nsamples; n++)
735 msb[n] = msb[n] * (SUINT)(1 << shift);
736 }
737 }
738 }
739}
740
742{
743 int ch, nsamples = s->nframesamples;
744 int32_t *ptr;
745
746 av_assert1(c->nfreqbands > 1);
747
748 // Reallocate frequency band assembly buffer
749 av_fast_malloc(&c->sample_buffer[2], &c->sample_size[2],
750 2 * nsamples * c->nchannels * sizeof(int32_t));
751 if (!c->sample_buffer[2])
752 return AVERROR(ENOMEM);
753
754 // Assemble frequency bands 0 and 1
755 ptr = c->sample_buffer[2];
756 for (ch = 0; ch < c->nchannels; ch++) {
757 int32_t *band0 = c->bands[0].msb_sample_buffer[ch];
758 int32_t *band1 = c->bands[1].msb_sample_buffer[ch];
759
760 // Copy decimator history
761 memcpy(band0 - DCA_XLL_DECI_HISTORY_MAX,
762 c->deci_history[ch], sizeof(c->deci_history[0]));
763
764 // Filter
765 s->dcadsp->assemble_freq_bands(ptr, band0, band1,
767 nsamples);
768
769 // Remap output channel pointer to assembly buffer
770 s->output_samples[c->ch_remap[ch]] = ptr;
771 ptr += nsamples * 2;
772 }
773
774 return 0;
775}
776
778{
779 int stream_ver, header_size, frame_size_nbits, nframesegs_log2;
780
781 // XLL extension sync word
782 if (get_bits_long(&s->gb, 32) != DCA_SYNCWORD_XLL) {
783 av_log(s->avctx, AV_LOG_VERBOSE, "Invalid XLL sync word\n");
784 return AVERROR(EAGAIN);
785 }
786
787 // Version number
788 stream_ver = get_bits(&s->gb, 4) + 1;
789 if (stream_ver > 1) {
790 avpriv_request_sample(s->avctx, "XLL stream version %d", stream_ver);
792 }
793
794 // Lossless frame header length
795 header_size = get_bits(&s->gb, 8) + 1;
796
797 // Check CRC
798 if (ff_dca_check_crc(s->avctx, &s->gb, 32, header_size * 8)) {
799 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL common header checksum\n");
800 return AVERROR_INVALIDDATA;
801 }
802
803 // Number of bits used to read frame size
804 frame_size_nbits = get_bits(&s->gb, 5) + 1;
805
806 // Number of bytes in a lossless frame
807 s->frame_size = get_bits_long(&s->gb, frame_size_nbits);
808 if (s->frame_size < 0 || s->frame_size >= DCA_XLL_PBR_BUFFER_MAX) {
809 av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL frame size (%d bytes)\n", s->frame_size);
810 return AVERROR_INVALIDDATA;
811 }
812 s->frame_size++;
813
814 // Number of channels sets per frame
815 s->nchsets = get_bits(&s->gb, 4) + 1;
816 if (s->nchsets > DCA_XLL_CHSETS_MAX) {
817 avpriv_request_sample(s->avctx, "%d XLL channel sets", s->nchsets);
819 }
820
821 // Number of segments per frame
822 nframesegs_log2 = get_bits(&s->gb, 4);
823 s->nframesegs = 1 << nframesegs_log2;
824 if (s->nframesegs > 1024) {
825 av_log(s->avctx, AV_LOG_ERROR, "Too many segments per XLL frame\n");
826 return AVERROR_INVALIDDATA;
827 }
828
829 // Samples in segment per one frequency band for the first channel set
830 // Maximum value is 256 for sampling frequencies <= 48 kHz
831 // Maximum value is 512 for sampling frequencies > 48 kHz
832 s->nsegsamples_log2 = get_bits(&s->gb, 4);
833 if (!s->nsegsamples_log2) {
834 av_log(s->avctx, AV_LOG_ERROR, "Too few samples per XLL segment\n");
835 return AVERROR_INVALIDDATA;
836 }
837 s->nsegsamples = 1 << s->nsegsamples_log2;
838 if (s->nsegsamples > 512) {
839 av_log(s->avctx, AV_LOG_ERROR, "Too many samples per XLL segment\n");
840 return AVERROR_INVALIDDATA;
841 }
842
843 // Samples in frame per one frequency band for the first channel set
844 s->nframesamples_log2 = s->nsegsamples_log2 + nframesegs_log2;
845 s->nframesamples = 1 << s->nframesamples_log2;
846 if (s->nframesamples > 65536) {
847 av_log(s->avctx, AV_LOG_ERROR, "Too many samples per XLL frame\n");
848 return AVERROR_INVALIDDATA;
849 }
850
851 // Number of bits used to read segment size
852 s->seg_size_nbits = get_bits(&s->gb, 5) + 1;
853
854 // Presence of CRC16 within each frequency band
855 // 0 - No CRC16 within band
856 // 1 - CRC16 placed at the end of MSB0
857 // 2 - CRC16 placed at the end of MSB0 and LSB0
858 // 3 - CRC16 placed at the end of MSB0 and LSB0 and other frequency bands
859 s->band_crc_present = get_bits(&s->gb, 2);
860
861 // MSB/LSB split flag
862 s->scalable_lsbs = get_bits1(&s->gb);
863
864 // Channel position mask
865 s->ch_mask_nbits = get_bits(&s->gb, 5) + 1;
866
867 // Fixed LSB width
868 if (s->scalable_lsbs)
869 s->fixed_lsb_width = get_bits(&s->gb, 4);
870 else
871 s->fixed_lsb_width = 0;
872
873 // Reserved
874 // Byte align
875 // Header CRC16 protection
876 if (ff_dca_seek_bits(&s->gb, header_size * 8)) {
877 av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL common header\n");
878 return AVERROR_INVALIDDATA;
879 }
880
881 return 0;
882}
883
885{
886 return !c->primary_chset && c->dmix_embedded && c->hier_chset;
887}
888
890{
891 if (c->hier_chset)
892 while (++c < &s->chset[s->nchsets])
894 return c;
895
896 return NULL;
897}
898
900{
901 int i, j, *coeff_ptr = c->dmix_coeff;
902
903 for (i = 0; i < c->hier_ofs; i++) {
904 int scale = o->dmix_scale[i];
905 int scale_inv = o->dmix_scale_inv[i];
906 c->dmix_scale[i] = mul15(c->dmix_scale[i], scale);
907 c->dmix_scale_inv[i] = mul16(c->dmix_scale_inv[i], scale_inv);
908 for (j = 0; j < c->nchannels; j++) {
909 int coeff = mul16(*coeff_ptr, scale_inv);
910 *coeff_ptr++ = mul15(coeff, o->dmix_scale[c->hier_ofs + j]);
911 }
912 }
913}
914
916{
917 DCAContext *dca = s->avctx->priv_data;
918 DCAXllChSet *c;
919 int i, ret;
920
921 // Parse channel set headers
922 s->nfreqbands = 0;
923 s->nchannels = 0;
924 s->nreschsets = 0;
925 for (i = 0, c = s->chset; i < s->nchsets; i++, c++) {
926 c->hier_ofs = s->nchannels;
927 if ((ret = chs_parse_header(s, c, asset)) < 0)
928 return ret;
929 if (c->nfreqbands > s->nfreqbands)
930 s->nfreqbands = c->nfreqbands;
931 if (c->hier_chset)
932 s->nchannels += c->nchannels;
933 if (c->residual_encode != (1 << c->nchannels) - 1)
934 s->nreschsets++;
935 }
936
937 // Pre-scale downmixing coefficients for all non-primary channel sets
938 for (i = s->nchsets - 1, c = &s->chset[i]; i > 0; i--, c--) {
939 if (is_hier_dmix_chset(c)) {
941 if (o)
943 }
944 }
945
946 // Determine number of active channel sets to decode
947 switch (dca->request_channel_layout) {
949 s->nactivechsets = 1;
950 break;
953 s->nactivechsets = (s->chset[0].nchannels < 5 && s->nchsets > 1) ? 2 : 1;
954 break;
955 default:
956 s->nactivechsets = s->nchsets;
957 break;
958 }
959
960 return 0;
961}
962
964{
965 int chs, seg, band, navi_nb, navi_pos, *navi_ptr;
966 DCAXllChSet *c;
967
968 // Determine size of NAVI table
969 navi_nb = s->nfreqbands * s->nframesegs * s->nchsets;
970 if (navi_nb > 1024) {
971 av_log(s->avctx, AV_LOG_ERROR, "Too many NAVI entries (%d)\n", navi_nb);
972 return AVERROR_INVALIDDATA;
973 }
974
975 // Reallocate NAVI table
976 av_fast_malloc(&s->navi, &s->navi_size, navi_nb * sizeof(*s->navi));
977 if (!s->navi)
978 return AVERROR(ENOMEM);
979
980 // Parse NAVI
981 navi_pos = get_bits_count(&s->gb);
982 navi_ptr = s->navi;
983 for (band = 0; band < s->nfreqbands; band++) {
984 for (seg = 0; seg < s->nframesegs; seg++) {
985 for (chs = 0, c = s->chset; chs < s->nchsets; chs++, c++) {
986 int size = 0;
987 if (c->nfreqbands > band) {
988 size = get_bits_long(&s->gb, s->seg_size_nbits);
989 if (size < 0 || size >= s->frame_size) {
990 av_log(s->avctx, AV_LOG_ERROR, "Invalid NAVI segment size (%d bytes)\n", size);
991 return AVERROR_INVALIDDATA;
992 }
993 size++;
994 }
995 *navi_ptr++ = size;
996 }
997 }
998 }
999
1000 // Byte align
1001 // CRC16
1002 skip_bits(&s->gb, -get_bits_count(&s->gb) & 7);
1003 skip_bits(&s->gb, 16);
1004
1005 // Check CRC
1006 if (ff_dca_check_crc(s->avctx, &s->gb, navi_pos, get_bits_count(&s->gb))) {
1007 av_log(s->avctx, AV_LOG_ERROR, "Invalid NAVI checksum\n");
1008 return AVERROR_INVALIDDATA;
1009 }
1010
1011 return 0;
1012}
1013
1015{
1016 int ret, chs, seg, band, navi_pos, *navi_ptr;
1017 DCAXllChSet *c;
1018
1019 for (chs = 0, c = s->chset; chs < s->nactivechsets; chs++, c++) {
1020 if ((ret = chs_alloc_msb_band_data(s, c)) < 0)
1021 return ret;
1022 if ((ret = chs_alloc_lsb_band_data(s, c)) < 0)
1023 return ret;
1024 }
1025
1026 navi_pos = get_bits_count(&s->gb);
1027 navi_ptr = s->navi;
1028 for (band = 0; band < s->nfreqbands; band++) {
1029 for (seg = 0; seg < s->nframesegs; seg++) {
1030 for (chs = 0, c = s->chset; chs < s->nchsets; chs++, c++) {
1031 if (c->nfreqbands > band) {
1032 navi_pos += *navi_ptr * 8;
1033 if (navi_pos > s->gb.size_in_bits) {
1034 av_log(s->avctx, AV_LOG_ERROR, "Invalid NAVI position\n");
1035 return AVERROR_INVALIDDATA;
1036 }
1037 if (chs < s->nactivechsets &&
1038 (ret = chs_parse_band_data(s, c, band, seg, navi_pos)) < 0) {
1039 if (s->avctx->err_recognition & AV_EF_EXPLODE)
1040 return ret;
1041 chs_clear_band_data(s, c, band, seg);
1042 }
1043 skip_bits_long(&s->gb, navi_pos - get_bits_count(&s->gb));
1044 }
1045 navi_ptr++;
1046 }
1047 }
1048 }
1049
1050 return 0;
1051}
1052
1053static int parse_frame(DCAXllDecoder *s, const uint8_t *data, int size, DCAExssAsset *asset)
1054{
1055 int ret;
1056
1057 if ((ret = init_get_bits8(&s->gb, data, size)) < 0)
1058 return ret;
1059 if ((ret = parse_common_header(s)) < 0)
1060 return ret;
1061 if ((ret = parse_sub_headers(s, asset)) < 0)
1062 return ret;
1063 if ((ret = parse_navi_table(s)) < 0)
1064 return ret;
1065 if ((ret = parse_band_data(s)) < 0)
1066 return ret;
1067
1068 if (s->frame_size * 8 > FFALIGN(get_bits_count(&s->gb), 32)) {
1069 unsigned int extradata_syncword;
1070
1071 // Align to dword
1072 skip_bits_long(&s->gb, -get_bits_count(&s->gb) & 31);
1073
1074 extradata_syncword = show_bits_long(&s->gb, 32);
1075
1076 if (extradata_syncword == DCA_SYNCWORD_XLL_X) {
1077 s->x_syncword_present = 1;
1078 } else if ((extradata_syncword >> 1) == (DCA_SYNCWORD_XLL_X_IMAX >> 1)) {
1079 s->x_imax_syncword_present = 1;
1080 }
1081 }
1082
1083 if (ff_dca_seek_bits(&s->gb, s->frame_size * 8)) {
1084 av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL frame\n");
1085 return AVERROR_INVALIDDATA;
1086 }
1087 return ret;
1088}
1089
1091{
1092 s->pbr_length = 0;
1093 s->pbr_delay = 0;
1094}
1095
1096static int copy_to_pbr(DCAXllDecoder *s, const uint8_t *data, int size, int delay)
1097{
1099 return AVERROR(ENOSPC);
1100
1101 if (!s->pbr_buffer && !(s->pbr_buffer = av_malloc(DCA_XLL_PBR_BUFFER_MAX + AV_INPUT_BUFFER_PADDING_SIZE)))
1102 return AVERROR(ENOMEM);
1103
1104 memcpy(s->pbr_buffer, data, size);
1105 memset(s->pbr_buffer + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1106 s->pbr_length = size;
1107 s->pbr_delay = delay;
1108 return 0;
1109}
1110
1111static int parse_frame_no_pbr(DCAXllDecoder *s, const uint8_t *data, int size, DCAExssAsset *asset)
1112{
1113 int ret = parse_frame(s, data, size, asset);
1114
1115 // If XLL packet data didn't start with a sync word, we must have jumped
1116 // right into the middle of PBR smoothing period
1117 if (ret == AVERROR(EAGAIN) && asset->xll_sync_present && asset->xll_sync_offset < size) {
1118 // Skip to the next sync word in this packet
1119 data += asset->xll_sync_offset;
1120 size -= asset->xll_sync_offset;
1121
1122 // If decoding delay is set, put the frame into PBR buffer and return
1123 // failure code. Higher level decoder is expected to switch to lossy
1124 // core decoding or mute its output until decoding delay expires.
1125 if (asset->xll_delay_nframes > 0) {
1126 if ((ret = copy_to_pbr(s, data, size, asset->xll_delay_nframes)) < 0)
1127 return ret;
1128 return AVERROR(EAGAIN);
1129 }
1130
1131 // No decoding delay, just parse the frame in place
1132 ret = parse_frame(s, data, size, asset);
1133 }
1134
1135 if (ret < 0)
1136 return ret;
1137
1138 if (s->frame_size > size)
1139 return AVERROR(EINVAL);
1140
1141 // If the XLL decoder didn't consume full packet, start PBR smoothing period
1142 if (s->frame_size < size)
1143 if ((ret = copy_to_pbr(s, data + s->frame_size, size - s->frame_size, 0)) < 0)
1144 return ret;
1145
1146 return 0;
1147}
1148
1149static int parse_frame_pbr(DCAXllDecoder *s, const uint8_t *data, int size, DCAExssAsset *asset)
1150{
1151 int ret;
1152
1153 if (size > DCA_XLL_PBR_BUFFER_MAX - s->pbr_length) {
1154 ret = AVERROR(ENOSPC);
1155 goto fail;
1156 }
1157
1158 memcpy(s->pbr_buffer + s->pbr_length, data, size);
1159 s->pbr_length += size;
1160 memset(s->pbr_buffer + s->pbr_length, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1161
1162 // Respect decoding delay after synchronization error
1163 if (s->pbr_delay > 0 && --s->pbr_delay)
1164 return AVERROR(EAGAIN);
1165
1166 if ((ret = parse_frame(s, s->pbr_buffer, s->pbr_length, asset)) < 0)
1167 goto fail;
1168
1169 if (s->frame_size > s->pbr_length) {
1170 ret = AVERROR(EINVAL);
1171 goto fail;
1172 }
1173
1174 if (s->frame_size == s->pbr_length) {
1175 // End of PBR smoothing period
1176 clear_pbr(s);
1177 } else {
1178 s->pbr_length -= s->frame_size;
1179 memmove(s->pbr_buffer, s->pbr_buffer + s->frame_size, s->pbr_length);
1180 }
1181
1182 return 0;
1183
1184fail:
1185 // For now, throw out all PBR state on failure.
1186 // Perhaps we can be smarter and try to resync somehow.
1187 clear_pbr(s);
1188 return ret;
1189}
1190
1191int ff_dca_xll_parse(DCAXllDecoder *s, const uint8_t *data, DCAExssAsset *asset)
1192{
1193 int ret;
1194
1195 if (s->hd_stream_id != asset->hd_stream_id) {
1196 clear_pbr(s);
1197 s->hd_stream_id = asset->hd_stream_id;
1198 }
1199
1200 if (s->pbr_length)
1201 ret = parse_frame_pbr(s, data + asset->xll_offset, asset->xll_size, asset);
1202 else
1203 ret = parse_frame_no_pbr(s, data + asset->xll_offset, asset->xll_size, asset);
1204
1205 return ret;
1206}
1207
1208static void undo_down_mix(DCAXllDecoder *s, DCAXllChSet *o, int band)
1209{
1210 int i, j, k, nchannels = 0, *coeff_ptr = o->dmix_coeff;
1211 DCAXllChSet *c;
1212
1213 for (i = 0, c = s->chset; i < s->nactivechsets; i++, c++) {
1214 if (!c->hier_chset)
1215 continue;
1216
1217 av_assert1(band < c->nfreqbands);
1218 for (j = 0; j < c->nchannels; j++) {
1219 for (k = 0; k < o->nchannels; k++) {
1220 int coeff = *coeff_ptr++;
1221 if (coeff) {
1222 s->dcadsp->dmix_sub(c->bands[band].msb_sample_buffer[j],
1223 o->bands[band].msb_sample_buffer[k],
1224 coeff, s->nframesamples);
1225 if (band)
1226 s->dcadsp->dmix_sub(c->deci_history[j],
1227 o->deci_history[k],
1229 }
1230 }
1231 }
1232
1233 nchannels += c->nchannels;
1234 if (nchannels >= o->hier_ofs)
1235 break;
1236 }
1237}
1238
1239static void scale_down_mix(DCAXllDecoder *s, DCAXllChSet *o, int band)
1240{
1241 int i, j, nchannels = 0;
1242 DCAXllChSet *c;
1243
1244 for (i = 0, c = s->chset; i < s->nactivechsets; i++, c++) {
1245 if (!c->hier_chset)
1246 continue;
1247
1248 av_assert1(band < c->nfreqbands);
1249 for (j = 0; j < c->nchannels; j++) {
1250 int scale = o->dmix_scale[nchannels++];
1251 if (scale != (1 << 15)) {
1252 s->dcadsp->dmix_scale(c->bands[band].msb_sample_buffer[j],
1253 scale, s->nframesamples);
1254 if (band)
1255 s->dcadsp->dmix_scale(c->deci_history[j],
1257 }
1258 }
1259
1260 if (nchannels >= o->hier_ofs)
1261 break;
1262 }
1263}
1264
1265// Clear all band data and replace non-residual encoded channels with lossy
1266// counterparts
1268{
1269 DCAContext *dca = s->avctx->priv_data;
1270 int band, ch;
1271
1272 for (band = 0; band < c->nfreqbands; band++)
1273 chs_clear_band_data(s, c, band, -1);
1274
1275 for (ch = 0; ch < c->nchannels; ch++) {
1276 if (!(c->residual_encode & (1 << ch)))
1277 continue;
1278 if (ff_dca_core_map_spkr(&dca->core, c->ch_remap[ch]) < 0)
1279 continue;
1280 c->residual_encode &= ~(1 << ch);
1281 }
1282}
1283
1285{
1286 DCAContext *dca = s->avctx->priv_data;
1287 int ch, nsamples = s->nframesamples;
1288 DCAXllChSet *o;
1289
1290 // Verify that core is compatible
1291 if (!(dca->packet & DCA_PACKET_CORE)) {
1292 av_log(s->avctx, AV_LOG_ERROR, "Residual encoded channels are present without core\n");
1293 return AVERROR(EINVAL);
1294 }
1295
1296 if (c->freq != dca->core.output_rate) {
1297 av_log(s->avctx, AV_LOG_WARNING, "Sample rate mismatch between core (%d Hz) and XLL (%d Hz)\n", dca->core.output_rate, c->freq);
1298 return AVERROR_INVALIDDATA;
1299 }
1300
1301 if (nsamples != dca->core.npcmsamples) {
1302 av_log(s->avctx, AV_LOG_WARNING, "Number of samples per frame mismatch between core (%d) and XLL (%d)\n", dca->core.npcmsamples, nsamples);
1303 return AVERROR_INVALIDDATA;
1304 }
1305
1306 // See if this channel set is downmixed and find the next channel set in
1307 // hierarchy. If downmixed, undo core pre-scaling before combining with
1308 // residual (residual is not scaled).
1310
1311 // Reduce core bit width and combine with residual
1312 for (ch = 0; ch < c->nchannels; ch++) {
1313 int n, spkr, shift, round;
1314 int32_t *src, *dst;
1315
1316 if (c->residual_encode & (1 << ch))
1317 continue;
1318
1319 // Map this channel to core speaker
1320 spkr = ff_dca_core_map_spkr(&dca->core, c->ch_remap[ch]);
1321 if (spkr < 0) {
1322 av_log(s->avctx, AV_LOG_WARNING, "Residual encoded channel (%d) references unavailable core channel\n", c->ch_remap[ch]);
1323 return AVERROR_INVALIDDATA;
1324 }
1325
1326 // Account for LSB width
1327 shift = 24 - c->pcm_bit_res + chs_get_lsb_width(s, c, 0, ch);
1328 if (shift > 24) {
1329 av_log(s->avctx, AV_LOG_WARNING, "Invalid core shift (%d bits)\n", shift);
1330 return AVERROR_INVALIDDATA;
1331 }
1332
1333 round = shift > 0 ? 1 << (shift - 1) : 0;
1334
1335 src = dca->core.output_samples[spkr];
1336 dst = c->bands[0].msb_sample_buffer[ch];
1337 if (o) {
1338 // Undo embedded core downmix pre-scaling
1339 int scale_inv = o->dmix_scale_inv[c->hier_ofs + ch];
1340 for (n = 0; n < nsamples; n++)
1341 dst[n] += (SUINT)clip23((mul16(src[n], scale_inv) + round) >> shift);
1342 } else {
1343 // No downmix scaling
1344 for (n = 0; n < nsamples; n++)
1345 dst[n] += (unsigned)((src[n] + round) >> shift);
1346 }
1347 }
1348
1349 return 0;
1350}
1351
1353{
1354 AVCodecContext *avctx = s->avctx;
1355 DCAContext *dca = avctx->priv_data;
1356 DCAExssAsset *asset = &dca->exss.assets[0];
1357 DCAXllChSet *p = &s->chset[0], *c;
1358 enum AVMatrixEncoding matrix_encoding = AV_MATRIX_ENCODING_NONE;
1359 int i, j, k, ret, shift, nsamples, request_mask;
1360 int ch_remap[DCA_SPEAKER_COUNT];
1361
1362 // Force lossy downmixed output during recovery
1363 if (dca->packet & DCA_PACKET_RECOVERY) {
1364 for (i = 0, c = s->chset; i < s->nchsets; i++, c++) {
1365 if (i < s->nactivechsets)
1367
1368 if (!c->primary_chset)
1369 c->dmix_embedded = 0;
1370 }
1371
1372 s->scalable_lsbs = 0;
1373 s->fixed_lsb_width = 0;
1374 }
1375
1376 // Filter frequency bands for active channel sets
1377 s->output_mask = 0;
1378 for (i = 0, c = s->chset; i < s->nactivechsets; i++, c++) {
1380
1381 if (c->residual_encode != (1 << c->nchannels) - 1
1382 && (ret = combine_residual_frame(s, c)) < 0)
1383 return ret;
1384
1385 if (s->scalable_lsbs)
1387
1388 if (c->nfreqbands > 1) {
1391 }
1392
1393 s->output_mask |= c->ch_mask;
1394 }
1395
1396 // Undo hierarchial downmix and/or apply scaling
1397 for (i = 1, c = &s->chset[1]; i < s->nchsets; i++, c++) {
1398 if (!is_hier_dmix_chset(c))
1399 continue;
1400
1401 if (i >= s->nactivechsets) {
1402 for (j = 0; j < c->nfreqbands; j++)
1403 if (c->bands[j].dmix_embedded)
1404 scale_down_mix(s, c, j);
1405 break;
1406 }
1407
1408 for (j = 0; j < c->nfreqbands; j++)
1409 if (c->bands[j].dmix_embedded)
1410 undo_down_mix(s, c, j);
1411 }
1412
1413 // Assemble frequency bands for active channel sets
1414 if (s->nfreqbands > 1) {
1415 for (i = 0; i < s->nactivechsets; i++)
1416 if ((ret = chs_assemble_freq_bands(s, &s->chset[i])) < 0)
1417 return ret;
1418 }
1419
1420 // Normalize to regular 5.1 layout if downmixing
1421 if (dca->request_channel_layout) {
1422 if (s->output_mask & DCA_SPEAKER_MASK_Lss) {
1423 s->output_samples[DCA_SPEAKER_Ls] = s->output_samples[DCA_SPEAKER_Lss];
1424 s->output_mask = (s->output_mask & ~DCA_SPEAKER_MASK_Lss) | DCA_SPEAKER_MASK_Ls;
1425 }
1426 if (s->output_mask & DCA_SPEAKER_MASK_Rss) {
1427 s->output_samples[DCA_SPEAKER_Rs] = s->output_samples[DCA_SPEAKER_Rss];
1428 s->output_mask = (s->output_mask & ~DCA_SPEAKER_MASK_Rss) | DCA_SPEAKER_MASK_Rs;
1429 }
1430 }
1431
1432 // Handle downmixing to stereo request
1434 && DCA_HAS_STEREO(s->output_mask) && p->dmix_embedded
1435 && (p->dmix_type == DCA_DMIX_TYPE_LoRo ||
1436 p->dmix_type == DCA_DMIX_TYPE_LtRt))
1437 request_mask = DCA_SPEAKER_LAYOUT_STEREO;
1438 else
1439 request_mask = s->output_mask;
1440 if (!ff_dca_set_channel_layout(avctx, ch_remap, request_mask))
1441 return AVERROR(EINVAL);
1442
1443 avctx->sample_rate = p->freq << (s->nfreqbands - 1);
1444
1445 switch (p->storage_bit_res) {
1446 case 16:
1448 shift = 16 - p->pcm_bit_res;
1449 break;
1450 case 20:
1451 case 24:
1453 shift = 24 - p->pcm_bit_res;
1454 break;
1455 default:
1456 return AVERROR(EINVAL);
1457 }
1458
1459 if (s->x_imax_syncword_present) {
1461 } else if (s->x_syncword_present) {
1463 } else {
1465 }
1466
1467 avctx->bits_per_raw_sample = p->storage_bit_res;
1468 avctx->bit_rate = 0;
1469
1470 frame->nb_samples = nsamples = s->nframesamples << (s->nfreqbands - 1);
1471 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1472 return ret;
1473
1474 // Downmix primary channel set to stereo
1475 if (request_mask != s->output_mask) {
1476 ff_dca_downmix_to_stereo_fixed(s->dcadsp, s->output_samples,
1477 p->dmix_coeff, nsamples,
1478 s->output_mask);
1479 }
1480
1481 for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
1482 int32_t *samples = s->output_samples[ch_remap[i]];
1483 if (frame->format == AV_SAMPLE_FMT_S16P) {
1484 int16_t *plane = (int16_t *)frame->extended_data[i];
1485 for (k = 0; k < nsamples; k++)
1486 plane[k] = av_clip_int16(samples[k] * (SUINT)(1 << shift));
1487 } else {
1488 int32_t *plane = (int32_t *)frame->extended_data[i];
1489 for (k = 0; k < nsamples; k++)
1490 plane[k] = clip23(samples[k] * (SUINT)(1 << shift)) * (1 << 8);
1491 }
1492 }
1493
1494 if (!asset->one_to_one_map_ch_to_spkr) {
1496 matrix_encoding = AV_MATRIX_ENCODING_DOLBY;
1497 else if (asset->representation_type == DCA_REPR_TYPE_LhRh)
1498 matrix_encoding = AV_MATRIX_ENCODING_DOLBYHEADPHONE;
1499 } else if (request_mask != s->output_mask && p->dmix_type == DCA_DMIX_TYPE_LtRt) {
1500 matrix_encoding = AV_MATRIX_ENCODING_DOLBY;
1501 }
1502
1503 // TODO: Support downmix when the primary channel set lacks coeffs.
1504 if (p->ch_mask == s->output_mask && !dca->request_channel_layout &&
1505 p->dmix_embedded && (p->dmix_type == DCA_DMIX_TYPE_LoRo ||
1506 p->dmix_type == DCA_DMIX_TYPE_LtRt)) {
1507 ret = ff_dca_export_downmix_matrix(avctx, frame, p->dmix_type, s->output_mask,
1508 p->dmix_coeff);
1509 if (ret < 0)
1510 return ret;
1511 }
1512
1513 if ((ret = ff_side_data_update_matrix_encoding(frame, matrix_encoding)) < 0)
1514 return ret;
1515
1516 return 0;
1517}
1518
1523
1525{
1526 DCAXllChSet *c;
1527 int i, j;
1528
1529 for (i = 0, c = s->chset; i < DCA_XLL_CHSETS_MAX; i++, c++) {
1530 for (j = 0; j < DCA_XLL_SAMPLE_BUFFERS_MAX; j++) {
1531 av_freep(&c->sample_buffer[j]);
1532 c->sample_size[j] = 0;
1533 }
1534 }
1535
1536 av_freep(&s->navi);
1537 s->navi_size = 0;
1538
1539 av_freep(&s->pbr_buffer);
1540 clear_pbr(s);
1541}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
int32_t
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
#define av_popcount
Definition common.h:154
#define av_clip_int16
Definition common.h:115
#define av_ceil_log2
Definition common.h:97
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
const uint32_t ff_dca_sampling_freqs[16]
Definition dca.c:36
@ DCA_SPEAKER_L
Definition dca.h:78
@ DCA_SPEAKER_Rs
Definition dca.h:79
@ DCA_SPEAKER_COUNT
Definition dca.h:87
@ DCA_SPEAKER_Lss
Definition dca.h:80
@ DCA_SPEAKER_Rss
Definition dca.h:80
@ DCA_SPEAKER_Ls
Definition dca.h:78
@ DCA_SPEAKER_R
Definition dca.h:78
#define DCA_SPEAKER_LAYOUT_5POINT0
Definition dca.h:128
@ DCA_DMIX_TYPE_COUNT
Definition dca.h:194
@ DCA_DMIX_TYPE_LoRo
Definition dca.h:187
@ DCA_DMIX_TYPE_LtRt
Definition dca.h:188
#define DCA_SPEAKER_LAYOUT_STEREO
Definition dca.h:122
#define DCA_HAS_STEREO(mask)
Definition dca.h:133
@ DCA_REPR_TYPE_LtRt
Definition dca.h:164
@ DCA_REPR_TYPE_LhRh
Definition dca.h:165
#define DCA_SPEAKER_LAYOUT_5POINT1
Definition dca.h:129
@ DCA_SPEAKER_MASK_Ls
Definition dca.h:94
@ DCA_SPEAKER_MASK_Rs
Definition dca.h:95
@ DCA_SPEAKER_MASK_Rss
Definition dca.h:101
@ DCA_SPEAKER_MASK_Lss
Definition dca.h:100
static int ff_dca_core_map_spkr(DCACoreDecoder *core, int spkr)
Definition dca_core.h:215
#define DCA_SYNCWORD_XLL_X_IMAX
#define DCA_SYNCWORD_XLL
#define DCA_SYNCWORD_XLL_X
static int combine_residual_frame(DCAXllDecoder *s, DCAXllChSet *c)
Definition dca_xll.c:1284
static int get_rice(GetBitContext *gb, int k)
Definition dca_xll.c:43
static int parse_navi_table(DCAXllDecoder *s)
Definition dca_xll.c:963
int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame)
Definition dca_xll.c:1352
static int parse_sub_headers(DCAXllDecoder *s, DCAExssAsset *asset)
Definition dca_xll.c:915
static void prescale_down_mix(DCAXllChSet *c, DCAXllChSet *o)
Definition dca_xll.c:899
static int get_rice_array(GetBitContext *gb, int32_t *array, int size, int k)
Definition dca_xll.c:67
int ff_dca_xll_parse(DCAXllDecoder *s, const uint8_t *data, DCAExssAsset *asset)
Definition dca_xll.c:1191
static void chs_filter_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band)
Definition dca_xll.c:639
static int chs_assemble_freq_bands(DCAXllDecoder *s, DCAXllChSet *c)
Definition dca_xll.c:741
static DCAXllChSet * find_next_hier_dmix_chset(DCAXllDecoder *s, DCAXllChSet *c)
Definition dca_xll.c:889
static int parse_frame_no_pbr(DCAXllDecoder *s, const uint8_t *data, int size, DCAExssAsset *asset)
Definition dca_xll.c:1111
static int parse_frame_pbr(DCAXllDecoder *s, const uint8_t *data, int size, DCAExssAsset *asset)
Definition dca_xll.c:1149
static int parse_dmix_coeffs(DCAXllDecoder *s, DCAXllChSet *c)
Definition dca_xll.c:79
static int chs_parse_header(DCAXllDecoder *s, DCAXllChSet *c, DCAExssAsset *asset)
Definition dca_xll.c:124
static void clear_pbr(DCAXllDecoder *s)
Definition dca_xll.c:1090
static int chs_alloc_msb_band_data(DCAXllDecoder *s, DCAXllChSet *c)
Definition dca_xll.c:394
static int get_linear(GetBitContext *gb, int n)
Definition dca_xll.c:31
static int get_rice_un(GetBitContext *gb, int k)
Definition dca_xll.c:37
av_cold void ff_dca_xll_flush(DCAXllDecoder *s)
Definition dca_xll.c:1519
static int copy_to_pbr(DCAXllDecoder *s, const uint8_t *data, int size, int delay)
Definition dca_xll.c:1096
static void get_linear_array(GetBitContext *gb, int32_t *array, int size, int n)
Definition dca_xll.c:57
static av_cold void chs_clear_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band, int seg)
Definition dca_xll.c:611
static int chs_get_lsb_width(DCAXllDecoder *s, DCAXllChSet *c, int band, int ch)
Definition dca_xll.c:704
static void scale_down_mix(DCAXllDecoder *s, DCAXllChSet *o, int band)
Definition dca_xll.c:1239
static void get_array(GetBitContext *gb, int32_t *array, int size, int n)
Definition dca_xll.c:49
static void undo_down_mix(DCAXllDecoder *s, DCAXllChSet *o, int band)
Definition dca_xll.c:1208
static int parse_common_header(DCAXllDecoder *s)
Definition dca_xll.c:777
static av_cold void force_lossy_output(DCAXllDecoder *s, DCAXllChSet *c)
Definition dca_xll.c:1267
static void chs_assemble_msbs_lsbs(DCAXllDecoder *s, DCAXllChSet *c, int band)
Definition dca_xll.c:719
static int parse_frame(DCAXllDecoder *s, const uint8_t *data, int size, DCAExssAsset *asset)
Definition dca_xll.c:1053
static int is_hier_dmix_chset(DCAXllChSet *c)
Definition dca_xll.c:884
static int chs_alloc_lsb_band_data(DCAXllDecoder *s, DCAXllChSet *c)
Definition dca_xll.c:417
static int parse_band_data(DCAXllDecoder *s)
Definition dca_xll.c:1014
av_cold void ff_dca_xll_close(DCAXllDecoder *s)
Definition dca_xll.c:1524
static int chs_parse_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band, int seg, int band_data_end)
Definition dca_xll.c:450
#define DCA_XLL_CHANNELS_MAX
Definition dca_xll.h:33
#define DCA_XLL_DECI_HISTORY_MAX
Definition dca_xll.h:36
#define DCA_XLL_CHSETS_MAX
Definition dca_xll.h:32
#define DCA_XLL_SAMPLE_BUFFERS_MAX
Definition dca_xll.h:40
#define DCA_XLL_PBR_BUFFER_MAX
Definition dca_xll.h:39
#define DCA_XLL_ADAPT_PRED_ORDER_MAX
Definition dca_xll.h:35
const uint16_t ff_dca_dmixtable[FF_DCA_DMIXTABLE_SIZE]
Definition dcadata.c:8642
const uint16_t ff_dca_xll_refl_coeff[128]
Definition dcadata.c:8705
const int32_t ff_dca_xll_band_coeff[20]
Definition dcadata.c:8724
const uint8_t ff_dca_dmix_primary_nch[8]
Definition dcadata.c:45
const uint32_t ff_dca_inv_dmixtable[FF_DCA_INV_DMIXTABLE_SIZE]
Definition dcadata.c:8676
#define FF_DCA_INV_DMIXTABLE_SIZE
Definition dcadata.h:70
#define FF_DCA_DMIXTABLE_SIZE
Definition dcadata.h:69
#define FF_DCA_DMIXTABLE_OFFSET
Definition dcadata.h:71
int ff_dca_export_downmix_matrix(AVCodecContext *avctx, AVFrame *frame, enum DCADownMixType downmix_type, int output_mask, const int *coeff_l)
Definition dcadec.c:162
int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask)
Definition dcadec.c:48
void ff_dca_downmix_to_stereo_fixed(DCADSPContext *dcadsp, int32_t **samples, int *coeff_l, int nsamples, int ch_mask)
Definition dcadec.c:97
#define DCA_PACKET_CORE
Definition dcadec.h:39
#define DCA_PACKET_RECOVERY
Sync error recovery flag.
Definition dcadec.h:45
static int ff_dca_check_crc(AVCodecContext *avctx, GetBitContext *s, int p1, int p2)
Definition dcadec.h:87
static int ff_dca_seek_bits(GetBitContext *s, int p)
Definition dcadec.h:101
static int32_t mul16(int32_t a, int32_t b)
Definition dcamath.h:47
static int32_t norm16(int64_t a)
Definition dcamath.h:41
static int32_t clip23(int32_t a)
Definition dcamath.h:54
static int32_t mul15(int32_t a, int32_t b)
Definition dcamath.h:46
#define SUINT
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1777
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
Definition utils.c:121
#define AV_PROFILE_DTS_HD_MA
Definition defs.h:91
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition defs.h:51
#define AV_PROFILE_DTS_HD_MA_X
Definition defs.h:93
#define AV_PROFILE_DTS_HD_MA_X_IMAX
Definition defs.h:94
static AVFrame * frame
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition get_bits.h:474
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition get_bits.h:498
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition get_bits.h:424
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition get_bits.h:280
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static int get_bits_count(const GetBitContext *s)
Definition get_bits.h:254
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
#define fail
Definition test.h:479
AVMatrixEncoding
@ AV_MATRIX_ENCODING_NONE
@ AV_MATRIX_ENCODING_DOLBY
@ AV_MATRIX_ENCODING_DOLBYHEADPHONE
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition mem.c:555
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition samplefmt.h:64
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition samplefmt.h:65
int index
Definition gxfenc.c:90
#define b
Definition input.c:43
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition intra.c:278
unsigned offset
Definition libaomenc.c:763
static int shift(int a, int b)
Definition bonk.c:261
#define av_cold
Definition attributes.h:117
static av_always_inline av_const double round(double x)
Definition libm.h:446
#define FFALIGN(x, a)
Definition macros.h:78
Memory handling functions.
const char data[16]
Definition mxf.c:149
#define av_malloc(s)
Definition ops_static.c:52
const uint8_t * code
Definition spdifenc.c:433
int nb_channels
Number of channels in this layout.
main external API structure.
Definition avcodec.h:443
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1055
enum AVSampleFormat sample_fmt
audio sample format
Definition avcodec.h:1047
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
int profile
profile
Definition avcodec.h:1636
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1571
int sample_rate
samples per second
Definition avcodec.h:1040
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
DCACoreDecoder core
Core decoder context.
Definition dcadec.h:57
DCAExssParser exss
EXSS parser context.
Definition dcadec.h:58
int packet
Packet flags.
Definition dcadec.h:69
int request_channel_layout
Converted from avctx.request_channel_layout.
Definition dcadec.h:71
int npcmsamples
Number of PCM samples per channel.
Definition dca_core.h:209
int output_rate
Output sample rate (1x or 2x header rate)
Definition dca_core.h:210
int32_t * output_samples[DCA_SPEAKER_COUNT]
PCM output for fixed point mode.
Definition dca_core.h:202
int xll_offset
Offset to XLL data from start of substream.
Definition dca_exss.h:62
int hd_stream_id
DTS-HD stream ID.
Definition dca_exss.h:68
int xll_sync_present
XLL sync word present flag.
Definition dca_exss.h:64
int xll_size
Size of XLL data in extension substream.
Definition dca_exss.h:63
int xll_delay_nframes
Initial XLL decoding delay in frames.
Definition dca_exss.h:65
int representation_type
Representation type.
Definition dca_exss.h:42
int xll_sync_offset
Number of bytes offset to XLL sync.
Definition dca_exss.h:66
int one_to_one_map_ch_to_spkr
One to one channel to speaker mapping flag.
Definition dca_exss.h:37
DCAExssAsset assets[1]
Audio asset descriptors.
Definition dca_exss.h:87
int32_t * msb_sample_buffer[DCA_XLL_CHANNELS_MAX]
MSB sample buffer pointers.
Definition dca_xll.h:58
int32_t deci_history[DCA_XLL_CHANNELS_MAX][DCA_XLL_DECI_HISTORY_MAX]
Decimator history for frequency band 1.
Definition dca_xll.h:96
int nchannels
Number of channels in the channel set (N)
Definition dca_xll.h:64
DCAXllBand bands[DCA_XLL_BANDS_MAX]
Frequency bands.
Definition dca_xll.h:85
int dmix_scale[DCA_XLL_DMIX_SCALES_MAX]
Downmixing scales.
Definition dca_xll.h:77
int dmix_coeff[DCA_XLL_DMIX_COEFFS_MAX]
Downmixing coefficients.
Definition dca_xll.h:76
int dmix_scale_inv[DCA_XLL_DMIX_SCALES_MAX]
Inverse downmixing scales.
Definition dca_xll.h:78
int hier_ofs
Number of preceding channels in a hierarchy (M)
Definition dca_xll.h:75
#define avpriv_request_sample(...)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define src
Definition vp8dsp.c:248
static int array[MAX_W *MAX_W]
int size
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition unary.h:46
static const double coeff[2][5]
static double c[64]