annotate tta.c @ 11739:ceffa0ca7596 libavcodec

Change the order of parameters for ff_eval_expr() and ff_parse_and_eval_expr(), place the names for constants/functions before the corresponding values. This looks more readable, as the user is expected to know the names before the values.
author stefano
date Sun, 16 May 2010 23:00:22 +0000
parents 7dd2a45249a9
children c592b59ea05f
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
5215
2b72f9bc4f06 license header consistency cosmetics
diego
parents: 3985
diff changeset
19 * Foundation, Inc., 51 Franklin Street, 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 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11560
diff changeset
23 * @file
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
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"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9355
diff changeset
34 #include "get_bits.h"
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
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
7129
322023e630a6 mark read-only data as const
stefang
parents: 7040
diff changeset
79 static const uint32_t * const 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
7129
322023e630a6 mark read-only data as const
stefang
parents: 7040
diff changeset
90 static const 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
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6287
diff changeset
200 static av_cold int tta_decode_init(AVCodecContext * avctx)
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
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);
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 7823
diff changeset
212 if (show_bits_long(&s->gb, 32) == AV_RL32("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);
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 7823
diff changeset
216 // if (get_bits_long(&s->gb, 32) != bswap_32(AV_RL32("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
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);
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7129
diff changeset
229 avctx->bits_per_coded_sample = get_bits(&s->gb, 16);
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7129
diff changeset
230 s->bps = (avctx->bits_per_coded_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",
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7129
diff changeset
264 s->flags, avctx->channels, avctx->bits_per_coded_sample, avctx->sample_rate,
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
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,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 9082
diff changeset
290 AVPacket *avpkt)
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
291 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 9082
diff changeset
292 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 9082
diff changeset
293 int buf_size = avpkt->size;
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
294 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
295 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
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 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
298 {
3151
27e1b9632715 64bit fixes for the tta decoder, sizeof(long) is 8 on amd64, 4 on x86, the patch
banan
parents: 3118
diff changeset
299 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
300 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
301 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
302 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
303 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
304
11546
1d81cd330928 TTA : Check if the output buffer size is within bounds.
jai_menon
parents: 11343
diff changeset
305 if (*data_size < (framelen * s->channels * 2)) {
11549
12416eb1ba88 Cosmetics : add a space after ",".
jai_menon
parents: 11546
diff changeset
306 av_log(avctx, AV_LOG_ERROR, "Output buffer size is too small.\n");
11546
1d81cd330928 TTA : Check if the output buffer size is within bounds.
jai_menon
parents: 11343
diff changeset
307 return -1;
1d81cd330928 TTA : Check if the output buffer size is within bounds.
jai_menon
parents: 11343
diff changeset
308 }
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
309 // 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
310 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
311 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
312 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
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 // 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
315 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
316 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
317 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
318 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
319 }
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
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 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
322 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
323 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
324 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
325 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
326 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
327
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 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
329
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 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
331 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
332 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
333 } 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
334 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
335 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
336 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
11343
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
339 if (get_bits_left(&s->gb) < k)
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
340 return -1;
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
341
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
342 if (k) {
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
343 if (k > MIN_CACHE_BITS)
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
344 return -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
345 value = (unary << k) + get_bits(&s->gb, k);
11343
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
346 } else
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
347 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
348
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 // 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
350 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
351 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
352 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
353 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
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 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
356 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
357 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
358 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
359 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
360 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
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 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
363 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
364 }
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
3985
082a52023a5b Rename SIGN macro to the more fitting UNFOLD.
diego
parents: 3947
diff changeset
366 // extract coded value
082a52023a5b Rename SIGN macro to the more fitting UNFOLD.
diego
parents: 3947
diff changeset
367 #define UNFOLD(x) (((x)&1) ? (++(x)>>1) : (-(x)>>1))
082a52023a5b Rename SIGN macro to the more fitting UNFOLD.
diego
parents: 3947
diff changeset
368 *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
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 // 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
371 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
372
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 // 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
374 #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
375 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
376 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
377 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
378 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
379 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
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 *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
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 #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
384 // 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
385 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
386 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
387 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
388 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
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 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
391 // 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
392 *(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
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 #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
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 /*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
397 {
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 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
399 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
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
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 // 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
403 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
404 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
405 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
406 // 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
407 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
408 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
409 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
410 *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
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 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
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 }
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
11343
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
416 if (get_bits_left(&s->gb) < 32)
2b78e800f630 Fixed overreads in TTA decoder with corrupted bistreams.
fenrir
parents: 9428
diff changeset
417 return -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
418 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
419
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 // 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
421 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
422 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
423 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
424 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
425 // *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
426 // *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
427 *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
428 }
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 *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
430 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
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 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
433 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
434 }
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 // 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
438 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
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
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6287
diff changeset
441 static av_cold int tta_decode_close(AVCodecContext *avctx) {
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
442 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
443
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 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
445 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
446
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 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
448 }
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
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 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
451 "tta",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 11549
diff changeset
452 AVMEDIA_TYPE_AUDIO,
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
453 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
454 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
455 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
456 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
457 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
458 tta_decode_frame,
9082
ac81b12341d0 Add some missing codecs and update names to match the codec long_name
jbr
parents: 8718
diff changeset
459 .long_name = NULL_IF_CONFIG_SMALL("True Audio (TTA)"),
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
460 };