annotate tta.c @ 4681:b82cff2e2e83 libavcodec

indentation
author kostya
date Sun, 18 Mar 2007 07:53:16 +0000
parents 082a52023a5b
children 2b72f9bc4f06
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 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3763
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3763
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3763
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
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
8 * 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
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3763
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
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
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3763
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
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
13 * 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
14 * 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
15 * 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
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
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3763
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3517
84c509024ee9 Fix FSF postal address.
diego
parents: 3303
diff changeset
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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
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
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 /**
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 * @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
24 * 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
25 * (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
26 * @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
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 */
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
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 #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
31 //#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
32 #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
33 #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
34 #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
35
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 #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
37 #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
38
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 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
40 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
41 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
42
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 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
44 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
45
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
46 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
47 } 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
48
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 #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
50 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
51 {
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 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
53 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
54 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
55 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
56 }
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 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
59 {
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 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
61 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
62 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
63 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
64 }
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 #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
66 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
67 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
68 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
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 };
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
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
79 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
80 #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
81
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
82 #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
83 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
84 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
85 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
86 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
87 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
88 } 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
89
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
90 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
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 {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
93 {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
94 {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
95 };
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
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
97 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
98 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
99 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
100 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
101 // 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
102 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
103 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
104
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 // 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
106 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
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 *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
114 *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
115 }
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
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
117 // 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
118 // 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
119 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
120 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
121
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 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
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 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
130 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
131 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
132 } 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
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 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
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 } 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
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 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
149 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
150 }
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
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-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
153 *(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
154 *(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
155 *(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
156
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 // 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
158 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
159 *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
160 *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
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 } 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
163 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
164 *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
165 *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
166 }
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
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 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
169 *(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
170 *(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
171 *(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
172 }
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
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 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
175 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
176 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
177
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 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
179 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
180 } 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
181
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
182 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
183 {
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->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
185 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
186 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
187 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
188 }
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 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
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 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
193
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 // 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
195 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
196 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
197 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
198 }
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
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 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
201 {
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 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
203 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
204
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 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
206
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 // 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
208 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
209 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
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 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size);
3761
c559d45f66e8 Changes needed due to show_bits_long behaviour changes/fixes
reimar
parents: 3517
diff changeset
212 if (show_bits_long(&s->gb, 32) == ff_get_fourcc("TTA1"))
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
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 /* 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
215 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
216 // 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
217 // 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
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
3763
5ecf721e6148 remove get_le16 and get_le32, get_bits and get_bits_long can just be used directly.
reimar
parents: 3761
diff changeset
221 s->flags = get_bits(&s->gb, 16);
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
222 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
223 {
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 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
225 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
226 }
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 s->is_float = (s->flags == FORMAT_FLOAT);
3763
5ecf721e6148 remove get_le16 and get_le32, get_bits and get_bits_long can just be used directly.
reimar
parents: 3761
diff changeset
228 avctx->channels = s->channels = get_bits(&s->gb, 16);
5ecf721e6148 remove get_le16 and get_le32, get_bits and get_bits_long can just be used directly.
reimar
parents: 3761
diff changeset
229 avctx->bits_per_sample = get_bits(&s->gb, 16);
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
230 s->bps = (avctx->bits_per_sample + 7) / 8;
3763
5ecf721e6148 remove get_le16 and get_le32, get_bits and get_bits_long can just be used directly.
reimar
parents: 3761
diff changeset
231 avctx->sample_rate = get_bits_long(&s->gb, 32);
3303
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
232 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
233 av_log(avctx, AV_LOG_ERROR, "sample_rate too large\n");
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
234 return -1;
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
235 }
3763
5ecf721e6148 remove get_le16 and get_le32, get_bits and get_bits_long can just be used directly.
reimar
parents: 3761
diff changeset
236 s->data_length = get_bits_long(&s->gb, 32);
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
237 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
238
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 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
240 {
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
241 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
242 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
243 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
244 }
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 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
246 // 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
247 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
248 // 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
249 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
250 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
251 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
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
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 // 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
256 #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
257 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
258
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 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
260 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
261 (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
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 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
264 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
265 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
266 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
267 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
268
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 // 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
270 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
271 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
272 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
273
3303
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
274 if(s->frame_length >= UINT_MAX / (s->channels * sizeof(int32_t))){
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
275 av_log(avctx, AV_LOG_ERROR, "frame_length too large\n");
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
276 return -1;
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
277 }
68721b62a528 sanity checks, some might have been exploitable ...
michael
parents: 3151
diff changeset
278
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
279 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
280 } 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
281 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
282 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
283 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
284
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
285 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
286 }
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
287
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
288 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
289 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
290 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
291 {
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 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
293 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
294
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 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
296 {
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
297 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
298 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
299 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
300 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
301 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
302
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 // 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
304 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
305 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
306 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
307
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 // 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
309 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
310 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
311 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
312 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
313 }
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
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 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
316 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
317 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
318 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
319 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
320 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
321
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 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
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 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
325 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
326 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
327 } 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
328 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
329 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
330 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
331 }
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 (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
334 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
335 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
336 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
337
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 // 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
339 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
340 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
341 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
342 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
343 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
344 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
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 }
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
3985
082a52023a5b Rename SIGN macro to the more fitting UNFOLD.
diego
parents: 3947
diff changeset
355 // extract coded value
082a52023a5b Rename SIGN macro to the more fitting UNFOLD.
diego
parents: 3947
diff changeset
356 #define UNFOLD(x) (((x)&1) ? (++(x)>>1) : (-(x)>>1))
082a52023a5b Rename SIGN macro to the more fitting UNFOLD.
diego
parents: 3947
diff changeset
357 *p = UNFOLD(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
358
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 // 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
360 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
361
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 // 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
363 #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
364 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
365 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
366 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
367 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
368 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
369 }
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 *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
371
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
372 #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
373 // 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
374 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
375 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
376 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
377 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
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 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
380 // 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
381 *(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
382 }
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 #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
384
01b58c3b8a91 tta decoder, tested with 44khz mono and stereo (for the latter use ffplay or change MAX_AUDIO_FRAME_SIZE)
alex
parents:
diff changeset
385 /*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
386 {
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 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
388 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
389 }*/
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
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 // 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
392 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
393 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
394 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
395 // 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
396 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
397 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
398 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
399 *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
400 }
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 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
402 }
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 }
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
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 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
406
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 // 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
408 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
409 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
410 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
411 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
412 // *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
413 // *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
414 *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
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 *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
417 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
418 }
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 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
420 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
421 }
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 }
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
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 // 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
425 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
426 }
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 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
429 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
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 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
432 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
433
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 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
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 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
438 "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
439 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
440 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
441 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
442 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
443 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
444 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
445 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
446 };