31#include "config_components.h"
39#define BITSTREAM_READER_LE
47#define MAX_DCT_CHANNELS 6
49#define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
102 if (sample_rate > INT_MAX /
channels)
113 s->frame_len = 1 << frame_len_bits;
114 s->overlap_len =
s->frame_len / 16;
116 sample_rate_half = (sample_rate + 1LL) / 2;
118 s->root = 2.0 / (sqrt(
s->frame_len) * 32768.0);
120 s->root =
s->frame_len / (sqrt(
s->frame_len) * 32768.0);
121 for (
i = 0;
i < 96;
i++) {
123 s->quant_table[
i] =
expf(
i * 0.15289164787221953823f) *
s->root;
127 for (
s->num_bands = 1;
s->num_bands < 25;
s->num_bands++)
133 for (
i = 1;
i <
s->num_bands;
i++)
135 s->bands[
s->num_bands] =
s->frame_len;
142 }
else if (CONFIG_BINKAUDIO_DCT_DECODER) {
143 float scale = 1.0 / (1 << frame_len_bits);
166 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
201 for (
i = 0;
i <
s->num_bands;
i++) {
224 j =
FFMIN(j,
s->frame_len);
228 memset(coeffs +
i, 0, (j -
i) *
sizeof(*coeffs));
230 while (
s->bands[k] <
i)
234 if (
s->bands[k] ==
i)
252 if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
254 s->tx_fn(
s->tx,
out[ch + ch_offset], coeffs,
sizeof(
float));
255 }
else if (CONFIG_BINKAUDIO_RDFT_DECODER) {
256 for (
int i = 2;
i <
s->frame_len;
i += 2)
259 coeffs[
s->frame_len + 0] = coeffs[1];
260 coeffs[
s->frame_len + 1] = coeffs[1] = 0;
271 out[ch + ch_offset][
i] = (
s->previous[ch + ch_offset][
i] * (count - j) +
272 out[ch + ch_offset][
i] * j) / count;
274 memcpy(
s->previous[ch + ch_offset], &
out[ch + ch_offset][
s->frame_len -
s->overlap_len],
275 s->overlap_len *
sizeof(*
s->previous[ch + ch_offset]));
303 new_pkt = !
s->pkt->data;
311 if (
s->pkt->size < 4) {
326 if (
s->ch_offset == 0) {
327 frame->nb_samples =
s->frame_len;
344 memset(gb, 0,
sizeof(*gb));
347 if (
s->ch_offset >=
s->channels) {
373 .p.name =
"binkaudio_rdft",
387 .p.name =
"binkaudio_dct",
static av_cold void decode_flush(AVCodecContext *avctx)
const FFCodec ff_binkaudio_rdft_decoder
const FFCodec ff_binkaudio_dct_decoder
static av_cold void close(AVCodecParserContext *s)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_cold void decode_flush(AVCodecContext *avctx)
static const uint8_t rle_length_tab[16]
#define BINK_BLOCK_MAX_SIZE
static av_cold int decode_init(AVCodecContext *avctx)
static av_cold int decode_end(AVCodecContext *avctx)
static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame)
static int decode_block(BinkAudioContext *s, float **out, int use_dct, int channels, int ch_offset)
Decode Bink Audio block.
static void get_bits_align32(GetBitContext *s)
static float get_float(GetBitContext *gb)
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
#define FF_CODEC_RECEIVE_FRAME_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
void(* flush)(AVBSFContext *ctx)
int(* init)(AVBSFContext *ctx)
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AV_CODEC_ID_BINKAUDIO_DCT
@ AV_CODEC_ID_BINKAUDIO_RDFT
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_NOPTS_VALUE
Undefined timestamp value.
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold int decode_init(AVCodecContext *avctx)
static av_cold int decode_end(AVCodecContext *avctx)
common internal api header.
Macro definitions for various function/variable attributes.
#define LOCAL_ALIGNED_32(t, v,...)
static float power(float r, float g, float b, float max)
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
const struct AVCodec * codec
int sample_rate
samples per second
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
struct AVCodecInternal * internal
Private context used for internal data.
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
float previous[MAX_DCT_CHANNELS][BINK_BLOCK_MAX_SIZE/16]
coeffs from previous audio block
int overlap_len
overlap size (samples)
int frame_len
transform size (samples)
int version_b
Bink version 'b'.
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FLOAT_RDFT
Real to complex and complex to real DFTs.
@ AV_TX_FLOAT_DCT
Real to real (DCT) transforms.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static const double coeff[2][5]
static const uint8_t quant[64]
const uint16_t ff_wma_critical_freqs[25]