#define MAX_ORDER 16
typedef struct TTAFilter {
- int32_t shift, round, error, mode;
+ int32_t shift, round, error;
int32_t qm[MAX_ORDER];
int32_t dx[MAX_ORDER];
int32_t dl[MAX_ORDER];
GetBitContext gb;
const AVCRC *crc_table;
- int format, channels, bps, data_length;
+ int format, channels, bps;
+ unsigned data_length;
int frame_length, last_frame_length, total_frames;
int32_t *decode_buffer;
static const uint32_t * const shift_16 = shift_1 + 4;
-static const int32_t ttafilter_configs[4][2] = {
- {10, 1},
- {9, 1},
- {10, 1},
- {12, 0}
+static const int32_t ttafilter_configs[4] = {
+ 10,
+ 9,
+ 10,
+ 12
};
-static void ttafilter_init(TTAFilter *c, int32_t shift, int32_t mode) {
+static void ttafilter_init(TTAFilter *c, int32_t shift) {
memset(c, 0, sizeof(TTAFilter));
c->shift = shift;
c->round = shift_1[shift-1];
// c->round = 1 << (shift - 1);
- c->mode = mode;
}
// FIXME: copy paste from original
*a = *b;
}
-// FIXME: copy paste from original
-// mode=1 encoder, mode=0 decoder
-static inline void ttafilter_process(TTAFilter *c, int32_t *in, int32_t mode) {
+static inline void ttafilter_process(TTAFilter *c, int32_t *in)
+{
register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round;
if (!c->error) {
*(dx-2) = ((*(dl-3) >> 30) | 1) << 1;
*(dx-3) = ((*(dl-4) >> 30) | 1);
- // compress
- if (mode) {
- *dl = *in;
- *in -= (sum >> c->shift);
- c->error = *in;
- } else {
- c->error = *in;
- *in += (sum >> c->shift);
- *dl = *in;
- }
+ c->error = *in;
+ *in += (sum >> c->shift);
+ *dl = *in;
- if (c->mode) {
- *(dl-1) = *dl - *(dl-1);
- *(dl-2) = *(dl-1) - *(dl-2);
- *(dl-3) = *(dl-2) - *(dl-3);
- }
+ *(dl-1) = *dl - *(dl-1);
+ *(dl-2) = *(dl-1) - *(dl-2);
+ *(dl-3) = *(dl-2) - *(dl-3);
memshl(c->dl, c->dl + 1);
memshl(c->dx, c->dx + 1);
{
if (avctx->err_recognition & AV_EF_CRCCHECK) {
s->crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
- if (tta_check_crc(s, avctx->extradata, 18))
- return AVERROR_INVALIDDATA;
+ tta_check_crc(s, avctx->extradata, 18);
}
/* signature */
}
// prevent overflow
- if (avctx->sample_rate > 0x7FFFFF) {
+ if (avctx->sample_rate > 0x7FFFFFu) {
av_log(avctx, AV_LOG_ERROR, "sample_rate too large\n");
return AVERROR(EINVAL);
}
s->data_length, s->frame_length, s->last_frame_length, s->total_frames);
// FIXME: seek table
- if (get_bits_left(&s->gb) < 32 * s->total_frames + 32)
+ if (avctx->extradata_size <= 26 || s->total_frames > INT_MAX / 4 ||
+ avctx->extradata_size - 26 < s->total_frames * 4)
av_log(avctx, AV_LOG_WARNING, "Seek table missing or too small\n");
else if (avctx->err_recognition & AV_EF_CRCCHECK) {
if (tta_check_crc(s, avctx->extradata + 22, s->total_frames * 4))
// init per channel states
for (i = 0; i < s->channels; i++) {
s->ch_ctx[i].predictor = 0;
- ttafilter_init(&s->ch_ctx[i].filter, ttafilter_configs[s->bps-1][0], ttafilter_configs[s->bps-1][1]);
+ ttafilter_init(&s->ch_ctx[i].filter, ttafilter_configs[s->bps-1]);
rice_init(&s->ch_ctx[i].rice, 10, 10);
}
}
// extract coded value
-#define UNFOLD(x) (((x)&1) ? (++(x)>>1) : (-(x)>>1))
- *p = UNFOLD(value);
+ *p = 1 + ((value >> 1) ^ ((value & 1) - 1));
// run hybrid filter
- ttafilter_process(filter, p, 0);
+ ttafilter_process(filter, p);
// fixed order prediction
#define PRED(x, k) (int32_t)((((uint64_t)x << k) - x) >> k)
switch (s->bps) {
- case 1: *p += PRED(*predictor, 4); break;
- case 2:
- case 3: *p += PRED(*predictor, 5); break;
- case 4: *p += *predictor; break;
+ case 1: *p += PRED(*predictor, 4); break;
+ case 2:
+ case 3: *p += PRED(*predictor, 5); break;
+ case 4: *p += *predictor; break;
}
*predictor = *p;
if (cur_chan < (s->channels-1))
cur_chan++;
else {
- // decorrelate in case of stereo integer
+ // decorrelate in case of multiple channels
if (s->channels > 1) {
int32_t *r = p - 1;
for (*p += *r / 2; r > p - s->channels; r--)
AVCodec ff_tta_decoder = {
.name = "tta",
.type = AVMEDIA_TYPE_AUDIO,
- .id = CODEC_ID_TTA,
+ .id = AV_CODEC_ID_TTA,
.priv_data_size = sizeof(TTAContext),
.init = tta_decode_init,
.close = tta_decode_close,
.decode = tta_decode_frame,
.capabilities = CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("True Audio (TTA)"),
+ .long_name = NULL_IF_CONFIG_SMALL("TTA (True Audio)"),
};