annotate tta.c @ 3346:052765f11f1c libavcodec

Cosmetics: should not hurt performance, scream if are
author lu_zero
date Sat, 17 Jun 2006 18:46:06 +0000
parents 68721b62a528
children 84c509024ee9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
1 /*
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
2 * TTA (The Lossless True Audio) decoder
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
3 * Copyright (c) 2006 Alex Beregszaszi
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
4 *
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
9 *
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
13 * Lesser General Public License for more details.
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
14 *
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
18 */
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
19
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
20 /**
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
21 * @file tta.c
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
22 * TTA (The Lossless True Audio) decoder
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
23 * (www.true-audio.com or tta.corecodec.org)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
24 * @author Alex Beregszaszi
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
25 *
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
26 */
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
27
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
28 #define ALT_BITSTREAM_READER_LE
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
29 //#define DEBUG
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
30 #include <limits.h>
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
31 #include "avcodec.h"
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
32 #include "bitstream.h"
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
33
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
34 #define FORMAT_INT 1
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
35 #define FORMAT_FLOAT 3
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
36
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
37 typedef struct TTAContext {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
38 AVCodecContext *avctx;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
39 GetBitContext gb;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
40
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
41 int flags, channels, bps, is_float, data_length;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
42 int frame_length, last_frame_length, total_frames;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
43
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
44 int32_t *decode_buffer;
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
45 } TTAContext;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
46
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
47 #if 0
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
48 static inline int shift_1(int i)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
49 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
50 if (i < 32)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
51 return 1 << i;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
52 else
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
53 return 0x80000000; // 16 << 31
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
54 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
55
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
56 static inline int shift_16(int i)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
57 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
58 if (i < 28)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
59 return 16 << i;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
60 else
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
61 return 0x80000000; // 16 << 27
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
62 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
63 #else
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
64 static const uint32_t shift_1[] = {
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
65 0x00000001, 0x00000002, 0x00000004, 0x00000008,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
66 0x00000010, 0x00000020, 0x00000040, 0x00000080,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
67 0x00000100, 0x00000200, 0x00000400, 0x00000800,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
68 0x00001000, 0x00002000, 0x00004000, 0x00008000,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
69 0x00010000, 0x00020000, 0x00040000, 0x00080000,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
70 0x00100000, 0x00200000, 0x00400000, 0x00800000,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
71 0x01000000, 0x02000000, 0x04000000, 0x08000000,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
72 0x10000000, 0x20000000, 0x40000000, 0x80000000,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
73 0x80000000, 0x80000000, 0x80000000, 0x80000000,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
74 0x80000000, 0x80000000, 0x80000000, 0x80000000
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
75 };
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
76
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
77 static const uint32_t *shift_16 = shift_1 + 4;
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
78 #endif
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
79
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
80 #define MAX_ORDER 16
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
81 typedef struct TTAFilter {
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
82 int32_t shift, round, error, mode;
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
83 int32_t qm[MAX_ORDER];
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
84 int32_t dx[MAX_ORDER];
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
85 int32_t dl[MAX_ORDER];
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
86 } TTAFilter;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
87
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
88 static int32_t ttafilter_configs[4][2] = {
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
89 {10, 1},
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
90 {9, 1},
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
91 {10, 1},
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
92 {12, 0}
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
93 };
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
94
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
95 static void ttafilter_init(TTAFilter *c, int32_t shift, int32_t mode) {
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
96 memset(c, 0, sizeof(TTAFilter));
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
97 c->shift = shift;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
98 c->round = shift_1[shift-1];
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
99 // c->round = 1 << (shift - 1);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
100 c->mode = mode;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
101 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
102
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
103 // FIXME: copy paste from original
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
104 static inline void memshl(register int32_t *a, register int32_t *b) {
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
105 *a++ = *b++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
106 *a++ = *b++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
107 *a++ = *b++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
108 *a++ = *b++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
109 *a++ = *b++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
110 *a++ = *b++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
111 *a++ = *b++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
112 *a = *b;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
113 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
114
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
115 // FIXME: copy paste from original
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
116 // mode=1 encoder, mode=0 decoder
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
117 static inline void ttafilter_process(TTAFilter *c, int32_t *in, int32_t mode) {
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
118 register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round;
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
119
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
120 if (!c->error) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
121 sum += *dl++ * *qm, qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
122 sum += *dl++ * *qm, qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
123 sum += *dl++ * *qm, qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
124 sum += *dl++ * *qm, qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
125 sum += *dl++ * *qm, qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
126 sum += *dl++ * *qm, qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
127 sum += *dl++ * *qm, qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
128 sum += *dl++ * *qm, qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
129 dx += 8;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
130 } else if(c->error < 0) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
131 sum += *dl++ * (*qm -= *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
132 sum += *dl++ * (*qm -= *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
133 sum += *dl++ * (*qm -= *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
134 sum += *dl++ * (*qm -= *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
135 sum += *dl++ * (*qm -= *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
136 sum += *dl++ * (*qm -= *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
137 sum += *dl++ * (*qm -= *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
138 sum += *dl++ * (*qm -= *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
139 } else {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
140 sum += *dl++ * (*qm += *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
141 sum += *dl++ * (*qm += *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
142 sum += *dl++ * (*qm += *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
143 sum += *dl++ * (*qm += *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
144 sum += *dl++ * (*qm += *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
145 sum += *dl++ * (*qm += *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
146 sum += *dl++ * (*qm += *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
147 sum += *dl++ * (*qm += *dx++), qm++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
148 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
149
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
150 *(dx-0) = ((*(dl-1) >> 30) | 1) << 2;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
151 *(dx-1) = ((*(dl-2) >> 30) | 1) << 1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
152 *(dx-2) = ((*(dl-3) >> 30) | 1) << 1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
153 *(dx-3) = ((*(dl-4) >> 30) | 1);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
154
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
155 // compress
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
156 if (mode) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
157 *dl = *in;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
158 *in -= (sum >> c->shift);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
159 c->error = *in;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
160 } else {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
161 c->error = *in;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
162 *in += (sum >> c->shift);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
163 *dl = *in;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
164 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
165
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
166 if (c->mode) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
167 *(dl-1) = *dl - *(dl-1);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
168 *(dl-2) = *(dl-1) - *(dl-2);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
169 *(dl-3) = *(dl-2) - *(dl-3);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
170 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
171
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
172 memshl(c->dl, c->dl + 1);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
173 memshl(c->dx, c->dx + 1);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
174 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
175
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
176 typedef struct TTARice {
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
177 uint32_t k0, k1, sum0, sum1;
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
178 } TTARice;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
179
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
180 static void rice_init(TTARice *c, uint32_t k0, uint32_t k1)
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
181 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
182 c->k0 = k0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
183 c->k1 = k1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
184 c->sum0 = shift_16[k0];
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
185 c->sum1 = shift_16[k1];
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
186 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
187
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
188 static int tta_get_unary(GetBitContext *gb)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
189 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
190 int ret = 0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
191
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
192 // count ones
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
193 while(get_bits1(gb))
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
194 ret++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
195 return ret;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
196 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
197
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
198 // shamelessly copied from shorten.c
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
199 static int inline get_le16(GetBitContext *gb)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
200 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
201 return bswap_16(get_bits_long(gb, 16));
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
202 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
203
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
204 static int inline get_le32(GetBitContext *gb)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
205 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
206 return bswap_32(get_bits_long(gb, 32));
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
207 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
208
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
209 static int tta_decode_init(AVCodecContext * avctx)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
210 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
211 TTAContext *s = avctx->priv_data;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
212 int i;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
213
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
214 s->avctx = avctx;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
215
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
216 // 30bytes includes a seektable with one frame
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
217 if (avctx->extradata_size < 30)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
218 return -1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
219
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
220 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
221 if (show_bits_long(&s->gb, 32) == bswap_32(ff_get_fourcc("TTA1")))
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
222 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
223 /* signature */
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
224 skip_bits(&s->gb, 32);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
225 // if (get_bits_long(&s->gb, 32) != bswap_32(ff_get_fourcc("TTA1"))) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
226 // av_log(s->avctx, AV_LOG_ERROR, "Missing magic\n");
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
227 // return -1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
228 // }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
229
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
230 s->flags = get_le16(&s->gb);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
231 if (s->flags != 1 && s->flags != 3)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
232 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
233 av_log(s->avctx, AV_LOG_ERROR, "Invalid flags\n");
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
234 return -1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
235 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
236 s->is_float = (s->flags == FORMAT_FLOAT);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
237 avctx->channels = s->channels = get_le16(&s->gb);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
238 avctx->bits_per_sample = get_le16(&s->gb);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
239 s->bps = (avctx->bits_per_sample + 7) / 8;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
240 avctx->sample_rate = get_le32(&s->gb);
3303
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
241 if(avctx->sample_rate > 1000000){ //prevent FRAME_TIME * avctx->sample_rate from overflowing and sanity check
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
242 av_log(avctx, AV_LOG_ERROR, "sample_rate too large\n");
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
243 return -1;
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
244 }
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
245 s->data_length = get_le32(&s->gb);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
246 skip_bits(&s->gb, 32); // CRC32 of header
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
247
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
248 if (s->is_float)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
249 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
250 avctx->sample_fmt = SAMPLE_FMT_FLT;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
251 av_log(s->avctx, AV_LOG_ERROR, "Unsupported sample format. Please contact the developers.\n");
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
252 return -1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
253 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
254 else switch(s->bps) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
255 // case 1: avctx->sample_fmt = SAMPLE_FMT_U8; break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
256 case 2: avctx->sample_fmt = SAMPLE_FMT_S16; break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
257 // case 3: avctx->sample_fmt = SAMPLE_FMT_S24; break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
258 case 4: avctx->sample_fmt = SAMPLE_FMT_S32; break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
259 default:
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
260 av_log(s->avctx, AV_LOG_ERROR, "Invalid/unsupported sample format. Please contact the developers.\n");
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
261 return -1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
262 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
263
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
264 // FIXME: horribly broken, but directly from reference source
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
265 #define FRAME_TIME 1.04489795918367346939
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
266 s->frame_length = (int)(FRAME_TIME * avctx->sample_rate);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
267
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
268 s->last_frame_length = s->data_length % s->frame_length;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
269 s->total_frames = s->data_length / s->frame_length +
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
270 (s->last_frame_length ? 1 : 0);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
271
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
272 av_log(s->avctx, AV_LOG_DEBUG, "flags: %x chans: %d bps: %d rate: %d block: %d\n",
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
273 s->flags, avctx->channels, avctx->bits_per_sample, avctx->sample_rate,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
274 avctx->block_align);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
275 av_log(s->avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d total: %d\n",
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
276 s->data_length, s->frame_length, s->last_frame_length, s->total_frames);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
277
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
278 // FIXME: seek table
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
279 for (i = 0; i < s->total_frames; i++)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
280 skip_bits(&s->gb, 32);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
281 skip_bits(&s->gb, 32); // CRC32 of seektable
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
282
3303
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
283 if(s->frame_length >= UINT_MAX / (s->channels * sizeof(int32_t))){
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
284 av_log(avctx, AV_LOG_ERROR, "frame_length too large\n");
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
285 return -1;
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
286 }
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
287
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
288 s->decode_buffer = av_mallocz(sizeof(int32_t)*s->frame_length*s->channels);
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
289 } else {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
290 av_log(avctx, AV_LOG_ERROR, "Wrong extradata present\n");
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
291 return -1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
292 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
293
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
294 return 0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
295 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
296
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
297 static int tta_decode_frame(AVCodecContext *avctx,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
298 void *data, int *data_size,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
299 uint8_t *buf, int buf_size)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
300 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
301 TTAContext *s = avctx->priv_data;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
302 int i;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
303
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
304 init_get_bits(&s->gb, buf, buf_size*8);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
305 {
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
306 int32_t predictors[s->channels];
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
307 TTAFilter filters[s->channels];
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
308 TTARice rices[s->channels];
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
309 int cur_chan = 0, framelen = s->frame_length;
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
310 int32_t *p;
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
311
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
312 // FIXME: seeking
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
313 s->total_frames--;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
314 if (!s->total_frames && s->last_frame_length)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
315 framelen = s->last_frame_length;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
316
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
317 // init per channel states
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
318 for (i = 0; i < s->channels; i++) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
319 predictors[i] = 0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
320 ttafilter_init(&(filters[i]), ttafilter_configs[s->bps-1][0], ttafilter_configs[s->bps-1][1]);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
321 rice_init(&(rices[i]), 10, 10);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
322 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
323
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
324 for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) {
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
325 int32_t *predictor = &(predictors[cur_chan]);
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
326 TTAFilter *filter = &(filters[cur_chan]);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
327 TTARice *rice = &(rices[cur_chan]);
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
328 uint32_t unary, depth, k;
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
329 int32_t value;
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
330
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
331 unary = tta_get_unary(&s->gb);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
332
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
333 if (unary == 0) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
334 depth = 0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
335 k = rice->k0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
336 } else {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
337 depth = 1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
338 k = rice->k1;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
339 unary--;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
340 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
341
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
342 if (k)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
343 value = (unary << k) + get_bits(&s->gb, k);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
344 else
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
345 value = unary;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
346
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
347 // FIXME: copy paste from original
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
348 switch (depth) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
349 case 1:
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
350 rice->sum1 += value - (rice->sum1 >> 4);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
351 if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1])
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
352 rice->k1--;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
353 else if(rice->sum1 > shift_16[rice->k1 + 1])
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
354 rice->k1++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
355 value += shift_1[rice->k0];
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
356 default:
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
357 rice->sum0 += value - (rice->sum0 >> 4);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
358 if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0])
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
359 rice->k0--;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
360 else if(rice->sum0 > shift_16[rice->k0 + 1])
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
361 rice->k0++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
362 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
363
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
364 // extract sign
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
365 #define SIGN(x) (((x)&1) ? (++(x)>>1) : (-(x)>>1))
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
366 *p = SIGN(value);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
367
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
368 // run hybrid filter
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
369 ttafilter_process(filter, p, 0);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
370
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
371 // fixed order prediction
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
372 #define PRED(x, k) (int32_t)((((uint64_t)x << k) - x) >> k)
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
373 switch (s->bps) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
374 case 1: *p += PRED(*predictor, 4); break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
375 case 2:
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
376 case 3: *p += PRED(*predictor, 5); break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
377 case 4: *p += *predictor; break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
378 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
379 *predictor = *p;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
380
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
381 #if 0
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
382 // extract 32bit float from last two int samples
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
383 if (s->is_float && ((p - data) & 1)) {
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
384 uint32_t neg = *p & 0x80000000;
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
385 uint32_t hi = *(p - 1);
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
386 uint32_t lo = abs(*p) - 1;
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
387
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
388 hi += (hi || lo) ? 0x3f80 : 0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
389 // SWAP16: swap all the 16 bits
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
390 *(p - 1) = (hi << 16) | SWAP16(lo) | neg;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
391 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
392 #endif
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
393
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
394 /*if ((get_bits_count(&s->gb)+7)/8 > buf_size)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
395 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
396 av_log(NULL, AV_LOG_INFO, "overread!!\n");
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
397 break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
398 }*/
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
399
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
400 // flip channels
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
401 if (cur_chan < (s->channels-1))
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
402 cur_chan++;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
403 else {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
404 // decorrelate in case of stereo integer
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
405 if (!s->is_float && (s->channels > 1)) {
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
406 int32_t *r = p - 1;
3118
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
407 for (*p += *r / 2; r > p - s->channels; r--)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
408 *r = *(r + 1) - *r;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
409 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
410 cur_chan = 0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
411 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
412 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
413
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
414 skip_bits(&s->gb, 32); // frame crc
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
415
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
416 // convert to output buffer
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
417 switch(s->bps) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
418 case 2: {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
419 uint16_t *samples = data;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
420 for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
421 // *samples++ = (unsigned char)*p;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
422 // *samples++ = (unsigned char)(*p >> 8);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
423 *samples++ = *p;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
424 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
425 *data_size = (uint8_t *)samples - (uint8_t *)data;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
426 break;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
427 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
428 default:
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
429 av_log(s->avctx, AV_LOG_ERROR, "Error, only 16bit samples supported!\n");
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
430 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
431 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
432
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
433 // return get_bits_count(&s->gb)+7)/8;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
434 return buf_size;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
435 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
436
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
437 static int tta_decode_close(AVCodecContext *avctx) {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
438 TTAContext *s = avctx->priv_data;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
439
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
440 if (s->decode_buffer)
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
441 av_free(s->decode_buffer);
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
442
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
443 return 0;
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
444 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
445
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
446 AVCodec tta_decoder = {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
447 "tta",
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
448 CODEC_TYPE_AUDIO,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
449 CODEC_ID_TTA,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
450 sizeof(TTAContext),
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
451 tta_decode_init,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
452 NULL,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
453 tta_decode_close,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
454 tta_decode_frame,
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
455 };