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) {
227 int v;
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)
312 return ret;
313 consumed = avpkt->
size;
314
315 /* skip reported size */
317 }
318
319 /* get output buffer */
322 return ret;
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 };
union BinkAudioContext::@38 trans
av_cold void ff_rdft_end(RDFTContext *s)
const struct AVCodec * codec
static float get_float(GetBitContext *gb)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_cold int decode_end(AVCodecContext *avctx)
static void skip_bits_long(GetBitContext *s, int n)
static av_cold int init(AVCodecContext *avctx)
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
static const uint8_t rle_length_tab[16]
#define DECLARE_ALIGNED(n, t, v)
const uint16_t ff_wma_critical_freqs[25]
#define AV_CH_LAYOUT_STEREO
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
enum AVSampleFormat sample_fmt
audio sample format
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE/16]
coeffs from previous audio block
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define BINK_BLOCK_MAX_SIZE
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void get_bits_align32(GetBitContext *s)
static int decode_block(BinkAudioContext *s, float **out, int use_dct)
Decode Bink Audio block.
const char * name
Name of the codec implementation.
uint64_t channel_layout
Audio channel layout.
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
audio channel layout utility functions
GLsizei GLboolean const GLfloat * value
static float quant_table[96]
static av_cold int decode_init(AVCodecContext *avctx)
AVCodec ff_binkaudio_rdft_decoder
int overlap_len
overlap size (samples)
Libavcodec external API header.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
int sample_rate
samples per second
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
AVCodec ff_binkaudio_dct_decoder
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
int frame_len
transform size (samples)
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
int version_b
Bink version 'b'.
common internal api header.
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
FFTSample coeffs[BINK_BLOCK_MAX_SIZE]
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static const int16_t coeffs[]
int channels
number of audio channels
static const double coeff[2][5]
av_cold void ff_dct_end(DCTContext *s)
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.