1 /*
2 * Bink Audio decoder
3 * Copyright (c) 2007-2011 Peter Ross (pross@xvid.org)
4 * Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu)
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * Bink Audio decoder
26 *
27 * Technical details here:
28 * http://wiki.multimedia.cx/index.php?title=Bink_Audio
29 */
30
33 #define BITSTREAM_READER_LE
40
42
43 #define MAX_CHANNELS 2
44 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
45
60 union {
65
66
68 {
71 int sample_rate_half;
72 int i;
73 int frame_len_bits;
74
75 /* determine frame length */
77 frame_len_bits = 9;
79 frame_len_bits = 10;
80 } else {
81 frame_len_bits = 11;
82 }
83
87 }
90
92
94 // audio is already interleaved for the RDFT format variant
100 } else {
103 }
104
108 sample_rate_half = (sample_rate + 1) / 2;
111 else
113 for (i = 0; i < 96; i++) {
114 /* constant is result of 0.066399999/log10(M_E) */
116 }
117
118 /* calculate number of bands */
121 break;
122
126
127 /* populate bands data */
132
134
137 else if (CONFIG_BINKAUDIO_DCT_DECODER)
139 else
140 return -1;
141
142 return 0;
143 }
144
146 {
150 f = -f;
151 return f;
152 }
153
155 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
156 };
157
158 /**
159 * Decode Bink Audio block
160 * @param[out] out Output buffer (must contain s->block_size elements)
161 * @return 0 on success, negative error code on failure
162 */
164 {
165 int ch, i, j, k;
169
170 if (use_dct)
172
173 for (ch = 0; ch < s->
channels; ch++) {
175
181 } else {
186 }
187
193 }
194
195 k = 0;
196 q = quant[0];
197
198 // parse coefficients
199 i = 2;
200 while (i < s->frame_len) {
202 j = i + 16;
203 } else {
205 if (v) {
208 } else {
209 j = i + 8;
210 }
211 }
212
214
216 if (width == 0) {
217 memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));
218 i = j;
219 while (s->
bands[k] < i)
220 q = quant[k++];
221 } else {
222 while (i < j) {
223 if (s->
bands[k] == i)
224 q = quant[k++];
226 if (coeff) {
229 if (v)
230 coeffs[i] = -q *
coeff;
231 else
232 coeffs[i] = q *
coeff;
233 } else {
234 coeffs[i] = 0.0f;
235 }
236 i++;
237 }
238 }
239 }
240
241 if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
242 coeffs[0] /= 0.5;
244 }
245 else if (CONFIG_BINKAUDIO_RDFT_DECODER)
247 }
248
249 for (ch = 0; ch < s->
channels; ch++) {
250 int j;
253 j = ch;
255 out[ch][i] = (s->
previous[ch][i] * (count - j) +
256 out[ch][i] * j) /
count;
257 }
260 }
261
263
264 return 0;
265 }
266
268 {
274 else if (CONFIG_BINKAUDIO_DCT_DECODER)
276
277 return 0;
278 }
279
281 {
284 }
285
287 int *got_frame_ptr,
AVPacket *avpkt)
288 {
292 int ret, consumed = 0;
293
296 /* handle end-of-stream */
298 *got_frame_ptr = 0;
299 return 0;
300 }
301 if (avpkt->
size < 4) {
304 }
306 if (!buf)
313 consumed = avpkt->
size;
314
315 /* skip reported size */
317 }
318
319 /* get output buffer */
323
328 }
330
332 *got_frame_ptr = 1;
333
334 return consumed;
335 }
336
338 .
name =
"binkaudio_rdft",
347 };
348
350 .
name =
"binkaudio_dct",
359 };