1 /*
2 * Copyright (C) 2008 Jaikrishnan Menon
3 * Copyright (C) 2011 Stefano Sabatini
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 * 8svx audio decoder
25 * @author Jaikrishnan Menon
26 *
27 * supports: fibonacci delta encoding
28 * : exponential encoding
29 *
30 * For more information about the 8SVX format:
31 * http://netghost.narod.ru/gff/vendspec/iff/iff.txt
32 * http://sox.sourceforge.net/AudioFormats-11.html
33 * http://aminet.net/package/mus/misc/wavepak
34 * http://amigan.1emu.net/reg/8SVX.txt
35 *
36 * Samples can be found here:
37 * http://aminet.net/mods/smpl/
38 */
39
44
45 /** decoder context */
49
50 /* buffer used to store the whole first packet.
51 data is only sent as one large packet */
56
57 static const int8_t
fibonacci[16] = { -34, -21, -13, -8, -5, -3, -2, -1, 0, 1, 2, 3, 5, 8, 13, 21 };
58 static const int8_t
exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32, 64 };
59
60 #define MAX_FRAME_SIZE 2048
61
62 /**
63 * Delta decode the compressed values in src, and put the resulting
64 * decoded samples in dst.
65 *
66 * @param[in,out] state starting value. it is saved for use in the next call.
67 * @param table delta sequence table
68 */
71 {
73
74 while (src_size--) {
76 val = av_clip_uint8(val + table[d & 0xF]);
78 val = av_clip_uint8(val + table[d >> 4]);
80 }
81
83 }
84
85 /** decode a frame */
88 {
91 int buf_size;
93 int hdr_size = 2;
94
95 /* decode and interleave the first packet */
96 if (!esc->
data[0] && avpkt) {
97 int chan_size = avpkt->
size / avctx->
channels - hdr_size;
98
101 }
105 }
106
109 esc->
fib_acc[1] = avpkt->
data[2+chan_size+1] + 128;
110
119 }
120 }
121 memcpy(esc->
data[0], &avpkt->
data[hdr_size], chan_size);
123 memcpy(esc->
data[1], &avpkt->
data[2*hdr_size+chan_size], chan_size);
124 }
128 }
129
130 /* decode next piece of data from the buffer */
132 if (buf_size <= 0) {
133 *got_frame_ptr = 0;
135 }
136
137 /* get output buffer */
141
142 for (ch = 0; ch < avctx->
channels; ch++) {
145 }
146
148
149 *got_frame_ptr = 1;
150
152 }
153
155 {
157
161 }
162
166 default:
169 }
171
172 return 0;
173 }
174
176 {
178
183
184 return 0;
185 }
186
187 #if CONFIG_EIGHTSVX_FIB_DECODER
188 AVCodec ff_eightsvx_fib_decoder = {
200 };
201 #endif
202 #if CONFIG_EIGHTSVX_EXP_DECODER
203 AVCodec ff_eightsvx_exp_decoder = {
215 };
216 #endif