FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "get_bits.h"
38 #include "internal.h"
39 #include "rdft.h"
40 #include "wma_freqs.h"
41 
42 static float quant_table[96];
43 
44 #define MAX_CHANNELS 2
45 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
46 
47 typedef struct BinkAudioContext {
49  int version_b; ///< Bink version 'b'
50  int first;
51  int channels;
52  int frame_len; ///< transform size (samples)
53  int overlap_len; ///< overlap size (samples)
55  int num_bands;
56  unsigned int *bands;
57  float root;
59  float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block
61  union {
64  } trans;
66 
67 
69 {
70  BinkAudioContext *s = avctx->priv_data;
71  int sample_rate = avctx->sample_rate;
72  int sample_rate_half;
73  int i;
74  int frame_len_bits;
75 
76  /* determine frame length */
77  if (avctx->sample_rate < 22050) {
78  frame_len_bits = 9;
79  } else if (avctx->sample_rate < 44100) {
80  frame_len_bits = 10;
81  } else {
82  frame_len_bits = 11;
83  }
84 
85  if (avctx->channels < 1 || avctx->channels > MAX_CHANNELS) {
86  av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", avctx->channels);
87  return AVERROR_INVALIDDATA;
88  }
89  avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
91 
92  s->version_b = avctx->extradata_size >= 4 && avctx->extradata[3] == 'b';
93 
94  if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) {
95  // audio is already interleaved for the RDFT format variant
97  sample_rate *= avctx->channels;
98  s->channels = 1;
99  if (!s->version_b)
100  frame_len_bits += av_log2(avctx->channels);
101  } else {
102  s->channels = avctx->channels;
104  }
105 
106  s->frame_len = 1 << frame_len_bits;
107  s->overlap_len = s->frame_len / 16;
108  s->block_size = (s->frame_len - s->overlap_len) * s->channels;
109  sample_rate_half = (sample_rate + 1) / 2;
110  if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
111  s->root = 2.0 / (sqrt(s->frame_len) * 32768.0);
112  else
113  s->root = s->frame_len / (sqrt(s->frame_len) * 32768.0);
114  for (i = 0; i < 96; i++) {
115  /* constant is result of 0.066399999/log10(M_E) */
116  quant_table[i] = expf(i * 0.15289164787221953823f) * s->root;
117  }
118 
119  /* calculate number of bands */
120  for (s->num_bands = 1; s->num_bands < 25; s->num_bands++)
121  if (sample_rate_half <= ff_wma_critical_freqs[s->num_bands - 1])
122  break;
123 
124  s->bands = av_malloc((s->num_bands + 1) * sizeof(*s->bands));
125  if (!s->bands)
126  return AVERROR(ENOMEM);
127 
128  /* populate bands data */
129  s->bands[0] = 2;
130  for (i = 1; i < s->num_bands; i++)
131  s->bands[i] = (ff_wma_critical_freqs[i - 1] * s->frame_len / sample_rate_half) & ~1;
132  s->bands[s->num_bands] = s->frame_len;
133 
134  s->first = 1;
135 
136  if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
137  ff_rdft_init(&s->trans.rdft, frame_len_bits, DFT_C2R);
138  else if (CONFIG_BINKAUDIO_DCT_DECODER)
139  ff_dct_init(&s->trans.dct, frame_len_bits, DCT_III);
140  else
141  return -1;
142 
143  return 0;
144 }
145 
146 static float get_float(GetBitContext *gb)
147 {
148  int power = get_bits(gb, 5);
149  float f = ldexpf(get_bits_long(gb, 23), power - 23);
150  if (get_bits1(gb))
151  f = -f;
152  return f;
153 }
154 
155 static const uint8_t rle_length_tab[16] = {
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  */
164 static int decode_block(BinkAudioContext *s, float **out, int use_dct)
165 {
166  int ch, i, j, k;
167  float q, quant[25];
168  int width, coeff;
169  GetBitContext *gb = &s->gb;
170 
171  if (use_dct)
172  skip_bits(gb, 2);
173 
174  for (ch = 0; ch < s->channels; ch++) {
175  FFTSample *coeffs = out[ch];
176 
177  if (s->version_b) {
178  if (get_bits_left(gb) < 64)
179  return AVERROR_INVALIDDATA;
180  coeffs[0] = av_int2float(get_bits_long(gb, 32)) * s->root;
181  coeffs[1] = av_int2float(get_bits_long(gb, 32)) * s->root;
182  } else {
183  if (get_bits_left(gb) < 58)
184  return AVERROR_INVALIDDATA;
185  coeffs[0] = get_float(gb) * s->root;
186  coeffs[1] = get_float(gb) * s->root;
187  }
188 
189  if (get_bits_left(gb) < s->num_bands * 8)
190  return AVERROR_INVALIDDATA;
191  for (i = 0; i < s->num_bands; i++) {
192  int value = get_bits(gb, 8);
193  quant[i] = quant_table[FFMIN(value, 95)];
194  }
195 
196  k = 0;
197  q = quant[0];
198 
199  // parse coefficients
200  i = 2;
201  while (i < s->frame_len) {
202  if (s->version_b) {
203  j = i + 16;
204  } else {
205  int v = get_bits1(gb);
206  if (v) {
207  v = get_bits(gb, 4);
208  j = i + rle_length_tab[v] * 8;
209  } else {
210  j = i + 8;
211  }
212  }
213 
214  j = FFMIN(j, s->frame_len);
215 
216  width = get_bits(gb, 4);
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++];
226  coeff = get_bits(gb, width);
227  if (coeff) {
228  int v;
229  v = get_bits1(gb);
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;
244  s->trans.dct.dct_calc(&s->trans.dct, coeffs);
245  }
246  else if (CONFIG_BINKAUDIO_RDFT_DECODER)
247  s->trans.rdft.rdft_calc(&s->trans.rdft, coeffs);
248  }
249 
250  for (ch = 0; ch < s->channels; ch++) {
251  int j;
252  int count = s->overlap_len * s->channels;
253  if (!s->first) {
254  j = ch;
255  for (i = 0; i < s->overlap_len; i++, j += s->channels)
256  out[ch][i] = (s->previous[ch][i] * (count - j) +
257  out[ch][i] * j) / count;
258  }
259  memcpy(s->previous[ch], &out[ch][s->frame_len - s->overlap_len],
260  s->overlap_len * sizeof(*s->previous[ch]));
261  }
262 
263  s->first = 0;
264 
265  return 0;
266 }
267 
269 {
270  BinkAudioContext * s = avctx->priv_data;
271  av_freep(&s->bands);
272  av_freep(&s->packet_buffer);
273  if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
274  ff_rdft_end(&s->trans.rdft);
275  else if (CONFIG_BINKAUDIO_DCT_DECODER)
276  ff_dct_end(&s->trans.dct);
277 
278  return 0;
279 }
280 
282 {
283  int n = (-get_bits_count(s)) & 31;
284  if (n) skip_bits(s, n);
285 }
286 
287 static int decode_frame(AVCodecContext *avctx, void *data,
288  int *got_frame_ptr, AVPacket *avpkt)
289 {
290  BinkAudioContext *s = avctx->priv_data;
291  AVFrame *frame = data;
292  GetBitContext *gb = &s->gb;
293  int ret, consumed = 0;
294 
295  if (!get_bits_left(gb)) {
296  uint8_t *buf;
297  /* handle end-of-stream */
298  if (!avpkt->size) {
299  *got_frame_ptr = 0;
300  return 0;
301  }
302  if (avpkt->size < 4) {
303  av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
304  return AVERROR_INVALIDDATA;
305  }
307  if (!buf)
308  return AVERROR(ENOMEM);
309  memset(buf + avpkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
310  s->packet_buffer = buf;
311  memcpy(s->packet_buffer, avpkt->data, avpkt->size);
312  if ((ret = init_get_bits8(gb, s->packet_buffer, avpkt->size)) < 0)
313  return ret;
314  consumed = avpkt->size;
315 
316  /* skip reported size */
317  skip_bits_long(gb, 32);
318  }
319 
320  /* get output buffer */
321  frame->nb_samples = s->frame_len;
322  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
323  return ret;
324 
325  if (decode_block(s, (float **)frame->extended_data,
326  avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT)) {
327  av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n");
328  return AVERROR_INVALIDDATA;
329  }
330  get_bits_align32(gb);
331 
332  frame->nb_samples = s->block_size / avctx->channels;
333  *got_frame_ptr = 1;
334 
335  return consumed;
336 }
337 
339  .name = "binkaudio_rdft",
340  .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)"),
341  .type = AVMEDIA_TYPE_AUDIO,
343  .priv_data_size = sizeof(BinkAudioContext),
344  .init = decode_init,
345  .close = decode_end,
346  .decode = decode_frame,
347  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
348 };
349 
351  .name = "binkaudio_dct",
352  .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)"),
353  .type = AVMEDIA_TYPE_AUDIO,
355  .priv_data_size = sizeof(BinkAudioContext),
356  .init = decode_init,
357  .close = decode_end,
358  .decode = decode_frame,
359  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
360 };
av_cold void ff_rdft_end(RDFTContext *s)
Definition: rdft.c:132
float, planar
Definition: samplefmt.h:69
const struct AVCodec * codec
Definition: avcodec.h:1741
static float get_float(GetBitContext *gb)
Definition: binkaudio.c:146
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define MAX_CHANNELS
Definition: binkaudio.c:44
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
Definition: avfft.h:75
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
Definition: dct.h:38
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:135
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
static av_cold int decode_end(AVCodecContext *avctx)
Definition: binkaudio.c:268
Definition: avfft.h:95
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:204
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:155
int size
Definition: avcodec.h:1658
int av_log2(unsigned v)
Definition: intmath.c:26
uint8_t * packet_buffer
Definition: binkaudio.c:60
const uint16_t ff_wma_critical_freqs[25]
Definition: wma_freqs.c:23
#define AV_CH_LAYOUT_STEREO
AVCodec.
Definition: avcodec.h:3681
#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:1019
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2502
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1847
unsigned int * bands
Definition: binkaudio.c:56
static AVFrame * frame
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:104
uint8_t * data
Definition: avcodec.h:1657
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:199
bitstream reader API header.
float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE/16]
coeffs from previous audio block
Definition: binkaudio.c:59
#define av_log(a,...)
#define expf(x)
Definition: libm.h:283
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:587
enum AVCodecID id
Definition: avcodec.h:3695
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define BINK_BLOCK_MAX_SIZE
Definition: binkaudio.c:45
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
static void get_bits_align32(GetBitContext *s)
Definition: binkaudio.c:281
static int decode_block(BinkAudioContext *s, float **out, int use_dct)
Decode Bink Audio block.
Definition: binkaudio.c:164
const char * name
Name of the codec implementation.
Definition: avcodec.h:3688
GLsizei count
Definition: opengl_enc.c:109
float FFTSample
Definition: avfft.h:35
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2545
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
Definition: rdft.h:60
GetBitContext gb
Definition: binkaudio.c:48
audio channel layout utility functions
#define FFMIN(a, b)
Definition: common.h:96
#define width
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
static float quant_table[96]
Definition: binkaudio.c:42
DCTContext dct
Definition: binkaudio.c:63
Definition: dct.h:32
static av_cold int decode_init(AVCodecContext *avctx)
Definition: binkaudio.c:68
int n
Definition: avisynth_c.h:684
AVCodec ff_binkaudio_rdft_decoder
Definition: binkaudio.c:338
int overlap_len
overlap size (samples)
Definition: binkaudio.c:53
sample_rate
Libavcodec external API header.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: binkaudio.c:287
int sample_rate
samples per second
Definition: avcodec.h:2494
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:456
AVCodec ff_binkaudio_dct_decoder
Definition: binkaudio.c:350
main external API structure.
Definition: avcodec.h:1732
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:953
#define ldexpf(x, exp)
Definition: libm.h:389
void * buf
Definition: avisynth_c.h:690
int extradata_size
Definition: avcodec.h:1848
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:313
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:306
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:346
const uint8_t * quant
int frame_len
transform size (samples)
Definition: binkaudio.c:52
int version_b
Bink version 'b'.
Definition: binkaudio.c:49
common internal api header.
RDFTContext rdft
Definition: binkaudio.c:62
FFTSample coeffs[BINK_BLOCK_MAX_SIZE]
Definition: binkaudio.c:58
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_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),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){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) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;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)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&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);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:769
void * priv_data
Definition: avcodec.h:1774
static const int16_t coeffs[]
int channels
number of audio channels
Definition: avcodec.h:2495
static const double coeff[2][5]
Definition: vf_owdenoise.c:72
av_cold void ff_dct_end(DCTContext *s)
Definition: dct.c:220
FILE * out
Definition: movenc.c:54
#define av_freep(p)
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: ffmpeg.c:2257
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:234
#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:99
union BinkAudioContext::@50 trans
This structure stores compressed data.
Definition: avcodec.h:1634
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:244
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:994