49 unsigned idx = code & 0xff;
53 "XLL: Invalid channel set downmix code %x\n", code);
55 }
else if (!inverse) {
57 }
else if (idx < inv_offset) {
59 "XLL: Invalid channel set inverse downmix code %x\n", code);
79 int hdr_pos, hdr_size;
106 "XLL: fixed lsb width = %d, non-zero not supported.\n",
111 if (hdr_pos + hdr_size * 8 > i)
114 for (chset_index = 0; chset_index < s->
xll_nch_sets; chset_index++) {
138 "XLL: Invalid channel set downmix type\n");
156 static const char dmix_table[7] = { 1, 2, 2, 3, 3, 4, 4 };
163 "XLL: More than %d downmix coefficients",
175 for (r = 1; r <= chset->
channels; r++) {
213 for (i = 0; i < chset->
channels; i++) {
217 "Original channel order value %u too large, only %d channels.\n",
224 for (i = 0; i < chset->
channels / 2; i++) {
231 for (i = 0; i < chset->
channels; i++)
239 for (i = 0; i < chset->
channels; i++) {
246 for (i = 0; i < chset->
channels; i++)
250 for (i = 0; i < chset->
channels; i++) {
259 for (i = 0; i < chset->
channels; i++)
261 for (i = 0; i < chset->
channels; i++)
278 if (hdr_pos + 8 * hdr_size < i) {
280 "chset header too large, %d bits, should be <= %d bits\n",
281 i - hdr_pos, 8 * hdr_size);
284 if (hdr_pos + 8 * hdr_size > i)
293 int nbands,
band, chset, seg, data_start;
298 for (band = 0; band < nbands; band++) {
308 if (band < s->xll_chsets[chset].num_freq_bands) {
323 "XLL: Data in NAVI table exceeds containing asset\n"
324 "start: %d (bit), size %u (bytes), end %d (bit), error %u\n",
335 const int *prev,
const uint8_t *q_ind)
337 static const uint16_t
table[0x81] = {
338 0, 3070, 5110, 7140, 9156, 11154, 13132, 15085,
339 17010, 18904, 20764, 22588, 24373, 26117, 27818, 29474,
340 31085, 32648, 34164, 35631, 37049, 38418, 39738, 41008,
341 42230, 43404, 44530, 45609, 46642, 47630, 48575, 49477,
342 50337, 51157, 51937, 52681, 53387, 54059, 54697, 55302,
343 55876, 56421, 56937, 57426, 57888, 58326, 58741, 59132,
344 59502, 59852, 60182, 60494, 60789, 61066, 61328, 61576,
345 61809, 62029, 62236, 62431, 62615, 62788, 62951, 63105,
346 63250, 63386, 63514, 63635, 63749, 63855, 63956, 64051,
347 64140, 64224, 64302, 64376, 64446, 64512, 64573, 64631,
348 64686, 64737, 64785, 64830, 64873, 64913, 64950, 64986,
349 65019, 65050, 65079, 65107, 65133, 65157, 65180, 65202,
350 65222, 65241, 65259, 65275, 65291, 65306, 65320, 65333,
351 65345, 65357, 65368, 65378, 65387, 65396, 65405, 65413,
352 65420, 65427, 65434, 65440, 65446, 65451, 65456, 65461,
353 65466, 65470, 65474, 65478, 65481, 65485, 65488, 65491,
360 for (i = 0; i < order; i++) {
364 c[i] = -table[(q_ind[i] >> 1) + 1];
366 c[i] = table[q_ind[i] >> 1];
371 for (i = 1; i < order; i++) {
378 c[i / 2] += ((int64_t) c[i] * c[i / 2] + 0x8000) >> 16;
379 for (j = 0; j < i / 2; j++) {
381 int r1 = c[i - j - 1];
382 c[j] += ((int64_t) c[i] * r1 + 0x8000) >> 16;
383 c[i - j - 1] += ((int64_t) c[i] * r0 + 0x8000) >> 16;
390 for (i = 0; i < order; i++) {
391 for (j = s = 0; j < i; j++)
392 s += (int64_t) c[j] * samples[i - 1 - j];
393 for (; j < order; j++)
396 samples[i] -= av_clip_intp2((s + 0x8000) >> 16, 24);
399 for (i = order; i < nsamples; i++) {
400 for (j = s = 0; j < order; j++)
401 s += (int64_t) c[j] * samples[i - 1 - j];
405 samples[i] -= av_clip_intp2((s + 0x8000) >> 16, 24);
415 struct coding_params {
417 int rice_code_flag[16];
441 for (chset_i = in_channel = 0; chset_i < s->
xll_nch_sets; chset_i++) {
446 struct coding_params *
params = ¶m_state[chset_i];
449 int use_seg_state_code_param;
457 "XLL: unexpected chset sample rate %d, expected %d\n",
462 use_seg_state_code_param =
get_bits(gb, 1);
464 use_seg_state_code_param = 0;
466 if (!use_seg_state_code_param) {
467 int num_param_sets, i;
471 num_param_sets = params->seg_type ? 1 : chset->
channels;
484 for (i = 0; i < num_param_sets; i++) {
485 params->rice_code_flag[i] =
get_bits(gb, 1);
486 if (!params->seg_type && params->rice_code_flag[i] &&
get_bits(gb, 1))
487 params->pancAuxABIT[i] =
get_bits(gb, bits4ABIT) + 1;
489 params->pancAuxABIT[i] = 0;
492 for (i = 0; i < num_param_sets; i++) {
495 params->pancABIT0[i] =
get_bits(gb, bits4ABIT);
496 if (params->rice_code_flag[i] == 0 && params->pancABIT0[i] > 0)
498 params->pancABIT0[i]++;
501 if (params->seg_type == 0)
506 params->nSamplPart0[i] = 0;
509 params->pancABIT[i] =
get_bits(gb, bits4ABIT);
510 if (params->rice_code_flag[i] == 0 && params->pancABIT[i] > 0)
512 params->pancABIT[i]++;
515 for (i = 0; i < chset->
channels; i++) {
516 int param_index = params->seg_type ? 0 : i;
517 int part0 = params->nSamplPart0[param_index];
518 int bits = part0 ? params->pancABIT0[param_index] : 0;
522 if (!params->rice_code_flag[param_index]) {
525 for (j = 0; j < part0; j++)
528 memset(sample_buf, 0, part0 *
sizeof(sample_buf[0]));
531 bits = params->pancABIT[param_index];
536 memset(sample_buf + part0, 0,
539 int aux_bits = params->pancAuxABIT[param_index];
541 for (j = 0; j < part0; j++) {
547 sample_buf[j] = (t & 1) ? -(t >> 1) - 1 : (t >> 1);
551 bits = params->pancABIT[param_index];
555 memset(sample_buf + part0, 0,
568 for (j = 0; j <
count; j++)
572 if (!sample_buf[j]) {
576 sample_buf[j] = (t & 1) ? -(t >> 1) - 1 : (t >> 1);
583 for (i = 0; i < chset->
channels; i++) {
591 for (order = chset->
fixed_order[0][i]; order > 0; order--) {
594 sample_buf[j] += sample_buf[j - 1];
599 adapt_order, seg ? prev :
NULL,
604 for (i = 1; i < chset->
channels; i += 2) {
613 sample_buf[j] += ((int64_t) coeff * prev[j] + 4) >> 3;
618 int lsb_start = end_pos - 8 * chset->
lsb_fsize[0] -
624 "chset data lsb exceeds NAVI size, end_pos %d, lsb_start %d, pos %d\n",
625 end_pos, lsb_start, i);
631 for (i = done = 0; i < chset->
channels; i++) {
641 int msb_shift = bits;
645 msb_shift += adj - 1;
648 sample_buf[j] = (sample_buf[j] << msb_shift) +
656 "chset lsb exceeds lsb_size\n");
662 for (i = 0; i < chset->
channels; i++) {
672 (chset->
ch_mask & 7) == 7 && out_channel < 3)
673 out_channel = out_channel ? out_channel - 1 : 2;
675 out_channel += in_channel;
698 unsigned mix_channel;
699 for (mix_channel = 0; mix_channel < in_channel; mix_channel++) {
706 (chset->
ch_mask & 7) == 7 && mix_channel < 3)
707 mix_buf = (
float *) frame->
extended_data[mix_channel ? mix_channel - 1 : 2];
715 coeff =
ldexpf(col[0], -16);
723 const float *new_channel =
726 coeff =
ldexpf(col[row + 1], -15);
728 mix_buf[j] -= coeff * new_channel[j];
739 "chset data exceeds NAVI size\n");
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
int ff_dca_xll_decode_header(DCAContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static void skip_bits_long(GetBitContext *s, int n)
static int32_t dca_get_dmix_coeff(DCAContext *s)
int xll_bits4ch_mask
channel position mask
static int get_bits_sm(GetBitContext *s, unsigned n)
#define DCA_XLL_DMIX_NCOEFFS_MAX
Macro definitions for various function/variable attributes.
int xll_channels
total number of channels (in all channel sets)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int xll_nch_sets
number of channel sets per frame
int xll_residual_channels
number of residual channels
unsigned int xll_sample_buf_size
int ff_dca_xll_decode_navi(DCAContext *s, int asset_end)
XllChSetSubHeader xll_chsets[DCA_XLL_CHSETS_MAX]
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
unsigned band_size[DCA_XLL_FBANDS_MAX]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void dca_xll_inv_adapt_pred(int *samples, int nsamples, unsigned order, const int *prev, const uint8_t *q_ind)
static const struct endianess table[]
const uint16_t ff_dca_dmixtable[FF_DCA_DMIXTABLE_SIZE]
int xll_log_smpl_in_seg
supposedly this is "nBits4SamplLoci"
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Libavcodec external API header.
common internal API header
static int32_t dca_get_inv_dmix_coeff(DCAContext *s)
int ff_dca_xll_decode_audio(DCAContext *s, AVFrame *frame)
unsigned chset_size[DCA_XLL_FBANDS_MAX][DCA_XLL_SEGMENTS_MAX][DCA_XLL_CHSETS_MAX]
const uint32_t ff_dca_inv_dmixtable[FF_DCA_INV_DMIXTABLE_SIZE]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int sample_rate
samples per second
#define FF_DCA_INV_DMIXTABLE_SIZE
int xll_bits4seg_size
number of bits used to read segment size
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int xll_segments
number of segments per frame
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
const int32_t ff_dca_sampling_freqs[16]
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int xll_banddata_crc
presence of CRC16 within each frequency band
static int32_t get_dmix_coeff(DCAContext *s, int inverse)
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
common internal and external API header
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
int xll_smpl_in_seg
samples in segment per one frequency band for the first channel set
#define FF_DCA_DMIXTABLE_SIZE
unsigned segment_size[DCA_XLL_FBANDS_MAX][DCA_XLL_SEGMENTS_MAX]
int channels
number of audio channels
static const double coeff[2][5]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
#define DCA_XLL_AORDER_MAX
uint8_t ** extended_data
pointers to the data planes/channels.