FFmpeg
binkaudio.c
Go to the documentation of this file.
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 
32 #include "libavutil/intfloat.h"
33 
34 #define BITSTREAM_READER_LE
35 #include "avcodec.h"
36 #include "dct.h"
37 #include "decode.h"
38 #include "get_bits.h"
39 #include "internal.h"
40 #include "rdft.h"
41 #include "wma_freqs.h"
42 
43 static float quant_table[96];
44 
45 #define MAX_CHANNELS 2
46 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
47 
48 typedef struct BinkAudioContext {
50  int version_b; ///< Bink version 'b'
51  int first;
52  int channels;
53  int frame_len; ///< transform size (samples)
54  int overlap_len; ///< overlap size (samples)
56  int num_bands;
57  unsigned int *bands;
58  float root;
60  float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block
62  union {
65  } trans;
67 
68 
70 {
71  BinkAudioContext *s = avctx->priv_data;
72  int sample_rate = avctx->sample_rate;
73  int sample_rate_half;
74  int i;
75  int frame_len_bits;
76 
77  /* determine frame length */
78  if (avctx->sample_rate < 22050) {
79  frame_len_bits = 9;
80  } else if (avctx->sample_rate < 44100) {
81  frame_len_bits = 10;
82  } else {
83  frame_len_bits = 11;
84  }
85 
86  if (avctx->channels < 1 || avctx->channels > MAX_CHANNELS) {
87  av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", avctx->channels);
88  return AVERROR_INVALIDDATA;
89  }
90  avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
92 
93  s->version_b = avctx->extradata_size >= 4 && avctx->extradata[3] == 'b';
94 
95  if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) {
96  // audio is already interleaved for the RDFT format variant
98  sample_rate *= avctx->channels;
99  s->channels = 1;
100  if (!s->version_b)
101  frame_len_bits += av_log2(avctx->channels);
102  } else {
103  s->channels = avctx->channels;
105  }
106 
107  s->frame_len = 1 << frame_len_bits;
108  s->overlap_len = s->frame_len / 16;
109  s->block_size = (s->frame_len - s->overlap_len) * s->channels;
110  sample_rate_half = (sample_rate + 1) / 2;
111  if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
112  s->root = 2.0 / (sqrt(s->frame_len) * 32768.0);
113  else
114  s->root = s->frame_len / (sqrt(s->frame_len) * 32768.0);
115  for (i = 0; i < 96; i++) {
116  /* constant is result of 0.066399999/log10(M_E) */
117  quant_table[i] = expf(i * 0.15289164787221953823f) * s->root;
118  }
119 
120  /* calculate number of bands */
121  for (s->num_bands = 1; s->num_bands < 25; s->num_bands++)
122  if (sample_rate_half <= ff_wma_critical_freqs[s->num_bands - 1])
123  break;
124 
125  s->bands = av_malloc((s->num_bands + 1) * sizeof(*s->bands));
126  if (!s->bands)
127  return AVERROR(ENOMEM);
128 
129  /* populate bands data */
130  s->bands[0] = 2;
131  for (i = 1; i < s->num_bands; i++)
132  s->bands[i] = (ff_wma_critical_freqs[i - 1] * s->frame_len / sample_rate_half) & ~1;
133  s->bands[s->num_bands] = s->frame_len;
134 
135  s->first = 1;
136 
137  if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
138  ff_rdft_init(&s->trans.rdft, frame_len_bits, DFT_C2R);
139  else if (CONFIG_BINKAUDIO_DCT_DECODER)
140  ff_dct_init(&s->trans.dct, frame_len_bits, DCT_III);
141  else
142  av_assert0(0);
143 
144  s->pkt = av_packet_alloc();
145  if (!s->pkt)
146  return AVERROR(ENOMEM);
147 
148  return 0;
149 }
150 
151 static float get_float(GetBitContext *gb)
152 {
153  int power = get_bits(gb, 5);
154  float f = ldexpf(get_bits_long(gb, 23), power - 23);
155  if (get_bits1(gb))
156  f = -f;
157  return f;
158 }
159 
160 static const uint8_t rle_length_tab[16] = {
161  2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
162 };
163 
164 /**
165  * Decode Bink Audio block
166  * @param[out] out Output buffer (must contain s->block_size elements)
167  * @return 0 on success, negative error code on failure
168  */
169 static int decode_block(BinkAudioContext *s, float **out, int use_dct)
170 {
171  int ch, i, j, k;
172  float q, quant[25];
173  int width, coeff;
174  GetBitContext *gb = &s->gb;
175 
176  if (use_dct)
177  skip_bits(gb, 2);
178 
179  for (ch = 0; ch < s->channels; ch++) {
180  FFTSample *coeffs = out[ch];
181 
182  if (s->version_b) {
183  if (get_bits_left(gb) < 64)
184  return AVERROR_INVALIDDATA;
185  coeffs[0] = av_int2float(get_bits_long(gb, 32)) * s->root;
186  coeffs[1] = av_int2float(get_bits_long(gb, 32)) * s->root;
187  } else {
188  if (get_bits_left(gb) < 58)
189  return AVERROR_INVALIDDATA;
190  coeffs[0] = get_float(gb) * s->root;
191  coeffs[1] = get_float(gb) * s->root;
192  }
193 
194  if (get_bits_left(gb) < s->num_bands * 8)
195  return AVERROR_INVALIDDATA;
196  for (i = 0; i < s->num_bands; i++) {
197  int value = get_bits(gb, 8);
198  quant[i] = quant_table[FFMIN(value, 95)];
199  }
200 
201  k = 0;
202  q = quant[0];
203 
204  // parse coefficients
205  i = 2;
206  while (i < s->frame_len) {
207  if (s->version_b) {
208  j = i + 16;
209  } else {
210  int v = get_bits1(gb);
211  if (v) {
212  v = get_bits(gb, 4);
213  j = i + rle_length_tab[v] * 8;
214  } else {
215  j = i + 8;
216  }
217  }
218 
219  j = FFMIN(j, s->frame_len);
220 
221  width = get_bits(gb, 4);
222  if (width == 0) {
223  memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));
224  i = j;
225  while (s->bands[k] < i)
226  q = quant[k++];
227  } else {
228  while (i < j) {
229  if (s->bands[k] == i)
230  q = quant[k++];
231  coeff = get_bits(gb, width);
232  if (coeff) {
233  int v;
234  v = get_bits1(gb);
235  if (v)
236  coeffs[i] = -q * coeff;
237  else
238  coeffs[i] = q * coeff;
239  } else {
240  coeffs[i] = 0.0f;
241  }
242  i++;
243  }
244  }
245  }
246 
247  if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
248  coeffs[0] /= 0.5;
249  s->trans.dct.dct_calc(&s->trans.dct, coeffs);
250  }
251  else if (CONFIG_BINKAUDIO_RDFT_DECODER)
252  s->trans.rdft.rdft_calc(&s->trans.rdft, coeffs);
253  }
254 
255  for (ch = 0; ch < s->channels; ch++) {
256  int j;
257  int count = s->overlap_len * s->channels;
258  if (!s->first) {
259  j = ch;
260  for (i = 0; i < s->overlap_len; i++, j += s->channels)
261  out[ch][i] = (s->previous[ch][i] * (count - j) +
262  out[ch][i] * j) / count;
263  }
264  memcpy(s->previous[ch], &out[ch][s->frame_len - s->overlap_len],
265  s->overlap_len * sizeof(*s->previous[ch]));
266  }
267 
268  s->first = 0;
269 
270  return 0;
271 }
272 
274 {
275  BinkAudioContext * s = avctx->priv_data;
276  av_freep(&s->bands);
277  if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
278  ff_rdft_end(&s->trans.rdft);
279  else if (CONFIG_BINKAUDIO_DCT_DECODER)
280  ff_dct_end(&s->trans.dct);
281 
282  av_packet_free(&s->pkt);
283 
284  return 0;
285 }
286 
288 {
289  int n = (-get_bits_count(s)) & 31;
290  if (n) skip_bits(s, n);
291 }
292 
294 {
295  BinkAudioContext *s = avctx->priv_data;
296  GetBitContext *gb = &s->gb;
297  int ret;
298 
299  if (!s->pkt->data) {
300  ret = ff_decode_get_packet(avctx, s->pkt);
301  if (ret < 0)
302  return ret;
303 
304  if (s->pkt->size < 4) {
305  av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
306  ret = AVERROR_INVALIDDATA;
307  goto fail;
308  }
309 
310  ret = init_get_bits8(gb, s->pkt->data, s->pkt->size);
311  if (ret < 0)
312  goto fail;
313 
314  /* skip reported size */
315  skip_bits_long(gb, 32);
316  }
317 
318  /* get output buffer */
319  frame->nb_samples = s->frame_len;
320  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
321  return ret;
322 
323  if (decode_block(s, (float **)frame->extended_data,
324  avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT)) {
325  av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n");
326  return AVERROR_INVALIDDATA;
327  }
328  get_bits_align32(gb);
329  if (!get_bits_left(gb)) {
330  memset(gb, 0, sizeof(*gb));
331  av_packet_unref(s->pkt);
332  }
333 
334  frame->nb_samples = s->block_size / avctx->channels;
335 
336  return 0;
337 fail:
338  av_packet_unref(s->pkt);
339  return ret;
340 }
341 
343  .name = "binkaudio_rdft",
344  .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)"),
345  .type = AVMEDIA_TYPE_AUDIO,
347  .priv_data_size = sizeof(BinkAudioContext),
348  .init = decode_init,
349  .close = decode_end,
351  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
352 };
353 
355  .name = "binkaudio_dct",
356  .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)"),
357  .type = AVMEDIA_TYPE_AUDIO,
359  .priv_data_size = sizeof(BinkAudioContext),
360  .init = decode_init,
361  .close = decode_end,
363  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
364 };
av_cold void ff_rdft_end(RDFTContext *s)
Definition: rdft.c:114
float, planar
Definition: samplefmt.h:69
const struct AVCodec * codec
Definition: avcodec.h:1565
static float get_float(GetBitContext *gb)
Definition: binkaudio.c:151
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define MAX_CHANNELS
Definition: binkaudio.c:45
This structure describes decoded (raw) audio or video data.
Definition: frame.h:268
Definition: avfft.h:75
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:381
static av_cold int decode_end(AVCodecContext *avctx)
Definition: binkaudio.c:273
Definition: avfft.h:95
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:293
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
Definition: intfloat.h:40
static const uint8_t rle_length_tab[16]
Definition: binkaudio.c:160
int size
Definition: avcodec.h:1469
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63)))#define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};static void cpy1(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, len);}static void cpy2(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 2 *len);}static void cpy4(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 4 *len);}static void cpy8(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;}void swri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len){int ch;int off=0;const int os=(out->planar?1:out->ch_count)*out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){int planes=in->planar?in->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){int planes=out->planar?out->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){int planes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
int av_log2(unsigned v)
Definition: intmath.c:26
const uint16_t ff_wma_critical_freqs[25]
Definition: wma_freqs.c:23
static CopyRet receive_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame)
Definition: crystalhd.c:560
#define AV_CH_LAYOUT_STEREO
AVCodec.
Definition: avcodec.h:3468
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:997
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:62
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2220
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
#define f(width, name)
Definition: cbs_vp9.c:255
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition: decode.c:329
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1657
unsigned int * bands
Definition: binkaudio.c:57
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
uint8_t * data
Definition: avcodec.h:1468
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: binkaudio.c:293
bitstream reader API header.
float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE/16]
coeffs from previous audio block
Definition: binkaudio.c:60
#define av_log(a,...)
#define expf(x)
Definition: libm.h:283
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:815
enum AVCodecID id
Definition: avcodec.h:3482
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define BINK_BLOCK_MAX_SIZE
Definition: binkaudio.c:46
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static void get_bits_align32(GetBitContext *s)
Definition: binkaudio.c:287
static int decode_block(BinkAudioContext *s, float **out, int use_dct)
Decode Bink Audio block.
Definition: binkaudio.c:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:3475
GLsizei count
Definition: opengl_enc.c:109
float FFTSample
Definition: avfft.h:35
#define fail()
Definition: checkasm.h:118
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2263
GetBitContext gb
Definition: binkaudio.c:49
audio channel layout utility functions
#define FFMIN(a, b)
Definition: common.h:96
#define width
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
Definition: dct.h:38
static float quant_table[96]
Definition: binkaudio.c:43
DCTContext dct
Definition: binkaudio.c:64
Definition: dct.h:32
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define s(width, name)
Definition: cbs_vp9.c:257
static av_cold int decode_init(AVCodecContext *avctx)
Definition: binkaudio.c:69
int n
Definition: avisynth_c.h:684
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
Definition: rdft.h:38
AVCodec ff_binkaudio_rdft_decoder
Definition: binkaudio.c:342
int overlap_len
overlap size (samples)
Definition: binkaudio.c:54
sample_rate
Libavcodec external API header.
int sample_rate
samples per second
Definition: avcodec.h:2212
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:651
AVCodec ff_binkaudio_dct_decoder
Definition: binkaudio.c:354
main external API structure.
Definition: avcodec.h:1556
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:598
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1919
#define ldexpf(x, exp)
Definition: libm.h:389
int extradata_size
Definition: avcodec.h:1658
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:488
AVPacket * pkt
Definition: binkaudio.c:61
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:461
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
Definition: dct.c:177
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:532
const uint8_t * quant
int frame_len
transform size (samples)
Definition: binkaudio.c:53
int version_b
Bink version &#39;b&#39;.
Definition: binkaudio.c:50
common internal api header.
union BinkAudioContext::@45 trans
RDFTContext rdft
Definition: binkaudio.c:63
FFTSample coeffs[BINK_BLOCK_MAX_SIZE]
Definition: binkaudio.c:59
void * priv_data
Definition: avcodec.h:1583
int channels
number of audio channels
Definition: avcodec.h:2213
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:51
static const double coeff[2][5]
Definition: vf_owdenoise.c:72
av_cold void ff_dct_end(DCTContext *s)
Definition: dct.c:221
FILE * out
Definition: movenc.c:54
#define av_freep(p)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:315
#define AV_CH_LAYOUT_MONO
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
Definition: rdft.c:88
This structure stores compressed data.
Definition: avcodec.h:1445
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:334
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:972