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
429OBJS-$(CONFIG_TRUESPEECH_DECODER) += truespeech.o429OBJS-$(CONFIG_TRUESPEECH_DECODER) += truespeech.o
430OBJS-$(CONFIG_TSCC_DECODER) += tscc.o msrledec.o430OBJS-$(CONFIG_TSCC_DECODER) += tscc.o msrledec.o
431OBJS-$(CONFIG_TSCC2_DECODER) += tscc2.o431OBJS-$(CONFIG_TSCC2_DECODER) += tscc2.o
432OBJS-$(CONFIG_TTA_DECODER) += tta.o432OBJS-$(CONFIG_TTA_DECODER) += tta.o ttadata.o
433OBJS-$(CONFIG_TWINVQ_DECODER) += twinvq.o433OBJS-$(CONFIG_TWINVQ_DECODER) += twinvq.o
434OBJS-$(CONFIG_TXD_DECODER) += txd.o s3tc.o434OBJS-$(CONFIG_TXD_DECODER) += txd.o s3tc.o
435OBJS-$(CONFIG_ULTI_DECODER) += ulti.o435OBJS-$(CONFIG_ULTI_DECODER) += ulti.o
libavcodec/tta.c+14−67
@@ -29,6 +29,7 @@ · 28 unmodified lines
29 29
30#define BITSTREAM_READER_LE30#define BITSTREAM_READER_LE
31#include <limits.h>31#include <limits.h>
32#include "ttadata.h"
32#include "avcodec.h"33#include "avcodec.h"
33#include "get_bits.h"34#include "get_bits.h"
34#include "unary.h"35#include "unary.h"
@@ -40,24 +41,6 @@ · 5 unmodified lines
40#define FORMAT_SIMPLE 141#define FORMAT_SIMPLE 1
41#define FORMAT_ENCRYPTED 242#define FORMAT_ENCRYPTED 2
42 43
43#define MAX_ORDER 16
44typedef 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
51typedef struct TTARice {
52 uint32_t k0, k1, sum0, sum1;
53} TTARice;
54
55typedef struct TTAChannel {
56 int32_t predictor;
57 TTAFilter filter;
58 TTARice rice;
59} TTAChannel;
60
61typedef struct TTAContext {44typedef struct TTAContext {
62 AVClass *class;45 AVClass *class;
63 AVCodecContext *avctx;46 AVCodecContext *avctx;
@@ -75,40 +58,6 @@ typedef struct TTAContext { · 11 unmodified lines
75 TTAChannel *ch_ctx;58 TTAChannel *ch_ctx;
76} TTAContext;59} TTAContext;
77 60
78static 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
91static const uint32_t * const shift_16 = shift_1 + 4;
92
93static const int32_t ttafilter_configs[4] = {
94 10,
95 9,
96 10,
97 12
98};
99
100static 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
112static inline void ttafilter_process(TTAFilter *c, int32_t *in)61static inline void ttafilter_process(TTAFilter *c, int32_t *in)
113{62{
114 register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round;63 register int32_t *dl = c->dl, *qm = c->qm, *dx = c->dx, sum = c->round;
@@ -140,14 +89,6 @@ static inline void ttafilter_process(TTAFilter *c, int32_t *in) · 25 unmodified lines
140 dl[5] += dl[6]; dl[4] += dl[5];89 dl[5] += dl[6]; dl[4] += dl[5];
141}90}
142 91
143static 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
151static const int64_t tta_channel_layouts[7] = {92static const int64_t tta_channel_layouts[7] = {
152 AV_CH_LAYOUT_STEREO,93 AV_CH_LAYOUT_STEREO,
153 AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY,94 AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY,
@@ -319,9 +260,15 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, · 165 unmodified lines
319 260
320 // init per channel states261 // init per channel states
321 for (i = 0; i < s->channels; i++) {262 for (i = 0; i < s->channels; i++) {
263 TTAFilter *filter = &s->ch_ctx[i].filter;
322 s->ch_ctx[i].predictor = 0;264 s->ch_ctx[i].predictor = 0;
323 ttafilter_init(s, &s->ch_ctx[i].filter, ttafilter_configs[s->bps-1]);265 ff_tta_filter_init(filter, ff_tta_filter_configs[s->bps-1]);
324 rice_init(&s->ch_ctx[i].rice, 10, 10);266 if (s->format == FORMAT_ENCRYPTED) {
267 int i;
268 for (i = 0; i < 8; i++)
269 filter->qm[i] = sign_extend(s->crc_pass[i], 8);
270 }
271 ff_tta_rice_init(&s->ch_ctx[i].rice, 10, 10);
325 }272 }
326 273
327 i = 0;274 i = 0;
@@ -361,16 +308,16 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, · 33 unmodified lines
361 switch (depth) {308 switch (depth) {
362 case 1:309 case 1:
363 rice->sum1 += value - (rice->sum1 >> 4);310 rice->sum1 += value - (rice->sum1 >> 4);
364 if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1])311 if (rice->k1 > 0 && rice->sum1 < ff_tta_shift_16[rice->k1])
365 rice->k1--;312 rice->k1--;
366 else if(rice->sum1 > shift_16[rice->k1 + 1])313 else if(rice->sum1 > ff_tta_shift_16[rice->k1 + 1])
367 rice->k1++;314 rice->k1++;
368 value += shift_1[rice->k0];315 value += ff_tta_shift_1[rice->k0];
369 default:316 default:
370 rice->sum0 += value - (rice->sum0 >> 4);317 rice->sum0 += value - (rice->sum0 >> 4);
371 if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0])318 if (rice->k0 > 0 && rice->sum0 < ff_tta_shift_16[rice->k0])
372 rice->k0--;319 rice->k0--;
373 else if(rice->sum0 > shift_16[rice->k0 + 1])320 else if(rice->sum0 > ff_tta_shift_16[rice->k0 + 1])
374 rice->k0++;321 rice->k0++;
375 }322 }
376 323
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
23const 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
36const uint32_t * const ff_tta_shift_16 = ff_tta_shift_1 + 4;
37
38const uint8_t ff_tta_filter_configs[] = { 10, 9, 10, 12 };
39
40void 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
48void 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
27typedef 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
34typedef struct TTARice {
35 uint32_t k0, k1, sum0, sum1;
36} TTARice;
37
38typedef struct TTAChannel {
39 int32_t predictor;
40 TTAFilter filter;
41 TTARice rice;
42} TTAChannel;
43
44extern const uint32_t ff_tta_shift_1[];
45extern const uint32_t * const ff_tta_shift_16;
46extern const uint8_t ff_tta_filter_configs[];
47
48void ff_tta_rice_init(TTARice *c, uint32_t k0, uint32_t k1);
49void 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