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
41
43
44 #define MAX_CHANNELS 2
45 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
46
61 union {
64 } trans;
66
67
69 {
72 int sample_rate_half;
73 int i;
74 int frame_len_bits;
75
76 /* determine frame length */
78 frame_len_bits = 9;
80 frame_len_bits = 10;
81 } else {
82 frame_len_bits = 11;
83 }
84
88 }
91
93
95 // audio is already interleaved for the RDFT format variant
101 } else {
104 }
105
109 sample_rate_half = (sample_rate + 1) / 2;
112 else
114 for (i = 0; i < 96; i++) {
115 /* constant is result of 0.066399999/log10(M_E) */
117 }
118
119 /* calculate number of bands */
122 break;
123
127
128 /* populate bands data */
133
135
138 else if (CONFIG_BINKAUDIO_DCT_DECODER)
140 else
141 return -1;
142
143 return 0;
144 }
145
147 {
151 f = -f;
152 return f;
153 }
154
156 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
157 };
158
159 /**
160 * Decode Bink Audio block
161 * @param[out] out Output buffer (must contain s->block_size elements)
162 * @return 0 on success, negative error code on failure
163 */
165 {
166 int ch, i, j, k;
170
171 if (use_dct)
173
174 for (ch = 0; ch < s->
channels; ch++) {
176
182 } else {
187 }
188
194 }
195
196 k = 0;
197 q = quant[0];
198
199 // parse coefficients
200 i = 2;
201 while (i < s->frame_len) {
203 j = i + 16;
204 } else {
206 if (v) {
209 } else {
210 j = i + 8;
211 }
212 }
213
215
217 if (width == 0) {
218 memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));
219 i = j;
220 while (s->
bands[k] < i)
221 q = quant[k++];
222 } else {
223 while (i < j) {
224 if (s->
bands[k] == i)
225 q = quant[k++];
227 if (coeff) {
230 if (v)
231 coeffs[i] = -q *
coeff;
232 else
233 coeffs[i] = q *
coeff;
234 } else {
235 coeffs[i] = 0.0f;
236 }
237 i++;
238 }
239 }
240 }
241
242 if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
243 coeffs[0] /= 0.5;
245 }
246 else if (CONFIG_BINKAUDIO_RDFT_DECODER)
248 }
249
250 for (ch = 0; ch < s->
channels; ch++) {
251 int j;
254 j = ch;
256 out[ch][i] = (s->
previous[ch][i] * (count - j) +
257 out[ch][i] * j) /
count;
258 }
261 }
262
264
265 return 0;
266 }
267
269 {
275 else if (CONFIG_BINKAUDIO_DCT_DECODER)
277
278 return 0;
279 }
280
282 {
285 }
286
288 int *got_frame_ptr,
AVPacket *avpkt)
289 {
293 int ret, consumed = 0;
294
297 /* handle end-of-stream */
299 *got_frame_ptr = 0;
300 return 0;
301 }
302 if (avpkt->
size < 4) {
305 }
307 if (!buf)
312 consumed = avpkt->
size;
313
314 /* skip reported size */
316 }
317
318 /* get output buffer */
322
327 }
329
331 *got_frame_ptr = 1;
332
333 return consumed;
334 }
335
337 .
name =
"binkaudio_rdft",
346 };
347
349 .
name =
"binkaudio_dct",
358 };