1 /*
2 * ADX ADPCM codecs
3 * Copyright (c) 2001,2003 BERO
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
28
29 /**
30 * @file
31 * SEGA CRI adx codecs.
32 *
33 * Reference documents:
34 * http://ku-www.ss.titech.ac.jp/~yatsushi/adx.html
35 * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/
36 */
37
38 /**
39 * Decode ADX stream header.
40 * Sets avctx->channels and avctx->sample_rate.
41 *
42 * @param avctx codec context
43 * @param buf header data
44 * @param bufsize data size, should be at least 24 bytes
45 * @param[out] header_size size of ADX header
46 * @param[out] coeff 2 LPC coefficients, can be NULL
47 * @return data offset or negative error code if header is invalid
48 */
50 int bufsize,
int *header_size,
int *
coeff)
51 {
53
54 if (bufsize < 24)
56
60
61 /* if copyright string is within the provided data, validate it */
64
65 /* check for encoding=3 block_size=18, sample_size=4 */
66 if (buf[4] != 3 || buf[5] != 18 || buf[6] != 4) {
69 }
70
71 /* channels */
75
80 }
81
82 /* sample rate */
87
88 /* bit rate */
90
91 /* LPC coefficients */
95 }
96
98 return 0;
99 }
100
102 {
104 int ret, header_size;
105
112 }
114 c->header_parsed = 1;
115 }
116
118
119 return 0;
120 }
121
122 /**
123 * Decode 32 samples from 18 bytes.
124 *
125 * A 16-bit scalar value is applied to 32 residuals, which then have a
126 * 2nd-order LPC filter applied to it to form the output signal for a single
127 * channel.
128 */
130 const uint8_t *in, int ch)
131 {
136 int s0, s1, s2, d;
137
138 /* check if this is an EOF packet */
140 return -1;
141
149 s2 = s1;
152 }
155
156 return 0;
157 }
158
160 int *got_frame_ptr,
AVPacket *avpkt)
161 {
162 int buf_size = avpkt->
size;
165 int samples_offset;
166 const uint8_t *buf = avpkt->
data;
167 const uint8_t *buf_end = buf + avpkt->
size;
168 int num_blocks, ch,
ret;
169 size_t new_extradata_size;
170 uint8_t *new_extradata;
171
173 &new_extradata_size);
174 if (new_extradata && new_extradata_size > 0) {
175 int header_size;
177 new_extradata_size, &header_size,
181 }
182
184 }
185
187 *got_frame_ptr = 0;
188 return buf_size;
189 }
190
191 if (!
c->header_parsed && buf_size >= 2 &&
AV_RB16(buf) == 0x8000) {
192 int header_size;
197 }
199 c->header_parsed = 1;
200 if (buf_size < header_size)
202 buf += header_size;
203 buf_size -= header_size;
204 }
205 if (!
c->header_parsed)
207
208 /* calculate number of blocks in the packet */
209 num_blocks = buf_size / (
BLOCK_SIZE *
c->channels);
210
211 /* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF
212 packet */
213 if (!num_blocks || buf_size % (
BLOCK_SIZE *
c->channels)) {
214 if (buf_size >= 4 && (
AV_RB16(buf) & 0x8000)) {
216 *got_frame_ptr = 0;
218 }
220 }
221
222 /* get output buffer */
227 samples_offset = 0;
228
229 while (num_blocks--) {
230 for (ch = 0; ch <
c->channels; ch++) {
234 break;
235 }
238 }
241 }
242
243 frame->nb_samples = samples_offset;
244 *got_frame_ptr = 1;
245
246 return buf - avpkt->
data;
247 }
248
250 {
252 memset(
c->prev, 0,
sizeof(
c->prev));
254 }
255
257 .
p.
name =
"adpcm_adx",
269 };