1 /*
2 * Westwood SNDx codecs
3 * Copyright (c) 2005 Konstantin Shishkov
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 #include <stdint.h>
23
30
31 /**
32 * @file
33 * Westwood SNDx codecs
34 *
35 * Reference documents about VQA format and its audio codecs
36 * can be found here:
37 * http://www.multimedia.cx
38 */
39
41 -9, -8, -6, -5, -4, -3, -2, -1,
42 0, 1, 2, 3, 4, 5, 6, 8
43 };
44
46 {
50
51 return 0;
52 }
53
56 {
57 const uint8_t *buf = avpkt->
data;
58 int buf_size = avpkt->
size;
59
63 uint8_t *samples_end;
64
65 if (!buf_size)
66 return 0;
67
68 if (buf_size < 4) {
71 }
72
75 buf += 4;
76
77 if (in_size > buf_size) {
80 }
81
82 /* get output buffer */
88
91 *got_frame_ptr = 1;
92 return buf_size;
93 }
94
95 while (samples < samples_end && buf - avpkt->
data < buf_size) {
97 uint8_t count;
99 count = *buf & 0x3F;
100 buf++;
101
102 /* make sure we don't write past the output buffer */
104 case 0: smp = 4 * (count + 1); break;
105 case 1: smp = 2 * (count + 1); break;
106 case 2: smp = (count & 0x20) ? 1 : count + 1; break;
107 default: smp = count + 1; break;
108 }
109 if (samples_end -
samples < smp)
110 break;
111
112 /* make sure we don't read past the input buffer */
113 size = ((
code == 2 && (count & 0x20)) ||
code == 3) ? 0 : count + 1;
114 if ((buf - avpkt->
data) +
size > buf_size)
115 break;
116
118 case 0: /* ADPCM 2-bit */
119 for (count++; count > 0; count--) {
133 }
134 break;
135 case 1: /* ADPCM 4-bit */
136 for (count++; count > 0; count--) {
144 }
145 break;
146 case 2: /* no compression */
147 if (count & 0x20) { /* big delta */
148 int8_t t;
149 t = count;
150 t <<= 3;
154 } else { /* copy */
157 buf += smp;
159 }
160 break;
161 default: /* run */
164 }
165 }
166
168 *got_frame_ptr = 1;
169
170 return buf_size;
171 }
172
181 };