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
37
38 #define BITSTREAM_READER_LE
45
46 #define MAX_DCT_CHANNELS 6
47 #define MAX_CHANNELS 2
48 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
49
68
69
71 {
74 int sample_rate_half;
76 int frame_len_bits;
79
80 /* determine frame length */
82 frame_len_bits = 9;
84 frame_len_bits = 10;
85 } else {
86 frame_len_bits = 11;
87 }
88
92 }
95
97
99 // audio is already interleaved for the RDFT format variant
101 if (sample_rate > INT_MAX /
channels)
107 } else {
110 }
111
112 s->frame_len = 1 << frame_len_bits;
113 s->overlap_len =
s->frame_len / 16;
115 sample_rate_half = (sample_rate + 1LL) / 2;
117 s->root = 2.0 / (sqrt(
s->frame_len) * 32768.0);
118 else
119 s->root =
s->frame_len / (sqrt(
s->frame_len) * 32768.0);
120 for (
i = 0;
i < 96;
i++) {
121 /* constant is result of 0.066399999/log10(M_E) */
122 s->quant_table[
i] =
expf(
i * 0.15289164787221953823
f) *
s->root;
123 }
124
125 /* calculate number of bands */
126 for (
s->num_bands = 1;
s->num_bands < 25;
s->num_bands++)
128 break;
129
130 /* populate bands data */
132 for (
i = 1;
i <
s->num_bands;
i++)
134 s->bands[
s->num_bands] =
s->frame_len;
135
137
141 } else if (CONFIG_BINKAUDIO_DCT_DECODER) {
142 float scale = 1.0 / (1 << frame_len_bits);
144 } else {
146 }
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 {
181
182 if (use_dct)
184
191 } else {
196 }
197
200 for (
i = 0;
i <
s->num_bands;
i++) {
203 }
204
205 k = 0;
207
208 // parse coefficients
210 while (i < s->frame_len) {
213 } else {
215 if (v) {
218 } else {
220 }
221 }
222
223 j =
FFMIN(j,
s->frame_len);
224
227 memset(coeffs +
i, 0, (j -
i) *
sizeof(*coeffs));
229 while (
s->bands[k] <
i)
231 } else {
233 if (
s->bands[k] ==
i)
237 int v;
239 if (v)
241 else
243 } else {
245 }
247 }
248 }
249 }
250
251 if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
252 coeffs[0] /= 0.5;
253 s->tx_fn(
s->tx,
out[ch + ch_offset], coeffs,
sizeof(
float));
254 } else if (CONFIG_BINKAUDIO_RDFT_DECODER) {
255 for (
int i = 2;
i <
s->frame_len;
i += 2)
257
258 coeffs[
s->frame_len + 0] = coeffs[1];
259 coeffs[
s->frame_len + 1] = coeffs[1] = 0;
261 }
262 }
263
265 int j;
268 j = ch;
270 out[ch + ch_offset][
i] = (
s->previous[ch + ch_offset][
i] * (count - j) +
271 out[ch + ch_offset][
i] * j) / count;
272 }
273 memcpy(
s->previous[ch + ch_offset], &
out[ch + ch_offset][
s->frame_len -
s->overlap_len],
274 s->overlap_len *
sizeof(*
s->previous[ch + ch_offset]));
275 }
276
278
279 return 0;
280 }
281
283 {
286 return 0;
287 }
288
290 {
293 }
294
296 {
300
302 new_pkt = !
s->pkt->data;
308 }
309
310 if (
s->pkt->size < 4) {
314 }
315
319
320 /* skip reported size */
322 }
323
324 /* get output buffer */
325 if (
s->ch_offset == 0) {
326 frame->nb_samples =
s->frame_len;
329 if (!new_pkt)
331 }
332
339 }
343 memset(gb, 0, sizeof(*gb));
345 }
346 if (
s->ch_offset >=
s->channels) {
348 } else {
350 }
351
353
354 return 0;
359 }
360
362 {
364
365 /* s->pkt coincides with avctx->internal->in_pkt
366 * and is unreferenced generically when flushing. */
369 }
370
372 .
p.
name =
"binkaudio_rdft",
383 };
384
386 .
p.
name =
"binkaudio_dct",
397 };