35 #define BITSTREAM_READER_LE
44 #define MAX_CHANNELS 2
45 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
108 s->frame_len = 1 << frame_len_bits;
109 s->overlap_len =
s->frame_len / 16;
110 s->block_size = (
s->frame_len -
s->overlap_len) *
s->channels;
113 s->root = 2.0 / (sqrt(
s->frame_len) * 32768.0);
115 s->root =
s->frame_len / (sqrt(
s->frame_len) * 32768.0);
116 for (
i = 0;
i < 96;
i++) {
118 s->quant_table[
i] =
expf(
i * 0.15289164787221953823f) *
s->root;
122 for (
s->num_bands = 1;
s->num_bands < 25;
s->num_bands++)
128 for (
i = 1;
i <
s->num_bands;
i++)
130 s->bands[
s->num_bands] =
s->frame_len;
160 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
178 for (ch = 0; ch <
s->channels; ch++) {
195 for (
i = 0;
i <
s->num_bands;
i++) {
205 while (i < s->frame_len) {
218 j =
FFMIN(j,
s->frame_len);
222 memset(coeffs +
i, 0, (j -
i) *
sizeof(*coeffs));
224 while (
s->bands[k] <
i)
228 if (
s->bands[k] ==
i)
248 s->trans.dct.dct_calc(&
s->trans.dct, coeffs);
251 s->trans.rdft.rdft_calc(&
s->trans.rdft, coeffs);
254 for (ch = 0; ch <
s->channels; ch++) {
256 int count =
s->overlap_len *
s->channels;
259 for (
i = 0;
i <
s->overlap_len;
i++, j +=
s->channels)
260 out[ch][
i] = (
s->previous[ch][
i] * (count - j) +
261 out[ch][
i] * j) / count;
263 memcpy(
s->previous[ch], &
out[ch][
s->frame_len -
s->overlap_len],
264 s->overlap_len *
sizeof(*
s->previous[ch]));
302 if (
s->pkt->size < 4) {
328 memset(gb, 0,
sizeof(*gb));
341 .
name =
"binkaudio_rdft",
354 .
name =
"binkaudio_dct",
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static const uint8_t rle_length_tab[16]
static int decode_block(BinkAudioContext *s, float **out, int use_dct)
Decode Bink Audio block.
#define BINK_BLOCK_MAX_SIZE
AVCodec ff_binkaudio_rdft_decoder
AVCodec ff_binkaudio_dct_decoder
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 void get_bits_align32(GetBitContext *s)
static float get_float(GetBitContext *gb)
audio channel layout utility functions
#define CONFIG_BINKAUDIO_RDFT_DECODER
#define CONFIG_BINKAUDIO_DCT_DECODER
static CopyRet receive_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame)
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
av_cold void ff_dct_end(DCTContext *s)
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.
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_CH_LAYOUT_MONO
#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...
#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_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
#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
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
av_cold void ff_rdft_end(RDFTContext *s)
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
const struct AVCodec * codec
int sample_rate
samples per second
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
uint64_t channel_layout
Audio channel layout.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
union BinkAudioContext::@23 trans
int overlap_len
overlap size (samples)
int frame_len
transform size (samples)
int version_b
Bink version 'b'.
float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE/16]
coeffs from previous audio block
static const double coeff[2][5]
const uint16_t ff_wma_critical_freqs[25]