History

tta: move code that will be shared with encoder to separate file

Paul B Mahol committed 13 years ago

Commit 2e67dde1 parent a4b58634 files · +117 −68Browse files

Unified · Split

4 files
  1. libavcodec/Makefile +1 −1
  2. libavcodec/tta.c +14 −67
  3. libavcodec/ttadata.c +52 −0
  4. libavcodec/ttadata.h +50 −0
libavcodec/Makefile+1−1
@@ -429,7 +429,7 @@ OBJS-$(CONFIG_TRUEMOTION2_DECODER) += truemotion2.o · 428 unmodified lines
429429 OBJS-$(CONFIG_TRUESPEECH_DECODER) += truespeech.o
430430 OBJS-$(CONFIG_TSCC_DECODER) += tscc.o msrledec.o
431431 OBJS-$(CONFIG_TSCC2_DECODER) += tscc2.o
432−OBJS-$(CONFIG_TTA_DECODER) += tta.o
432+OBJS-$(CONFIG_TTA_DECODER) += tta.o ttadata.o
433433 OBJS-$(CONFIG_TWINVQ_DECODER) += twinvq.o
434434 OBJS-$(CONFIG_TXD_DECODER) += txd.o s3tc.o
435435 OBJS-$(CONFIG_ULTI_DECODER) += ulti.o
libavcodec/tta.c+14−67
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929
3030 #define BITSTREAM_READER_LE
3131 #include <limits.h>
32+#include "ttadata.h"
3233 #include "avcodec.h"
3334 #include "get_bits.h"
3435 #include "unary.h"
@@ -40,24 +41,6 @@ · 5 unmodified lines
4041 #define FORMAT_SIMPLE 1
4142 #define FORMAT_ENCRYPTED 2
4243
43−#define MAX_ORDER 16
44−typedef struct TTAFilter {
45− int32_t shift, round, error;
46− int32_t qm[MAX_ORDER];
47− int32_t dx[MAX_ORDER];
48− int32_t dl[MAX_ORDER];
49−} TTAFilter;
50−
51−typedef struct TTARice {
52− uint32_t k0, k1, sum0, sum1;
53−} TTARice;
54−
55−typedef struct TTAChannel {
56− int32_t predictor;
57− TTAFilter filter;
58− TTARice rice;
59−} TTAChannel;
60−
6144 typedef struct TTAContext {
6245 AVClass *class;
6346 AVCodecContext *avctx;
@@ -75,40 +58,6 @@ typedef struct TTAContext { · 11 unmodified lines
7558 TTAChannel *ch_ctx;
7659 } TTAContext;
7760
78−static const uint32_t shift_1[] = {
79− 0x00000001, 0x00000002, 0x00000004, 0x00000008,
80− 0x00000010, 0x00000020, 0x00000040, 0x00000080,
81− 0x00000100, 0x00000200, 0x00000400, 0x00000800,
82− 0x00001000, 0x00002000, 0x00004000, 0x00008000,
83− 0x00010000, 0x00020000, 0x00040000, 0x00080000,
84− 0x00100000, 0x00200000, 0x00400000, 0x00800000,
85− 0x01000000, 0x02000000, 0x04000000, 0x08000000,
86− 0x10000000, 0x20000000, 0x40000000, 0x80000000,
87− 0x80000000, 0x80000000, 0x80000000, 0x80000000,
88− 0x80000000, 0x80000000, 0x80000000, 0x80000000
89−};
90−
91−static const uint32_t * const shift_16 = shift_1 + 4;
92−
93−static const int32_t ttafilter_configs[4] = {
94− 10,
95− 9,
96− 10,
97− 12
98−};
99−
100−static void ttafilter_init(TTAContext *s, TTAFilter *c, int32_t shift) {
101− memset(c, 0, sizeof(TTAFilter));
102− if (s->format == FORMAT_ENCRYPTED) {
103− int i;
104− for (i = 0; i < 8; i++)
105− c->qm[i] = sign_extend(s->crc_pass[i], 8);
106− }
107− c->shift = shift;
108− c->round = shift_1[shift-1];
109−// c->round = 1 << (shift - 1);
110−}
111−
11261 static inline void ttafilter_process(TTAFilter *c, int32_t *in)
11362 {
11463 register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round;
@@ -140,14 +89,6 @@ static inline void ttafilter_process(TTAFilter *c, int32_t *in) · 25 unmodified lines
14089 dl[5] += dl[6]; dl[4] += dl[5];
14190 }
14291
143−static void rice_init(TTARice *c, uint32_t k0, uint32_t k1)
144−{
145− c->k0 = k0;
146− c->k1 = k1;
147− c->sum0 = shift_16[k0];
148− c->sum1 = shift_16[k1];
149−}
150−
15192 static const int64_t tta_channel_layouts[7] = {
15293 AV_CH_LAYOUT_STEREO,
15394 AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY,
@@ -319,9 +260,15 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, · 165 unmodified lines
319260
320261 // init per channel states
321262 for (i = 0; i < s->channels; i++) {
263+ TTAFilter *filter = &s->ch_ctx[i].filter;
322264 s->ch_ctx[i].predictor = 0;
323− ttafilter_init(s, &s->ch_ctx[i].filter, ttafilter_configs[s->bps-1]);
324− rice_init(&s->ch_ctx[i].rice, 10, 10);
265+ ff_tta_filter_init(filter, ff_tta_filter_configs[s->bps-1]);
266+ if (s->format == FORMAT_ENCRYPTED) {
267+ int i;
268+ for (i = 0; i < 8; i++)
269+ filter->qm[i] = sign_extend(s->crc_pass[i], 8);
270+ }
271+ ff_tta_rice_init(&s->ch_ctx[i].rice, 10, 10);
325272 }
326273
327274 i = 0;
@@ -361,16 +308,16 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, · 33 unmodified lines
361308 switch (depth) {
362309 case 1:
363310 rice->sum1 += value - (rice->sum1 >> 4);
364− if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1])
311+ if (rice->k1 > 0 && rice->sum1 < ff_tta_shift_16[rice->k1])
365312 rice->k1--;
366− else if(rice->sum1 > shift_16[rice->k1 + 1])
313+ else if(rice->sum1 > ff_tta_shift_16[rice->k1 + 1])
367314 rice->k1++;
368− value += shift_1[rice->k0];
315+ value += ff_tta_shift_1[rice->k0];
369316 default:
370317 rice->sum0 += value - (rice->sum0 >> 4);
371− if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0])
318+ if (rice->k0 > 0 && rice->sum0 < ff_tta_shift_16[rice->k0])
372319 rice->k0--;
373− else if(rice->sum0 > shift_16[rice->k0 + 1])
320+ else if(rice->sum0 > ff_tta_shift_16[rice->k0 + 1])
374321 rice->k0++;
375322 }
376323
libavcodec/ttadata.c+52−0
@@ -0,0 +1,52 @@
1+/*
2+ * TTA (The Lossless True Audio) data
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#include "ttadata.h"
22+
23+const uint32_t ff_tta_shift_1[] = {
24+ 0x00000001, 0x00000002, 0x00000004, 0x00000008,
25+ 0x00000010, 0x00000020, 0x00000040, 0x00000080,
26+ 0x00000100, 0x00000200, 0x00000400, 0x00000800,
27+ 0x00001000, 0x00002000, 0x00004000, 0x00008000,
28+ 0x00010000, 0x00020000, 0x00040000, 0x00080000,
29+ 0x00100000, 0x00200000, 0x00400000, 0x00800000,
30+ 0x01000000, 0x02000000, 0x04000000, 0x08000000,
31+ 0x10000000, 0x20000000, 0x40000000, 0x80000000,
32+ 0x80000000, 0x80000000, 0x80000000, 0x80000000,
33+ 0x80000000, 0x80000000, 0x80000000, 0x80000000
34+};
35+
36+const uint32_t * const ff_tta_shift_16 = ff_tta_shift_1 + 4;
37+
38+const uint8_t ff_tta_filter_configs[] = { 10, 9, 10, 12 };
39+
40+void ff_tta_rice_init(TTARice *c, uint32_t k0, uint32_t k1)
41+{
42+ c->k0 = k0;
43+ c->k1 = k1;
44+ c->sum0 = ff_tta_shift_16[k0];
45+ c->sum1 = ff_tta_shift_16[k1];
46+}
47+
48+void ff_tta_filter_init(TTAFilter *c, int32_t shift) {
49+ memset(c, 0, sizeof(TTAFilter));
50+ c->shift = shift;
51+ c->round = ff_tta_shift_1[shift-1];
52+}
libavcodec/ttadata.h+50−0
@@ -0,0 +1,50 @@
1+/*
2+ * TTA (The Lossless True Audio) data
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#ifndef AVCODEC_TTADATA_H
22+#define AVCODEC_TTADATA_H
23+
24+#include "internal.h"
25+
26+#define MAX_ORDER 16
27+typedef struct TTAFilter {
28+ int32_t shift, round, error;
29+ int32_t qm[MAX_ORDER];
30+ int32_t dx[MAX_ORDER];
31+ int32_t dl[MAX_ORDER];
32+} TTAFilter;
33+
34+typedef struct TTARice {
35+ uint32_t k0, k1, sum0, sum1;
36+} TTARice;
37+
38+typedef struct TTAChannel {
39+ int32_t predictor;
40+ TTAFilter filter;
41+ TTARice rice;
42+} TTAChannel;
43+
44+extern const uint32_t ff_tta_shift_1[];
45+extern const uint32_t * const ff_tta_shift_16;
46+extern const uint8_t ff_tta_filter_configs[];
47+
48+void ff_tta_rice_init(TTARice *c, uint32_t k0, uint32_t k1);
49+void ff_tta_filter_init(TTAFilter *c, int32_t shift);
50+#endif /* AVCODEC_TTADATA_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t