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
40 {
44 int s0, s1, s2, d;
47
50 for (
i = 0, j = 0; j < 32;
i +=
channels, j++) {
52 d = s0 + ((-
c->coeff[0] * s1 -
c->coeff[1] * s2) >>
COEFF_BITS);
57 s2 = s1;
58 s1 = s0;
59 }
60
61 if (
max == 0 &&
min == 0) {
65 return;
66 }
67
70 else
72
75
77
79
82 for (
i = 0, j = 0; j < 32;
i +=
channels, j++) {
83 d = wav[
i] + ((-
c->coeff[0] * s1 -
c->coeff[1] * s2) >>
COEFF_BITS);
84
86
88
90 s2 = s1;
91 s1 = s0;
92 }
95
97 }
98
99 #define HEADER_SIZE 36
100
102 {
104
105 bytestream_put_be16(&buf, 0x8000); /* header signature */
106 bytestream_put_be16(&buf,
HEADER_SIZE - 4);
/* copyright offset */
107 bytestream_put_byte(&buf, 3); /* encoding */
108 bytestream_put_byte(&buf,
BLOCK_SIZE);
/* block size */
109 bytestream_put_byte(&buf, 4); /* sample size */
111 bytestream_put_be32(&buf, avctx->
sample_rate);
/* sample rate */
112 bytestream_put_be32(&buf, 0); /* total sample count */
113 bytestream_put_be16(&buf,
c->cutoff);
/* cutoff frequency */
114 bytestream_put_byte(&buf, 3); /* version */
115 bytestream_put_byte(&buf, 0); /* flags */
116 bytestream_put_be32(&buf, 0); /* unknown */
117 bytestream_put_be32(&buf, 0); /* loop enabled */
118 bytestream_put_be16(&buf, 0); /* padding */
120
122 }
123
125 {
127
131 }
133
134 /* the cutoff can be adjusted, but this seems to work pretty well */
137
138 return 0;
139 }
140
143 {
149
152 return 0;
157 bytestream_put_be16(&
dst, 0x8001);
158 bytestream_put_be16(&
dst, 0x000E);
159 bytestream_put_be64(&
dst, 0x0);
160 bytestream_put_be32(&
dst, 0x0);
161 bytestream_put_be16(&
dst, 0x0);
162 *got_packet_ptr = 1;
163 return 0;
164 }
165
170
171 if (!
c->header_parsed) {
172 int hdrsize;
176 }
178 c->header_parsed = 1;
179 }
180
184 }
185
186 *got_packet_ptr = 1;
187 return 0;
188 }
189
191 .
p.
name =
"adpcm_adx",
203 };