32 #define BITSTREAM_READER_LE
41 #define MAX_SUBFRAMES 8
42 #define MAX_PREDICTORS 256
83 4, 8, 12, 16, 24, 32, 48, 64, 80, 96, 128, 160, 192, 224, 256, 0,
93 { 0x01, 0x0000001, 0x0000001, 0x0000003, 0x0000008 },
94 { 0x02, 0x0000003, 0x0000001, 0x0000007, 0x0000006 },
95 { 0x03, 0x0000005, 0x0000002, 0x000000E, 0x000000D },
96 { 0x03, 0x0000003, 0x0000003, 0x000000D, 0x0000018 },
97 { 0x04, 0x000000B, 0x0000004, 0x000001C, 0x0000019 },
98 { 0x04, 0x0000006, 0x0000006, 0x000001A, 0x0000030 },
99 { 0x05, 0x0000016, 0x0000008, 0x0000038, 0x0000032 },
100 { 0x05, 0x000000C, 0x000000C, 0x0000034, 0x0000060 },
101 { 0x06, 0x000002C, 0x0000010, 0x0000070, 0x0000064 },
102 { 0x06, 0x0000018, 0x0000018, 0x0000068, 0x00000C0 },
103 { 0x07, 0x0000058, 0x0000020, 0x00000E0, 0x00000C8 },
104 { 0x07, 0x0000030, 0x0000030, 0x00000D0, 0x0000180 },
105 { 0x08, 0x00000B0, 0x0000040, 0x00001C0, 0x0000190 },
106 { 0x08, 0x0000060, 0x0000060, 0x00001A0, 0x0000300 },
107 { 0x09, 0x0000160, 0x0000080, 0x0000380, 0x0000320 },
108 { 0x09, 0x00000C0, 0x00000C0, 0x0000340, 0x0000600 },
109 { 0x0A, 0x00002C0, 0x0000100, 0x0000700, 0x0000640 },
110 { 0x0A, 0x0000180, 0x0000180, 0x0000680, 0x0000C00 },
111 { 0x0B, 0x0000580, 0x0000200, 0x0000E00, 0x0000C80 },
112 { 0x0B, 0x0000300, 0x0000300, 0x0000D00, 0x0001800 },
113 { 0x0C, 0x0000B00, 0x0000400, 0x0001C00, 0x0001900 },
114 { 0x0C, 0x0000600, 0x0000600, 0x0001A00, 0x0003000 },
115 { 0x0D, 0x0001600, 0x0000800, 0x0003800, 0x0003200 },
116 { 0x0D, 0x0000C00, 0x0000C00, 0x0003400, 0x0006000 },
117 { 0x0E, 0x0002C00, 0x0001000, 0x0007000, 0x0006400 },
118 { 0x0E, 0x0001800, 0x0001800, 0x0006800, 0x000C000 },
119 { 0x0F, 0x0005800, 0x0002000, 0x000E000, 0x000C800 },
120 { 0x0F, 0x0003000, 0x0003000, 0x000D000, 0x0018000 },
121 { 0x10, 0x000B000, 0x0004000, 0x001C000, 0x0019000 },
122 { 0x10, 0x0006000, 0x0006000, 0x001A000, 0x0030000 },
123 { 0x11, 0x0016000, 0x0008000, 0x0038000, 0x0032000 },
124 { 0x11, 0x000C000, 0x000C000, 0x0034000, 0x0060000 },
125 { 0x12, 0x002C000, 0x0010000, 0x0070000, 0x0064000 },
126 { 0x12, 0x0018000, 0x0018000, 0x0068000, 0x00C0000 },
127 { 0x13, 0x0058000, 0x0020000, 0x00E0000, 0x00C8000 },
128 { 0x13, 0x0030000, 0x0030000, 0x00D0000, 0x0180000 },
129 { 0x14, 0x00B0000, 0x0040000, 0x01C0000, 0x0190000 },
130 { 0x14, 0x0060000, 0x0060000, 0x01A0000, 0x0300000 },
131 { 0x15, 0x0160000, 0x0080000, 0x0380000, 0x0320000 },
132 { 0x15, 0x00C0000, 0x00C0000, 0x0340000, 0x0600000 },
133 { 0x16, 0x02C0000, 0x0100000, 0x0700000, 0x0640000 },
134 { 0x16, 0x0180000, 0x0180000, 0x0680000, 0x0C00000 },
135 { 0x17, 0x0580000, 0x0200000, 0x0E00000, 0x0C80000 },
136 { 0x17, 0x0300000, 0x0300000, 0x0D00000, 0x1800000 },
137 { 0x18, 0x0B00000, 0x0400000, 0x1C00000, 0x1900000 },
138 { 0x18, 0x0600000, 0x0600000, 0x1A00000, 0x3000000 },
139 { 0x19, 0x1600000, 0x0800000, 0x3800000, 0x3200000 },
140 { 0x19, 0x0C00000, 0x0C00000, 0x3400000, 0x6000000 },
141 { 0x1A, 0x2C00000, 0x1000000, 0x7000000, 0x6400000 },
142 { 0x1A, 0x1800000, 0x1800000, 0x6800000, 0xC000000 },
207 unsigned a1 = *coeffs++;
208 for (
i = 0;
i < length - 1 >> 1;
i++) {
210 coeffs[1] += (unsigned)*coeffs;
216 }
else if (
mode == 2) {
217 unsigned a1 = coeffs[1];
218 unsigned a2 =
a1 + *coeffs;
222 for (
i = 0;
i < length - 2 >> 1;
i++) {
223 unsigned a3 = *coeffs +
a1;
234 }
else if (
mode == 3) {
235 unsigned a1 = coeffs[1];
236 unsigned a2 =
a1 + *coeffs;
239 unsigned a3 = coeffs[2];
244 for (
i = 0;
i < length - 3;
i++) {
262 memset(decoded, 0,
len *
sizeof(*decoded));
270 for (
i = 0;
i <
len;
i++) {
274 if (x >=
code.aescape) {
278 if (scale_bits > 0) {
279 if (scale_bits == 7) {
293 decoded[
i] = (x >> 1) ^ -(x & 1);
304 if (length >
s->nb_samples)
310 wlength = length /
s->uval;
312 rval = length - (wlength *
s->uval);
314 if (rval < s->uval / 2)
319 if (wlength <= 1 || wlength > 128)
324 for (
i = 1;
i < wlength;
i++) {
336 mode += (-sign ^ (
c - 1)) + sign;
350 while (
i < wlength) {
355 if (
i >= wlength - 1)
363 }
while (
s->coding_mode[
i] ==
mode);
387 int subframe_size,
int prev_subframe_size)
390 int x, y,
i, j, ret = 0;
391 int dshift,
size, filter_quant, filter_order;
399 if (prev_subframe_size > 0 &&
get_bits1(gb)) {
400 if (filter_order > prev_subframe_size)
403 decoded -= filter_order;
404 subframe_size += filter_order;
406 if (filter_order > subframe_size)
411 if (filter_order > subframe_size)
430 filter_quant -=
get_bits(gb, 3) + 1;
431 if (filter_quant < 3)
442 if (filter_order > 4) {
445 for (
i = 4;
i < filter_order;
i++) {
452 tfilter[0] =
s->predictors[0] * 64;
453 for (
i = 1;
i < filter_order;
i++) {
454 uint32_t *p1 = &tfilter[0];
455 uint32_t *p2 = &tfilter[
i - 1];
457 for (j = 0; j < (
i + 1) / 2; j++) {
458 x = *p1 + ((
int32_t)(
s->predictors[
i] * *p2 + 256) >> 9);
459 *p2 += (
int32_t)(
s->predictors[
i] * *p1 + 256) >> 9;
464 tfilter[
i] =
s->predictors[
i] * 64;
467 x = 1 << (32 - (15 - filter_quant));
468 y = 1 << ((15 - filter_quant) - 1);
469 for (
i = 0, j = filter_order - 1;
i < filter_order / 2;
i++, j--) {
470 s->filter[j] = x - ((tfilter[
i] + y) >> (15 - filter_quant));
471 s->filter[
i] = x - ((tfilter[j] + y) >> (15 - filter_quant));
475 subframe_size - filter_order)) < 0)
478 for (
i = 0;
i < filter_order;
i++)
479 s->residues[
i] = *decoded++ >> dshift;
482 x = subframe_size - filter_order;
486 for (
i = 0;
i <
tmp;
i++) {
487 int v = 1 << (filter_quant - 1);
489 if (filter_order & -16)
490 v += (unsigned)
s->adsp.scalarproduct_int16(&
s->residues[
i],
s->filter,
492 for (j = filter_order & -16; j < filter_order; j += 4) {
493 v +=
s->residues[
i + j + 3] * (unsigned)
s->filter[j + 3] +
494 s->residues[
i + j + 2] * (
unsigned)
s->filter[j + 2] +
495 s->residues[
i + j + 1] * (unsigned)
s->filter[j + 1] +
496 s->residues[
i + j ] * (
unsigned)
s->filter[j ];
498 v = (
av_clip_intp2(v >> filter_quant, 13) * (1 << dshift)) - (unsigned)*decoded;
500 s->residues[filter_order +
i] = v >> dshift;
505 memcpy(
s->residues, &
s->residues[y], 2 * filter_order);
517 int32_t *decoded =
s->decoded[chan];
518 int left =
s->nb_samples - 1;
519 int i = 0, ret, prev = 0;
529 if (
s->nb_subframes > 1) {
533 for (;
i <
s->nb_subframes - 1;
i++) {
536 s->subframe_len[
i] = (v - prev) *
s->subframe_scale;
537 if (
s->subframe_len[
i] <= 0)
540 left -=
s->subframe_len[
i];
547 s->subframe_len[
i] = left;
550 for (
i = 0;
i <
s->nb_subframes;
i++) {
553 decoded +=
s->subframe_len[
i];
554 prev =
s->subframe_len[
i];
570 length +=
s->dmode < 6;
574 s->tdsp.decorrelate_ls(p1, p2, length);
577 s->tdsp.decorrelate_sr(p1, p2, length);
580 s->tdsp.decorrelate_sm(p1, p2, length);
588 s->tdsp.decorrelate_sf(p1, p2, length, dshift, dfactor);
593 int length2, order_half, filter_order, dval1, dval2;
594 int tmp, x, code_size;
604 for (
i = 0;
i < filter_order;
i++) {
610 order_half = filter_order / 2;
611 length2 = length - (filter_order - 1);
615 for (
i = 0;
i < order_half;
i++) {
624 for (
i = length2 + order_half;
i < length;
i++) {
632 for (
i = 0;
i < filter_order;
i++)
633 s->residues[
i] = *p2++ >> dshift;
637 for (; length2 > 0; length2 -=
tmp) {
640 for (
i = 0;
i <
tmp - (
tmp == length2);
i++)
641 s->residues[filter_order +
i] = *p2++ >> dshift;
646 if (filter_order == 16) {
647 v +=
s->adsp.scalarproduct_int16(&
s->residues[
i],
s->filter,
650 v +=
s->residues[
i + 7] *
s->filter[7] +
651 s->residues[
i + 6] *
s->filter[6] +
652 s->residues[
i + 5] *
s->filter[5] +
653 s->residues[
i + 4] *
s->filter[4] +
654 s->residues[
i + 3] *
s->filter[3] +
655 s->residues[
i + 2] *
s->filter[2] +
656 s->residues[
i + 1] *
s->filter[1] +
657 s->residues[
i ] *
s->filter[0];
664 memmove(
s->residues, &
s->residues[
tmp], 2 * filter_order);
672 if (
s->dmode > 0 &&
s->dmode < 6) {
687 int chan,
i, ret, hsize;
712 if (
s->ti.data_type) {
714 "unsupported data type: %d\n",
s->ti.data_type);
719 "invalid number of channels: %d\n",
s->ti.channels);
722 if (
s->ti.channels > 6) {
724 "unsupported number of channels: %d\n",
s->ti.channels);
728 if (
s->ti.frame_samples <= 0) {
744 s->nb_samples =
s->ti.last_frame_samples ?
s->ti.last_frame_samples
745 :
s->ti.frame_samples;
759 if (!
s->decode_buffer)
767 for (chan = 0; chan < avctx->
channels; chan++)
771 if (
s->nb_samples < 16) {
772 for (chan = 0; chan < avctx->
channels; chan++) {
773 int32_t *decoded =
s->decoded[chan];
774 for (
i = 0;
i <
s->nb_samples;
i++)
779 for (chan = 0; chan < avctx->
channels; chan++)
785 if (
s->nb_subframes > 1) {
801 for (
i = 0;
i < chan;
i++) {
807 if (ch_mask & 1 << nbit)
811 if (
s->mcdparams[
i].present) {
814 if (
s->mcdparams[
i].chan2 >= avctx->
channels) {
816 "invalid channel 2 (%d) for %d channel(s)\n",
820 if (
s->mcdparams[
i].index == 1) {
821 if ((nbit ==
s->mcdparams[
i].chan2) ||
822 (ch_mask & 1 <<
s->mcdparams[
i].chan2))
825 ch_mask |= 1 <<
s->mcdparams[
i].chan2;
826 }
else if (!(ch_mask & 1 <<
s->mcdparams[
i].chan2)) {
830 s->mcdparams[
i].chan1 = nbit;
832 ch_mask |= 1 << nbit;
836 for (
i = 0;
i < chan;
i++) {
837 s->mcdparams[
i].present = 0;
838 s->mcdparams[
i].chan1 =
i;
842 for (
i = 0;
i < chan;
i++) {
843 if (
s->mcdparams[
i].present &&
s->mcdparams[
i].index == 1)
850 if (
s->mcdparams[
i].present) {
853 s->mcdparams[
i].chan2,
854 s->mcdparams[
i].chan1,
861 for (chan = 0; chan < avctx->
channels; chan++) {
862 int32_t *decoded =
s->decoded[chan];
864 if (
s->lpc_mode[chan])
867 if (
s->sample_shift[chan] > 0)
868 for (
i = 0;
i <
s->nb_samples;
i++)
869 decoded[
i] *= 1U <<
s->sample_shift[chan];
892 for (chan = 0; chan < avctx->
channels; chan++) {
894 int32_t *decoded =
s->decoded[chan];
895 for (
i = 0;
i <
s->nb_samples;
i++)
896 samples[
i] = decoded[
i] + 0x80U;
900 for (chan = 0; chan < avctx->
channels; chan++) {
902 int32_t *decoded =
s->decoded[chan];
903 for (
i = 0;
i <
s->nb_samples;
i++)
904 samples[
i] = decoded[
i];
908 for (chan = 0; chan < avctx->
channels; chan++) {
910 for (
i = 0;
i <
s->nb_samples;
i++)
911 samples[
i] *= 1U << 8;
Libavcodec external API header.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define AV_EF_EXPLODE
abort decoding on minor error detection
static av_cold int init(AVCodecContext *avctx)
#define FFSWAP(type, a, b)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
mode
Use these values in ebur128_init (or'ed).
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_sbits(GetBitContext *s, int n)
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static const uint8_t * align_get_bits(GetBitContext *s)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
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.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
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 plane data pointers and linesize for samples with sample format sample_fmt.
av_cold void ff_audiodsp_init(AudioDSPContext *c)
static int get_bits_esc4(GetBitContext *gb)
static const uint16_t predictor_sizes[]
static int decode_channel(TAKDecContext *s, int chan)
static const int8_t mc_dmodes[]
static int decode_subframe(TAKDecContext *s, int32_t *decoded, int subframe_size, int prev_subframe_size)
static av_cold int tak_decode_close(AVCodecContext *avctx)
static const struct CParam xcodes[50]
static int decorrelate(TAKDecContext *s, int c1, int c2, int length)
static int decode_residues(TAKDecContext *s, int32_t *decoded, int length)
static void decode_lpc(int32_t *coeffs, int mode, int length)
static int decode_segment(TAKDecContext *s, int8_t mode, int32_t *decoded, int len)
#define MAX_SUBFRAMES
max number of subframes per channel
static av_cold int tak_decode_init(AVCodecContext *avctx)
static int set_bps_params(AVCodecContext *avctx)
static void set_sample_rate_params(AVCodecContext *avctx)
static int tak_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *pkt)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
#define FF_ARRAY_ELEMS(a)
static int shift(int a, int b)
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
int channels
number of audio channels
uint64_t channel_layout
Audio channel layout.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
int8_t index
index into array of decorrelation types
int8_t present
decorrelation parameter availability for this channel
int8_t dmode
channel decorrelation type in the current frame
int16_t filter[MAX_PREDICTORS]
int16_t subframe_len[MAX_SUBFRAMES]
subframe length in samples
int16_t predictors[MAX_PREDICTORS]
int8_t lpc_mode[TAK_MAX_CHANNELS]
GetBitContext gb
bitstream reader initialized to start at the current frame
int nb_subframes
number of subframes in the current frame
MCDParam mcdparams[TAK_MAX_CHANNELS]
multichannel decorrelation parameters
int32_t * decoded[TAK_MAX_CHANNELS]
decoded samples for each channel
unsigned int decode_buffer_size
int nb_samples
number of samples in the current frame
AVCodecContext * avctx
parent AVCodecContext
int8_t sample_shift[TAK_MAX_CHANNELS]
shift applied to every sample in the channel
int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, TAKStreamInfo *ti, int log_level_offset)
Validate and decode a frame header.
TAK (Tom's lossless Audio Kompressor) decoder/demuxer common functions.
#define TAK_MIN_FRAME_HEADER_BYTES
av_cold void ff_takdsp_init(TAKDSPContext *c)
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.