| @@ -29,6 +29,7 @@ · 28 unmodified lines |
| 29 | | 29 | |
| 30 | #define BITSTREAM_READER_LE | 30 | #define BITSTREAM_READER_LE |
| 31 | #include <limits.h> | 31 | #include <limits.h> |
| | 32 | #include "ttadata.h" |
| 32 | #include "avcodec.h" | 33 | #include "avcodec.h" |
| 33 | #include "get_bits.h" | 34 | #include "get_bits.h" |
| 34 | #include "unary.h" | 35 | #include "unary.h" |
| @@ -40,24 +41,6 @@ · 5 unmodified lines |
| 40 | #define FORMAT_SIMPLE 1 | 41 | #define FORMAT_SIMPLE 1 |
| 41 | #define FORMAT_ENCRYPTED 2 | 42 | #define FORMAT_ENCRYPTED 2 |
| 42 | | 43 | |
| 43 | #define MAX_ORDER 16 | | |
| 44 | typedef struct TTAFilter { | | |
| 45 | int32_t shift, round, error; | | |
| 46 | int32_t qm[MAX_ORDER]; | | |
| 47 | int32_t dx[MAX_ORDER]; | | |
| 48 | int32_t dl[MAX_ORDER]; | | |
| 49 | } TTAFilter; | | |
| 50 | | | |
| 51 | typedef struct TTARice { | | |
| 52 | uint32_t k0, k1, sum0, sum1; | | |
| 53 | } TTARice; | | |
| 54 | | | |
| 55 | typedef struct TTAChannel { | | |
| 56 | int32_t predictor; | | |
| 57 | TTAFilter filter; | | |
| 58 | TTARice rice; | | |
| 59 | } TTAChannel; | | |
| 60 | | | |
| 61 | typedef struct TTAContext { | 44 | typedef struct TTAContext { |
| 62 | AVClass *class; | 45 | AVClass *class; |
| 63 | AVCodecContext *avctx; | 46 | AVCodecContext *avctx; |
| @@ -75,40 +58,6 @@ typedef struct TTAContext { · 11 unmodified lines |
| 75 | TTAChannel *ch_ctx; | 58 | TTAChannel *ch_ctx; |
| 76 | } TTAContext; | 59 | } TTAContext; |
| 77 | | 60 | |
| 78 | static const uint32_t shift_1[] = { | | |
| 79 | 0x00000001, 0x00000002, 0x00000004, 0x00000008, | | |
| 80 | 0x00000010, 0x00000020, 0x00000040, 0x00000080, | | |
| 81 | 0x00000100, 0x00000200, 0x00000400, 0x00000800, | | |
| 82 | 0x00001000, 0x00002000, 0x00004000, 0x00008000, | | |
| 83 | 0x00010000, 0x00020000, 0x00040000, 0x00080000, | | |
| 84 | 0x00100000, 0x00200000, 0x00400000, 0x00800000, | | |
| 85 | 0x01000000, 0x02000000, 0x04000000, 0x08000000, | | |
| 86 | 0x10000000, 0x20000000, 0x40000000, 0x80000000, | | |
| 87 | 0x80000000, 0x80000000, 0x80000000, 0x80000000, | | |
| 88 | 0x80000000, 0x80000000, 0x80000000, 0x80000000 | | |
| 89 | }; | | |
| 90 | | | |
| 91 | static const uint32_t * const shift_16 = shift_1 + 4; | | |
| 92 | | | |
| 93 | static const int32_t ttafilter_configs[4] = { | | |
| 94 | 10, | | |
| 95 | 9, | | |
| 96 | 10, | | |
| 97 | 12 | | |
| 98 | }; | | |
| 99 | | | |
| 100 | static void ttafilter_init(TTAContext *s, TTAFilter *c, int32_t shift) { | | |
| 101 | memset(c, 0, sizeof(TTAFilter)); | | |
| 102 | if (s->format == FORMAT_ENCRYPTED) { | | |
| 103 | int i; | | |
| 104 | for (i = 0; i < 8; i++) | | |
| 105 | c->qm[i] = sign_extend(s->crc_pass[i], 8); | | |
| 106 | } | | |
| 107 | c->shift = shift; | | |
| 108 | c->round = shift_1[shift-1]; | | |
| 109 | // c->round = 1 << (shift - 1); | | |
| 110 | } | | |
| 111 | | | |
| 112 | static inline void ttafilter_process(TTAFilter *c, int32_t *in) | 61 | static inline void ttafilter_process(TTAFilter *c, int32_t *in) |
| 113 | { | 62 | { |
| 114 | register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round; | 63 | register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round; |
| @@ -140,14 +89,6 @@ static inline void ttafilter_process(TTAFilter *c, int32_t *in) · 25 unmodified lines |
| 140 | dl[5] += dl[6]; dl[4] += dl[5]; | 89 | dl[5] += dl[6]; dl[4] += dl[5]; |
| 141 | } | 90 | } |
| 142 | | 91 | |
| 143 | static void rice_init(TTARice *c, uint32_t k0, uint32_t k1) | | |
| 144 | { | | |
| 145 | c->k0 = k0; | | |
| 146 | c->k1 = k1; | | |
| 147 | c->sum0 = shift_16[k0]; | | |
| 148 | c->sum1 = shift_16[k1]; | | |
| 149 | } | | |
| 150 | | | |
| 151 | static const int64_t tta_channel_layouts[7] = { | 92 | static const int64_t tta_channel_layouts[7] = { |
| 152 | AV_CH_LAYOUT_STEREO, | 93 | AV_CH_LAYOUT_STEREO, |
| 153 | AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, | 94 | AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, |
| @@ -319,9 +260,15 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, · 165 unmodified lines |
| 319 | | 260 | |
| 320 | // init per channel states | 261 | // init per channel states |
| 321 | for (i = 0; i < s->channels; i++) { | 262 | for (i = 0; i < s->channels; i++) { |
| | 263 | TTAFilter *filter = &s->ch_ctx[i].filter; |
| 322 | s->ch_ctx[i].predictor = 0; | 264 | s->ch_ctx[i].predictor = 0; |
| 323 | ttafilter_init(s, &s->ch_ctx[i].filter, ttafilter_configs[s->bps-1]); | 265 | ff_tta_filter_init(filter, ff_tta_filter_configs[s->bps-1]); |
| 324 | rice_init(&s->ch_ctx[i].rice, 10, 10); | 266 | if (s->format == FORMAT_ENCRYPTED) { |
| | 267 | int i; |
| | 268 | for (i = 0; i < 8; i++) |
| | 269 | filter->qm[i] = sign_extend(s->crc_pass[i], 8); |
| | 270 | } |
| | 271 | ff_tta_rice_init(&s->ch_ctx[i].rice, 10, 10); |
| 325 | } | 272 | } |
| 326 | | 273 | |
| 327 | i = 0; | 274 | i = 0; |
| @@ -361,16 +308,16 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, · 33 unmodified lines |
| 361 | switch (depth) { | 308 | switch (depth) { |
| 362 | case 1: | 309 | case 1: |
| 363 | rice->sum1 += value - (rice->sum1 >> 4); | 310 | rice->sum1 += value - (rice->sum1 >> 4); |
| 364 | if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1]) | 311 | if (rice->k1 > 0 && rice->sum1 < ff_tta_shift_16[rice->k1]) |
| 365 | rice->k1--; | 312 | rice->k1--; |
| 366 | else if(rice->sum1 > shift_16[rice->k1 + 1]) | 313 | else if(rice->sum1 > ff_tta_shift_16[rice->k1 + 1]) |
| 367 | rice->k1++; | 314 | rice->k1++; |
| 368 | value += shift_1[rice->k0]; | 315 | value += ff_tta_shift_1[rice->k0]; |
| 369 | default: | 316 | default: |
| 370 | rice->sum0 += value - (rice->sum0 >> 4); | 317 | rice->sum0 += value - (rice->sum0 >> 4); |
| 371 | if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0]) | 318 | if (rice->k0 > 0 && rice->sum0 < ff_tta_shift_16[rice->k0]) |
| 372 | rice->k0--; | 319 | rice->k0--; |
| 373 | else if(rice->sum0 > shift_16[rice->k0 + 1]) | 320 | else if(rice->sum0 > ff_tta_shift_16[rice->k0 + 1]) |
| 374 | rice->k0++; | 321 | rice->k0++; |
| 375 | } | 322 | } |
| 376 | | 323 | |