annotate dtsdec.c @ 2126:181cb6785f6b libavcodec

remove dts_internal.h avoiding code redundance license copy paste fix patch by (Benjamin Zores <ben at geexbox dot org>)
author michael
date Wed, 14 Jul 2004 20:23:35 +0000
parents ef54decf5624
children a0f5f4731ccd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
1 /*
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
2 * dtsdec.c : free DTS Coherent Acoustics stream decoder.
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
3 * Copyright (C) 2004 Benjamin Zores <ben@geexbox.org>
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
4 *
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
5 * This file is part of libavcodec.
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
6 *
2126
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
7 * This library is free software; you can redistribute it and/or modify
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
8 * it under the terms of the GNU General Public License as published by
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
10 * (at your option) any later version.
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
11 *
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
12 * This library is distributed in the hope that it will be useful,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2126
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
15 * GNU General Public License for more details.
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
16 *
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
17 * You should have received a copy of the GNU General Public License
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
18 * along with this program; if not, write to the Free Software
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
20 */
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
21
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
22 #ifdef HAVE_AV_CONFIG_H
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
23 #undef HAVE_AV_CONFIG_H
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
24 #endif
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
25
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
26 #include "avcodec.h"
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
27 #include <dts.h>
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
28
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
29 #include <stdlib.h>
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
30 #include <string.h>
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
31 #include <malloc.h>
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
32
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
33 #define INBUF_SIZE 4096
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
34 #define BUFFER_SIZE 4096
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
35 #define HEADER_SIZE 14
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
36
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
37 #ifdef LIBDTS_FIXED
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
38 #define CONVERT_LEVEL (1 << 26)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
39 #define CONVERT_BIAS 0
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
40 #else
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
41 #define CONVERT_LEVEL 1
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
42 #define CONVERT_BIAS 384
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
43 #endif
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
44
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
45 static inline
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
46 int16_t convert (int32_t i)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
47 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
48 #ifdef LIBDTS_FIXED
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
49 i >>= 15;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
50 #else
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
51 i -= 0x43c00000;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
52 #endif
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
53 return (i > 32767) ? 32767 : ((i < -32768) ? -32768 : i);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
54 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
55
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
56 void
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
57 convert2s16_2 (sample_t * _f, int16_t * s16)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
58 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
59 int i;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
60 int32_t * f = (int32_t *) _f;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
61
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
62 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
63 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
64 s16[2*i] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
65 s16[2*i+1] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
66 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
67 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
68
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
69 void
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
70 convert2s16_4 (sample_t * _f, int16_t * s16)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
71 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
72 int i;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
73 int32_t * f = (int32_t *) _f;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
74
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
75 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
76 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
77 s16[4*i] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
78 s16[4*i+1] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
79 s16[4*i+2] = convert (f[i+512]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
80 s16[4*i+3] = convert (f[i+768]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
81 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
82 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
83
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
84 void
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
85 convert2s16_5 (sample_t * _f, int16_t * s16)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
86 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
87 int i;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
88 int32_t * f = (int32_t *) _f;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
89
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
90 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
91 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
92 s16[5*i] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
93 s16[5*i+1] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
94 s16[5*i+2] = convert (f[i+512]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
95 s16[5*i+3] = convert (f[i+768]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
96 s16[5*i+4] = convert (f[i+1024]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
97 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
98 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
99
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
100 static void
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
101 convert2s16_multi (sample_t * _f, int16_t * s16, int flags)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
102 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
103 int i;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
104 int32_t * f = (int32_t *) _f;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
105
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
106 switch (flags)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
107 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
108 case DTS_MONO:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
109 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
110 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
111 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
112 s16[5*i+4] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
113 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
114 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
115 case DTS_CHANNEL:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
116 case DTS_STEREO:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
117 case DTS_DOLBY:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
118 convert2s16_2 (_f, s16);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
119 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
120 case DTS_3F:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
121 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
122 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
123 s16[5*i] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
124 s16[5*i+1] = convert (f[i+512]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
125 s16[5*i+2] = s16[5*i+3] = 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
126 s16[5*i+4] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
127 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
128 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
129 case DTS_2F2R:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
130 convert2s16_4 (_f, s16);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
131 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
132 case DTS_3F2R:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
133 convert2s16_5 (_f, s16);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
134 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
135 case DTS_MONO | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
136 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
137 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
138 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
139 s16[6*i+4] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
140 s16[6*i+5] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
141 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
142 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
143 case DTS_CHANNEL | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
144 case DTS_STEREO | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
145 case DTS_DOLBY | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
146 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
147 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
148 s16[6*i] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
149 s16[6*i+1] = convert (f[i+512]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
150 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
151 s16[6*i+5] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
152 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
153 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
154 case DTS_3F | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
155 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
156 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
157 s16[6*i] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
158 s16[6*i+1] = convert (f[i+768]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
159 s16[6*i+2] = s16[6*i+3] = 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
160 s16[6*i+4] = convert (f[i+512]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
161 s16[6*i+5] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
162 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
163 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
164 case DTS_2F2R | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
165 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
166 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
167 s16[6*i] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
168 s16[6*i+1] = convert (f[i+512]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
169 s16[6*i+2] = convert (f[i+768]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
170 s16[6*i+3] = convert (f[i+1024]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
171 s16[6*i+4] = 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
172 s16[6*i+5] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
173 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
174 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
175 case DTS_3F2R | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
176 for (i = 0; i < 256; i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
177 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
178 s16[6*i] = convert (f[i+256]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
179 s16[6*i+1] = convert (f[i+768]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
180 s16[6*i+2] = convert (f[i+1024]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
181 s16[6*i+3] = convert (f[i+1280]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
182 s16[6*i+4] = convert (f[i+512]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
183 s16[6*i+5] = convert (f[i]);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
184 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
185 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
186 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
187 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
188
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
189 static int
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
190 channels_multi (int flags)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
191 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
192 if (flags & DTS_LFE)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
193 return 6;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
194 else if (flags & 1) /* center channel */
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
195 return 5;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
196 else if ((flags & DTS_CHANNEL_MASK) == DTS_2F2R)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
197 return 4;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
198 else
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
199 return 2;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
200 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
201
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
202 static int
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
203 dts_decode_frame (AVCodecContext *avctx, void *data, int *data_size,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
204 uint8_t *buff, int buff_size)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
205 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
206 uint8_t * start = buff;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
207 uint8_t * end = buff + buff_size;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
208 *data_size = 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
209
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
210 static uint8_t buf[BUFFER_SIZE];
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
211 static uint8_t * bufptr = buf;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
212 static uint8_t * bufpos = buf + HEADER_SIZE;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
213
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
214 static int sample_rate;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
215 static int frame_length;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
216 static int flags;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
217 int bit_rate;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
218 int len;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
219 dts_state_t *state = avctx->priv_data;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
220
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
221 while (1)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
222 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
223 len = end - start;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
224 if (!len)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
225 break;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
226 if (len > bufpos - bufptr)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
227 len = bufpos - bufptr;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
228 memcpy (bufptr, start, len);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
229 bufptr += len;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
230 start += len;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
231 if (bufptr == bufpos)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
232 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
233 if (bufpos == buf + HEADER_SIZE)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
234 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
235 int length;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
236
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
237 length = dts_syncinfo (state, buf, &flags, &sample_rate,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
238 &bit_rate, &frame_length);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
239 if (!length)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
240 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
241 av_log (NULL, AV_LOG_INFO, "skip\n");
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
242 for (bufptr = buf; bufptr < buf + HEADER_SIZE-1; bufptr++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
243 bufptr[0] = bufptr[1];
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
244 continue;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
245 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
246 bufpos = buf + length;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
247 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
248 else
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
249 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
250 level_t level;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
251 sample_t bias;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
252 int i;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
253
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
254 flags = 2; /* ???????????? */
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
255 level = CONVERT_LEVEL;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
256 bias = CONVERT_BIAS;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
257
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
258 flags |= DTS_ADJUST_LEVEL;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
259 if (dts_frame (state, buf, &flags, &level, bias))
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
260 goto error;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
261 for (i = 0; i < dts_blocks_num (state); i++)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
262 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
263 if (dts_block (state))
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
264 goto error;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
265 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
266 int chans;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
267 chans = channels_multi (flags);
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
268 convert2s16_multi (dts_samples (state), data,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
269 flags & (DTS_CHANNEL_MASK | DTS_LFE));
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
270
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
271 data += 256 * sizeof (int16_t) * chans;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
272 *data_size += 256 * sizeof (int16_t) * chans;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
273 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
274 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
275 bufptr = buf;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
276 bufpos = buf + HEADER_SIZE;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
277 continue;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
278 error:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
279 av_log (NULL, AV_LOG_ERROR, "error\n");
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
280 bufptr = buf;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
281 bufpos = buf + HEADER_SIZE;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
282 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
283 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
284 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
285
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
286 return buff_size;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
287 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
288
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
289 static int
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
290 dts_decode_init (AVCodecContext *avctx)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
291 {
2126
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
292 avctx->priv_data = dts_init (0);
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
293 if (avctx->priv_data == NULL)
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
294 return 1;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
295
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
296 return 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
297 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
298
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
299 static int
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
300 dts_decode_end (AVCodecContext *s)
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
301 {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
302 return 0;
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
303 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
304
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
305 AVCodec dts_decoder = {
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
306 "dts",
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
307 CODEC_TYPE_AUDIO,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
308 CODEC_ID_DTS,
2126
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
309 sizeof (dts_state_t *),
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
310 dts_decode_init,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
311 NULL,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
312 dts_decode_end,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
313 dts_decode_frame,
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
314 };