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
31 #include "config_components.h"
32
36
37 #define BITSTREAM_READER_LE
46
47 #define MAX_DCT_CHANNELS 6
48 #define MAX_CHANNELS 2
49 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
50
66 union {
71
72
74 {
77 int sample_rate_half;
79 int frame_len_bits;
82
83 /* determine frame length */
85 frame_len_bits = 9;
87 frame_len_bits = 10;
88 } else {
89 frame_len_bits = 11;
90 }
91
95 }
98
100
102 // audio is already interleaved for the RDFT format variant
110 } else {
113 }
114
115 s->frame_len = 1 << frame_len_bits;
116 s->overlap_len =
s->frame_len / 16;
120 s->root = 2.0 / (sqrt(
s->frame_len) * 32768.0);
121 else
122 s->root =
s->frame_len / (sqrt(
s->frame_len) * 32768.0);
123 for (
i = 0;
i < 96;
i++) {
124 /* constant is result of 0.066399999/log10(M_E) */
125 s->quant_table[
i] =
expf(
i * 0.15289164787221953823
f) *
s->root;
126 }
127
128 /* calculate number of bands */
129 for (
s->num_bands = 1;
s->num_bands < 25;
s->num_bands++)
131 break;
132
133 /* populate bands data */
135 for (
i = 1;
i <
s->num_bands;
i++)
137 s->bands[
s->num_bands] =
s->frame_len;
138
140
143 else if (CONFIG_BINKAUDIO_DCT_DECODER)
145 else
149
151
152 return 0;
153 }
154
156 {
162 }
163
165 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
166 };
167
168 /**
169 * Decode Bink Audio block
170 * @param[out] out Output buffer (must contain s->block_size elements)
171 * @return 0 on success, negative error code on failure
172 */
175 {
180
181 if (use_dct)
183
186
192 } else {
197 }
198
201 for (
i = 0;
i <
s->num_bands;
i++) {
204 }
205
206 k = 0;
208
209 // parse coefficients
211 while (i < s->frame_len) {
214 } else {
216 if (v) {
219 } else {
221 }
222 }
223
224 j =
FFMIN(j,
s->frame_len);
225
228 memset(coeffs +
i, 0, (j -
i) *
sizeof(*coeffs));
230 while (
s->bands[k] <
i)
232 } else {
234 if (
s->bands[k] ==
i)
238 int v;
240 if (v)
242 else
244 } else {
246 }
248 }
249 }
250 }
251
252 if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
253 coeffs[0] /= 0.5;
254 s->trans.dct.dct_calc(&
s->trans.dct, coeffs);
255 }
256 else if (CONFIG_BINKAUDIO_RDFT_DECODER)
257 s->trans.rdft.rdft_calc(&
s->trans.rdft, coeffs);
258 }
259
261 int j;
264 j = ch;
266 out[ch + ch_offset][
i] = (
s->previous[ch + ch_offset][
i] * (count - j) +
267 out[ch + ch_offset][
i] * j) / count;
268 }
269 memcpy(
s->previous[ch + ch_offset], &
out[ch + ch_offset][
s->frame_len -
s->overlap_len],
270 s->overlap_len *
sizeof(*
s->previous[ch + ch_offset]));
271 }
272
274
275 return 0;
276 }
277
279 {
283 else if (CONFIG_BINKAUDIO_DCT_DECODER)
285
286 return 0;
287 }
288
290 {
293 }
294
296 {
300
307 }
308
309 if (
s->pkt->size < 4) {
313 }
314
318
319 /* skip reported size */
321 }
322
323 /* get output buffer */
324 if (
s->ch_offset == 0) {
325 frame->nb_samples =
s->frame_len;
328 }
329
336 }
340 memset(gb, 0, sizeof(*gb));
342 }
343 if (
s->ch_offset >=
s->channels) {
345 } else {
347 }
348
350
351 return 0;
356 }
357
359 {
361
362 /* s->pkt coincides with avctx->internal->in_pkt
363 * and is unreferenced generically when flushing. */
366 }
367
369 .
p.
name =
"binkaudio_rdft",
380 };
381
383 .
p.
name =
"binkaudio_dct",
394 };