Mercurial > libavcodec.hg
annotate dtsdec.c @ 4076:aeb514c163ad libavcodec
reverse my last change, it was wrong and broken
author | michael |
---|---|
date | Tue, 24 Oct 2006 10:13:26 +0000 |
parents | 418b123f1b74 |
children | f97a2081b5b1 |
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 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3267
diff
changeset
|
5 * This file is part of FFmpeg. |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
6 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3267
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or modify |
2126 | 8 * it under the terms of the GNU General Public License as published by |
3965 | 9 * the Free Software Foundation; either version 2 of the License, or |
2126 | 10 * (at your option) any later version. |
2967 | 11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3267
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2123
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 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 * GNU General Public License for more details. | |
2967 | 16 * |
2126 | 17 * You should have received a copy of the GNU General Public License |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3267
diff
changeset
|
18 * along with FFmpeg; if not, write to the Free Software |
2126 | 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> |
2186 | 31 |
32 #ifdef HAVE_MALLOC_H | |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
33 #include <malloc.h> |
2186 | 34 #endif |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
35 |
3267
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
36 #define BUFFER_SIZE 18726 |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
37 #define HEADER_SIZE 14 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
38 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
39 #ifdef LIBDTS_FIXED |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
40 #define CONVERT_LEVEL (1 << 26) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
41 #define CONVERT_BIAS 0 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
42 #else |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
43 #define CONVERT_LEVEL 1 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
44 #define CONVERT_BIAS 384 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
45 #endif |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
46 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
47 static inline |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
48 int16_t convert (int32_t i) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
49 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
50 #ifdef LIBDTS_FIXED |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
51 i >>= 15; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
52 #else |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
53 i -= 0x43c00000; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
54 #endif |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
55 return (i > 32767) ? 32767 : ((i < -32768) ? -32768 : i); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
56 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
57 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
58 void |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
59 convert2s16_2 (sample_t * _f, int16_t * s16) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
60 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
61 int i; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
62 int32_t * f = (int32_t *) _f; |
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 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
65 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
66 s16[2*i] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
67 s16[2*i+1] = convert (f[i+256]); |
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 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
70 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
71 void |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
72 convert2s16_4 (sample_t * _f, int16_t * s16) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
73 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
74 int i; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
75 int32_t * f = (int32_t *) _f; |
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 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
78 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
79 s16[4*i] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
80 s16[4*i+1] = convert (f[i+256]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
81 s16[4*i+2] = convert (f[i+512]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
82 s16[4*i+3] = convert (f[i+768]); |
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 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
85 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
86 void |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
87 convert2s16_5 (sample_t * _f, int16_t * s16) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
88 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
89 int i; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
90 int32_t * f = (int32_t *) _f; |
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 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
93 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
94 s16[5*i] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
95 s16[5*i+1] = convert (f[i+256]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
96 s16[5*i+2] = convert (f[i+512]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
97 s16[5*i+3] = convert (f[i+768]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
98 s16[5*i+4] = convert (f[i+1024]); |
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 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
101 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
102 static void |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
103 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
|
104 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
105 int i; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
106 int32_t * f = (int32_t *) _f; |
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 switch (flags) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
109 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
110 case DTS_MONO: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
111 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
112 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
113 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
|
114 s16[5*i+4] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
115 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
116 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
117 case DTS_CHANNEL: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
118 case DTS_STEREO: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
119 case DTS_DOLBY: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
120 convert2s16_2 (_f, s16); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
121 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
122 case DTS_3F: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
123 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
124 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
125 s16[5*i] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
126 s16[5*i+1] = convert (f[i+512]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
127 s16[5*i+2] = s16[5*i+3] = 0; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
128 s16[5*i+4] = convert (f[i+256]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
129 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
130 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
131 case DTS_2F2R: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
132 convert2s16_4 (_f, s16); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
133 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
134 case DTS_3F2R: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
135 convert2s16_5 (_f, s16); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
136 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
137 case DTS_MONO | DTS_LFE: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
138 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
139 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
140 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
|
141 s16[6*i+4] = convert (f[i+256]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
142 s16[6*i+5] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
143 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
144 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
145 case DTS_CHANNEL | DTS_LFE: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
146 case DTS_STEREO | DTS_LFE: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
147 case DTS_DOLBY | DTS_LFE: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
148 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
149 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
150 s16[6*i] = convert (f[i+256]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
151 s16[6*i+1] = convert (f[i+512]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
152 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
|
153 s16[6*i+5] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
154 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
155 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
156 case DTS_3F | DTS_LFE: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
157 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
158 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
159 s16[6*i] = convert (f[i+256]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
160 s16[6*i+1] = convert (f[i+768]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
161 s16[6*i+2] = s16[6*i+3] = 0; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
162 s16[6*i+4] = convert (f[i+512]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
163 s16[6*i+5] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
164 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
165 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
166 case DTS_2F2R | DTS_LFE: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
167 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
168 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
169 s16[6*i] = convert (f[i+256]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
170 s16[6*i+1] = convert (f[i+512]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
171 s16[6*i+2] = convert (f[i+768]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
172 s16[6*i+3] = convert (f[i+1024]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
173 s16[6*i+4] = 0; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
174 s16[6*i+5] = convert (f[i]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
175 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
176 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
177 case DTS_3F2R | DTS_LFE: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
178 for (i = 0; i < 256; i++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
179 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
180 s16[6*i] = convert (f[i+256]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
181 s16[6*i+1] = convert (f[i+768]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
182 s16[6*i+2] = convert (f[i+1024]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
183 s16[6*i+3] = convert (f[i+1280]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
184 s16[6*i+4] = convert (f[i+512]); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
185 s16[6*i+5] = convert (f[i]); |
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 break; |
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 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
190 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
191 static int |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
192 channels_multi (int flags) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
193 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
194 if (flags & DTS_LFE) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
195 return 6; |
2979 | 196 else if (flags & 1) /* center channel */ |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
197 return 5; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
198 else if ((flags & DTS_CHANNEL_MASK) == DTS_2F2R) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
199 return 4; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
200 else |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
201 return 2; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
202 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
203 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
204 static int |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
205 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
|
206 uint8_t *buff, int buff_size) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
207 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
208 uint8_t * start = buff; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
209 uint8_t * end = buff + buff_size; |
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 |
2222 | 221 *data_size = 0; |
222 | |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
223 while (1) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
224 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
225 len = end - start; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
226 if (!len) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
227 break; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
228 if (len > bufpos - bufptr) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
229 len = bufpos - bufptr; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
230 memcpy (bufptr, start, len); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
231 bufptr += len; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
232 start += len; |
3267
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
233 if (bufptr != bufpos) |
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
234 return start - buff; |
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
235 if (bufpos != buf + HEADER_SIZE) |
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
236 break; |
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
237 |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
238 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
239 int 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 length = dts_syncinfo (state, buf, &flags, &sample_rate, |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
242 &bit_rate, &frame_length); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
243 if (!length) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
244 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
245 av_log (NULL, AV_LOG_INFO, "skip\n"); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
246 for (bufptr = buf; bufptr < buf + HEADER_SIZE-1; bufptr++) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
247 bufptr[0] = bufptr[1]; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
248 continue; |
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 bufpos = buf + length; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
251 } |
3267
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
252 } |
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
253 |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
254 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
255 level_t level; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
256 sample_t bias; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
257 int i; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
258 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
259 flags = 2; /* ???????????? */ |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
260 level = CONVERT_LEVEL; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
261 bias = CONVERT_BIAS; |
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 flags |= DTS_ADJUST_LEVEL; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
264 if (dts_frame (state, buf, &flags, &level, bias)) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
265 goto error; |
2141 | 266 avctx->sample_rate = sample_rate; |
267 avctx->channels = channels_multi (flags); | |
268 avctx->bit_rate = bit_rate; | |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
269 for (i = 0; i < dts_blocks_num (state); i++) |
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 if (dts_block (state)) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
272 goto error; |
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 int chans; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
275 chans = channels_multi (flags); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
276 convert2s16_multi (dts_samples (state), data, |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
277 flags & (DTS_CHANNEL_MASK | DTS_LFE)); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
278 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
279 data += 256 * sizeof (int16_t) * chans; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
280 *data_size += 256 * sizeof (int16_t) * chans; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
281 } |
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 bufptr = buf; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
284 bufpos = buf + HEADER_SIZE; |
3267
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
285 return start-buff; |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
286 error: |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
287 av_log (NULL, AV_LOG_ERROR, "error\n"); |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
288 bufptr = buf; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
289 bufpos = buf + HEADER_SIZE; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
290 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
291 |
3267
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
292 return start-buff; |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
293 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
294 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
295 static int |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
296 dts_decode_init (AVCodecContext *avctx) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
297 { |
2126 | 298 avctx->priv_data = dts_init (0); |
299 if (avctx->priv_data == NULL) | |
3267
8072ed8993f6
dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents:
2979
diff
changeset
|
300 return -1; |
2123
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 static int |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
306 dts_decode_end (AVCodecContext *s) |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
307 { |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
308 return 0; |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
309 } |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
310 |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
311 AVCodec dts_decoder = { |
2967 | 312 "dts", |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
313 CODEC_TYPE_AUDIO, |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
314 CODEC_ID_DTS, |
2126 | 315 sizeof (dts_state_t *), |
2123
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
316 dts_decode_init, |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
317 NULL, |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
318 dts_decode_end, |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
319 dts_decode_frame, |
ef54decf5624
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff
changeset
|
320 }; |