1 /*
2 * LucasArts VIMA decoder
3 * Copyright (c) 2012 Paul B Mahol
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * LucasArts VIMA audio decoder
25 * @author Paul B Mahol
26 */
27
29
34
37
39 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
40 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
41 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
42 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
43 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
44 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
45 };
46
48 -1, 4, -1, 4
49 };
50
52 -1, -1, 2, 6, -1, -1, 2, 6
53 };
54
56 -1, -1, -1, -1, 1, 2, 4, 6, -1, -1, -1, -1, 1, 2, 4, 6
57 };
58
60 -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 2, 2, 4, 5, 6,
61 -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 2, 2, 4, 5, 6
62 };
63
65 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
66 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 5, 5, 6, 6,
67 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
68 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 5, 5, 6, 6
69 };
70
72 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
73 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
74 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
75 2, 2, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6,
76 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
77 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
78 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
79 2, 2, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6
80 };
81
85 };
86
88 {
89 int start_pos;
90
92
94 return 0;
95
96 for (start_pos = 0; start_pos < 64; start_pos++) {
97 unsigned int dest_pos, table_pos;
98
99 for (table_pos = 0, dest_pos = start_pos;
101 table_pos++, dest_pos += 64) {
102 int put = 0,
count, table_value;
103
106 if (start_pos &
count)
107 put += table_value;
108 table_value >>= 1;
109 }
111 }
112 }
114
115 return 0;
116 }
117
120 {
123 int16_t pcm_data[2];
124 uint32_t samples;
125 int8_t channel_hint[2];
127 int channels = 1;
128
131
134
136 if (samples == 0xffffffff) {
139 }
140
141 if (samples > pkt->
size * 2)
143
145 if (channel_hint[0] & 0x80) {
146 channel_hint[0] = ~channel_hint[0];
147 channels = 2;
148 }
153 if (channels > 1) {
156 }
157
161
162 for (chan = 0; chan < channels; chan++) {
163 uint16_t *dest = (uint16_t *)frame->
data[0] + chan;
164 int step_index = channel_hint[chan];
165 int output = pcm_data[chan];
167
169 int lookup_size,
lookup, highbit, lowbits;
170
171 step_index = av_clip(step_index, 0, 88);
173 lookup =
get_bits(&gb, lookup_size);
174 highbit = 1 << (lookup_size - 1);
175 lowbits = highbit - 1;
176
177 if (lookup & highbit)
178 lookup ^= highbit;
179 else
180 highbit = 0;
181
182 if (lookup == lowbits) {
184 } else {
185 int predict_index,
diff;
186
187 predict_index = (lookup << (7 - lookup_size)) | (step_index << 6);
188 predict_index = av_clip(predict_index, 0, 5785);
190 if (lookup)
192 if (highbit)
194
195 output = av_clip_int16(output + diff);
196 }
197
198 *dest = output;
199 dest += channels;
200
202 }
203 }
204
205 *got_frame_ptr = 1;
206
208 }
209
211 .
name =
"adpcm_vima",
218 };
219
220 #if FF_API_VIMA_DECODER
229 };
230 #endif